From afcd9e5397e3e1bde0392811d0482d76aac391dc Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Wed, 17 Jun 2015 11:14:34 +0530 Subject: add books --- .../screenshots/chapter5.png | Bin 0 -> 112741 bytes .../screenshots/chapter7.png | Bin 0 -> 84950 bytes .../screenshots/chapter_4.png | Bin 0 -> 129817 bytes .../CHAPTER4.ipynb | 220 ++ .../CHAPTER5.ipynb | 149 ++ .../CHAPTER6.ipynb | 391 ++++ .../CHAPTER7.ipynb | 185 ++ .../screenshots/chapter141.png | Bin 0 -> 23129 bytes .../screenshots/chapter142.png | Bin 0 -> 32548 bytes .../screenshots/chapter143.png | Bin 0 -> 25904 bytes .../screenshots/chapter14_1.png | Bin 0 -> 31008 bytes .../screenshots/chapter5_1.png | Bin 0 -> 30662 bytes .../screenshots/chapter9_1.png | Bin 0 -> 27119 bytes .../Chapter10.ipynb | 1094 +++++++++ .../Chapter10_1.ipynb | 1094 +++++++++ .../Chapter11.ipynb | 1098 +++++++++ .../Chapter11_1.ipynb | 1098 +++++++++ .../Chapter12.ipynb | 1236 ++++++++++ .../Chapter12_1.ipynb | 1236 ++++++++++ .../Chapter13.ipynb | 169 ++ .../Chapter13_1.ipynb | 169 ++ .../Chapter14.ipynb | 625 +++++ .../Chapter14_1.ipynb | 625 +++++ .../Chapter4.ipynb | 431 ++++ .../Chapter4_1.ipynb | 431 ++++ .../Chapter5.ipynb | 657 ++++++ .../Chapter5_1.ipynb | 657 ++++++ .../Chapter6.ipynb | 1304 +++++++++++ .../Chapter6_1.ipynb | 1304 +++++++++++ .../Chapter7.ipynb | 1655 +++++++++++++ .../Chapter7_1.ipynb | 1655 +++++++++++++ .../Chapter8.ipynb | 665 ++++++ .../Chapter8_1.ipynb | 665 ++++++ .../Chapter9.ipynb | 1638 +++++++++++++ .../Chapter9_1.ipynb | 1638 +++++++++++++ .../screenshots/Chapter1.png | Bin 0 -> 219422 bytes .../screenshots/Chapter2.png | Bin 0 -> 220642 bytes .../screenshots/Chapter3.png | Bin 0 -> 207957 bytes .../Chapter1.ipynb | 185 ++ .../Chapter10.ipynb | 473 ++++ .../Chapter11.ipynb | 595 +++++ .../Chapter12.ipynb | 109 + .../Chapter13.ipynb | 192 ++ .../Chapter14.ipynb | 185 ++ .../Chapter15.ipynb | 207 ++ .../Chapter16.ipynb | 338 +++ .../Chapter17.ipynb | 259 ++ .../Chapter2.ipynb | 430 ++++ .../Chapter3.ipynb | 238 ++ .../Chapter4.ipynb | 260 ++ .../Chapter5.ipynb | 423 ++++ .../Chapter6.ipynb | 589 +++++ .../Chapter7.ipynb | 548 +++++ .../Chapter8.ipynb | 309 +++ .../Chapter9.ipynb | 660 ++++++ Applied_Chemistry/screenshots/1.png | Bin 0 -> 75812 bytes Applied_Chemistry/screenshots/2.png | Bin 0 -> 120130 bytes Applied_Chemistry/screenshots/3.png | Bin 0 -> 101972 bytes .../Chapter_01_Water.ipynb | 2471 ++++++++++++++++++++ .../Chapter_03_Lubricants.ipynb | 843 +++++++ C++_By_Example/screenshots/Arrays.png | Bin 0 -> 32344 bytes C++_By_Example/screenshots/class.png | Bin 0 -> 43323 bytes C++_By_Example/screenshots/factorial.png | Bin 0 -> 31856 bytes C++_By_Example_by_Greg__M._Perry/Chapter1_1.ipynb | 733 ++++++ C++_By_Example_by_Greg__M._Perry/Chapter2_1.ipynb | 756 ++++++ C++_By_Example_by_Greg__M._Perry/Chapter3_1.ipynb | 1983 ++++++++++++++++ C++_By_Example_by_Greg__M._Perry/Chapter4_1.ipynb | 1073 +++++++++ C++_By_Example_by_Greg__M._Perry/Chapter5_1.ipynb | 184 ++ C++_By_Example_by_Greg__M._Perry/Chapter6_1.ipynb | 1457 ++++++++++++ C++_By_Example_by_Greg__M._Perry/Chapter7_1.ipynb | 1046 +++++++++ .../screenshots/Screenshot_(18).png | Bin 0 -> 40384 bytes .../screenshots/Screenshot_(19).png | Bin 0 -> 28732 bytes .../screenshots/Screenshot_(20).png | Bin 0 -> 40328 bytes .../Chapter_02_Fundamentals_of_C_language.ipynb | 1 + ..._03_Input_Output_Functions_and_Statements.ipynb | 1 + .../Chapter_04_Control_Statements_in_C.ipynb | 1 + .../Chapter_05_Loop_Control_Structures_In_C.ipynb | 1 + ...apter_06_Arrays_and_Subscripted_Variables.ipynb | 1 + .../Chapter_07_String_Manipulations_in_C.ipynb | 1 + .../Chapter_08_Functins_in_C.ipynb | 1 + .../Chapter_09_Structures_and_Unions.ipynb | 1 + .../Chapter_11_Files.ipynb | 1 + .../screenshots/Screenshot01.png | Bin 0 -> 97876 bytes .../screenshots/Screenshot02.png | Bin 0 -> 95379 bytes .../screenshots/Screenshot03.png | Bin 0 -> 106156 bytes .../chapter1.ipynb | 1596 +++++++++++++ .../chapter10.ipynb | 455 ++++ .../chapter11.ipynb | 170 ++ .../chapter2.ipynb | 567 +++++ .../chapter3.ipynb | 1548 ++++++++++++ .../chapter4.ipynb | 1219 ++++++++++ .../chapter5.ipynb | 653 ++++++ .../chapter6.ipynb | 545 +++++ .../chapter7.ipynb | 645 +++++ .../chapter8.ipynb | 435 ++++ .../chapter9.ipynb | 189 ++ .../screenshots/screen1.png | Bin 0 -> 71886 bytes .../screenshots/screen2.png | Bin 0 -> 90552 bytes .../screenshots/screen3.png | Bin 0 -> 74523 bytes .../Chapter_1.ipynb | 307 +++ .../Chapter_10.ipynb | 336 +++ .../Chapter_11.ipynb | 280 +++ .../Chapter_12.ipynb | 252 ++ .../Chapter_14.ipynb | 678 ++++++ .../Chapter_15.ipynb | 354 +++ .../Chapter_18.ipynb | 346 +++ .../Chapter_19.ipynb | 1129 +++++++++ .../Chapter_2.ipynb | 515 ++++ .../Chapter_21.ipynb | 296 +++ .../Chapter_3.ipynb | 978 ++++++++ .../Chapter_4.ipynb | 825 +++++++ .../Chapter_5.ipynb | 147 ++ .../Chapter_6.ipynb | 202 ++ .../Chapter_7.ipynb | 451 ++++ .../Chapter_8.ipynb | 271 +++ .../Chapter_9.ipynb | 312 +++ .../Chapter1.ipynb | 684 ++++++ .../Chapter10.ipynb | 627 +++++ .../Chapter11.ipynb | 613 +++++ .../Chapter12.ipynb | 351 +++ .../Chapter13.ipynb | 243 ++ .../Chapter15.ipynb | 71 + .../Chapter2.ipynb | 156 ++ .../Chapter3.ipynb | 1072 +++++++++ .../Chapter4.ipynb | 499 ++++ .../Chapter5.ipynb | 193 ++ .../Chapter6.ipynb | 267 +++ .../Chapter7.ipynb | 781 +++++++ .../Chapter8.ipynb | 669 ++++++ .../Chapter9.ipynb | 585 +++++ .../README.txt | 10 + Meachanics-DEMO/README.txt | 10 + Meachanics-DEMO/screenshots/screen2.png | Bin 0 -> 18650 bytes Meachanics-DEMO/screenshots/screen2_1.png | Bin 0 -> 18650 bytes Meachanics-DEMO/screenshots/screen2_2.png | Bin 0 -> 18650 bytes Meachanics-DEMO_by_Unknown/chapter1.ipynb | 423 ++++ Meachanics-DEMO_by_Unknown/chapter2.ipynb | 501 ++++ Non_Conventional_Energy_Resources/README.txt | 10 + .../screenshots/Channels_separation.png | Bin 0 -> 76946 bytes .../screenshots/Difraction_loss.png | Bin 0 -> 71190 bytes .../screenshots/Path_gain.png | Bin 0 -> 94865 bytes .../Chapter1.ipynb | 109 + .../Chapter2.ipynb | 436 ++++ .../Chapter3.ipynb | 769 ++++++ .../Chapter4.ipynb | 534 +++++ .../Chapter5.ipynb | 465 ++++ .../Chapter6.ipynb | 957 ++++++++ .../Chapter7.ipynb | 750 ++++++ sample_notebooks/Jaya Sravya/Chapter10.ipynb | 694 ++++++ sample_notebooks/KumarRaju/Chapter12.ipynb | 647 +++++ sample_notebooks/MohdAkhlak/ch3.ipynb | 256 ++ sample_notebooks/PradeepChoudari/Chapter01.ipynb | 326 +++ .../RajbeeVakkalagadda/Chapter04.ipynb | 476 ++++ sample_notebooks/ajinkyakhair/chapter2.ipynb | 240 ++ sample_notebooks/kartiksankhla/Chapter2.ipynb | 159 ++ .../samplebook(process_heat_transfer).ipynb | 278 +++ sample_notebooks/kumargugloth/Chapter1.ipynb | 348 +++ sample_notebooks/nemichand /Chapter1_1.ipynb | 227 ++ sample_notebooks/saikiranm/CHAPTER4.ipynb | 196 ++ .../saikomalchanagam/AKmaini_(1).ipynb | 293 +++ sample_notebooks/vinodkumar/Chapter1.ipynb | 339 +++ 161 files changed, 70609 insertions(+) create mode 100755 A_First_Course_on_Electrical_Drives/screenshots/chapter5.png create mode 100755 A_First_Course_on_Electrical_Drives/screenshots/chapter7.png create mode 100755 A_First_Course_on_Electrical_Drives/screenshots/chapter_4.png create mode 100755 A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER4.ipynb create mode 100755 A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER5.ipynb create mode 100755 A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER6.ipynb create mode 100755 A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER7.ipynb create mode 100755 A_First_course_in_Programming_with_C/screenshots/chapter141.png create mode 100755 A_First_course_in_Programming_with_C/screenshots/chapter142.png create mode 100755 A_First_course_in_Programming_with_C/screenshots/chapter143.png create mode 100755 A_First_course_in_Programming_with_C/screenshots/chapter14_1.png create mode 100755 A_First_course_in_Programming_with_C/screenshots/chapter5_1.png create mode 100755 A_First_course_in_Programming_with_C/screenshots/chapter9_1.png create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_1.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9.ipynb create mode 100755 A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_1.ipynb create mode 100755 Advanced_Mechanics_of_Materials/screenshots/Chapter1.png create mode 100755 Advanced_Mechanics_of_Materials/screenshots/Chapter2.png create mode 100755 Advanced_Mechanics_of_Materials/screenshots/Chapter3.png create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter1.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter10.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter11.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter12.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter13.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter14.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter15.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter16.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter17.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter2.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter3.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter4.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter5.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter6.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter7.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter8.ipynb create mode 100755 Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter9.ipynb create mode 100755 Applied_Chemistry/screenshots/1.png create mode 100755 Applied_Chemistry/screenshots/2.png create mode 100755 Applied_Chemistry/screenshots/3.png create mode 100755 Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_01_Water.ipynb create mode 100755 Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_03_Lubricants.ipynb create mode 100755 C++_By_Example/screenshots/Arrays.png create mode 100755 C++_By_Example/screenshots/class.png create mode 100755 C++_By_Example/screenshots/factorial.png create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter1_1.ipynb create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter2_1.ipynb create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter3_1.ipynb create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter4_1.ipynb create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter5_1.ipynb create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter6_1.ipynb create mode 100755 C++_By_Example_by_Greg__M._Perry/Chapter7_1.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(18).png create mode 100755 Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(19).png create mode 100755 Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(20).png create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions.ipynb create mode 100755 Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files.ipynb create mode 100755 Electronic_Devices_and_Circuits/screenshots/Screenshot01.png create mode 100755 Electronic_Devices_and_Circuits/screenshots/Screenshot02.png create mode 100755 Electronic_Devices_and_Circuits/screenshots/Screenshot03.png create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter1.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter10.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter11.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter2.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter3.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter4.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter5.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter6.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter7.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter8.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/chapter9.ipynb create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen1.png create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen2.png create mode 100755 Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen3.png create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_1.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_10.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_11.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_12.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_14.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_15.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_18.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_19.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_2.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_21.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_3.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_4.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_5.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_6.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_7.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_8.ipynb create mode 100755 Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_9.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter1.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter10.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter11.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter12.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter13.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter15.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter2.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter3.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter4.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter5.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter6.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter7.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter8.ipynb create mode 100755 Engineering_Physics_By_G_Vijayakumari/Chapter9.ipynb create mode 100755 Fundamental_Electrical_and_Electronic_Principles/README.txt create mode 100755 Meachanics-DEMO/README.txt create mode 100755 Meachanics-DEMO/screenshots/screen2.png create mode 100755 Meachanics-DEMO/screenshots/screen2_1.png create mode 100755 Meachanics-DEMO/screenshots/screen2_2.png create mode 100755 Meachanics-DEMO_by_Unknown/chapter1.ipynb create mode 100755 Meachanics-DEMO_by_Unknown/chapter2.ipynb create mode 100755 Non_Conventional_Energy_Resources/README.txt create mode 100755 Propagation_Engineering_in_Wireless_Communications/screenshots/Channels_separation.png create mode 100755 Propagation_Engineering_in_Wireless_Communications/screenshots/Difraction_loss.png create mode 100755 Propagation_Engineering_in_Wireless_Communications/screenshots/Path_gain.png create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1.ipynb create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2.ipynb create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3.ipynb create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4.ipynb create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5.ipynb create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6.ipynb create mode 100755 Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7.ipynb create mode 100755 sample_notebooks/Jaya Sravya/Chapter10.ipynb create mode 100755 sample_notebooks/KumarRaju/Chapter12.ipynb create mode 100755 sample_notebooks/MohdAkhlak/ch3.ipynb create mode 100755 sample_notebooks/PradeepChoudari/Chapter01.ipynb create mode 100755 sample_notebooks/RajbeeVakkalagadda/Chapter04.ipynb create mode 100755 sample_notebooks/ajinkyakhair/chapter2.ipynb create mode 100755 sample_notebooks/kartiksankhla/Chapter2.ipynb create mode 100755 sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer).ipynb create mode 100755 sample_notebooks/kumargugloth/Chapter1.ipynb create mode 100755 sample_notebooks/nemichand /Chapter1_1.ipynb create mode 100755 sample_notebooks/saikiranm/CHAPTER4.ipynb create mode 100755 sample_notebooks/saikomalchanagam/AKmaini_(1).ipynb create mode 100755 sample_notebooks/vinodkumar/Chapter1.ipynb diff --git a/A_First_Course_on_Electrical_Drives/screenshots/chapter5.png b/A_First_Course_on_Electrical_Drives/screenshots/chapter5.png new file mode 100755 index 00000000..b37a92b0 Binary files /dev/null and b/A_First_Course_on_Electrical_Drives/screenshots/chapter5.png differ diff --git a/A_First_Course_on_Electrical_Drives/screenshots/chapter7.png b/A_First_Course_on_Electrical_Drives/screenshots/chapter7.png new file mode 100755 index 00000000..e1ae64b1 Binary files /dev/null and b/A_First_Course_on_Electrical_Drives/screenshots/chapter7.png differ diff --git a/A_First_Course_on_Electrical_Drives/screenshots/chapter_4.png b/A_First_Course_on_Electrical_Drives/screenshots/chapter_4.png new file mode 100755 index 00000000..30790bbb Binary files /dev/null and b/A_First_Course_on_Electrical_Drives/screenshots/chapter_4.png differ diff --git a/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER4.ipynb b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER4.ipynb new file mode 100755 index 00000000..fe19aa3d --- /dev/null +++ b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER4.ipynb @@ -0,0 +1,220 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:1ba99fc29004084d876cd850f1fd3c2c655722555fcfd0cfeb46ce97813eed98" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 4 - Characteristics of AC motor" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.1 - PG NO.65" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.1, Page 65\n", + "import numpy\n", + "import math\n", + "l=([1, -3, 1])\n", + "a=numpy.asarray(l[0])\n", + "b=numpy.asarray(l[1])\n", + "c=numpy.asarray(l[2])\n", + "d = (b**2) - (4*a*c)\n", + "sol1 = (-b-math.sqrt(d))/(2*a)\n", + "sol2 = (-b+math.sqrt(d))/(2*a)\n", + "print('Part a')\n", + "print('roots of the equation when slip at max torque')\n", + "print'%.3f %s %.3f' %(sol1,'or',sol2)\n", + "\n", + "l1=([1, -1.719,0.146])\n", + "a1=numpy.asarray(l1[0])\n", + "b1=numpy.asarray(l1[1])\n", + "c1=numpy.asarray(l1[2])\n", + "d1 = (b1**2) - (4*a1*c1)\n", + "solution1 = (-b1-math.sqrt(d1))/(2*a1)\n", + "solution2 = (-b1+math.sqrt(d1))/(2*a1)\n", + "print('\\n')\n", + "print('Part b')\n", + "print('roots of the equation when slip at max load')\n", + "print'%.2f %s %.2f' %(solution1,'or',solution2)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part a\n", + "roots of the equation when slip at max torque\n", + "0.382 or 2.618\n", + "\n", + "\n", + "Part b\n", + "roots of the equation when slip at max load\n", + "0.09 or 1.63\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.3 - PG NO.70" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.3, Page 70\n", + "import numpy\n", + "import math\n", + "l=([0.04, -0.0266,.0016])\n", + "a=numpy.asarray(l[0])\n", + "b=numpy.asarray(l[1])\n", + "c=numpy.asarray(l[2])\n", + "d = (b**2.) - (4.*a*c)\n", + "sol1 = (-b-math.sqrt(d))/(2.*a)\n", + "sol2 = (-b+math.sqrt(d))/(2.*a)\n", + "print('Part a')\n", + "print('roots of the equation that slip will run is')\n", + "print'%.3f %s %.3f' %(sol1,'or',sol2)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part a\n", + "roots of the equation that slip will run is\n", + "0.067 or 0.598\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.5 - PG NO.74" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.5, page 74\n", + "import math\n", + "pole=24.\n", + "Ns=245.#in rpm\n", + "N=(120.*50.)/pole#synchronous speed in rpm\n", + "f=(N-Ns)/N\n", + "p=110.#in kw\n", + "T=(p*1000.*60.)/(2.*math.pi*Ns)\n", + "v1=440./math.sqrt(3)#in v\n", + "ws=(2*math.pi*250)/60\n", + "s=0.02\n", + "R=0.03125#in ohm\n", + "x=math.sqrt(((3*R*v1**2)/(T*ws*s))-(R/s)**2)#by rearranging formula\n", + "print'%s %.5f %s' %('Stator resistance per phase is=',x,'ohm')\n", + "#calculating original resistance\n", + "\n", + "#Example 4.1, Page 65\n", + "import numpy\n", + "import math\n", + "l=([3190,-3235,72.78])\n", + "a=numpy.asarray(l[0])\n", + "b=numpy.asarray(l[1])\n", + "c=numpy.asarray(l[2])\n", + "d = (b**2.) - (4.*a*c)\n", + "sol1 = (-b-math.sqrt(d))/(2.*a)\n", + "sol2 = (-b+math.sqrt(d))/(2.*a)\n", + "print('Part a')\n", + "print('The value of original resistance is')\n", + "print'%.4f %s %.5f' %(sol1,'or',sol2)\n", + "\n", + "#Taking r=0.99108\n", + "r=(0.99108-R)/1.25**2\n", + "\n", + "print'%s %.4f %s' %('The value of resistance to be added is =',r,' ohm')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Stator resistance per phase is= 0.50358 ohm\n", + "Part a\n", + "The value of original resistance is\n", + "0.0230 or 0.99109\n", + "The value of resistance to be added is = 0.6143 ohm\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.6 - PG NO.85" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.6, Page no 85\n", + "import math\n", + "print(\"Part ii\")\n", + "new_sin_delta=math.sin(math.pi/4)/.95\n", + "delta=math.asin(new_sin_delta)\n", + "x=math.degrees(delta)\n", + "print'%s %.2f %s' %('The value of delta is =',x,'degree')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part ii\n", + "The value of delta is = 48.10 degree\n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER5.ipynb b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER5.ipynb new file mode 100755 index 00000000..9c516a0f --- /dev/null +++ b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER5.ipynb @@ -0,0 +1,149 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:04cc3d88f86e793478d67491036a4036e88d0b6f1dc4a02713ba615d9d11fc6a" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 5 - Starting " + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 5.1 - PG NO.90" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#example 5.1, Page 90\n", + "import math\n", + "IL=(100*1000)/(math.sqrt(400*0.9*0.8*3))#Full load current\n", + "FS=(1000-950)/1000#Full load slip\n", + "x=[1,0.57736,0.7,0.333333333]\n", + "for i in range(0,4):\n", + "\tT=1.8*(x[i])**2\n", + "\tprint'%s %.6f %s %.3f' %('The value of Tst/Tf when x=',x[i],'is=',T)\n", + "#end\n", + "#the answers are more accurate due to approximations in program than textbook answers\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of Tst/Tf when x= 1.000000 is= 1.800\n", + "The value of Tst/Tf when x= 0.577360 is= 0.600\n", + "The value of Tst/Tf when x= 0.700000 is= 0.882\n", + "The value of Tst/Tf when x= 0.333333 is= 0.200\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 5.3 - PG NO.97" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 5.3, page 97\n", + "import math\n", + "s=.05#slip\n", + "x=1#ie x1+x2\n", + "s_max=((1-s**2)/(2*math.log(1/s)))**(1./2.)#max slip\n", + "#disp(s_max)\n", + "R2_opt=x*s_max\n", + "ws=(2*math.pi*1000)/60#angular frequency\n", + "v1=400/math.sqrt(3.)#voltage\n", + "j=10#angular V\n", + "Tmax=(3*v1**2)/(ws*2.*x)\n", + "Tmin=((j*ws)/(2.*Tmax))*(((1-s**2)/(2*R2_opt))+((R2_opt*math.log(1/s))))\n", + "print'%s %.3f %s' %('The value of T_min is =',Tmin,'sec ')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of T_min is = 1.676 sec \n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 5.4 - PG NO.102" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 5.4, Page no 102\n", + "import math\n", + "p=400*20*.88*math.sqrt(3)#input power in watt\n", + "l=12193.6-10000#in watt, full load loss\n", + "e=l*60#energy lost per minute\n", + "ws=(2*math.pi*1000)/60.#angular frequency\n", + "j=.5\n", + "R=1#resistance in ohm ir R1/R2\n", + "El=(0.5*j*ws**2)*(1+R)\n", + "#disp(El)\n", + "N=e/El\n", + "#disp(N)\n", + "print'%s %d' %(\"The number of starts that can be made is =\",N)\n", + "ws=(2*math.pi*1500)/60.#angular frequency\n", + "j=.5\n", + "R=1#resistance in ohm ir R1/R2\n", + "El=(0.5*j*ws**2.)*(1.+R)\n", + "#disp(El)\n", + "N=e/El\n", + "#disp(N)\n", + "print'%s %.2f %s' %(\"The number of permissible starts is =\",N,'say 10')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The number of starts that can be made is = 24\n", + "The number of permissible starts is = 10.67 say 10\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER6.ipynb b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER6.ipynb new file mode 100755 index 00000000..a434400f --- /dev/null +++ b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER6.ipynb @@ -0,0 +1,391 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:db271cf054287ba3955a22495e3d3573daeca2805ad6038b72c3632a873e8cb9" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 6 - Electric Braking " + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.1 - PG NO.114" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.1, page 114\n", + "import math\n", + "T=172.#in N-m\n", + "w=(2.*math.pi*960.)/60.\n", + "E=215.#in V\n", + "Ia=(T*w)/E\n", + "Ra=.062#in ohm\n", + "v=220.#in v\n", + "Eg=v+(Ia*Ra)\n", + "N=960.#in Rpm\n", + "S=(N*round(Eg))/E\n", + "print'%s %.2f %s' %(\"The speed of shunt machine is\",S,\"rpm \")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The speed of shunt machine is 1004.65 rpm \n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.2 - PG NO.114" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.2, page 114\n", + "import math\n", + "N=480.#in rpm\n", + "T=318.3#in N-m\n", + "P=(2.*math.pi*N*T)/60.\n", + "#From graph\n", + "E=333.3#in V\n", + "Ia=48.#Amp\n", + "R=E/Ia\n", + "#disp(R)\n", + "print'%s %.2f %s' %(\"The total resistance of circuit is =\",R,\"ohm\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The total resistance of circuit is = 6.94 ohm\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.3 - PG NO.116" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.3, Page 116\n", + "import math\n", + "per=.88\n", + "v=220.#in v\n", + "p=20.#in kw\n", + "I=(p*1000.)/(per*v)\n", + "T=(p*1000.*60.)/(2*math.pi*1200.)\n", + "#Part a\n", + "E_motor=v-(I*.1)\n", + "v_arm=v+E_motor\n", + "Ir=2.*I#Rated current\n", + "R=v_arm/Ir\n", + "print'%s %.2f %s' %('resistance at armature current=',R,'ohm')\n", + "R_Extra=R-.1\n", + "print'%s %.2f %s' %(\"\\n Extra resistance added to motor armature is =\",R_Extra,\" ohm \")\n", + "#Part b\n", + "T_Full_load=T*2\n", + "print'%s %.2f %s' %(\"\\n Full load torque is\",T_Full_load,\" N-m \\n\")\n", + "#Part c\n", + "E=(E_motor*400.)/1200.\n", + "print'%s %.2f %s' %('E=',E,'v')\n", + "I_braking=(v+E)/R\n", + "T_braking=(T/103.3)*I_braking\n", + "print'%s %.3f %s' %(\"\\n Braking current is =\",I_braking,\" A\")\n", + "print'%s %.3f %s' %(\"\\n Braking Torque is =\",T_braking,\" N-m \")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "resistance at armature current= 2.08 ohm\n", + "\n", + " Extra resistance added to motor armature is = 1.98 ohm \n", + "\n", + " Full load torque is 318.31 N-m \n", + "\n", + "E= 69.89 v\n", + "\n", + " Braking current is = 139.397 A\n", + "\n", + " Braking Torque is = 214.770 N-m \n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.4 - PG NO.124" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.4, page 124\n", + "import math\n", + "R1=.15#in ohm\n", + "Rs=.45#in ohm\n", + "x1=.6#in ohm\n", + "xz=1.8#in ohm\n", + "sf=0.05\n", + "Turn=1./math.sqrt(3.)\n", + "R_rotor=Rs*Turn#in ohm\n", + "X_rotor=xz*Turn**2.#in ohm\n", + "\n", + "#Part 1\n", + "#BY FIGURE\n", + "E1=math.sqrt((3.**2.+.6**2)/(3.15**2+1.2**2))*440./math.sqrt(3.)\n", + "s=1.-sf\n", + "I2=E1/math.sqrt(x1**2+2**2)\n", + "R2=2.*60.#ohm\n", + "w=2.*math.pi*600.\n", + "T=(R2*3.*(I2**2.))/(s*w)\n", + "print'%s %.3f %s' %(\"Initial braking torque of rheostatic is\",T,\"N-m\")\n", + "\n", + "#Part 2\n", + "s1=2.-sf\n", + "a=.15+(1.9/1.95)**2.\n", + "b=1.2**2.\n", + "I2=(440./math.sqrt(3.))*(1./math.sqrt(a+b))\n", + "T=(60.*1.9*3.*(I2**2.))/(1.95*w)\n", + "print('\\n')\n", + "print'%s %.3f %s' %(\"Initial braking torque during reverse is\",T,\" N-m\")\n", + "#the answers in textbook are less accurate due to approximations." + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.5 - PG NO.128" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.5, page no 128\n", + "import math\n", + "import cmath\n", + "Kva=3000./3.#kva per phase\n", + "v=2300./math.sqrt(3.)#voltage per phase\n", + "#disp(v)\n", + "i=(1000.*1000.)/1330.#current per phase\n", + "#disp(i)\n", + "s=i*.2\n", + "x=math.sqrt((v+s)**2.+(s**2.))\n", + "temp=((x/i)**2.)-2.**2.#temp=(.2+R)**2\n", + "#print(temp)\n", + "t=cmath.sqrt(temp)\n", + "temp1=t-(.2)\n", + "#disp(temp1)\n", + "#Answer difference is because of round off value of x\n", + "r=1.97#in ohms\n", + "T_br=(3.*i*i*r*60.)/(2*math.pi*200.)\n", + "print'%s %.2f %s' %(\"Initial braking torque is =\",T_br, \"N-m\")\n", + "#the answers in textbook are less accurate due to approximations." + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Initial braking torque is = 159523.84 N-m\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.6 - PG NO.131" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.6, Page 131\n", + "import math\n", + "pf=.85\n", + "N1=1500.#in rpm\n", + "N=1440.#in rpm\n", + "P=pf*230.*10.*math.sqrt(3.)\n", + "p_stator_loss=86.16#in w\n", + "p_rotor=P-p_stator_loss\n", + "rotor_copper_loss=((N1-N)/N1)*p_rotor\n", + "print'%s %.f %s' %(\"The rotor copper loss is =\",round(rotor_copper_loss),\"watt\")\n", + "inertia=.0486#in kg-m2\n", + "E=2*.96*inertia*((2*math.pi*50)/2)**2\n", + "print'%s %.f %s' %('total energy dissipiated in rotar during starting and braking',E,'J')\n", + "stops_starts=7920/E\n", + "print'%s %.2f %s' %(\"Total number of starts and stops is =\",stops_starts,\"say 3\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The rotor copper loss is = 132 watt\n", + "total energy dissipiated in rotar during starting and braking 2302 J\n", + "Total number of starts and stops is = 3.44 say 3\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.7 - PG NO.131" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.7, page 131\n", + "import math\n", + "v1=400/math.sqrt(3)#in v\n", + "ws=(2*math.pi*1000)/60#angular f\n", + "x=1#resistance in ohm\n", + "T_max=(3*v1**2)/(ws*2*x)\n", + "#print(T_max)\n", + "j=10#in kg-m2\n", + "s1=.05\n", + "s_maxT=0.2\n", + "a=(1.95**2-1)/(2*s_maxT)\n", + "temp=a+(.2*math.log(1.95))\n", + "r=((10*ws)/(2*T_max))*(temp)\n", + "#print(r)\n", + "Extra_R=r-(.2)\n", + "a=(1.95**2-1)/(2*1.45)\n", + "temp=a+(1.45*math.log(1.95))\n", + "t=((10*ws)/(2*T_max))*(temp)\n", + "#print(t)\n", + "print'%s %.3f %s' %(\"Minimum time to bring rotor to rest is \",t,\"sec\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Minimum time to bring rotor to rest is 1.326 sec\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 6.8 - PG NO.134" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 6.8, page 134\n", + "import math\n", + "#part a\n", + "w=(2.*math.pi*50.)/3.#angular f, rad/sec\n", + "k=6000./w\n", + "kw=6000.#n-m, initial brakin torque\n", + "Tf=300.#n-m, fictional torque\n", + "j=540.#kg-m2\n", + "tr=(j/k)*math.log((kw+Tf)/Tf)\n", + "#disp(tr)\n", + "s=math.e**((-k*tr)/j)\n", + "#disp(s)\n", + "temp=((j/k)*(kw+Tf)*(1.-s))-((Tf*tr))\n", + "Nr=(1./(2.*math.pi*k))*temp\n", + "#disp(Nr)\n", + "print'%s %.2f %s' %(\"Time taken for rheostatic braking is =\",Nr,\"s\")\n", + "#part b\n", + "beta=3600./j\n", + "motor_rest_time=w/6.67\n", + "#disp(motor_rest_time)\n", + "rev=(1000./60.)*.5*(motor_rest_time)\n", + "print'%s %.1f' %(\"Number of revolutions made is =\",rev)\n", + "#the answers in textbook are less accurate due to approximations." + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Time taken for rheostatic braking is = 133.17 s\n", + "Number of revolutions made is = 130.8\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER7.ipynb b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER7.ipynb new file mode 100755 index 00000000..f357767f --- /dev/null +++ b/A_First_Course_on_Electrical_Drives_by_S._K._Pillai/CHAPTER7.ipynb @@ -0,0 +1,185 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:b03229e77916ad783e59153e103e63631df4c4d4ccb9dc79e99256dcef4956a4" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 7- Rating and Heating Motors " + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 7.1 - PG NO.140" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 7.1, page 140\n", + "import math\n", + "G=500.#in kg\n", + "h=700.# in j/kg/c\n", + "s_lambda=math.pi*.7*1*12.5\n", + "h=(G*h)/s_lambda\n", + "#disp(h)\n", + "L=((10*1000.)/.9)-10000.\n", + "w=1111.\n", + "T=w/s_lambda\n", + "print'%s %.1f %s' %(\"Final tempearture rise is =\",T,\"degree C\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Final tempearture rise is = 40.4 degree C\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 7.3 - PG NO.155" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 7.3, page 155\n", + "import math\n", + "alpha=0.9\n", + "N=.5#in hr\n", + "tou=1.5#in hr\n", + "pr=25.#in kw\n", + "px=pr*math.sqrt(((1.+alpha)/(1.-math.exp(-N/tou)))-.9)\n", + "print'%s %.2f %s %s %d %s' %(\"Power is=\",px,\"kw\",'say',round(px),'kw')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Power is= 60.22 kw say 60 kw\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 7.4 - PG NO.157" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#example 7.4, page 157\n", + "import math\n", + "pr=100.#in kw\n", + "N=18.#in min\n", + "tou=90.#in min\n", + "R=30.#in min\n", + "tou_1=120.#in min\n", + "a=N/tou\n", + "b=R/tou_1\n", + "px=pr*math.sqrt((1-math.exp(-(a+b)))/(1-math.exp(-(a))))\n", + "print'%s %.1f %s %s %d %s' %(\"The power is =\",px,\"kw\",'say',round(px),'kw')\n", + "#answers in textbook are less accurate due to approximations" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The power is = 141.4 kw say 141 kw\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 7.5 - PG NO.161" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 7.5 , page 161\n", + "import math\n", + "Tr=(50.*1000.*60.)/(2.*math.pi*960.)\n", + "#print(Tr)\n", + "Tmax=2.*Tr\n", + "Tmin=300.#in nm\n", + "Tlh=1500.+Tmin\n", + "t=10.#in sec\n", + "ws=(2.*math.pi*1000.)/60.#angular f\n", + "wr=(2.*math.pi*960.)/60.#angular f\n", + "temp=math.log((Tlh-Tmin)/(Tlh-Tmax))\n", + "j=(Tr/(ws-wr))*(t/temp)\n", + "#disp(j)\n", + "r=.9#in m\n", + "wt=j/r**2\n", + "#disp(wt)\n", + "print'%s %.2f %s' %(\"Weight of fly wheel is=\",wt,\"kg\")\n", + "#Part b\n", + "Tmax=994.72\n", + "Tmin=700\n", + "TL1=300\n", + "temp=math.log((Tmax-TL1)/(Tmin-TL1))\n", + "t=(j*temp*(ws-wr))/Tr\n", + "print'%s %.2f %s' %(\"The estimated time is =\",t,\"s\")\n", + "#question number in textbook is printed wrong i.e 7.5 is printed as 5.7\n", + "#answer in textbook is wrong due to approximations\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Weight of fly wheel is= 2356.60 kg\n", + "The estimated time is = 8.87 s\n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter141.png b/A_First_course_in_Programming_with_C/screenshots/chapter141.png new file mode 100755 index 00000000..6648b8b8 Binary files /dev/null and b/A_First_course_in_Programming_with_C/screenshots/chapter141.png differ diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter142.png b/A_First_course_in_Programming_with_C/screenshots/chapter142.png new file mode 100755 index 00000000..87e3450d Binary files /dev/null and b/A_First_course_in_Programming_with_C/screenshots/chapter142.png differ diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter143.png b/A_First_course_in_Programming_with_C/screenshots/chapter143.png new file mode 100755 index 00000000..6a0bc31a Binary files /dev/null and b/A_First_course_in_Programming_with_C/screenshots/chapter143.png differ diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter14_1.png b/A_First_course_in_Programming_with_C/screenshots/chapter14_1.png new file mode 100755 index 00000000..b3709cd3 Binary files /dev/null and b/A_First_course_in_Programming_with_C/screenshots/chapter14_1.png differ diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter5_1.png b/A_First_course_in_Programming_with_C/screenshots/chapter5_1.png new file mode 100755 index 00000000..9286810e Binary files /dev/null and b/A_First_course_in_Programming_with_C/screenshots/chapter5_1.png differ diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter9_1.png b/A_First_course_in_Programming_with_C/screenshots/chapter9_1.png new file mode 100755 index 00000000..8ea89675 Binary files /dev/null and b/A_First_course_in_Programming_with_C/screenshots/chapter9_1.png differ diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10.ipynb new file mode 100755 index 00000000..6bb23256 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10.ipynb @@ -0,0 +1,1094 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter 10: Structures and Unions

" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 1, Page number: SAU - 5

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#student structure\n", + "\n", + "import sys\n", + "\n", + "class student:\n", + " rno = 0\n", + " sname = \"\"\n", + " tot = 0 \n", + " \n", + "x = student()\n", + "\n", + "x.rno = int(raw_input(\"\\nEnter roll number, name and total marks\"))\n", + "x.sname = raw_input(\"\")\n", + "x.tot = int(raw_input(\"\"))\n", + "\n", + "sys.stdout.write(\"\\n\\tDetails entered are \\n\")\n", + "sys.stdout.write(\"\\nRoll No. : %d\"%(x.rno))\n", + "sys.stdout.write(\"\\nStudent Name : %s\"%(x.sname))\n", + "sys.stdout.write(\"\\nTotal marks : %d\"%(x.tot))\n", + "sys.stdout.write(\"\\n\\nPress any key to continue...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter roll number, name and total marks20147\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "PRADEEP\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "64\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\tDetails entered are \n", + "\n", + "Roll No. : 20147\n", + "Student Name : PRADEEP\n", + "Total marks : 64\n", + "\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 2, Page number: SAU - 6

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class student:\n", + " rno = 0 \n", + " sname = \"\"\n", + " tot = 0\n", + " \n", + "ch = 'y'\n", + "std = [student() for i in range(0,50)]\n", + "\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "for 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", + " \n", + "while 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.\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 20201\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ARUN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 78\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 20208\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 69\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 20223\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? SUSMITHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 88\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter student roll number to display marks : 20208\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Marks obtained by 20208 DEEPAK\n", + "Total : 69" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "press y - to continue \n", + " any other key to stop.N\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 3, Page number: SAU - 8

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class student:\n", + " rno = 0 \n", + " sname = \"\"\n", + " tot = 0\n", + " \n", + "std = [student() for i in range(0,50)]\n", + "\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "for 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", + " \n", + "print \"\\n-------------------------------------------------------\"\n", + "print \"\\n Roll No. Name Total Marks\"\n", + "print \"\\n-------------------------------------------------------\"\n", + "\n", + "for 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", + " \n", + "print \"\\n-------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30401\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ANAND\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 59\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30404\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? NIRMAL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 64\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30428\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ISWARYA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 82\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30432\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? VIVEKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 79\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "-------------------------------------------------------\n", + "\n", + " Roll No. Name Total Marks\n", + "\n", + "-------------------------------------------------------\n", + "\n", + " 30428 ISWARYA 82\n", + " 30432 VIVEKA 79\n", + "-------------------------------------------------------\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 4, Page number: SAU - 10

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class employee:\n", + " eno = 0\n", + " ename = \"\"\n", + " epay = 0\n", + " jdate = \"\"\n", + " \n", + "def 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", + " \n", + "employs = [employee() for i in range(0,25)]\n", + "i = 0\n", + "ch = 'y'\n", + "\n", + "while 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", + " \n", + "n = i\n", + "sys.stdout.write(\"\\n\\n%d records are entered\"%(n))\n", + "sys.stdout.write(\"\\nPress any key to print the revised salary list\")\n", + "\n", + "for i in range(0,n):\n", + " employs[i].epay = revise(employs[i].epay)\n", + " \n", + "print \"\\n Employees Revised Pay List\"\n", + "print \"\\n----------------------------------------------------------------------------------\"\n", + "print \"\\n S.No Number Name Joinint date Pay\"\n", + "print \"\\n----------------------------------------------------------------------------------\"\n", + "\n", + "for 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", + " \n", + "print \"\\n----------------------------------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee No.? 20101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ASHIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Existing pay? 1000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Joining Date ? 31/04/2001\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to continue any other key to stop.Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee No.? 20182\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ASHWIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Existing pay? 6000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Joining Date ? 11/12/1995\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to continue any other key to stop.Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee No.? 20204\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? PRAVEEN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Existing pay? 3000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Joining Date ? 18/06/1994\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to continue any other key to stop.N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "3 records are entered\n", + "Press 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" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 5, Page number: SAU - 13

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class cricket:\n", + " pname = \"\"\n", + " tname = \"\"\n", + " bavg = 0\n", + " \n", + "probable = [cricket() for i in range(0,30)]\n", + "\n", + "n = int(raw_input(\"\\nHow many players ? \"))\n", + "\n", + "for 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", + " \n", + "j = 0\n", + "teams = ['' for i in range(0,20)]\n", + "\n", + "teams[j] = probable[0].tname\n", + "j += 1\n", + "i = 1\n", + "\n", + "for 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", + "\n", + "for 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-------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many players ? 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? KUMBLE\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? KARNATAKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 22\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? KAMBLI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? MUMBAI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 39\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? SRIKANTH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? TAMILNADU\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? SACHIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? MUMBAI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 69\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? RAHUL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? KARNATAKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 57\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? RAMESH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? TAMILNADU\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 48\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 6, Page number: SAU - 19

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class student:\n", + " roll_no = 0\n", + " sname = \"\"\n", + " marks = 0 \n", + " \n", + "std = [student() for i in range(0,10)]\n", + "\n", + "print \"\\n-----------------------------------------------------------------------\"\n", + "print \"\\n Main Menu\"\n", + "print \"\\n-----------------------------------------------------------------------\"\n", + "print \"\\nPress 1 to enter roll numbers\"\n", + "print \"\\n 2 to enter names\"\n", + "print \"\\n 3 to enter marks\"\n", + "print \"\\n 4 to stop\"\n", + "ch = int(raw_input(\"\\nEnter your choice : \"))\n", + "if 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-------------------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "-----------------------------------------------------------------------\n", + "\n", + " Main Menu\n", + "\n", + "-----------------------------------------------------------------------\n", + "\n", + "Press 1 to enter roll numbers\n", + "\n", + " 2 to enter names\n", + "\n", + " 3 to enter marks\n", + "\n", + " 4 to stop\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter your choice : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "How many students ? 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? AJITH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? RAJU\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? VIGNESH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? DIVYA\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "-------------------------------------------------------------------\n", + "\n", + " Students name list\n", + "\n", + "-------------------------------------------------------------------\n", + "\n", + "\tAJITH\n", + "\tRAJU\n", + "\tVIGNESH\n", + "\tDIVYA\n", + "-------------------------------------------------------------------\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_1.ipynb new file mode 100755 index 00000000..6bb23256 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_1.ipynb @@ -0,0 +1,1094 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter 10: Structures and Unions

" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 1, Page number: SAU - 5

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#student structure\n", + "\n", + "import sys\n", + "\n", + "class student:\n", + " rno = 0\n", + " sname = \"\"\n", + " tot = 0 \n", + " \n", + "x = student()\n", + "\n", + "x.rno = int(raw_input(\"\\nEnter roll number, name and total marks\"))\n", + "x.sname = raw_input(\"\")\n", + "x.tot = int(raw_input(\"\"))\n", + "\n", + "sys.stdout.write(\"\\n\\tDetails entered are \\n\")\n", + "sys.stdout.write(\"\\nRoll No. : %d\"%(x.rno))\n", + "sys.stdout.write(\"\\nStudent Name : %s\"%(x.sname))\n", + "sys.stdout.write(\"\\nTotal marks : %d\"%(x.tot))\n", + "sys.stdout.write(\"\\n\\nPress any key to continue...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter roll number, name and total marks20147\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "PRADEEP\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "64\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\tDetails entered are \n", + "\n", + "Roll No. : 20147\n", + "Student Name : PRADEEP\n", + "Total marks : 64\n", + "\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 2, Page number: SAU - 6

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class student:\n", + " rno = 0 \n", + " sname = \"\"\n", + " tot = 0\n", + " \n", + "ch = 'y'\n", + "std = [student() for i in range(0,50)]\n", + "\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "for 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", + " \n", + "while 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.\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 20201\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ARUN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 78\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 20208\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 69\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 20223\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? SUSMITHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 88\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter student roll number to display marks : 20208\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Marks obtained by 20208 DEEPAK\n", + "Total : 69" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "press y - to continue \n", + " any other key to stop.N\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 3, Page number: SAU - 8

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class student:\n", + " rno = 0 \n", + " sname = \"\"\n", + " tot = 0\n", + " \n", + "std = [student() for i in range(0,50)]\n", + "\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "for 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", + " \n", + "print \"\\n-------------------------------------------------------\"\n", + "print \"\\n Roll No. Name Total Marks\"\n", + "print \"\\n-------------------------------------------------------\"\n", + "\n", + "for 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", + " \n", + "print \"\\n-------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30401\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ANAND\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 59\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30404\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? NIRMAL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 64\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30428\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ISWARYA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 82\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Roll Number ? 30432\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? VIVEKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks ? 79\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "-------------------------------------------------------\n", + "\n", + " Roll No. Name Total Marks\n", + "\n", + "-------------------------------------------------------\n", + "\n", + " 30428 ISWARYA 82\n", + " 30432 VIVEKA 79\n", + "-------------------------------------------------------\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 4, Page number: SAU - 10

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class employee:\n", + " eno = 0\n", + " ename = \"\"\n", + " epay = 0\n", + " jdate = \"\"\n", + " \n", + "def 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", + " \n", + "employs = [employee() for i in range(0,25)]\n", + "i = 0\n", + "ch = 'y'\n", + "\n", + "while 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", + " \n", + "n = i\n", + "sys.stdout.write(\"\\n\\n%d records are entered\"%(n))\n", + "sys.stdout.write(\"\\nPress any key to print the revised salary list\")\n", + "\n", + "for i in range(0,n):\n", + " employs[i].epay = revise(employs[i].epay)\n", + " \n", + "print \"\\n Employees Revised Pay List\"\n", + "print \"\\n----------------------------------------------------------------------------------\"\n", + "print \"\\n S.No Number Name Joinint date Pay\"\n", + "print \"\\n----------------------------------------------------------------------------------\"\n", + "\n", + "for 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", + " \n", + "print \"\\n----------------------------------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee No.? 20101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ASHIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Existing pay? 1000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Joining Date ? 31/04/2001\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to continue any other key to stop.Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee No.? 20182\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? ASHWIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Existing pay? 6000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Joining Date ? 11/12/1995\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to continue any other key to stop.Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee No.? 20204\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Name ? PRAVEEN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Existing pay? 3000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Joining Date ? 18/06/1994\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to continue any other key to stop.N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "3 records are entered\n", + "Press 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" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 5, Page number: SAU - 13

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class cricket:\n", + " pname = \"\"\n", + " tname = \"\"\n", + " bavg = 0\n", + " \n", + "probable = [cricket() for i in range(0,30)]\n", + "\n", + "n = int(raw_input(\"\\nHow many players ? \"))\n", + "\n", + "for 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", + " \n", + "j = 0\n", + "teams = ['' for i in range(0,20)]\n", + "\n", + "teams[j] = probable[0].tname\n", + "j += 1\n", + "i = 1\n", + "\n", + "for 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", + "\n", + "for 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-------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many players ? 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? KUMBLE\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? KARNATAKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 22\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? KAMBLI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? MUMBAI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 39\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? SRIKANTH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? TAMILNADU\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? SACHIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? MUMBAI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 69\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? RAHUL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? KARNATAKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 57\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Player name ? RAMESH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Which team ? TAMILNADU\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Batting average ? 48\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 6, Page number: SAU - 19

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "class student:\n", + " roll_no = 0\n", + " sname = \"\"\n", + " marks = 0 \n", + " \n", + "std = [student() for i in range(0,10)]\n", + "\n", + "print \"\\n-----------------------------------------------------------------------\"\n", + "print \"\\n Main Menu\"\n", + "print \"\\n-----------------------------------------------------------------------\"\n", + "print \"\\nPress 1 to enter roll numbers\"\n", + "print \"\\n 2 to enter names\"\n", + "print \"\\n 3 to enter marks\"\n", + "print \"\\n 4 to stop\"\n", + "ch = int(raw_input(\"\\nEnter your choice : \"))\n", + "if 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-------------------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "-----------------------------------------------------------------------\n", + "\n", + " Main Menu\n", + "\n", + "-----------------------------------------------------------------------\n", + "\n", + "Press 1 to enter roll numbers\n", + "\n", + " 2 to enter names\n", + "\n", + " 3 to enter marks\n", + "\n", + " 4 to stop\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter your choice : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "How many students ? 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? AJITH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? RAJU\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? VIGNESH\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student name ? DIVYA\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "-------------------------------------------------------------------\n", + "\n", + " Students name list\n", + "\n", + "-------------------------------------------------------------------\n", + "\n", + "\tAJITH\n", + "\tRAJU\n", + "\tVIGNESH\n", + "\tDIVYA\n", + "-------------------------------------------------------------------\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11.ipynb new file mode 100755 index 00000000..b51ed5ad --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11.ipynb @@ -0,0 +1,1098 @@ +{ + "metadata": { + "name": "" + }, + "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 1, Page Number : PTR-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "xptr = id(a)\n", + "yptr = id(b)\n", + "\n", + "#There is no pointer concept in python\n", + "s = a + b\n", + "\n", + "print \"\\nSum = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum = 8\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : PTR-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "xptr = id(a)\n", + "yptr = id(b)\n", + "\n", + "#There is no pointer concept in python\n", + "if a > b:\n", + " big = a\n", + "else:\n", + " big = b\n", + " \n", + "print \"\\nBiggest number is \",big" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 25\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : PTR-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + " \n", + "a = 25\n", + "b = 10\n", + "\n", + "print \"\\nBefore function call a = \",a,\" b = \",b\n", + "a,b = add10(a,b)\n", + "print \"\\nAfter function call a = \",a,\" b = \",b" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Before function call a = 25 b = 10\n", + "\n", + "\n", + "Inside the function a = 35 b = 20\n", + "\n", + "After function call a = 35 b = 20\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : PTR-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "print \"\\nBefore function call a = \",a,\" b = \",b\n", + "\n", + "a,b = swap(a,b)\n", + "\n", + "print \"\\n\\nAfter function call, values are exchanged as \\n a = \",a,\" b = \",b" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "500\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Before function call a = 25 b = 500\n", + "\n", + "\n", + "After function call, values are exchanged as \n", + " a = 500 b = 25\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : PTR-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = [0.0 for i in range(0,10)]\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "\n", + "print \"\\nEnter all values in the list\\n\"\n", + "\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + "\n", + "sum1 = 0.0\n", + "#Since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + " #There is no pointer concept in python\n", + " \n", + "mean = sum1/n\n", + "\n", + "sys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(mean))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.48\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.54\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.26\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2.98\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Arithmetic mean = 3.315" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : PTR-19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "xp = [0 for i in range(0,10)]\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "\n", + "#There is no pointer concept in python\n", + "print \"\\nEnter all values\\n\"\n", + "\n", + "for i in range(0,n):\n", + " xp[i] = int(raw_input(\"\"))\n", + "\n", + "print \"\\nThe reversed list is\\n\"\n", + "for i in range(n-1,0-1,-1):\n", + " sys.stdout.write(\"%6d\"%(xp[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "11\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "14\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "16\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The reversed list is\n", + "\n", + " 16 15 14 13 12 11" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : PTR-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "a = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "b = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "\n", + "c = [[0 for i in range(0,5)]for i in range(0,5)]\n", + "m = int(raw_input(\"\\nFor A matrix \\nHow many rows and columns ? \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "print \"\\nEnter A matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + " \n", + "n = int(raw_input(\"\\nFor B matrix\\nHow many rows and columns ? \"))\n", + "l = int(raw_input(\"\"))\n", + "\n", + "for i in range(0,n):\n", + " for j in range(0,l):\n", + " b[i][j] = int(raw_input(\"\"))\n", + "\n", + "for 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", + " \n", + "print \"\\nResultant matrix is \\n\"\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "For A matrix \n", + "How many rows and columns ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix values\n", + "\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": [ + "0\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": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "For B matrix\n", + "How many rows and columns ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + "\n", + " 26 9 5\n", + " 4 -28 18\n", + " 18 19 -3\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : PTR-24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "count = 0\n", + "\n", + "st = raw_input(\"\\nEnter a string : \")\n", + "sptr = st\n", + "i = 0\n", + "\n", + "while 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", + " \n", + "print \"\\nNumber of vowels = \",count" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : GOOD LUCK to all\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Number of vowels = 5\n" + ] + } + ], + "prompt_number": 32 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : PTR-25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "n = int(raw_input(\"\\nHow many names ?\"))\n", + "\n", + "snames = [\"\" for i in range(0,10)]\n", + "\n", + "print \"\\nEnter all names \\n\"\n", + "for i in range(0,n):\n", + " snames[i] = raw_input(\"\")\n", + " \n", + "sort_names(snames,n)\n", + "\n", + "print \"\\nThe name list in alphabetical order\"\n", + "for i in range(0,n):\n", + " print snames[i]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many names ?4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all names \n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SHERIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SONIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "ARUN\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The name list in alphabetical order\n", + "ARUN\n", + "DEEPAK\n", + "SHERIN\n", + "SONIKA\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : PTR-27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"\\nEnter a string : \"\n", + "st = raw_input(\"\")\n", + "rst = ['' for i in range(0,80)]\n", + "\n", + "rst = st[::-1]\n", + " \n", + "if st == rst:\n", + " print st,\" is a palindrome string\"\n", + "else:\n", + " print st,\" is not a palindrome string\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "LIRIL\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "LIRIL is a palindrome string\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : PTR-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"\\nEnter a string : \"\n", + "st = raw_input(\"\")\n", + "\n", + "#There is no pointer concept in python\n", + "city = st\n", + "\n", + "print \"\\nThe copied string : \",city" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "NEW DELHI\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The copied string : NEW DELHI\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : PTR-30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#class is used instead of structure in python\n", + "\n", + "class student():\n", + " rno = 0\n", + " sname = ''\n", + " tot = 0\n", + "\n", + "sptr = student()\n", + "sptr.rno = int(raw_input(\"\\nEnter register No.:\"))\n", + "sptr.sname = raw_input(\"\\nEnter student name : \")\n", + "sptr.tot = int(raw_input(\"\\nEnter total marks : \"))\n", + "\n", + "print \"\\n\\tDetails entered are \\n\"\n", + "print \"\\nReg.No, : \",sptr.rno\n", + "print \"\\nName : \",sptr.sname\n", + "print \"\\nTotal : \",sptr.tot\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter register No.:101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter student name : Ashwin\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter total marks : 89\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\tDetails entered are \n", + "\n", + "\n", + "Reg.No, : 101\n", + "\n", + "Name : Ashwin\n", + "\n", + "Total : 89\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : PTR-32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#There is no pointer concept in python\n", + "def add(x,y):\n", + " return x+y\n", + "\n", + "def multiply(x,y):\n", + " return x*y\n", + "\n", + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "sum1 = add(a,b)\n", + "\n", + "print \"Sum a + b = \",sum1\n", + "\n", + "product = multiply(a,b)\n", + "print \"\\nProduct a * b = \",product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sum a + b = 8\n", + "\n", + "Product a * b = 15\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_1.ipynb new file mode 100755 index 00000000..b51ed5ad --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_1.ipynb @@ -0,0 +1,1098 @@ +{ + "metadata": { + "name": "" + }, + "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 1, Page Number : PTR-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "xptr = id(a)\n", + "yptr = id(b)\n", + "\n", + "#There is no pointer concept in python\n", + "s = a + b\n", + "\n", + "print \"\\nSum = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum = 8\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : PTR-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "xptr = id(a)\n", + "yptr = id(b)\n", + "\n", + "#There is no pointer concept in python\n", + "if a > b:\n", + " big = a\n", + "else:\n", + " big = b\n", + " \n", + "print \"\\nBiggest number is \",big" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 25\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : PTR-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + " \n", + "a = 25\n", + "b = 10\n", + "\n", + "print \"\\nBefore function call a = \",a,\" b = \",b\n", + "a,b = add10(a,b)\n", + "print \"\\nAfter function call a = \",a,\" b = \",b" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Before function call a = 25 b = 10\n", + "\n", + "\n", + "Inside the function a = 35 b = 20\n", + "\n", + "After function call a = 35 b = 20\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : PTR-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "print \"\\nBefore function call a = \",a,\" b = \",b\n", + "\n", + "a,b = swap(a,b)\n", + "\n", + "print \"\\n\\nAfter function call, values are exchanged as \\n a = \",a,\" b = \",b" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "500\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Before function call a = 25 b = 500\n", + "\n", + "\n", + "After function call, values are exchanged as \n", + " a = 500 b = 25\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : PTR-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = [0.0 for i in range(0,10)]\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "\n", + "print \"\\nEnter all values in the list\\n\"\n", + "\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + "\n", + "sum1 = 0.0\n", + "#Since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + " #There is no pointer concept in python\n", + " \n", + "mean = sum1/n\n", + "\n", + "sys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(mean))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.48\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.54\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.26\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2.98\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Arithmetic mean = 3.315" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : PTR-19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "xp = [0 for i in range(0,10)]\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "\n", + "#There is no pointer concept in python\n", + "print \"\\nEnter all values\\n\"\n", + "\n", + "for i in range(0,n):\n", + " xp[i] = int(raw_input(\"\"))\n", + "\n", + "print \"\\nThe reversed list is\\n\"\n", + "for i in range(n-1,0-1,-1):\n", + " sys.stdout.write(\"%6d\"%(xp[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "11\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "14\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "16\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The reversed list is\n", + "\n", + " 16 15 14 13 12 11" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : PTR-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "a = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "b = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "\n", + "c = [[0 for i in range(0,5)]for i in range(0,5)]\n", + "m = int(raw_input(\"\\nFor A matrix \\nHow many rows and columns ? \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "print \"\\nEnter A matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + " \n", + "n = int(raw_input(\"\\nFor B matrix\\nHow many rows and columns ? \"))\n", + "l = int(raw_input(\"\"))\n", + "\n", + "for i in range(0,n):\n", + " for j in range(0,l):\n", + " b[i][j] = int(raw_input(\"\"))\n", + "\n", + "for 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", + " \n", + "print \"\\nResultant matrix is \\n\"\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "For A matrix \n", + "How many rows and columns ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix values\n", + "\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": [ + "0\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": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "For B matrix\n", + "How many rows and columns ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + "\n", + " 26 9 5\n", + " 4 -28 18\n", + " 18 19 -3\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : PTR-24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "count = 0\n", + "\n", + "st = raw_input(\"\\nEnter a string : \")\n", + "sptr = st\n", + "i = 0\n", + "\n", + "while 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", + " \n", + "print \"\\nNumber of vowels = \",count" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : GOOD LUCK to all\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Number of vowels = 5\n" + ] + } + ], + "prompt_number": 32 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : PTR-25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "n = int(raw_input(\"\\nHow many names ?\"))\n", + "\n", + "snames = [\"\" for i in range(0,10)]\n", + "\n", + "print \"\\nEnter all names \\n\"\n", + "for i in range(0,n):\n", + " snames[i] = raw_input(\"\")\n", + " \n", + "sort_names(snames,n)\n", + "\n", + "print \"\\nThe name list in alphabetical order\"\n", + "for i in range(0,n):\n", + " print snames[i]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many names ?4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all names \n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SHERIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SONIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "ARUN\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The name list in alphabetical order\n", + "ARUN\n", + "DEEPAK\n", + "SHERIN\n", + "SONIKA\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : PTR-27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"\\nEnter a string : \"\n", + "st = raw_input(\"\")\n", + "rst = ['' for i in range(0,80)]\n", + "\n", + "rst = st[::-1]\n", + " \n", + "if st == rst:\n", + " print st,\" is a palindrome string\"\n", + "else:\n", + " print st,\" is not a palindrome string\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "LIRIL\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "LIRIL is a palindrome string\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : PTR-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"\\nEnter a string : \"\n", + "st = raw_input(\"\")\n", + "\n", + "#There is no pointer concept in python\n", + "city = st\n", + "\n", + "print \"\\nThe copied string : \",city" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "NEW DELHI\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The copied string : NEW DELHI\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : PTR-30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#class is used instead of structure in python\n", + "\n", + "class student():\n", + " rno = 0\n", + " sname = ''\n", + " tot = 0\n", + "\n", + "sptr = student()\n", + "sptr.rno = int(raw_input(\"\\nEnter register No.:\"))\n", + "sptr.sname = raw_input(\"\\nEnter student name : \")\n", + "sptr.tot = int(raw_input(\"\\nEnter total marks : \"))\n", + "\n", + "print \"\\n\\tDetails entered are \\n\"\n", + "print \"\\nReg.No, : \",sptr.rno\n", + "print \"\\nName : \",sptr.sname\n", + "print \"\\nTotal : \",sptr.tot\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter register No.:101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter student name : Ashwin\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter total marks : 89\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\tDetails entered are \n", + "\n", + "\n", + "Reg.No, : 101\n", + "\n", + "Name : Ashwin\n", + "\n", + "Total : 89\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : PTR-32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#There is no pointer concept in python\n", + "def add(x,y):\n", + " return x+y\n", + "\n", + "def multiply(x,y):\n", + " return x*y\n", + "\n", + "a = int(raw_input(\"\\nEnter two integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "sum1 = add(a,b)\n", + "\n", + "print \"Sum a + b = \",sum1\n", + "\n", + "product = multiply(a,b)\n", + "print \"\\nProduct a * b = \",product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sum a + b = 8\n", + "\n", + "Product a * b = 15\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12.ipynb new file mode 100755 index 00000000..1f9a4a84 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12.ipynb @@ -0,0 +1,1236 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 12: Files" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : FLS-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "fp = open(\"SAMPLE.TXT\",\"w\")\n", + "\n", + "print \"\\nType the text press enter key at end.\\n\\n\"\n", + "\n", + "ch = raw_input(\"\")\n", + "fp.write(ch)\n", + "\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Type the text press enter key at end.\n", + "\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Computer 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 : FLS-8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "count = 0 \n", + "\n", + "fp = open(\"SAMPLE.TXT\",\"r\")\n", + "\n", + "print \"\\nThe content of the text file is : \\n\\n\"\n", + "\n", + "ch = fp.read()\n", + "\n", + "for 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", + " \n", + "print \"\\nNumber of vowels present = \",count\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The content of the text file is : \n", + "\n", + "\n", + "Computer Programming in C language is widely used for Science and Engineering applications.\n", + "Number of vowels present = 31\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : FLS-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "fp = open(\"STUDENT.DAT\",\"w\")\n", + "\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "for 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", + " \n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "ARUN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "78\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 102\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "72\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 103\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SUSHMITHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "86\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : FLS-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "fptr = open(\"STUDENT.DAT\",\"r\")\n", + "\n", + "print \"\\n--------------------------------------------------------\"\n", + "print \"\\n Roll No Name Total \"\n", + "print \"\\n--------------------------------------------------------\"\n", + "\n", + "rno = 0\n", + "sname = ''\n", + "tot = 0\n", + "\n", + "lines = fptr.readlines()\n", + "\n", + "for 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", + " \n", + "print \"\\n--------------------------------------------------------\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : FLS-12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ch = 'y'\n", + "\n", + "fp = open(\"STUDENT.DAT\",\"a\")\n", + "\n", + "while 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", + " \n", + "print \"\\n-------------------------------------------------------\"\n", + "print \"\\n Roll No. Name Total\"\n", + "print \"\\n-------------------------------------------------------\"\n", + "\n", + "rno = 0\n", + "sname = ''\n", + "tot = 0\n", + "\n", + "fp.close()\n", + "fp = open(\"STUDENT.DAT\",\"r\")\n", + "\n", + "lines = fp.readlines()\n", + "\n", + "for line in lines:\n", + " rno,sname,tot = line.split(' ')\n", + " print \"\\n \",rno,\"\\t\\t\",sname,\"\\t\\t\",tot\n", + " \n", + "print \"\\n--------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 104\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "RAHUL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "67\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to add more records\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : FLS-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "source_name = raw_input(\"\\nEnter the source file name : \")\n", + "\n", + "source_fptr = open(source_name,\"r\")\n", + "\n", + "target_name = raw_input(\"\\nEnter the target file name : \")\n", + "target_fptr = open(target_name,\"w+\")\n", + "\n", + "if source_fptr == 0:\n", + " print \"\\nNo content/source file !!!\"\n", + " print \"\\n press any key...\"\n", + "else:\n", + " while True:\n", + " ch = source_fptr.read(1)\n", + " if not ch:\n", + " break\n", + " target_fptr.write(\"%c\"%(ch))\n", + " \n", + "target_fptr.close()\n", + "target_fptr = open(target_name,\"r\")\n", + "\n", + "print \"\\nThe contents of the target file are\"\n", + "print \"\\n---------------------------------------\\n\"\n", + "lines = target_fptr.readlines()\n", + "\n", + "for line in lines:\n", + " print line\n", + " \n", + "target_fptr.close()\n", + "source_fptr.close()\n", + "print \"\\n\\n Press any key...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the source file name : SAMPLE.TXT\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the target file name : SAMPLE.BAK\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The contents of the target file are\n", + "\n", + "---------------------------------------\n", + "\n", + "Computer Programming in C language is widely used for Science and Engineering applications.\n", + "\n", + "\n", + " Press any key...\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : FLS-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ch = 'y'\n", + "\n", + "while 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "\tEnter your choice : 1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter data, enter 0 at end of reading\n", + "23\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "76\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-56\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "876\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Press Y to continue, any other key to stop...y\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "\tEnter your choice : 2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Largest integer is 876\n", + "\n", + "\n", + "Smallest integer is -56\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Press Y to continue, any other key to stop...n\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : FLS-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import os\n", + "\n", + "class emp_record:\n", + " eno = 0\n", + " ename = ''\n", + " bpay = 0.0\n", + " \n", + "erec = emp_record()\n", + "\n", + "def 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", + " \n", + "def 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", + "\n", + "def 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", + " \n", + "def 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", + " \n", + "def 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", + " \n", + "n = 0\n", + "while 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No.2101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ?ARUN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?8500\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No.2102\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ?DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?8000\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "----------------------------------------------------\n", + "\n", + " Emp.No. Employee Name Basic pay\n", + "\n", + "----------------------------------------------------\n", + "\n", + "2101 \tARUN \t8500.000000\n", + "\n", + "\n", + "2102 \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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No. 2103\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ? SUSHMITHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?6400\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No. 2104\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ? ASHIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?6200\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "To modify a record \n", + "\n", + "------------------\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the Roll No.2101\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The given record is not present in the file!!!\n", + "\n", + "Press 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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "To delete a record\n", + "\n", + "------------------\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the Roll No.2102\n" + ] + }, + { + "ename": "ValueError", + "evalue": "need more than 1 value to unpack", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 128\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 130\u001b[1;33m \u001b[0mdeleterec\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 131\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 132\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mdeleterec\u001b[1;34m()\u001b[0m\n\u001b[0;32m 89\u001b[0m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"\\nEnter the Roll No.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 90\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[0mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 91\u001b[1;33m \u001b[0meno\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mename\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbpay\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mefile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 92\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0meno\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 93\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"\\nExisting record details\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: need more than 1 value to unpack" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_1.ipynb new file mode 100755 index 00000000..1f9a4a84 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_1.ipynb @@ -0,0 +1,1236 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 12: Files" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : FLS-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "fp = open(\"SAMPLE.TXT\",\"w\")\n", + "\n", + "print \"\\nType the text press enter key at end.\\n\\n\"\n", + "\n", + "ch = raw_input(\"\")\n", + "fp.write(ch)\n", + "\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Type the text press enter key at end.\n", + "\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Computer 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 : FLS-8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "count = 0 \n", + "\n", + "fp = open(\"SAMPLE.TXT\",\"r\")\n", + "\n", + "print \"\\nThe content of the text file is : \\n\\n\"\n", + "\n", + "ch = fp.read()\n", + "\n", + "for 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", + " \n", + "print \"\\nNumber of vowels present = \",count\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The content of the text file is : \n", + "\n", + "\n", + "Computer Programming in C language is widely used for Science and Engineering applications.\n", + "Number of vowels present = 31\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : FLS-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "fp = open(\"STUDENT.DAT\",\"w\")\n", + "\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "for 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", + " \n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "ARUN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "78\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 102\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "72\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 103\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SUSHMITHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "86\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : FLS-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "fptr = open(\"STUDENT.DAT\",\"r\")\n", + "\n", + "print \"\\n--------------------------------------------------------\"\n", + "print \"\\n Roll No Name Total \"\n", + "print \"\\n--------------------------------------------------------\"\n", + "\n", + "rno = 0\n", + "sname = ''\n", + "tot = 0\n", + "\n", + "lines = fptr.readlines()\n", + "\n", + "for 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", + " \n", + "print \"\\n--------------------------------------------------------\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : FLS-12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ch = 'y'\n", + "\n", + "fp = open(\"STUDENT.DAT\",\"a\")\n", + "\n", + "while 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", + " \n", + "print \"\\n-------------------------------------------------------\"\n", + "print \"\\n Roll No. Name Total\"\n", + "print \"\\n-------------------------------------------------------\"\n", + "\n", + "rno = 0\n", + "sname = ''\n", + "tot = 0\n", + "\n", + "fp.close()\n", + "fp = open(\"STUDENT.DAT\",\"r\")\n", + "\n", + "lines = fp.readlines()\n", + "\n", + "for line in lines:\n", + " rno,sname,tot = line.split(' ')\n", + " print \"\\n \",rno,\"\\t\\t\",sname,\"\\t\\t\",tot\n", + " \n", + "print \"\\n--------------------------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Student roll no., name, total ? 104\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "RAHUL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "67\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press y - to add more records\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : FLS-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "source_name = raw_input(\"\\nEnter the source file name : \")\n", + "\n", + "source_fptr = open(source_name,\"r\")\n", + "\n", + "target_name = raw_input(\"\\nEnter the target file name : \")\n", + "target_fptr = open(target_name,\"w+\")\n", + "\n", + "if source_fptr == 0:\n", + " print \"\\nNo content/source file !!!\"\n", + " print \"\\n press any key...\"\n", + "else:\n", + " while True:\n", + " ch = source_fptr.read(1)\n", + " if not ch:\n", + " break\n", + " target_fptr.write(\"%c\"%(ch))\n", + " \n", + "target_fptr.close()\n", + "target_fptr = open(target_name,\"r\")\n", + "\n", + "print \"\\nThe contents of the target file are\"\n", + "print \"\\n---------------------------------------\\n\"\n", + "lines = target_fptr.readlines()\n", + "\n", + "for line in lines:\n", + " print line\n", + " \n", + "target_fptr.close()\n", + "source_fptr.close()\n", + "print \"\\n\\n Press any key...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the source file name : SAMPLE.TXT\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the target file name : SAMPLE.BAK\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The contents of the target file are\n", + "\n", + "---------------------------------------\n", + "\n", + "Computer Programming in C language is widely used for Science and Engineering applications.\n", + "\n", + "\n", + " Press any key...\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : FLS-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ch = 'y'\n", + "\n", + "while 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "\tEnter your choice : 1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter data, enter 0 at end of reading\n", + "23\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "76\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-56\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "876\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Press Y to continue, any other key to stop...y\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "\tEnter your choice : 2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Largest integer is 876\n", + "\n", + "\n", + "Smallest integer is -56\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Press Y to continue, any other key to stop...n\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : FLS-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import os\n", + "\n", + "class emp_record:\n", + " eno = 0\n", + " ename = ''\n", + " bpay = 0.0\n", + " \n", + "erec = emp_record()\n", + "\n", + "def 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", + " \n", + "def 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", + "\n", + "def 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", + " \n", + "def 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", + " \n", + "def 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", + " \n", + "n = 0\n", + "while 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No.2101\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ?ARUN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?8500\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No.2102\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ?DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?8000\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "----------------------------------------------------\n", + "\n", + " Emp.No. Employee Name Basic pay\n", + "\n", + "----------------------------------------------------\n", + "\n", + "2101 \tARUN \t8500.000000\n", + "\n", + "\n", + "2102 \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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No. 2103\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ? SUSHMITHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?6400\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the employee No. 2104\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Employee Name ? ASHIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Basic pay ?6200\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Press Y - to continue\n", + "\n", + " any other key to stop.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "To modify a record \n", + "\n", + "------------------\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the Roll No.2101\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The given record is not present in the file!!!\n", + "\n", + "Press 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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Enter your choice : 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "To delete a record\n", + "\n", + "------------------\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the Roll No.2102\n" + ] + }, + { + "ename": "ValueError", + "evalue": "need more than 1 value to unpack", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 128\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 130\u001b[1;33m \u001b[0mdeleterec\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 131\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 132\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mdeleterec\u001b[1;34m()\u001b[0m\n\u001b[0;32m 89\u001b[0m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"\\nEnter the Roll No.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 90\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[0mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 91\u001b[1;33m \u001b[0meno\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mename\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbpay\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mefile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 92\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0meno\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 93\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"\\nExisting record details\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: need more than 1 value to unpack" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13.ipynb new file mode 100755 index 00000000..84f2242b --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13.ipynb @@ -0,0 +1,169 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13: C Preprocessor and Command Line Arguments" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : PCL-3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def BIG(a,b):\n", + " if a > b:\n", + " return a\n", + " else:\n", + " return b\n", + " \n", + "def WAITMSG():\n", + " return \"\\nPress any key to continue...\"\n", + " \n", + "x = int(raw_input(\"\\nEnter two integers : \"))\n", + "y = int(raw_input(\"\"))\n", + "\n", + "print \"\\nBiggest integer is \",BIG(x,y),WAITMSG()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest integer is 8 \n", + "Press any key to continue...\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : PCL-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import time\n", + "\n", + "argv1 = \"SAMPLE.TXT\"\n", + "argv2 = \"SAMPLE.BAK\"\n", + "\n", + "source_fptr = open(\"SAMPLE.TXT\",\"r\")\n", + "target_fptr = open(\"SAMPLE.BAK\",\"w+\")\n", + "\n", + "if source_fptr == 0:\n", + " print \"\\nNo content/source file!!!\"\n", + " print \"\\n press any key to continue...\"\n", + "else:\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...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Copying source file SAMPLE.TXT to target file SAMPLE.BAK\n", + "\n", + " please wait.\n", + ".\n", + ".\n", + ".\n", + ".\n", + "\n", + "\n", + "Copy completed, the target file contents\n", + "\n", + "----------------------------------------\n", + "\n", + "Computer Programming in C language is widely used for Science and Engineering applications.\n", + "\n", + "\n", + " press any key to continue...\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_1.ipynb new file mode 100755 index 00000000..84f2242b --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_1.ipynb @@ -0,0 +1,169 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13: C Preprocessor and Command Line Arguments" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : PCL-3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def BIG(a,b):\n", + " if a > b:\n", + " return a\n", + " else:\n", + " return b\n", + " \n", + "def WAITMSG():\n", + " return \"\\nPress any key to continue...\"\n", + " \n", + "x = int(raw_input(\"\\nEnter two integers : \"))\n", + "y = int(raw_input(\"\"))\n", + "\n", + "print \"\\nBiggest integer is \",BIG(x,y),WAITMSG()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two integers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest integer is 8 \n", + "Press any key to continue...\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : PCL-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import time\n", + "\n", + "argv1 = \"SAMPLE.TXT\"\n", + "argv2 = \"SAMPLE.BAK\"\n", + "\n", + "source_fptr = open(\"SAMPLE.TXT\",\"r\")\n", + "target_fptr = open(\"SAMPLE.BAK\",\"w+\")\n", + "\n", + "if source_fptr == 0:\n", + " print \"\\nNo content/source file!!!\"\n", + " print \"\\n press any key to continue...\"\n", + "else:\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...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Copying source file SAMPLE.TXT to target file SAMPLE.BAK\n", + "\n", + " please wait.\n", + ".\n", + ".\n", + ".\n", + ".\n", + "\n", + "\n", + "Copy completed, the target file contents\n", + "\n", + "----------------------------------------\n", + "\n", + "Computer Programming in C language is widely used for Science and Engineering applications.\n", + "\n", + "\n", + " press any key to continue...\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14.ipynb new file mode 100755 index 00000000..e1fefdcb --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14.ipynb @@ -0,0 +1,625 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 14: Graphics Using C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : GUC-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "a = int(raw_input(\"Enter the first number : \"))\n", + "b = int(raw_input(\"Enter the second number : \"))\n", + "\n", + "if a > b:\n", + " print a, \" IS THE BIGGEST NUMBER\"\n", + "else:\n", + " print b, \" IS THE BIGGEST NUMBER\"\n", + " \n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the first number : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the second number : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 IS THE BIGGEST NUMBER\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : GUC-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%pylab inline\n", + "import pylab\n", + "import matplotlib.pyplot as plt\n", + "\n", + "x1 = int(raw_input(\"Enter start point coordinate : \"))\n", + "y1 = int(raw_input())\n", + "\n", + "x2 = int(raw_input(\"Enter end point coordinate : \"))\n", + "y2 = int(raw_input())\n", + "\n", + "figure()\n", + "pylab.plot([x1,y1],[x2,y2])" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "WARNING: pylab import has clobbered these variables: ['pylab']\n", + "`%pylab --no-import-all` prevents importing * from pylab and numpy\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Populating the interactive namespace from numpy and matplotlib\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter start point coordinate : 50\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "40\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter end point coordinate : 200\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "180\n" + ] + }, + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 11, + "text": [ + "[]" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEACAYAAAC57G0KAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFM9JREFUeJzt3X9M1OcBx/HPETCx0Q6STWyB9VIR9RTW65TWRrIjE7ss\nk2hJSHCzVOg/2qzZOrW1fzh/bTCdLnXBTZdiuuyPtqaJmG5a29FD17TDpcY6SSZtIUOsRKa2sC26\nybM/nOehB8edd/f99X4ll9Dv/fg+PG0f3zx3X/QZY4wAAK6TZfUAAADpwQIPAC7FAg8ALsUCDwAu\nxQIPAC7FAg8ALjXuAt/X16fKykrNnTtX8+bN0+7duyVJly5dUlVVlUpKSrRkyRJduXIl8pympibN\nnDlTs2fP1tGjR9M7egDAmHzjfQ7+woULunDhgh566CENDw/r61//ug4ePKj9+/fry1/+stavX6+f\n/exnunz5spqbm9XV1aUVK1boxIkT6u/v1+LFi3X27FllZfGDAgBk2rgr7/Tp0/XQQw9JkqZMmaI5\nc+aov79fhw4dUn19vSSpvr5eBw8elCS1tbWprq5OOTk58vv9Ki4uVmdnZ5q/BQBALBNO697eXp08\neVKPPPKIBgYGlJ+fL0nKz8/XwMCAJOn8+fMqLCyMPKewsFD9/f0pHjIAYCImtMAPDw+rpqZGL730\nkqZOnTrqPp/PJ5/PN+Zzx7sPAJA+2fEe8J///Ec1NTVauXKlli1bJulGtV+4cEHTp0/XZ599pmnT\npkmSCgoK1NfXF3nuuXPnVFBQcMdrFhcX65NPPknV9wAAnjBjxgx9/PHHE378uAVvjFFjY6MCgYB+\n8IMfRI5XV1frlVdekSS98sorkYW/urpar776qq5du6aenh51d3ervLz8jtf95JNPZIzhZox+/OMf\nWz4Gu9yYC+aCubh1++Mfjfx+o1WrjC5fvnEs0TAet+Dfe+89/e53v1NZWZmCwaCkGx+DfOGFF1Rb\nW6uXX35Zfr9fr7/+uiQpEAiotrZWgUBA2dnZ2rNnD1s0AJCAoSFp/XrpzTelvXulb387+dcad4Ff\ntGiRRkZGYt73zjvvxDz+4osv6sUXX0x+RADgUe3tUmOjVFkpnT4t5ebe3evF3YNHeoVCIauHYBvM\nxS3MxS1emItUVnu0cS90ShefzycLTgsAthNd7bt2jV/tia6dFDwAWCBd1R6N3yEAABnW3i6VlUlX\nr97Ya0/H4i5R8ACQMZmo9mgUPABkQKaqPRoFDwBplOlqj0bBA0CaWFHt0Sh4AEgxK6s9GgUPAClk\ndbVHo+ABIAXsUu3RKHgAuEt2qvZoFDwAJMmO1R6NggeAJNi12qNR8ACQALtXezQKHgAmyAnVHo2C\nB4A4nFTt0Sh4ABiH06o9GgUPADE4tdqjUfAAcBsnV3s0Ch4A/s8N1R6NggcAuafao1HwADzNbdUe\njYIH4FlurPZoFDwAz3FztUej4AF4iturPRoFD8ATvFLt0Sh4AK7npWqPRsEDcC0vVns0Ch6AK3m1\n2qNR8ABcxevVHo2CB+AaVPtoFDwAx6PaY6PgATga1T42Ch6AI1Ht8VHwAByHap8YCh6AY1DtiaHg\nATgC1Z44Ch6ArVHtyaPgAdgW1X53KHgAtkO1pwYFD8BWqPbUoeAB2ALVnnoUPADLUe3pQcEDsAzV\nnl4UPABLUO3pR8EDyCiqPXPiFnxDQ4Py8/NVWloaOXbq1CktXLhQZWVlqq6u1tDQkCSpt7dXkydP\nVjAYVDAY1Jo1a9I3cgCOQ7Vnls8YY8Z7wPHjxzVlyhQ9+eSTOn36tCRpwYIF2rVrlyoqKrR//371\n9PRoy5Yt6u3t1dKlSyOPG/OkPp/inBaAi1DtqZHo2hm34CsqKpSXlzfqWHd3tyoqKiRJixcv1htv\nvJHgMAF4BdVunaTeZJ07d67a2tokSQcOHFBfX1/kvp6eHgWDQYVCIf3pT39KzSgBOM7QkLR6tVRf\nL7W0SK2tUm6u1aPylqTeZG1tbdWzzz6rrVu3qrq6WpMmTZIk3X///err61NeXp4+/PBDLVu2TGfO\nnNHUqVPveI1NmzZFvg6FQgqFQkl9AwDsp71damyUKitvVDsLe3LC4bDC4XDSz4+7By9p3L31s2fP\nauXKlfrzn/98x32VlZXauXOnHn744dEnZQ8ecCX22tMr5XvwsVy8eFGSNDIyom3btmn16tWSpMHB\nQV2/fl2S9Omnn6q7u1sPPvhgMqcA4DDstdtP3C2auro6dXR0aHBwUEVFRdq8ebOGh4fV0tIiSaqp\nqdFTTz0lSTp27Jg2btyonJwcZWVlae/evcrlZzPA1ah2+5rQFk3KT8oWDeAK0Xvtu3ax155uia6d\nXMkKIGFUuzPwu2gAJIS9dueg4AFMCNXuPBQ8gLiodmei4AGMiWp3NgoeQExUu/NR8ABGodrdg4IH\nEEG1uwsFD4BqdykKHvA4qt29KHjAo6h296PgAQ+i2r2Bggc8hGr3Fgoe8Aiq3XsoeMDlqHbvouAB\nF6PavY2CB1yIaodEwQOuQ7XjJgoecAmqHbej4AEXoNoRCwUPOBjVjvFQ8IBDUe2Ih4IHHIZqx0RR\n8ICDUO1IBAUPOADVjmRQ8IDNUe1IFgUP2BTVjrtFwQM2RLUjFSh4wEaodqQSBQ/YBNWOVKPgAYtR\n7UgXCh6wENWOdKLgAQtQ7cgECh7IMKodmULBAxlCtSPTKHggA6h2WIGCB9KIaoeVKHggTah2WI2C\nB1KMaoddUPBAClHtsBMKHkgBqh12RMEDd4lqh11R8ECSqHbYHQUPJIFqhxNQ8EACqHY4CQUPTBDV\nDqeh4IE4qHY4VdyCb2hoUH5+vkpLSyPHTp06pYULF6qsrEzV1dUaGhqK3NfU1KSZM2dq9uzZOnr0\naHpGDWQI1Q4ni7vAr1q1SkeOHBl17Omnn9b27dv10Ucfafny5dqxY4ckqaurS6+99pq6urp05MgR\nrVmzRiMjI+kZOZBGQ0PS6tVSfb3U0iK1tkq5uVaPCkhM3AW+oqJCeXl5o451d3eroqJCkrR48WK9\n8cYbkqS2tjbV1dUpJydHfr9fxcXF6uzsTMOwgfSh2uEWSb3JOnfuXLW1tUmSDhw4oL6+PknS+fPn\nVVhYGHlcYWGh+vv7UzBMIP2odrhNUm+ytra26tlnn9XWrVtVXV2tSZMmjflYn88X8/imTZsiX4dC\nIYVCoWSGAqREe7vU2ChVVt6odhZ22EE4HFY4HE76+Ukt8LNmzdJbb70lSTp79qx+//vfS5IKCgoi\nNS9J586dU0FBQczXiF7gAavwCRnY2e3xu3nz5oSen9QWzcWLFyVJIyMj2rZtm1avXi1Jqq6u1quv\nvqpr166pp6dH3d3dKi8vT+YUQNqx1w63i1vwdXV16ujo0ODgoIqKirR582YNDw+rpaVFklRTU6On\nnnpKkhQIBFRbW6tAIKDs7Gzt2bNnzC0awCpUO7zCZ4wxGT+pzycLTguM2mvftYu9djhLomsnV7LC\nE6h2eBG/iwaux147vIqCh2tR7fA6Ch6uRLUDFDxchmoHbqHg4RpUOzAaBQ/Ho9qB2Ch4OBrVDoyN\ngocjUe1AfBQ8HIdqByaGgodjUO1AYih4OALVDiSOgoetUe1A8ih42BbVDtwdCh62Q7UDqUHBw1ao\ndiB1KHjYAtUOpB4FD8tR7UB6UPCwDNUOpBcFD0tQ7UD6UfDIKKodyBwKHhlDtQOZRcEj7ah2wBoU\nPNKKagesQ8EjLah2wHoUPFKOagfsgYJHylDtgL1Q8EgJqh2wHwoed4VqB+yLgkfSqHbA3ih4JIxq\nB5yBgkdCqHbAOSh4TAjVDjgPBY+4qHbAmSh4jIlqB5yNgkdMVDvgfBQ8RqHaAfeg4BFBtQPuQsGD\nagdcioL3OKodcC8K3qOodsD9KHgPotoBb6DgPYRqB7yFgvcIqh3wHgre5ah2wLsoeBej2gFvo+Bd\niGoHIE2g4BsaGpSfn6/S0tLIsc7OTpWXlysYDGrBggU6ceKEJKm3t1eTJ09WMBhUMBjUmjVr0jdy\nxES1A7jJZ4wx4z3g+PHjmjJlip588kmdPn1akhQKhbRhwwY9/vjjOnz4sLZv3653331Xvb29Wrp0\naeRxY57U51Oc0yJBVDvgfomunXELvqKiQnl5eaOO3Xffffr8888lSVeuXFFBQUGCw0QqUe0AYklq\nD765uVmLFi3S2rVrNTIyovfffz9yX09Pj4LBoL70pS9p27ZtWrRoUcoGi9GodgDjSWqBb2xs1O7d\nu7V8+XIdOHBADQ0Nevvtt3X//ferr69PeXl5+vDDD7Vs2TKdOXNGU6dOveM1Nm3aFPk6FAopFAol\n+z14Unu71NgoVVbeqPbcXKtHBCDVwuGwwuFw0s+Puwcv6Y699XvvvVdffPGFJMkYo9zc3MiWTbTK\nykrt3LlTDz/88OiTsgefNKod8K6U78HHUlxcrI6ODklSe3u7SkpKJEmDg4O6fv26JOnTTz9Vd3e3\nHnzwwWROgRjYaweQiLhbNHV1dero6NDg4KCKioq0ZcsW7du3T88884yuXr2qyZMna9++fZKkY8eO\naePGjcrJyVFWVpb27t2rXPYO7hrVDiAZE9qiSflJ2aKZsOi99l272GsHvCzRtZMrWW2Kagdwt/hd\nNDbEXjuAVKDgbYRqB5BKFLxNUO0AUo2CtxjVDiBdKHgLUe0A0omCtwDVDiATKPgMo9oBZAoFnyFU\nO4BMo+AzgGoHYAUKPo2odgBWouDThGoHYDUKPsWodgB2QcGnENUOwE4o+BSg2gHYEQV/l6h2AHZF\nwSeJagdgdxR8Eqh2AE5AwSeAagfgJBT8BFHtAJyGgo+DagfgVBT8OKh2AE5GwcdAtQNwAwr+NlQ7\nALeg4P+PagfgNhS8qHYA7uTpgqfaAbiZZwueagfgdp4reKodgFd4quCpdgBe4omCp9oBeJHrC55q\nB+BVri14qh2A17my4Kl2AHBZwVPtAHCLawqeageA0Rxf8FQ7AMTm6IKn2gFgbI4seKodAOJzXMFT\n7QAwMY4peKodABLjiIKn2gEgcbYueKodAJJn24Kn2gHg7tiu4Kl2AEgNWxU81Q4AqRN3gW9oaFB+\nfr5KS0sjxzo7O1VeXq5gMKgFCxboxIkTkfuampo0c+ZMzZ49W0ePHp3QIIaGpNWrpfp6qaVFam2V\ncnOT+G4AABFxF/hVq1bpyJEjo46tX79eW7du1cmTJ7VlyxatX79ektTV1aXXXntNXV1dOnLkiNas\nWaORkZFxX9/r1R4Oh60egm0wF7cwF7cwF8mLu8BXVFQoLy9v1LH77rtPn3/+uSTpypUrKigokCS1\ntbWprq5OOTk58vv9Ki4uVmdnZ8zXpdpv4D/eW5iLW5iLW5iL5CX1Jmtzc7MWLVqktWvXamRkRO+/\n/74k6fz583r00UcjjyssLFR/f3/M1ygrkyorb1S7Fxd2AEi3pN5kbWxs1O7du/X3v/9dv/jFL9TQ\n0DDmY30+X8zjXq52AMgIMwE9PT1m3rx5kX+eOnVq5OuRkRFz7733GmOMaWpqMk1NTZH7Hn/8cfPB\nBx/c8XozZswwkrhx48aNWwK3GTNmTGTJjkhqi6a4uFgdHR36xje+ofb2dpWUlEiSqqurtWLFCj33\n3HPq7+9Xd3e3ysvL73j+xx9/nMxpAQAJiLvA19XVqaOjQ4ODgyoqKtKWLVu0b98+PfPMM7p69aom\nT56sffv2SZICgYBqa2sVCASUnZ2tPXv2jLlFAwBIL58xxlg9CABA6mXkStbr168rGAxq6dKlkqRL\nly6pqqpKJSUlWrJkia5cuZKJYdjC7XOxbt06zZkzR1/72tf0xBNPRD5+6gW3z8VNO3fuVFZWli5d\numTRyDIv1lz88pe/1Jw5czRv3jw9//zzFo4us26fi/EurHQzv9+vsrIyBYPByFZ3omtnRhb4l156\nSYFAILJd09zcrKqqKp09e1bf/OY31dzcnIlh2MLtc7FkyRKdOXNGp06dUklJiZqamiweYebcPheS\n1NfXp7ffflsPPPCAhSPLvNvn4t1339WhQ4f00Ucf6a9//avWrl1r8Qgz5/a5GOvCSrfz+XwKh8M6\nefJk5HqiRNfOtC/w586d0x/+8Ac9/fTTurkbdOjQIdXX10uS6uvrdfDgwXQPwxZizUVVVZWysm78\na3jkkUd07tw5K4eYMbHmQpKee+45bd++3cKRZV6sufjVr36lDRs2KCcnR5L0la98xcohZkysuRjr\nwkovuH0HPdG1M+0L/A9/+EPt2LEjsohJ0sDAgPLz8yVJ+fn5GhgYSPcwbCHWXERrbW3Vtz3yuxpi\nzUVbW5sKCwtVVlZm4cgyL9ZcdHd369ixY3r00UcVCoX0l7/8xcIRZk6suWhubtaPfvQjffWrX9W6\ndes881Ouz+fT4sWLNX/+fP3mN7+RlPjamdYF/s0339S0adMUDAbv+JPoJp/P54lP2sSbi5/85Cea\nNGmSVqxYYcHoMivWXPzrX//ST3/6U23evDnyOC+8/z/Wfxf//e9/dfnyZX3wwQfasWOHamtrLRxl\nZow1F4lcWOkm7733nk6ePKnDhw+rpaVFx48fH3X/hNbOhD41n6ANGzaYwsJC4/f7zfTp080999xj\nvve975lZs2aZzz77zBhjzPnz582sWbPSOQxbiDUXK1euNMYYs3//fvPYY4+Zf//73xaPMjNizUVN\nTY2ZNm2a8fv9xu/3m+zsbPPAAw+YgYEBq4ebVmP9P/Ktb33LhMPhyONmzJhhBgcHLRxp+o01F2Nd\nWOklmzZtMj//+c8TXjvTusBHC4fD5jvf+Y4xxph169aZ5uZmY8yNq1+ff/75TA3DFqLn4vDhwyYQ\nCJiLFy9aPCprRM9FNL/fb/7xj39YMCLrRM/Fr3/9a7Nx40ZjjDF/+9vfTFFRkZVDy7jouQgGg5E/\n7N555x0zf/58K4eWEf/85z/NF198YYwxZnh42Dz22GPmrbfeSnjtzOjf6HTzx4kXXnhBtbW1evnl\nl+X3+/X6669nchiWM8ZE5uL73/++rl27pqqqKknSwoULtWfPHiuHl3Gxfsz0wrZdLDe/74aGBjU0\nNKi0tFSTJk3Sb3/7W4tHlnk352KsCyvdbGBgQMuXL5d0Y7vuu9/9rpYsWaL58+cntHZyoRMAuJSt\n/so+AEDqsMADgEuxwAOAS7HAA4BLscADgEuxwAOAS7HAA4BLscADgEv9D8TPhbcY8WPyAAAAAElF\nTkSuQmCC\n", + "text": [ + "" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : GUC-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%pylab\n", + "#Tkinter package is used for graphics\n", + "from matplotlib.patches import Rectangle\n", + "from matplotlib.collections import PatchCollection\n", + "\n", + "e = Rectangle(xy=(35, -50), width=80, height=80)\n", + "fig = plt.gcf()\n", + "fig.gca().add_artist(e)\n", + "#e.set_clip_box(ax.bbox)\n", + "e.set_alpha(0.7)\n", + "pylab.xlim([20, 50])\n", + "pylab.ylim([-65, -35])\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Using matplotlib backend: Qt4Agg\n", + "Populating the interactive namespace from numpy and matplotlib\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "WARNING: pylab import has clobbered these variables: ['e']\n", + "`%pylab --no-import-all` prevents importing * from pylab and numpy\n" + ] + }, + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 22, + "text": [ + "(-65, -35)" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : GUC-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import turtle\n", + "turtle.speed(0)\n", + "\n", + "\n", + "turtle.forward(200)\n", + "turtle.left(120)\n", + "turtle.forward(200)\n", + "turtle.left(120)\n", + "turtle.forward(200)\n", + "turtle.left(180)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number: GUC-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import turtle\n", + "turtle.speed(0)\n", + "\n", + "\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 39 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : GUC-18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import turtle\n", + "turtle.speed(0)\n", + "\n", + "\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 41 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7: Page Number: GUC-22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "i=0\n", + "while i < 360:\n", + " forward(1)\n", + " left(1)\n", + " i+=1" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 42 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number:GUC-24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "i=0\n", + "while i < 360:\n", + " forward(3)\n", + " left(3)\n", + " i+=3\n", + "\n", + "penup()\n", + "right(90)\n", + "forward(50)\n", + "left(90)\n", + "forward(100)\n", + "left(90)\n", + "pendown()\n", + "forward(200)\n", + "left(90)\n", + "forward(200)\n", + "left(90)\n", + "forward(200)\n", + "left(90)\n", + "forward(200)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 50 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : GUC-25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "i=0\n", + "while i < 360:\n", + " forward(3)\n", + " left(1)\n", + " i+=1\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 54 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : GUC-26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "\n", + "left(90)\n", + "forward(50)\n", + "i=0\n", + "while i < 180:\n", + " forward(1)\n", + " left(1)\n", + " i+=1\n", + " \n", + "forward(150)\n", + "left(90)\n", + "forward(250)\n", + "left(90)\n", + "forward(100)\n", + "left(90)\n", + "forward(140)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : GUC-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "\n", + "OX = [1,2,3,4]\n", + "OY = [200,590,670,435]\n", + "\n", + "fig = plt.figure()\n", + "\n", + "width = .35\n", + "ind = np.arange(len(OY))\n", + "plt.bar(ind, OY)\n", + "plt.xticks(ind + width / 2, OX)\n", + "\n", + "fig.autofmt_xdate()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : GUC-30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from mpl_toolkits.mplot3d import Axes3D\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(111, projection='3d')\n", + "for 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", + " \n", + "ax.set_xlabel('X')\n", + "ax.set_ylabel('Y')\n", + "ax.set_zlabel('Z')\n", + "\n", + "plt.show()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : GUC-31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from pylab import *\n", + "\n", + "# make a square figure and axes\n", + "figure(1, figsize=(6,6))\n", + "ax = axes([0.1, 0.1, 0.8, 0.8])\n", + "\n", + "# The slices will be ordered and plotted counter-clockwise.\n", + "\n", + "sales = [200, 590, 670, 435]\n", + "explode=(0, 0.05, 0, 0)\n", + "\n", + "pie(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", + "\n", + "show()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14, Page Number : GUC-34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import turtle\n", + "\n", + "i=0\n", + "while i < 360:\n", + " turtle.forward(3)\n", + " turtle.left(3)\n", + " i+=3\n", + " \n", + "turtle.penup()\n", + "turtle.forward(200)\n", + "\n", + "turtle.pendown()\n", + "i=0\n", + "while i < 360:\n", + " turtle.forward(3)\n", + " turtle.left(3)\n", + " i+=3\n", + " \n", + "turtle.penup()\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(50)\n", + "turtle.pendown()\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(400)\n", + "turtle.left(90)\n", + "turtle.forward(100)\n", + "turtle.right(90)\n", + "turtle.forward(100)\n", + "turtle.right(90)\n", + "turtle.forward(150)\n", + "turtle.right(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(50)\n", + "turtle.right(90)\n", + "turtle.forward(400)\n", + "turtle.right(90)\n", + "turtle.forward(50)\n", + "turtle.left(90)\n", + "turtle.forward(50)\n", + "turtle.right(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(100)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 15 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_1.ipynb new file mode 100755 index 00000000..e1fefdcb --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_1.ipynb @@ -0,0 +1,625 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 14: Graphics Using C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : GUC-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "a = int(raw_input(\"Enter the first number : \"))\n", + "b = int(raw_input(\"Enter the second number : \"))\n", + "\n", + "if a > b:\n", + " print a, \" IS THE BIGGEST NUMBER\"\n", + "else:\n", + " print b, \" IS THE BIGGEST NUMBER\"\n", + " \n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the first number : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the second number : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 IS THE BIGGEST NUMBER\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : GUC-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%pylab inline\n", + "import pylab\n", + "import matplotlib.pyplot as plt\n", + "\n", + "x1 = int(raw_input(\"Enter start point coordinate : \"))\n", + "y1 = int(raw_input())\n", + "\n", + "x2 = int(raw_input(\"Enter end point coordinate : \"))\n", + "y2 = int(raw_input())\n", + "\n", + "figure()\n", + "pylab.plot([x1,y1],[x2,y2])" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "WARNING: pylab import has clobbered these variables: ['pylab']\n", + "`%pylab --no-import-all` prevents importing * from pylab and numpy\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Populating the interactive namespace from numpy and matplotlib\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter start point coordinate : 50\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "40\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter end point coordinate : 200\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "180\n" + ] + }, + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 11, + "text": [ + "[]" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEACAYAAAC57G0KAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFM9JREFUeJzt3X9M1OcBx/HPETCx0Q6STWyB9VIR9RTW65TWRrIjE7ss\nk2hJSHCzVOg/2qzZOrW1fzh/bTCdLnXBTZdiuuyPtqaJmG5a29FD17TDpcY6SSZtIUOsRKa2sC26\nybM/nOehB8edd/f99X4ll9Dv/fg+PG0f3zx3X/QZY4wAAK6TZfUAAADpwQIPAC7FAg8ALsUCDwAu\nxQIPAC7FAg8ALjXuAt/X16fKykrNnTtX8+bN0+7duyVJly5dUlVVlUpKSrRkyRJduXIl8pympibN\nnDlTs2fP1tGjR9M7egDAmHzjfQ7+woULunDhgh566CENDw/r61//ug4ePKj9+/fry1/+stavX6+f\n/exnunz5spqbm9XV1aUVK1boxIkT6u/v1+LFi3X27FllZfGDAgBk2rgr7/Tp0/XQQw9JkqZMmaI5\nc+aov79fhw4dUn19vSSpvr5eBw8elCS1tbWprq5OOTk58vv9Ki4uVmdnZ5q/BQBALBNO697eXp08\neVKPPPKIBgYGlJ+fL0nKz8/XwMCAJOn8+fMqLCyMPKewsFD9/f0pHjIAYCImtMAPDw+rpqZGL730\nkqZOnTrqPp/PJ5/PN+Zzx7sPAJA+2fEe8J///Ec1NTVauXKlli1bJulGtV+4cEHTp0/XZ599pmnT\npkmSCgoK1NfXF3nuuXPnVFBQcMdrFhcX65NPPknV9wAAnjBjxgx9/PHHE378uAVvjFFjY6MCgYB+\n8IMfRI5XV1frlVdekSS98sorkYW/urpar776qq5du6aenh51d3ervLz8jtf95JNPZIzhZox+/OMf\nWz4Gu9yYC+aCubh1++Mfjfx+o1WrjC5fvnEs0TAet+Dfe+89/e53v1NZWZmCwaCkGx+DfOGFF1Rb\nW6uXX35Zfr9fr7/+uiQpEAiotrZWgUBA2dnZ2rNnD1s0AJCAoSFp/XrpzTelvXulb387+dcad4Ff\ntGiRRkZGYt73zjvvxDz+4osv6sUXX0x+RADgUe3tUmOjVFkpnT4t5ebe3evF3YNHeoVCIauHYBvM\nxS3MxS1emItUVnu0cS90ShefzycLTgsAthNd7bt2jV/tia6dFDwAWCBd1R6N3yEAABnW3i6VlUlX\nr97Ya0/H4i5R8ACQMZmo9mgUPABkQKaqPRoFDwBplOlqj0bBA0CaWFHt0Sh4AEgxK6s9GgUPAClk\ndbVHo+ABIAXsUu3RKHgAuEt2qvZoFDwAJMmO1R6NggeAJNi12qNR8ACQALtXezQKHgAmyAnVHo2C\nB4A4nFTt0Sh4ABiH06o9GgUPADE4tdqjUfAAcBsnV3s0Ch4A/s8N1R6NggcAuafao1HwADzNbdUe\njYIH4FlurPZoFDwAz3FztUej4AF4iturPRoFD8ATvFLt0Sh4AK7npWqPRsEDcC0vVns0Ch6AK3m1\n2qNR8ABcxevVHo2CB+AaVPtoFDwAx6PaY6PgATga1T42Ch6AI1Ht8VHwAByHap8YCh6AY1DtiaHg\nATgC1Z44Ch6ArVHtyaPgAdgW1X53KHgAtkO1pwYFD8BWqPbUoeAB2ALVnnoUPADLUe3pQcEDsAzV\nnl4UPABLUO3pR8EDyCiqPXPiFnxDQ4Py8/NVWloaOXbq1CktXLhQZWVlqq6u1tDQkCSpt7dXkydP\nVjAYVDAY1Jo1a9I3cgCOQ7Vnls8YY8Z7wPHjxzVlyhQ9+eSTOn36tCRpwYIF2rVrlyoqKrR//371\n9PRoy5Yt6u3t1dKlSyOPG/OkPp/inBaAi1DtqZHo2hm34CsqKpSXlzfqWHd3tyoqKiRJixcv1htv\nvJHgMAF4BdVunaTeZJ07d67a2tokSQcOHFBfX1/kvp6eHgWDQYVCIf3pT39KzSgBOM7QkLR6tVRf\nL7W0SK2tUm6u1aPylqTeZG1tbdWzzz6rrVu3qrq6WpMmTZIk3X///err61NeXp4+/PBDLVu2TGfO\nnNHUqVPveI1NmzZFvg6FQgqFQkl9AwDsp71damyUKitvVDsLe3LC4bDC4XDSz4+7By9p3L31s2fP\nauXKlfrzn/98x32VlZXauXOnHn744dEnZQ8ecCX22tMr5XvwsVy8eFGSNDIyom3btmn16tWSpMHB\nQV2/fl2S9Omnn6q7u1sPPvhgMqcA4DDstdtP3C2auro6dXR0aHBwUEVFRdq8ebOGh4fV0tIiSaqp\nqdFTTz0lSTp27Jg2btyonJwcZWVlae/evcrlZzPA1ah2+5rQFk3KT8oWDeAK0Xvtu3ax155uia6d\nXMkKIGFUuzPwu2gAJIS9dueg4AFMCNXuPBQ8gLiodmei4AGMiWp3NgoeQExUu/NR8ABGodrdg4IH\nEEG1uwsFD4BqdykKHvA4qt29KHjAo6h296PgAQ+i2r2Bggc8hGr3Fgoe8Aiq3XsoeMDlqHbvouAB\nF6PavY2CB1yIaodEwQOuQ7XjJgoecAmqHbej4AEXoNoRCwUPOBjVjvFQ8IBDUe2Ih4IHHIZqx0RR\n8ICDUO1IBAUPOADVjmRQ8IDNUe1IFgUP2BTVjrtFwQM2RLUjFSh4wEaodqQSBQ/YBNWOVKPgAYtR\n7UgXCh6wENWOdKLgAQtQ7cgECh7IMKodmULBAxlCtSPTKHggA6h2WIGCB9KIaoeVKHggTah2WI2C\nB1KMaoddUPBAClHtsBMKHkgBqh12RMEDd4lqh11R8ECSqHbYHQUPJIFqhxNQ8EACqHY4CQUPTBDV\nDqeh4IE4qHY4VdyCb2hoUH5+vkpLSyPHTp06pYULF6qsrEzV1dUaGhqK3NfU1KSZM2dq9uzZOnr0\naHpGDWQI1Q4ni7vAr1q1SkeOHBl17Omnn9b27dv10Ucfafny5dqxY4ckqaurS6+99pq6urp05MgR\nrVmzRiMjI+kZOZBGQ0PS6tVSfb3U0iK1tkq5uVaPCkhM3AW+oqJCeXl5o451d3eroqJCkrR48WK9\n8cYbkqS2tjbV1dUpJydHfr9fxcXF6uzsTMOwgfSh2uEWSb3JOnfuXLW1tUmSDhw4oL6+PknS+fPn\nVVhYGHlcYWGh+vv7UzBMIP2odrhNUm+ytra26tlnn9XWrVtVXV2tSZMmjflYn88X8/imTZsiX4dC\nIYVCoWSGAqREe7vU2ChVVt6odhZ22EE4HFY4HE76+Ukt8LNmzdJbb70lSTp79qx+//vfS5IKCgoi\nNS9J586dU0FBQczXiF7gAavwCRnY2e3xu3nz5oSen9QWzcWLFyVJIyMj2rZtm1avXi1Jqq6u1quv\nvqpr166pp6dH3d3dKi8vT+YUQNqx1w63i1vwdXV16ujo0ODgoIqKirR582YNDw+rpaVFklRTU6On\nnnpKkhQIBFRbW6tAIKDs7Gzt2bNnzC0awCpUO7zCZ4wxGT+pzycLTguM2mvftYu9djhLomsnV7LC\nE6h2eBG/iwaux147vIqCh2tR7fA6Ch6uRLUDFDxchmoHbqHg4RpUOzAaBQ/Ho9qB2Ch4OBrVDoyN\ngocjUe1AfBQ8HIdqByaGgodjUO1AYih4OALVDiSOgoetUe1A8ih42BbVDtwdCh62Q7UDqUHBw1ao\ndiB1KHjYAtUOpB4FD8tR7UB6UPCwDNUOpBcFD0tQ7UD6UfDIKKodyBwKHhlDtQOZRcEj7ah2wBoU\nPNKKagesQ8EjLah2wHoUPFKOagfsgYJHylDtgL1Q8EgJqh2wHwoed4VqB+yLgkfSqHbA3ih4JIxq\nB5yBgkdCqHbAOSh4TAjVDjgPBY+4qHbAmSh4jIlqB5yNgkdMVDvgfBQ8RqHaAfeg4BFBtQPuQsGD\nagdcioL3OKodcC8K3qOodsD9KHgPotoBb6DgPYRqB7yFgvcIqh3wHgre5ah2wLsoeBej2gFvo+Bd\niGoHIE2g4BsaGpSfn6/S0tLIsc7OTpWXlysYDGrBggU6ceKEJKm3t1eTJ09WMBhUMBjUmjVr0jdy\nxES1A7jJZ4wx4z3g+PHjmjJlip588kmdPn1akhQKhbRhwwY9/vjjOnz4sLZv3653331Xvb29Wrp0\naeRxY57U51Oc0yJBVDvgfomunXELvqKiQnl5eaOO3Xffffr8888lSVeuXFFBQUGCw0QqUe0AYklq\nD765uVmLFi3S2rVrNTIyovfffz9yX09Pj4LBoL70pS9p27ZtWrRoUcoGi9GodgDjSWqBb2xs1O7d\nu7V8+XIdOHBADQ0Nevvtt3X//ferr69PeXl5+vDDD7Vs2TKdOXNGU6dOveM1Nm3aFPk6FAopFAol\n+z14Unu71NgoVVbeqPbcXKtHBCDVwuGwwuFw0s+Puwcv6Y699XvvvVdffPGFJMkYo9zc3MiWTbTK\nykrt3LlTDz/88OiTsgefNKod8K6U78HHUlxcrI6ODklSe3u7SkpKJEmDg4O6fv26JOnTTz9Vd3e3\nHnzwwWROgRjYaweQiLhbNHV1dero6NDg4KCKioq0ZcsW7du3T88884yuXr2qyZMna9++fZKkY8eO\naePGjcrJyVFWVpb27t2rXPYO7hrVDiAZE9qiSflJ2aKZsOi99l272GsHvCzRtZMrWW2Kagdwt/hd\nNDbEXjuAVKDgbYRqB5BKFLxNUO0AUo2CtxjVDiBdKHgLUe0A0omCtwDVDiATKPgMo9oBZAoFnyFU\nO4BMo+AzgGoHYAUKPo2odgBWouDThGoHYDUKPsWodgB2QcGnENUOwE4o+BSg2gHYEQV/l6h2AHZF\nwSeJagdgdxR8Eqh2AE5AwSeAagfgJBT8BFHtAJyGgo+DagfgVBT8OKh2AE5GwcdAtQNwAwr+NlQ7\nALeg4P+PagfgNhS8qHYA7uTpgqfaAbiZZwueagfgdp4reKodgFd4quCpdgBe4omCp9oBeJHrC55q\nB+BVri14qh2A17my4Kl2AHBZwVPtAHCLawqeageA0Rxf8FQ7AMTm6IKn2gFgbI4seKodAOJzXMFT\n7QAwMY4peKodABLjiIKn2gEgcbYueKodAJJn24Kn2gHg7tiu4Kl2AEgNWxU81Q4AqRN3gW9oaFB+\nfr5KS0sjxzo7O1VeXq5gMKgFCxboxIkTkfuampo0c+ZMzZ49W0ePHp3QIIaGpNWrpfp6qaVFam2V\ncnOT+G4AABFxF/hVq1bpyJEjo46tX79eW7du1cmTJ7VlyxatX79ektTV1aXXXntNXV1dOnLkiNas\nWaORkZFxX9/r1R4Oh60egm0wF7cwF7cwF8mLu8BXVFQoLy9v1LH77rtPn3/+uSTpypUrKigokCS1\ntbWprq5OOTk58vv9Ki4uVmdnZ8zXpdpv4D/eW5iLW5iLW5iL5CX1Jmtzc7MWLVqktWvXamRkRO+/\n/74k6fz583r00UcjjyssLFR/f3/M1ygrkyorb1S7Fxd2AEi3pN5kbWxs1O7du/X3v/9dv/jFL9TQ\n0DDmY30+X8zjXq52AMgIMwE9PT1m3rx5kX+eOnVq5OuRkRFz7733GmOMaWpqMk1NTZH7Hn/8cfPB\nBx/c8XozZswwkrhx48aNWwK3GTNmTGTJjkhqi6a4uFgdHR36xje+ofb2dpWUlEiSqqurtWLFCj33\n3HPq7+9Xd3e3ysvL73j+xx9/nMxpAQAJiLvA19XVqaOjQ4ODgyoqKtKWLVu0b98+PfPMM7p69aom\nT56sffv2SZICgYBqa2sVCASUnZ2tPXv2jLlFAwBIL58xxlg9CABA6mXkStbr168rGAxq6dKlkqRL\nly6pqqpKJSUlWrJkia5cuZKJYdjC7XOxbt06zZkzR1/72tf0xBNPRD5+6gW3z8VNO3fuVFZWli5d\numTRyDIv1lz88pe/1Jw5czRv3jw9//zzFo4us26fi/EurHQzv9+vsrIyBYPByFZ3omtnRhb4l156\nSYFAILJd09zcrKqqKp09e1bf/OY31dzcnIlh2MLtc7FkyRKdOXNGp06dUklJiZqamiweYebcPheS\n1NfXp7ffflsPPPCAhSPLvNvn4t1339WhQ4f00Ucf6a9//avWrl1r8Qgz5/a5GOvCSrfz+XwKh8M6\nefJk5HqiRNfOtC/w586d0x/+8Ac9/fTTurkbdOjQIdXX10uS6uvrdfDgwXQPwxZizUVVVZWysm78\na3jkkUd07tw5K4eYMbHmQpKee+45bd++3cKRZV6sufjVr36lDRs2KCcnR5L0la98xcohZkysuRjr\nwkovuH0HPdG1M+0L/A9/+EPt2LEjsohJ0sDAgPLz8yVJ+fn5GhgYSPcwbCHWXERrbW3Vtz3yuxpi\nzUVbW5sKCwtVVlZm4cgyL9ZcdHd369ixY3r00UcVCoX0l7/8xcIRZk6suWhubtaPfvQjffWrX9W6\ndes881Ouz+fT4sWLNX/+fP3mN7+RlPjamdYF/s0339S0adMUDAbv+JPoJp/P54lP2sSbi5/85Cea\nNGmSVqxYYcHoMivWXPzrX//ST3/6U23evDnyOC+8/z/Wfxf//e9/dfnyZX3wwQfasWOHamtrLRxl\nZow1F4lcWOkm7733nk6ePKnDhw+rpaVFx48fH3X/hNbOhD41n6ANGzaYwsJC4/f7zfTp080999xj\nvve975lZs2aZzz77zBhjzPnz582sWbPSOQxbiDUXK1euNMYYs3//fvPYY4+Zf//73xaPMjNizUVN\nTY2ZNm2a8fv9xu/3m+zsbPPAAw+YgYEBq4ebVmP9P/Ktb33LhMPhyONmzJhhBgcHLRxp+o01F2Nd\nWOklmzZtMj//+c8TXjvTusBHC4fD5jvf+Y4xxph169aZ5uZmY8yNq1+ff/75TA3DFqLn4vDhwyYQ\nCJiLFy9aPCprRM9FNL/fb/7xj39YMCLrRM/Fr3/9a7Nx40ZjjDF/+9vfTFFRkZVDy7jouQgGg5E/\n7N555x0zf/58K4eWEf/85z/NF198YYwxZnh42Dz22GPmrbfeSnjtzOjf6HTzx4kXXnhBtbW1evnl\nl+X3+/X6669nchiWM8ZE5uL73/++rl27pqqqKknSwoULtWfPHiuHl3Gxfsz0wrZdLDe/74aGBjU0\nNKi0tFSTJk3Sb3/7W4tHlnk352KsCyvdbGBgQMuXL5d0Y7vuu9/9rpYsWaL58+cntHZyoRMAuJSt\n/so+AEDqsMADgEuxwAOAS7HAA4BLscADgEuxwAOAS7HAA4BLscADgEv9D8TPhbcY8WPyAAAAAElF\nTkSuQmCC\n", + "text": [ + "" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : GUC-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%pylab\n", + "#Tkinter package is used for graphics\n", + "from matplotlib.patches import Rectangle\n", + "from matplotlib.collections import PatchCollection\n", + "\n", + "e = Rectangle(xy=(35, -50), width=80, height=80)\n", + "fig = plt.gcf()\n", + "fig.gca().add_artist(e)\n", + "#e.set_clip_box(ax.bbox)\n", + "e.set_alpha(0.7)\n", + "pylab.xlim([20, 50])\n", + "pylab.ylim([-65, -35])\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Using matplotlib backend: Qt4Agg\n", + "Populating the interactive namespace from numpy and matplotlib\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "WARNING: pylab import has clobbered these variables: ['e']\n", + "`%pylab --no-import-all` prevents importing * from pylab and numpy\n" + ] + }, + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 22, + "text": [ + "(-65, -35)" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : GUC-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import turtle\n", + "turtle.speed(0)\n", + "\n", + "\n", + "turtle.forward(200)\n", + "turtle.left(120)\n", + "turtle.forward(200)\n", + "turtle.left(120)\n", + "turtle.forward(200)\n", + "turtle.left(180)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number: GUC-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import turtle\n", + "turtle.speed(0)\n", + "\n", + "\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 39 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : GUC-18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import turtle\n", + "turtle.speed(0)\n", + "\n", + "\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(200)\n", + "turtle.left(90)\n", + "turtle.forward(100)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 41 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7: Page Number: GUC-22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "i=0\n", + "while i < 360:\n", + " forward(1)\n", + " left(1)\n", + " i+=1" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 42 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number:GUC-24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "i=0\n", + "while i < 360:\n", + " forward(3)\n", + " left(3)\n", + " i+=3\n", + "\n", + "penup()\n", + "right(90)\n", + "forward(50)\n", + "left(90)\n", + "forward(100)\n", + "left(90)\n", + "pendown()\n", + "forward(200)\n", + "left(90)\n", + "forward(200)\n", + "left(90)\n", + "forward(200)\n", + "left(90)\n", + "forward(200)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 50 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : GUC-25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "i=0\n", + "while i < 360:\n", + " forward(3)\n", + " left(1)\n", + " i+=1\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 54 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : GUC-26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from turtle import*\n", + "speed(0)\n", + "\n", + "left(90)\n", + "forward(50)\n", + "i=0\n", + "while i < 180:\n", + " forward(1)\n", + " left(1)\n", + " i+=1\n", + " \n", + "forward(150)\n", + "left(90)\n", + "forward(250)\n", + "left(90)\n", + "forward(100)\n", + "left(90)\n", + "forward(140)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : GUC-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "\n", + "OX = [1,2,3,4]\n", + "OY = [200,590,670,435]\n", + "\n", + "fig = plt.figure()\n", + "\n", + "width = .35\n", + "ind = np.arange(len(OY))\n", + "plt.bar(ind, OY)\n", + "plt.xticks(ind + width / 2, OX)\n", + "\n", + "fig.autofmt_xdate()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : GUC-30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from mpl_toolkits.mplot3d import Axes3D\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(111, projection='3d')\n", + "for 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", + " \n", + "ax.set_xlabel('X')\n", + "ax.set_ylabel('Y')\n", + "ax.set_zlabel('Z')\n", + "\n", + "plt.show()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : GUC-31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from pylab import *\n", + "\n", + "# make a square figure and axes\n", + "figure(1, figsize=(6,6))\n", + "ax = axes([0.1, 0.1, 0.8, 0.8])\n", + "\n", + "# The slices will be ordered and plotted counter-clockwise.\n", + "\n", + "sales = [200, 590, 670, 435]\n", + "explode=(0, 0.05, 0, 0)\n", + "\n", + "pie(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", + "\n", + "show()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14, Page Number : GUC-34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import turtle\n", + "\n", + "i=0\n", + "while i < 360:\n", + " turtle.forward(3)\n", + " turtle.left(3)\n", + " i+=3\n", + " \n", + "turtle.penup()\n", + "turtle.forward(200)\n", + "\n", + "turtle.pendown()\n", + "i=0\n", + "while i < 360:\n", + " turtle.forward(3)\n", + " turtle.left(3)\n", + " i+=3\n", + " \n", + "turtle.penup()\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(50)\n", + "turtle.pendown()\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(400)\n", + "turtle.left(90)\n", + "turtle.forward(100)\n", + "turtle.right(90)\n", + "turtle.forward(100)\n", + "turtle.right(90)\n", + "turtle.forward(150)\n", + "turtle.right(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(50)\n", + "turtle.right(90)\n", + "turtle.forward(400)\n", + "turtle.right(90)\n", + "turtle.forward(50)\n", + "turtle.left(90)\n", + "turtle.forward(50)\n", + "turtle.right(90)\n", + "turtle.forward(100)\n", + "turtle.left(90)\n", + "turtle.forward(100)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 15 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4.ipynb new file mode 100755 index 00000000..a3c3fdf3 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4.ipynb @@ -0,0 +1,431 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:beba487362ad72f7d0b5bcfa6d644d75a22e3d3f63f267f9db3f44d7a080a220" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 4: Input/Output Functions and Statements" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.0, Page number: IOF-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#Variable Declaration and Initialization\n", + "a = int(raw_input(\"\"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "#Calculation\n", + "sum1 = a + b\n", + "product = a * b\n", + "#Since sum is a keyword in python, sum1 is used\n", + "\n", + "#Output\n", + "print sum1, product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "8 15\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.1, Page number: IOF-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#Variable initialization\n", + "a = int(raw_input(\"Enter Value to A : \"))\n", + "b = int(raw_input(\"Enter Value to B : \"))\n", + "\n", + "#Calculation\n", + "sum1 = a + b\n", + "product = a * b\n", + "#Since sum is a keyword in python, sum1 is used\n", + "\n", + "#Output\n", + "print \"SUM = \",sum1,\"\\nPRODUCT = \", product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Value to A : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Value to B : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "SUM = 8 \n", + "PRODUCT = 15\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page number: IOF-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "f = int(raw_input(\"Degree fahrenheit ? \"))\n", + "\n", + "#Calculation\n", + "c = 5.0/9.0 * (f-32)\n", + "\n", + "#Output\n", + "sys.stdout.write(\"Degree centigrade = %6.2f\"%(c))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Degree fahrenheit ? 105\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Degree centigrade = 40.56" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page number: IOF-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "import math\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"Enter three sides : \"))\n", + "b = int(raw_input(\"Enter three sides : \"))\n", + "c = int(raw_input(\"Enter three sides : \"))\n", + "\n", + "#Calculation\n", + "s = (a+b+c)/2\n", + "area = math.sqrt(s * (s-a) * (s-b) * (s-c))\n", + "\n", + "#Output\n", + "sys.stdout.write(\"Area of Triangle = %6.2f Sq.units\"%(area))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Area of Triangle = 6.48 Sq.units" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page number: IOF-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#Variable Initialization\n", + "ch = raw_input(\"Enter a character : \")\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\n\\nASCII value of %c is %u\"%(ch,ord(ch)))\n", + "sys.stdout.write(\"\\nPress any key to stop...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a character : A\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "ASCII value of A is 65\n", + "Press any key to stop..." + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page number: IOF-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "#Variable initialization\n", + "sno = raw_input(\"Enter service number : \")\n", + "pmr = int(raw_input(\"\\nPrevious month reading ? \"))\n", + "cmr = int(raw_input(\"\\nCurrent month reading ? \"))\n", + "\n", + "#Calculation\n", + "units = cmr - pmr\n", + "amt = units * 1.50\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\n Electricity Bill\")\n", + "sys.stdout.write(\"\\n ________________\")\n", + "sys.stdout.write(\"\\nService No. %s\"%(sno))\n", + "sys.stdout.write(\"\\nUnits Consumed : %d\"%(units))\n", + "sys.stdout.write(\"\\nElectricity Charges Rs. %0.2f\"%(amt))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter service number : TMR65358\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Previous month reading ? 4305\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Current month reading ? 4410\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Electricity Bill\n", + " ________________\n", + "Service No. TMR65358\n", + "Units Consumed : 105\n", + "Electricity Charges Rs. 157.50" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page number: IOF-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"Enter value to A : \"))\n", + "b = int(raw_input(\"Enter value to B : \"))\n", + "\n", + "#Calculation\n", + "temp = a\n", + "a = b\n", + "b = temp\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\n\\nValue of A = %d\"%(a))\n", + "sys.stdout.write(\"\\nValue of B = %d\"%(b))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value to A : 15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value to B : 250\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Value of A = 250\n", + "Value of B = 15" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_1.ipynb new file mode 100755 index 00000000..a3c3fdf3 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_1.ipynb @@ -0,0 +1,431 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:beba487362ad72f7d0b5bcfa6d644d75a22e3d3f63f267f9db3f44d7a080a220" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 4: Input/Output Functions and Statements" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.0, Page number: IOF-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#Variable Declaration and Initialization\n", + "a = int(raw_input(\"\"))\n", + "b = int(raw_input(\"\"))\n", + "\n", + "#Calculation\n", + "sum1 = a + b\n", + "product = a * b\n", + "#Since sum is a keyword in python, sum1 is used\n", + "\n", + "#Output\n", + "print sum1, product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "8 15\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.1, Page number: IOF-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#Variable initialization\n", + "a = int(raw_input(\"Enter Value to A : \"))\n", + "b = int(raw_input(\"Enter Value to B : \"))\n", + "\n", + "#Calculation\n", + "sum1 = a + b\n", + "product = a * b\n", + "#Since sum is a keyword in python, sum1 is used\n", + "\n", + "#Output\n", + "print \"SUM = \",sum1,\"\\nPRODUCT = \", product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Value to A : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Value to B : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "SUM = 8 \n", + "PRODUCT = 15\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page number: IOF-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "f = int(raw_input(\"Degree fahrenheit ? \"))\n", + "\n", + "#Calculation\n", + "c = 5.0/9.0 * (f-32)\n", + "\n", + "#Output\n", + "sys.stdout.write(\"Degree centigrade = %6.2f\"%(c))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Degree fahrenheit ? 105\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Degree centigrade = 40.56" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page number: IOF-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "import math\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"Enter three sides : \"))\n", + "b = int(raw_input(\"Enter three sides : \"))\n", + "c = int(raw_input(\"Enter three sides : \"))\n", + "\n", + "#Calculation\n", + "s = (a+b+c)/2\n", + "area = math.sqrt(s * (s-a) * (s-b) * (s-c))\n", + "\n", + "#Output\n", + "sys.stdout.write(\"Area of Triangle = %6.2f Sq.units\"%(area))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Area of Triangle = 6.48 Sq.units" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page number: IOF-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#Variable Initialization\n", + "ch = raw_input(\"Enter a character : \")\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\n\\nASCII value of %c is %u\"%(ch,ord(ch)))\n", + "sys.stdout.write(\"\\nPress any key to stop...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a character : A\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "ASCII value of A is 65\n", + "Press any key to stop..." + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page number: IOF-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "#Variable initialization\n", + "sno = raw_input(\"Enter service number : \")\n", + "pmr = int(raw_input(\"\\nPrevious month reading ? \"))\n", + "cmr = int(raw_input(\"\\nCurrent month reading ? \"))\n", + "\n", + "#Calculation\n", + "units = cmr - pmr\n", + "amt = units * 1.50\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\n Electricity Bill\")\n", + "sys.stdout.write(\"\\n ________________\")\n", + "sys.stdout.write(\"\\nService No. %s\"%(sno))\n", + "sys.stdout.write(\"\\nUnits Consumed : %d\"%(units))\n", + "sys.stdout.write(\"\\nElectricity Charges Rs. %0.2f\"%(amt))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter service number : TMR65358\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Previous month reading ? 4305\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Current month reading ? 4410\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Electricity Bill\n", + " ________________\n", + "Service No. TMR65358\n", + "Units Consumed : 105\n", + "Electricity Charges Rs. 157.50" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page number: IOF-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"Enter value to A : \"))\n", + "b = int(raw_input(\"Enter value to B : \"))\n", + "\n", + "#Calculation\n", + "temp = a\n", + "a = b\n", + "b = temp\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\n\\nValue of A = %d\"%(a))\n", + "sys.stdout.write(\"\\nValue of B = %d\"%(b))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value to A : 15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value to B : 250\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Value of A = 250\n", + "Value of B = 15" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5.ipynb new file mode 100755 index 00000000..0380f60d --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5.ipynb @@ -0,0 +1,657 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5: Control Statements in C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : CSC-3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"\\nEnter two numbers : \"))\n", + "b = int(raw_input(\"\"))\n", + "big = a\n", + "\n", + "#Processing\n", + "if b > big:\n", + " big = b\n", + "\n", + "#Output\n", + "print \"\\nBiggest number is \",big\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two numbers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 8\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : CSC-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"\\nEnter three numbers : \"))\n", + "b = int(raw_input(\"\"))\n", + "c = int(raw_input(\"\"))\n", + "big = a\n", + "\n", + "#Processing\n", + "if b > big:\n", + " big = b\n", + " \n", + "if c > big:\n", + " big = c\n", + " \n", + "#Output\n", + "print \"\\nBiggest number is \",big" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three numbers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 13\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : CSC-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"\\nEnter three numbers : \"))\n", + "b = int(raw_input(\"\"))\n", + "c = int(raw_input(\"\"))\n", + "\n", + "#Processing\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", + "#Output\n", + "print \"\\nBiggest number is \",big" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three numbers : 18\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 18\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : CSC-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = float(raw_input(\"\\nEnter value to x and n : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "if n == 1:\n", + " y = 1 + x\n", + "else:\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", + " \n", + "print \"\\nValue of y(x,n) = \",y" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to x and n : 0.42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of y(x,n) = 3.1\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : CSC-9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = float(raw_input(\"\\nEnter value to x and n : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "#There is no switch statement in python\n", + "if n == 1:\n", + " y = 1 + x\n", + "else:\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", + " \n", + "sys.stdout.write(\"\\nValue of y(x,n) = %6.2f\"%(y))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to x and n : 0.42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of y(x,n) = 3.10" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : CSC-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "sales = int(raw_input(\"\\nSales amount ? \"))\n", + "\n", + "if sales <= 500:\n", + " comm = 0.05 * sales\n", + "else:\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", + " \n", + "sys.stdout.write(\"\\nCommission Amount Rs. %0.2f\"%(comm))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sales amount ? 4500\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Commission Amount Rs. 485.00" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : CSC-12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "a = int(raw_input(\"\\nEnter coefficients a,b and c : \"))\n", + "b = int(raw_input())\n", + "c = int(raw_input())\n", + "\n", + "d = b*b - 4*a*c\n", + "\n", + "if 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))\n", + "else:\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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter coefficients a,b and c : 1\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": [ + "\n", + "Roots are real and unequal\n", + " -1.00 -2.00" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : CSC-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "avg_marks = int(raw_input(\"\\nAverage Marks ? \"))\n", + "\n", + "if avg_marks >= 80 and avg_marks <= 100:\n", + " print \"\\nHonours\"\n", + "else:\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\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Average Marks ? 84\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Honours\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : CSC-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "units = int(raw_input(\"\\nEnter consumed units : \"))\n", + "\n", + "if units <= 200:\n", + " amt = 0.5 * units\n", + "else:\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", + " \n", + "sys.stdout.write(\"\\nAmount to be paid Rs.%0.2f\"%(amt))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter consumed units : 348\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Amount to be paid Rs.196.20" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : CSC-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ts = int(raw_input(\"\\nEnter tensile strength : \"))\n", + "rh = int(raw_input(\"\\nEnter rockwell hardness : \"))\n", + "cc = int(raw_input(\"\\nEnter carbon content : \"))\n", + "\n", + "if 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\"\n", + "else:\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\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter tensile strength : 800\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter rockwell hardness : 180\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter carbon content : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Grade is C\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_1.ipynb new file mode 100755 index 00000000..0380f60d --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_1.ipynb @@ -0,0 +1,657 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5: Control Statements in C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : CSC-3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"\\nEnter two numbers : \"))\n", + "b = int(raw_input(\"\"))\n", + "big = a\n", + "\n", + "#Processing\n", + "if b > big:\n", + " big = b\n", + "\n", + "#Output\n", + "print \"\\nBiggest number is \",big\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter two numbers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 8\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : CSC-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"\\nEnter three numbers : \"))\n", + "b = int(raw_input(\"\"))\n", + "c = int(raw_input(\"\"))\n", + "big = a\n", + "\n", + "#Processing\n", + "if b > big:\n", + " big = b\n", + " \n", + "if c > big:\n", + " big = c\n", + " \n", + "#Output\n", + "print \"\\nBiggest number is \",big" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three numbers : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 13\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : CSC-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "a = int(raw_input(\"\\nEnter three numbers : \"))\n", + "b = int(raw_input(\"\"))\n", + "c = int(raw_input(\"\"))\n", + "\n", + "#Processing\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", + "#Output\n", + "print \"\\nBiggest number is \",big" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three numbers : 18\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Biggest number is 18\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : CSC-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = float(raw_input(\"\\nEnter value to x and n : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "if n == 1:\n", + " y = 1 + x\n", + "else:\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", + " \n", + "print \"\\nValue of y(x,n) = \",y" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to x and n : 0.42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of y(x,n) = 3.1\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : CSC-9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = float(raw_input(\"\\nEnter value to x and n : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "#There is no switch statement in python\n", + "if n == 1:\n", + " y = 1 + x\n", + "else:\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", + " \n", + "sys.stdout.write(\"\\nValue of y(x,n) = %6.2f\"%(y))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to x and n : 0.42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of y(x,n) = 3.10" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : CSC-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "sales = int(raw_input(\"\\nSales amount ? \"))\n", + "\n", + "if sales <= 500:\n", + " comm = 0.05 * sales\n", + "else:\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", + " \n", + "sys.stdout.write(\"\\nCommission Amount Rs. %0.2f\"%(comm))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sales amount ? 4500\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Commission Amount Rs. 485.00" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : CSC-12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "a = int(raw_input(\"\\nEnter coefficients a,b and c : \"))\n", + "b = int(raw_input())\n", + "c = int(raw_input())\n", + "\n", + "d = b*b - 4*a*c\n", + "\n", + "if 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))\n", + "else:\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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter coefficients a,b and c : 1\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": [ + "\n", + "Roots are real and unequal\n", + " -1.00 -2.00" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : CSC-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "avg_marks = int(raw_input(\"\\nAverage Marks ? \"))\n", + "\n", + "if avg_marks >= 80 and avg_marks <= 100:\n", + " print \"\\nHonours\"\n", + "else:\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\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Average Marks ? 84\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Honours\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : CSC-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "units = int(raw_input(\"\\nEnter consumed units : \"))\n", + "\n", + "if units <= 200:\n", + " amt = 0.5 * units\n", + "else:\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", + " \n", + "sys.stdout.write(\"\\nAmount to be paid Rs.%0.2f\"%(amt))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter consumed units : 348\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Amount to be paid Rs.196.20" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : CSC-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ts = int(raw_input(\"\\nEnter tensile strength : \"))\n", + "rh = int(raw_input(\"\\nEnter rockwell hardness : \"))\n", + "cc = int(raw_input(\"\\nEnter carbon content : \"))\n", + "\n", + "if 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\"\n", + "else:\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\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter tensile strength : 800\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter rockwell hardness : 180\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter carbon content : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Grade is C\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6.ipynb new file mode 100755 index 00000000..e2aad83c --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6.ipynb @@ -0,0 +1,1304 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 6: Loop Control Structures in C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : LCS-2" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter value to n : \"))\n", + "\n", + "for i in range(1,n+1):\n", + " sys.stdout.write(\"%8d\"%(i))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to n : 15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : LCS-3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import numpy\n", + "import math\n", + "\n", + "print \"\\n--------------------------------\"\n", + "print \" X Y \"\n", + "print \"--------------------------------\"\n", + "\n", + "for 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", + " \n", + "print \"\\n--------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : LCS-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "k = int(raw_input(\"\\nEnter the number : \"))\n", + "\n", + "kfact = 1\n", + "\n", + "for i in range(1,k+1):\n", + " kfact = kfact * i\n", + " \n", + "print k,\" factorial is \",kfact" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the number : 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4 factorial is 24\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : LCS-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter value to N : \"))\n", + "\n", + "s = 0\n", + "\n", + "for 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", + " \n", + "print \"\\nSum of the series S = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to N : 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of the series S = 20\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : LCS-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy\n", + "import sys\n", + "\n", + "for 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))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Value of y(-1.50,0.00) = -18.75\n", + "\n", + "Value of y(-1.50,1.00) = -16.75\n", + "\n", + "Value of y(-1.50,2.00) = -2.75\n", + "\n", + "Value of y(-1.50,3.00) = 35.25\n", + "\n", + "Value of y(-1.00,0.00) = -22.50\n", + "\n", + "Value of y(-1.00,1.00) = -20.50\n", + "\n", + "Value of y(-1.00,2.00) = -6.50\n", + "\n", + "Value of y(-1.00,3.00) = 31.50\n", + "\n", + "Value of y(-0.50,0.00) = -24.75\n", + "\n", + "Value of y(-0.50,1.00) = -22.75\n", + "\n", + "Value of y(-0.50,2.00) = -8.75\n", + "\n", + "Value of y(-0.50,3.00) = 29.25\n", + "\n", + "Value of y(0.00,0.00) = -25.50\n", + "\n", + "Value of y(0.00,1.00) = -23.50\n", + "\n", + "Value of y(0.00,2.00) = -9.50\n", + "\n", + "Value of y(0.00,3.00) = 28.50\n", + "\n", + "Value of y(0.50,0.00) = -24.75\n", + "\n", + "Value of y(0.50,1.00) = -22.75\n", + "\n", + "Value of y(0.50,2.00) = -8.75\n", + "\n", + "Value of y(0.50,3.00) = 29.25\n", + "\n", + "Value of y(1.00,0.00) = -22.50\n", + "\n", + "Value of y(1.00,1.00) = -20.50\n", + "\n", + "Value of y(1.00,2.00) = -6.50\n", + "\n", + "Value of y(1.00,3.00) = 31.50\n", + "\n", + "Value of y(1.50,0.00) = -18.75\n", + "\n", + "Value of y(1.50,1.00) = -16.75\n", + "\n", + "Value of y(1.50,2.00) = -2.75\n", + "\n", + "Value of y(1.50,3.00) = 35.25" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : LCS-12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter value to N : \"))\n", + "\n", + "s = 0\n", + "i = 1\n", + "\n", + "while i <= n:\n", + " s = s + i\n", + " i = i + 2\n", + " \n", + "print \"\\nSum of odd integers = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to N : 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of odd integers = 25\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : LCS-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "print \"\\nInteger divisible by 7\"\n", + "\n", + "n = 7\n", + "\n", + "for i in range(1,50+1):\n", + " sys.stdout.write(\"%8d\"%(n))\n", + " n = n + 7" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Integer 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" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : LCS-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter the end value N : \"))\n", + "\n", + "print \"\\nIntegers not divisible by 7\"\n", + "\n", + "for k in range(1,n+1):\n", + " r = k % 7\n", + " if r != 0:\n", + " sys.stdout.write(\"%8d\"%(k))\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the end value N : 20\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : LCS-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter a positive integer : \"))\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", + "print \"\\nSum of digits = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a positive integer : 2466\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of digits = 18\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : LCS-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter an integer number : \"))\n", + "\n", + "q = n\n", + "s = 0\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 \"\\n\",n,\" is an Armstrong number\"\n", + "else:\n", + " print \"\\n\",n,\" is not an Armstrong number\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter an integer number : 153\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "153 is an Armstrong number\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : LCS-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter an integer number : \"))\n", + "\n", + "q = n\n", + "rn = 0\n", + "\n", + "while q > 0:\n", + " r = q % 10\n", + " rn = rn*10 + r\n", + " q = q/10\n", + " \n", + "print \"\\n\",n,\" is reversed as \",rn" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter an integer number : 18532\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "18532 is reversed as 23581\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : LCS-18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter an integer number : \"))\n", + "\n", + "q = n\n", + "rn = 0\n", + "\n", + "while q > 0:\n", + " r = q % 10\n", + " rn = rn*10 + r\n", + " q = q/10\n", + "\n", + "while 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter an integer number : 4352\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Four\n", + "Three\n", + "Five\n", + "Two\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : LCS-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "flag = 0\n", + "\n", + "n = int(raw_input(\"\\nEnter a positive integer : \"))\n", + "\n", + "for k in range(2,n/2+1):\n", + " if flag == 0:\n", + " r = n % k\n", + " if r == 0:\n", + " flag = 1\n", + " \n", + "if flag == 0:\n", + " print \"\\n\",n,\" is a prime number\"\n", + "else:\n", + " print \"\\n\",n,\" is not a prime number\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a positive integer : 17\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "17 is a prime number\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14, Page Number : LCS-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter the final term of the series : \"))\n", + "\n", + "n1 = 0\n", + "n2 = 1\n", + "\n", + "sys.stdout.write(\"%8d%8d\"%(n1,n2))\n", + "\n", + "newterm = n1 + n2\n", + "\n", + "while newterm <= n:\n", + " sys.stdout.write(\"%8d\"%(newterm))\n", + " n1 = n2\n", + " n2 = newterm\n", + " newterm = n1 + n2\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the final term of the series : 25\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 0 1 1 2 3 5 8 13 21" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 15, Page Number : LCS-22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "x = float(raw_input(\"\\nEnter x in radians : \"))\n", + "n = int(raw_input(\"\\nEnter end term power (n) : \"))\n", + "\n", + "s = 0\n", + "term = x\n", + "i = 1\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 \"\\nSum of the series = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter x in radians : 0.52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter end term power (n) : 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of the series = 0.496880137863\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 16, Page Number : LCS-24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "x = float(raw_input(\"\\nEnter x in radians : \"))\n", + "\n", + "s = 0\n", + "term = 1\n", + "i = 0\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 \"\\nSum of the series = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter x in radians : 0.52\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of the series = 0.867819179677\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 17, Page Number : LCS-25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "s = 0\n", + "dr = 1\n", + "sign = 1\n", + "term = 1.0/dr * sign\n", + "\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", + "sys.stdout.write(\"\\nValue of pie is %0.2f\"%(pie))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of pie is 3.14" + ] + } + ], + "prompt_number": 27 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 18, Page Number : LCS-27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter value to N : \"))\n", + "\n", + "s = 0\n", + "\n", + "for i in range(1,n+1):\n", + " s = s + 1.0/i\n", + " \n", + "sys.stdout.write(\"\\nSum of series = %8.4f\"%(s))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to N : 15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of series = 3.3182" + ] + } + ], + "prompt_number": 29 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 19, Page Number : LCS-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nHow many lines ? \"))\n", + "\n", + "for 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many lines ? 5\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 35 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 20, Page Number : LCS-29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nHow many rows ? \"))\n", + "\n", + "print \"\\n\\t\\t\\t\\t PASCAL TRIANGLE\\n\"\n", + "\n", + "m = 1\n", + "\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 21, Page Number : LCS-31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "for 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...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 22, Page Number : LCS-32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "n = int(raw_input(\"\\nEnter the binary number : \"))\n", + "\n", + "q = n\n", + "s = 0\n", + "k = 0\n", + "\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", + "print \"\\nThe decimal number is : \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the binary number : 1101\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The decimal number is : 13\n" + ] + } + ], + "prompt_number": 40 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : LCS-34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "flag = 0\n", + "k = 0\n", + "\n", + "n = int(raw_input(\"\\nEnter the decimal number : \"))\n", + "\n", + "q = n\n", + "rbi = 0\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", + "\n", + "while 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", + " \n", + "print \"\\nThe binary number is \",bi" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the decimal number : 28\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The binary number is 11100\n" + ] + } + ], + "prompt_number": 41 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_1.ipynb new file mode 100755 index 00000000..e2aad83c --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_1.ipynb @@ -0,0 +1,1304 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 6: Loop Control Structures in C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : LCS-2" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter value to n : \"))\n", + "\n", + "for i in range(1,n+1):\n", + " sys.stdout.write(\"%8d\"%(i))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to n : 15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : LCS-3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import numpy\n", + "import math\n", + "\n", + "print \"\\n--------------------------------\"\n", + "print \" X Y \"\n", + "print \"--------------------------------\"\n", + "\n", + "for 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", + " \n", + "print \"\\n--------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : LCS-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "k = int(raw_input(\"\\nEnter the number : \"))\n", + "\n", + "kfact = 1\n", + "\n", + "for i in range(1,k+1):\n", + " kfact = kfact * i\n", + " \n", + "print k,\" factorial is \",kfact" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the number : 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4 factorial is 24\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : LCS-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter value to N : \"))\n", + "\n", + "s = 0\n", + "\n", + "for 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", + " \n", + "print \"\\nSum of the series S = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to N : 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of the series S = 20\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : LCS-7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy\n", + "import sys\n", + "\n", + "for 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))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Value of y(-1.50,0.00) = -18.75\n", + "\n", + "Value of y(-1.50,1.00) = -16.75\n", + "\n", + "Value of y(-1.50,2.00) = -2.75\n", + "\n", + "Value of y(-1.50,3.00) = 35.25\n", + "\n", + "Value of y(-1.00,0.00) = -22.50\n", + "\n", + "Value of y(-1.00,1.00) = -20.50\n", + "\n", + "Value of y(-1.00,2.00) = -6.50\n", + "\n", + "Value of y(-1.00,3.00) = 31.50\n", + "\n", + "Value of y(-0.50,0.00) = -24.75\n", + "\n", + "Value of y(-0.50,1.00) = -22.75\n", + "\n", + "Value of y(-0.50,2.00) = -8.75\n", + "\n", + "Value of y(-0.50,3.00) = 29.25\n", + "\n", + "Value of y(0.00,0.00) = -25.50\n", + "\n", + "Value of y(0.00,1.00) = -23.50\n", + "\n", + "Value of y(0.00,2.00) = -9.50\n", + "\n", + "Value of y(0.00,3.00) = 28.50\n", + "\n", + "Value of y(0.50,0.00) = -24.75\n", + "\n", + "Value of y(0.50,1.00) = -22.75\n", + "\n", + "Value of y(0.50,2.00) = -8.75\n", + "\n", + "Value of y(0.50,3.00) = 29.25\n", + "\n", + "Value of y(1.00,0.00) = -22.50\n", + "\n", + "Value of y(1.00,1.00) = -20.50\n", + "\n", + "Value of y(1.00,2.00) = -6.50\n", + "\n", + "Value of y(1.00,3.00) = 31.50\n", + "\n", + "Value of y(1.50,0.00) = -18.75\n", + "\n", + "Value of y(1.50,1.00) = -16.75\n", + "\n", + "Value of y(1.50,2.00) = -2.75\n", + "\n", + "Value of y(1.50,3.00) = 35.25" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : LCS-12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter value to N : \"))\n", + "\n", + "s = 0\n", + "i = 1\n", + "\n", + "while i <= n:\n", + " s = s + i\n", + " i = i + 2\n", + " \n", + "print \"\\nSum of odd integers = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to N : 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of odd integers = 25\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : LCS-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "print \"\\nInteger divisible by 7\"\n", + "\n", + "n = 7\n", + "\n", + "for i in range(1,50+1):\n", + " sys.stdout.write(\"%8d\"%(n))\n", + " n = n + 7" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Integer 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" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : LCS-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter the end value N : \"))\n", + "\n", + "print \"\\nIntegers not divisible by 7\"\n", + "\n", + "for k in range(1,n+1):\n", + " r = k % 7\n", + " if r != 0:\n", + " sys.stdout.write(\"%8d\"%(k))\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the end value N : 20\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : LCS-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter a positive integer : \"))\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", + "print \"\\nSum of digits = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a positive integer : 2466\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of digits = 18\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : LCS-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter an integer number : \"))\n", + "\n", + "q = n\n", + "s = 0\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 \"\\n\",n,\" is an Armstrong number\"\n", + "else:\n", + " print \"\\n\",n,\" is not an Armstrong number\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter an integer number : 153\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "153 is an Armstrong number\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : LCS-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter an integer number : \"))\n", + "\n", + "q = n\n", + "rn = 0\n", + "\n", + "while q > 0:\n", + " r = q % 10\n", + " rn = rn*10 + r\n", + " q = q/10\n", + " \n", + "print \"\\n\",n,\" is reversed as \",rn" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter an integer number : 18532\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "18532 is reversed as 23581\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : LCS-18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n = int(raw_input(\"\\nEnter an integer number : \"))\n", + "\n", + "q = n\n", + "rn = 0\n", + "\n", + "while q > 0:\n", + " r = q % 10\n", + " rn = rn*10 + r\n", + " q = q/10\n", + "\n", + "while 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter an integer number : 4352\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Four\n", + "Three\n", + "Five\n", + "Two\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : LCS-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "flag = 0\n", + "\n", + "n = int(raw_input(\"\\nEnter a positive integer : \"))\n", + "\n", + "for k in range(2,n/2+1):\n", + " if flag == 0:\n", + " r = n % k\n", + " if r == 0:\n", + " flag = 1\n", + " \n", + "if flag == 0:\n", + " print \"\\n\",n,\" is a prime number\"\n", + "else:\n", + " print \"\\n\",n,\" is not a prime number\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a positive integer : 17\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "17 is a prime number\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14, Page Number : LCS-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter the final term of the series : \"))\n", + "\n", + "n1 = 0\n", + "n2 = 1\n", + "\n", + "sys.stdout.write(\"%8d%8d\"%(n1,n2))\n", + "\n", + "newterm = n1 + n2\n", + "\n", + "while newterm <= n:\n", + " sys.stdout.write(\"%8d\"%(newterm))\n", + " n1 = n2\n", + " n2 = newterm\n", + " newterm = n1 + n2\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the final term of the series : 25\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 0 1 1 2 3 5 8 13 21" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 15, Page Number : LCS-22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "x = float(raw_input(\"\\nEnter x in radians : \"))\n", + "n = int(raw_input(\"\\nEnter end term power (n) : \"))\n", + "\n", + "s = 0\n", + "term = x\n", + "i = 1\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 \"\\nSum of the series = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter x in radians : 0.52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter end term power (n) : 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of the series = 0.496880137863\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 16, Page Number : LCS-24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "x = float(raw_input(\"\\nEnter x in radians : \"))\n", + "\n", + "s = 0\n", + "term = 1\n", + "i = 0\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 \"\\nSum of the series = \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter x in radians : 0.52\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of the series = 0.867819179677\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 17, Page Number : LCS-25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "s = 0\n", + "dr = 1\n", + "sign = 1\n", + "term = 1.0/dr * sign\n", + "\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", + "sys.stdout.write(\"\\nValue of pie is %0.2f\"%(pie))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of pie is 3.14" + ] + } + ], + "prompt_number": 27 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 18, Page Number : LCS-27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nEnter value to N : \"))\n", + "\n", + "s = 0\n", + "\n", + "for i in range(1,n+1):\n", + " s = s + 1.0/i\n", + " \n", + "sys.stdout.write(\"\\nSum of series = %8.4f\"%(s))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to N : 15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of series = 3.3182" + ] + } + ], + "prompt_number": 29 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 19, Page Number : LCS-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nHow many lines ? \"))\n", + "\n", + "for 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" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many lines ? 5\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 35 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 20, Page Number : LCS-29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "n = int(raw_input(\"\\nHow many rows ? \"))\n", + "\n", + "print \"\\n\\t\\t\\t\\t PASCAL TRIANGLE\\n\"\n", + "\n", + "m = 1\n", + "\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 21, Page Number : LCS-31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "for 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...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue...\n", + "\n", + "Multiplication 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", + "\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 22, Page Number : LCS-32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "n = int(raw_input(\"\\nEnter the binary number : \"))\n", + "\n", + "q = n\n", + "s = 0\n", + "k = 0\n", + "\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", + "print \"\\nThe decimal number is : \",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the binary number : 1101\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The decimal number is : 13\n" + ] + } + ], + "prompt_number": 40 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : LCS-34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "flag = 0\n", + "k = 0\n", + "\n", + "n = int(raw_input(\"\\nEnter the decimal number : \"))\n", + "\n", + "q = n\n", + "rbi = 0\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", + "\n", + "while 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", + " \n", + "print \"\\nThe binary number is \",bi" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the decimal number : 28\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The binary number is 11100\n" + ] + } + ], + "prompt_number": 41 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7.ipynb new file mode 100755 index 00000000..aa78904d --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7.ipynb @@ -0,0 +1,1655 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 7: Arrays and Subscripted Variables" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : ASV-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many integers ? \"))\n", + "x = [0 for i in range(0,n)]\n", + "\n", + "for 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\n", + "sum1 = 0\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nSum of all integers = %d\"%(sum1))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many integers ? 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 1th value : 36\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 2th value : 45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 3th value : 52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 4th value : 44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 5th value : 62\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of all integers = 239" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : ASV-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable initialization\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "sys.stdout.write(\"\\nEnter all those numbers \")\n", + "x = [0 for i in range(0,n)]\n", + "\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "big = x[0]\n", + "for i in range(0,n):\n", + " if x[i] > big:\n", + " big = x[i]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\n%d is the biggest number\"%(big))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all those numbers " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-228\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "185\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "36\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "185 is the biggest number" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : ASV-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "x = [0.0 for i in range(0,n)]\n", + "\n", + "sys.stdout.write(\"\\nEnter all values in the list\\n\")\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "sum1 = 0\n", + "#Since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + "xbar = sum1 / n\n", + "vsum = 0\n", + "\n", + "for i in range(0,n):\n", + " vsum = vsum + (x[i] - xbar) * (x[i] - xbar)\n", + "sigmax = vsum / n\n", + "sd = math.sqrt(sigmax)\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(xbar))\n", + "sys.stdout.write(\"\\nVariance = %0.3f\"%(sigmax))\n", + "sys.stdout.write(\"\\nStandard deviation = %0.3f\"%(sd))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Arithmetic mean = 3.617\n", + "Variance = 0.088\n", + "Standard deviation = 0.297" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : ASV-8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter all the marks \\n\")\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "sum1 = 0.0\n", + "#Since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + " \n", + "mean = float(sum1/n)\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\nMean = %6.2f\"%(mean))\n", + "sys.stdout.write(\"\\n\\nMarks greater than mean : \")\n", + "\n", + "for i in range(0,n):\n", + " if x[i] > mean:\n", + " sys.stdout.write(\"%5d\"%(x[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all the marks \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "58\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "63\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "68\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "54\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "48\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Mean = 58.20\n", + "\n", + "Marks greater than mean : 63 68" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : ASV-9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter all values in the list \\n\")\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + " \n", + "psum = 0\n", + "nsum = 0\n", + "\n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nSum of positive values = %0.2f\"%(psum))\n", + "sys.stdout.write(\"\\nSum of negative values = %0.2f\"%(nsum))\n", + "if psum > math.fabs(nsum):\n", + " sys.stdout.write(\"\\nPositive sum is greater in magnitude\")\n", + "else:\n", + " sys.stdout.write(\"\\nNegative sum is greater in magnitude\")\n", + " \n", + "diff = math.fabs(psum - math.fabs(nsum))\n", + "sys.stdout.write(\"\\nDifference in magnitude = %0.2f\"%(diff))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-16\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : ASV-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"How many numbers ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter the list of %d numbers\\n\"%(n))\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nNumbers in ascending order\\n\")\n", + "for i in range(0,n):\n", + " sys.stdout.write(\"%5d\"%(x[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "How many numbers ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the list of 4 numbers\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Numbers in ascending order\n", + " -10 5 20 32" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : ASV-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = [0 for i in range(0,50)]\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many values in the list ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter all values in the list\\n\")\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + "s = int(raw_input(\"\\nEnter the key value to be searched : \"))\n", + "\n", + "#Processing\n", + "for 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", + " \n", + "if i == n+1:\n", + " sys.stdout.write(\"\\nThe key value %d is not present in the list\"%(s))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values in the list ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the key value to be searched : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "3 is available in 4th location" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : ASV-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "exchng = 0\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "sys.stdout.write(\"\\nEnter all numbers in the list\\n\")\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + "\n", + "#Processing\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", + "#Output\n", + "sys.stdout.write(\"\\nThe sorted list is\\n\")\n", + "for i in range(0,n):\n", + " sys.stdout.write(\"%5d\"%(x[i]))\n", + " \n", + "sys.stdout.write(\"\\nSorted in %d passes and %d exchanges\"%(n-1,exchng))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all numbers in the list\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The sorted list is\n", + " -2 3 6 8\n", + "Sorted in 3 passes and 3 exchanges" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : ASV-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nHow many rows and columns ? \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "b = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "c = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "\n", + "sys.stdout.write(\"\\nEnter A matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + " \n", + "sys.stdout.write(\"\\nEnter B matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " b[i][j] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nResultant matrix is \\n\")\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns ? 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\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": [ + "\n", + "Enter B matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + " 8 0\n", + " 4 -1\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : ASV-18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of A matrix : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "b = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "c = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "\n", + "sys.stdout.write(\"\\nEnter A matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "n = int(raw_input(\"\\nEnter order of B matrix : \"))\n", + "l = int(raw_input(\"\"))\n", + "\n", + "sys.stdout.write(\"\\nEnter B matrix\\n\")\n", + "for i in range(0,n):\n", + " for j in range(0,l):\n", + " b[i][j] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nResultant matrix is \\n\")\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of A matrix : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of B matrix : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter B matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + " 4 14\n", + " 16 -20\n" + ] + } + ], + "prompt_number": 34 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : ASV-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of the matrix : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "at = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "\n", + "sys.stdout.write(\"\\nEnter the matrix values\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "#Processing\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " at[j][i] = a[i][j]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nThe transposed matrix is\\n\")\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of the matrix : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix values\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\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": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The transposed matrix is\n", + " -3 3\n", + " 6 2\n", + " 0 8\n" + ] + } + ], + "prompt_number": 35 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : ASV-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of the square matrix : \"))\n", + "\n", + "a = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "\n", + "sys.stdout.write(\"\\nEnter the matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,m):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "#Processing\n", + "flag = 0\n", + "for 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\n", + "if flag == 0:\n", + " sys.stdout.write(\"\\nThe given matrix is a symmetric matrix\")\n", + "else:\n", + " sys.stdout.write(\"\\nThe given matrix is not a symmetric matrix\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of the square matrix : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\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": [ + "-7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The given matrix is a symmetric matrix" + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : ASV-23" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of the square matrix : \"))\n", + "\n", + "a = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "\n", + "sys.stdout.write(\"\\nEnter the matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,m):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "#Processing \n", + "sum1 = 0\n", + "#since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,m):\n", + " sum1 = sum1 + a[i][i]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nTrace of the matrix = %d\"%(sum1))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of the square matrix : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix\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": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\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": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Trace of the matrix = 6" + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_1.ipynb new file mode 100755 index 00000000..aa78904d --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_1.ipynb @@ -0,0 +1,1655 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 7: Arrays and Subscripted Variables" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number : ASV-4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many integers ? \"))\n", + "x = [0 for i in range(0,n)]\n", + "\n", + "for 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\n", + "sum1 = 0\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nSum of all integers = %d\"%(sum1))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many integers ? 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 1th value : 36\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 2th value : 45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 3th value : 52\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 4th value : 44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 5th value : 62\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of all integers = 239" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number : ASV-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable initialization\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "sys.stdout.write(\"\\nEnter all those numbers \")\n", + "x = [0 for i in range(0,n)]\n", + "\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "big = x[0]\n", + "for i in range(0,n):\n", + " if x[i] > big:\n", + " big = x[i]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\n%d is the biggest number\"%(big))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all those numbers " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-228\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "185\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "36\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "185 is the biggest number" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number : ASV-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "x = [0.0 for i in range(0,n)]\n", + "\n", + "sys.stdout.write(\"\\nEnter all values in the list\\n\")\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "sum1 = 0\n", + "#Since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + "xbar = sum1 / n\n", + "vsum = 0\n", + "\n", + "for i in range(0,n):\n", + " vsum = vsum + (x[i] - xbar) * (x[i] - xbar)\n", + "sigmax = vsum / n\n", + "sd = math.sqrt(sigmax)\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(xbar))\n", + "sys.stdout.write(\"\\nVariance = %0.3f\"%(sigmax))\n", + "sys.stdout.write(\"\\nStandard deviation = %0.3f\"%(sd))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Arithmetic mean = 3.617\n", + "Variance = 0.088\n", + "Standard deviation = 0.297" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number : ASV-8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many students ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter all the marks \\n\")\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "sum1 = 0.0\n", + "#Since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,n):\n", + " sum1 = sum1 + x[i]\n", + " \n", + "mean = float(sum1/n)\n", + "\n", + "#Output\n", + "sys.stdout.write(\"\\nMean = %6.2f\"%(mean))\n", + "sys.stdout.write(\"\\n\\nMarks greater than mean : \")\n", + "\n", + "for i in range(0,n):\n", + " if x[i] > mean:\n", + " sys.stdout.write(\"%5d\"%(x[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many students ? 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all the marks \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "58\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "63\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "68\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "54\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "48\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Mean = 58.20\n", + "\n", + "Marks greater than mean : 63 68" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number : ASV-9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "import math\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many values ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter all values in the list \\n\")\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + " \n", + "psum = 0\n", + "nsum = 0\n", + "\n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nSum of positive values = %0.2f\"%(psum))\n", + "sys.stdout.write(\"\\nSum of negative values = %0.2f\"%(nsum))\n", + "if psum > math.fabs(nsum):\n", + " sys.stdout.write(\"\\nPositive sum is greater in magnitude\")\n", + "else:\n", + " sys.stdout.write(\"\\nNegative sum is greater in magnitude\")\n", + " \n", + "diff = math.fabs(psum - math.fabs(nsum))\n", + "sys.stdout.write(\"\\nDifference in magnitude = %0.2f\"%(diff))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-16\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\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" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number : ASV-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"How many numbers ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter the list of %d numbers\\n\"%(n))\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nNumbers in ascending order\\n\")\n", + "for i in range(0,n):\n", + " sys.stdout.write(\"%5d\"%(x[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "How many numbers ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the list of 4 numbers\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Numbers in ascending order\n", + " -10 5 20 32" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number : ASV-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "x = [0 for i in range(0,50)]\n", + "\n", + "#Variable Initialization\n", + "n = int(raw_input(\"\\nHow many values in the list ? \"))\n", + "\n", + "sys.stdout.write(\"\\nEnter all values in the list\\n\")\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + "s = int(raw_input(\"\\nEnter the key value to be searched : \"))\n", + "\n", + "#Processing\n", + "for 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", + " \n", + "if i == n+1:\n", + " sys.stdout.write(\"\\nThe key value %d is not present in the list\"%(s))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values in the list ? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values in the list\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the key value to be searched : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "3 is available in 4th location" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number : ASV-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable Initialization\n", + "exchng = 0\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "sys.stdout.write(\"\\nEnter all numbers in the list\\n\")\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + "\n", + "#Processing\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", + "#Output\n", + "sys.stdout.write(\"\\nThe sorted list is\\n\")\n", + "for i in range(0,n):\n", + " sys.stdout.write(\"%5d\"%(x[i]))\n", + " \n", + "sys.stdout.write(\"\\nSorted in %d passes and %d exchanges\"%(n-1,exchng))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all numbers in the list\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The sorted list is\n", + " -2 3 6 8\n", + "Sorted in 3 passes and 3 exchanges" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number : ASV-17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nHow many rows and columns ? \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "b = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "c = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "\n", + "sys.stdout.write(\"\\nEnter A matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + " \n", + "sys.stdout.write(\"\\nEnter B matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " b[i][j] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nResultant matrix is \\n\")\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns ? 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\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": [ + "\n", + "Enter B matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + " 8 0\n", + " 4 -1\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number : ASV-18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of A matrix : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "b = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "c = [[0 for i in range(0,m)] for j in range(0,n)]\n", + "\n", + "sys.stdout.write(\"\\nEnter A matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "n = int(raw_input(\"\\nEnter order of B matrix : \"))\n", + "l = int(raw_input(\"\"))\n", + "\n", + "sys.stdout.write(\"\\nEnter B matrix\\n\")\n", + "for i in range(0,n):\n", + " for j in range(0,l):\n", + " b[i][j] = int(raw_input(\"\"))\n", + " \n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\nResultant matrix is \\n\")\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of A matrix : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of B matrix : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter B matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + " 4 14\n", + " 16 -20\n" + ] + } + ], + "prompt_number": 34 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number : ASV-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of the matrix : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "at = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "\n", + "sys.stdout.write(\"\\nEnter the matrix values\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "#Processing\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " at[j][i] = a[i][j]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nThe transposed matrix is\\n\")\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of the matrix : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix values\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\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": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The transposed matrix is\n", + " -3 3\n", + " 6 2\n", + " 0 8\n" + ] + } + ], + "prompt_number": 35 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number : ASV-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of the square matrix : \"))\n", + "\n", + "a = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "\n", + "sys.stdout.write(\"\\nEnter the matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,m):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "#Processing\n", + "flag = 0\n", + "for 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\n", + "if flag == 0:\n", + " sys.stdout.write(\"\\nThe given matrix is a symmetric matrix\")\n", + "else:\n", + " sys.stdout.write(\"\\nThe given matrix is not a symmetric matrix\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of the square matrix : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\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": [ + "-7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The given matrix is a symmetric matrix" + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number : ASV-23" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "#Variable declaration and initialization\n", + "\n", + "m = int(raw_input(\"\\nEnter order of the square matrix : \"))\n", + "\n", + "a = [[0 for i in range(0,10)] for j in range(0,10)]\n", + "\n", + "sys.stdout.write(\"\\nEnter the matrix\\n\")\n", + "for i in range(0,m):\n", + " for j in range(0,m):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "#Processing \n", + "sum1 = 0\n", + "#since sum is a predefined function in python, sum1 is used\n", + "for i in range(0,m):\n", + " sum1 = sum1 + a[i][i]\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nTrace of the matrix = %d\"%(sum1))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of the square matrix : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix\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": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\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": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Trace of the matrix = 6" + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8.ipynb new file mode 100755 index 00000000..2121f615 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8.ipynb @@ -0,0 +1,665 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter 8: String Manipulations in C

" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 1, Page number: SMC-4

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Count a character in a string\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter the string : \")\n", + "ch = raw_input(\"Which char to be counted ?\")\n", + "\n", + "#Checking\n", + "l = len(st)\n", + "count = 0\n", + "for i in st:\n", + " if i == ch:\n", + " count = count + 1\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nThe character %c occurs %d times\"%(ch,count))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the string : MISSISSIPPI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Which char to be counted ?S\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The character S occurs 4 times" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 2, Page number: SMC-5

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Counting vowels\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter the sentence :\")\n", + "count = 0\n", + "\n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"%d vowels are present in the sentence\"%(count))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the sentence :This is a book\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 vowels are present in the sentence" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 3, Page number: SMC-6

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Palindrome or not \n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "rst = ['' for i in range(0,20)]\n", + "st = raw_input(\"Enter the string : \")\n", + "j = len(st)-1\n", + "\n", + "#Processing\n", + "rst = st[::-1]\n", + "\n", + "#Result\n", + "if st == rst:\n", + " sys.stdout.write(\"%s is a palindrome string\"%(st))\n", + "else:\n", + " sys.stdout.write(\"%s is not a palindrome string\"%(st))\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the string : HYDERABAD\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "HYDERABAD is not a palindrome string" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 4, Page number: SMC-8

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#String Concatenation\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st1 = raw_input(\"Enter first string : \")\n", + "st2 = raw_input(\"Enter second string : \")\n", + "\n", + "#Processing\n", + "st = st1 + \" \" + st2\n", + "\n", + "#Result\n", + "sys.stdout.write(\"\\nResultant string is %s\"%(st))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter first string : NEW\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter second string : DELHI\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant string is NEW DELHI" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 5, Page number: SMC-10

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Print greater string\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st1 = raw_input(\"Enter string 1 : \")\n", + "st2 = raw_input(\"Enter string 2 : \")\n", + "\n", + "\n", + "#Result\n", + "if st1 > st2:\n", + " sys.stdout.write(\"%s is alphabetically greater string\"%(st1))\n", + "else:\n", + " sys.stdout.write(\"%s is alphabetically greater string\"%(st2))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter string 1 : ALPHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter string 2 : BETA\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "BETA is alphabetically greater string" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 6, Page number: SMC-11

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#String sorting\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "names = [\"\" for i in range(0,50)]\n", + "n = int(raw_input(\"How many names ? \"))\n", + "sys.stdout.write(\"\\nEnter the %d names one by one\"%(n))\n", + "\n", + "for i in range(0,n):\n", + " names[i] = raw_input(\"\")\n", + " \n", + "for 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\n", + "sys.stdout.write(\"\\nNames in alphabetical order\")\n", + "for i in range(0,n):\n", + " sys.stdout.write(\"\\n%s\"%(names[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "How many names ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 4 names one by one" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SHERIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SONIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "ARUN\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Names in alphabetical order\n", + "ARUN\n", + "DEEPAK\n", + "SHERIN\n", + "SONIKA" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 7, Page number: SMC-13

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Lower case text to upper case\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter a sentence : \")\n", + "\n", + "#Result\n", + "st = st.upper()\n", + "\n", + "sys.stdout.write(\"\\nThe converted upper case string is \\n%s\"%(st))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a sentence : logical thinking is a must to learn programming\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The converted upper case string is \n", + "LOGICAL THINKING IS A MUST TO LEARN PROGRAMMING" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 8, Page number: SMC-14

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Determine the longest word\n", + "\n", + "import sys\n", + "\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter a sentence \")\n", + "\n", + "#Processing\n", + "lngst = max(st.split(), key=len)\n", + "\n", + "#Result\n", + "sys.stdout.write(\"\\nLongest word is %s\"%(lngst))\n", + "sys.stdout.write(\"\\nPress any key to continue...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a sentence SMALL THINGS MAKE PERFECTION BUT PERFECTION IS NO SMALL THING\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Longest word is PERFECTION\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 9, Page number: SMC-16

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Remove particular word in a text\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter a sentence : \")\n", + "\n", + "omit = raw_input(\"\\nEnter word to omit : \")\n", + "word = st.split()\n", + "newst = ' '.join([i for i in word if i not in omit])\n", + "\n", + "#Result\n", + "sys.stdout.write(\"\\nAfter omitting the word %s\\n%s\"%(omit,newst))\n", + "sys.stdout.write(\"\\nPress any key to continue...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a sentence : TO ACCESS THE NAME OF THE CITY IN THE LIST\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter word to omit : THE\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "After omitting the word THE\n", + "TO ACCESS NAME OF CITY IN LIST\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 10, Page number: SMC-17

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Telegram expense calculation\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Type the sentence for Telegram : \")\n", + "\n", + "count = len(st.split())\n", + "\n", + "if count <= 10:\n", + " amt = 5\n", + "else:\n", + " amt = 5 + (count - 10) * 1.25\n", + " \n", + "#Result\n", + "sys.stdout.write(\"\\nAmount to be paid for telegram = Rs. %6.2f\"%(amt))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Type the sentence for Telegram : Congratulations on your success in Examinations.\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Amount to be paid for telegram = Rs. 5.00" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 11, Page number: SMC-19

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Count lines, words and characters\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "txt = raw_input(\"Enter the text, type $st end\\n\\n\")\n", + "\n", + "wds = 0\n", + "lns = 0\n", + "chs = 0\n", + "\n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\n\\nNumber of char(incl.blanks) = %d\"%(chs))\n", + "sys.stdout.write(\"\\nNumber of words = %d\"%(wds))\n", + "sys.stdout.write(\"\\nNumber of lines = %d\"%(lns))\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the text, type $st end\n", + "\n", + "What is a string? How do you initialize it? Explain with example.$\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Number of char(incl.blanks) = 63\n", + "Number of words = 12\n", + "Number of lines = 3" + ] + } + ], + "prompt_number": 5 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_1.ipynb new file mode 100755 index 00000000..2121f615 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_1.ipynb @@ -0,0 +1,665 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter 8: String Manipulations in C

" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 1, Page number: SMC-4

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Count a character in a string\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter the string : \")\n", + "ch = raw_input(\"Which char to be counted ?\")\n", + "\n", + "#Checking\n", + "l = len(st)\n", + "count = 0\n", + "for i in st:\n", + " if i == ch:\n", + " count = count + 1\n", + " \n", + "#Output\n", + "sys.stdout.write(\"\\nThe character %c occurs %d times\"%(ch,count))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the string : MISSISSIPPI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Which char to be counted ?S\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The character S occurs 4 times" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 2, Page number: SMC-5

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Counting vowels\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter the sentence :\")\n", + "count = 0\n", + "\n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"%d vowels are present in the sentence\"%(count))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the sentence :This is a book\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 vowels are present in the sentence" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 3, Page number: SMC-6

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Palindrome or not \n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "rst = ['' for i in range(0,20)]\n", + "st = raw_input(\"Enter the string : \")\n", + "j = len(st)-1\n", + "\n", + "#Processing\n", + "rst = st[::-1]\n", + "\n", + "#Result\n", + "if st == rst:\n", + " sys.stdout.write(\"%s is a palindrome string\"%(st))\n", + "else:\n", + " sys.stdout.write(\"%s is not a palindrome string\"%(st))\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the string : HYDERABAD\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "HYDERABAD is not a palindrome string" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 4, Page number: SMC-8

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#String Concatenation\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st1 = raw_input(\"Enter first string : \")\n", + "st2 = raw_input(\"Enter second string : \")\n", + "\n", + "#Processing\n", + "st = st1 + \" \" + st2\n", + "\n", + "#Result\n", + "sys.stdout.write(\"\\nResultant string is %s\"%(st))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter first string : NEW\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter second string : DELHI\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant string is NEW DELHI" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 5, Page number: SMC-10

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Print greater string\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st1 = raw_input(\"Enter string 1 : \")\n", + "st2 = raw_input(\"Enter string 2 : \")\n", + "\n", + "\n", + "#Result\n", + "if st1 > st2:\n", + " sys.stdout.write(\"%s is alphabetically greater string\"%(st1))\n", + "else:\n", + " sys.stdout.write(\"%s is alphabetically greater string\"%(st2))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter string 1 : ALPHA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter string 2 : BETA\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "BETA is alphabetically greater string" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 6, Page number: SMC-11

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#String sorting\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "names = [\"\" for i in range(0,50)]\n", + "n = int(raw_input(\"How many names ? \"))\n", + "sys.stdout.write(\"\\nEnter the %d names one by one\"%(n))\n", + "\n", + "for i in range(0,n):\n", + " names[i] = raw_input(\"\")\n", + " \n", + "for 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\n", + "sys.stdout.write(\"\\nNames in alphabetical order\")\n", + "for i in range(0,n):\n", + " sys.stdout.write(\"\\n%s\"%(names[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "How many names ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the 4 names one by one" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "DEEPAK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SHERIN\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "SONIKA\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "ARUN\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Names in alphabetical order\n", + "ARUN\n", + "DEEPAK\n", + "SHERIN\n", + "SONIKA" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 7, Page number: SMC-13

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Lower case text to upper case\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter a sentence : \")\n", + "\n", + "#Result\n", + "st = st.upper()\n", + "\n", + "sys.stdout.write(\"\\nThe converted upper case string is \\n%s\"%(st))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a sentence : logical thinking is a must to learn programming\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The converted upper case string is \n", + "LOGICAL THINKING IS A MUST TO LEARN PROGRAMMING" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 8, Page number: SMC-14

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Determine the longest word\n", + "\n", + "import sys\n", + "\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter a sentence \")\n", + "\n", + "#Processing\n", + "lngst = max(st.split(), key=len)\n", + "\n", + "#Result\n", + "sys.stdout.write(\"\\nLongest word is %s\"%(lngst))\n", + "sys.stdout.write(\"\\nPress any key to continue...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a sentence SMALL THINGS MAKE PERFECTION BUT PERFECTION IS NO SMALL THING\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Longest word is PERFECTION\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 9, Page number: SMC-16

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Remove particular word in a text\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Enter a sentence : \")\n", + "\n", + "omit = raw_input(\"\\nEnter word to omit : \")\n", + "word = st.split()\n", + "newst = ' '.join([i for i in word if i not in omit])\n", + "\n", + "#Result\n", + "sys.stdout.write(\"\\nAfter omitting the word %s\\n%s\"%(omit,newst))\n", + "sys.stdout.write(\"\\nPress any key to continue...\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a sentence : TO ACCESS THE NAME OF THE CITY IN THE LIST\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter word to omit : THE\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "After omitting the word THE\n", + "TO ACCESS NAME OF CITY IN LIST\n", + "Press any key to continue..." + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 10, Page number: SMC-17

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Telegram expense calculation\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "st = raw_input(\"Type the sentence for Telegram : \")\n", + "\n", + "count = len(st.split())\n", + "\n", + "if count <= 10:\n", + " amt = 5\n", + "else:\n", + " amt = 5 + (count - 10) * 1.25\n", + " \n", + "#Result\n", + "sys.stdout.write(\"\\nAmount to be paid for telegram = Rs. %6.2f\"%(amt))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Type the sentence for Telegram : Congratulations on your success in Examinations.\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Amount to be paid for telegram = Rs. 5.00" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 11, Page number: SMC-19

" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Count lines, words and characters\n", + "\n", + "import sys\n", + "\n", + "#Variable Initialization\n", + "txt = raw_input(\"Enter the text, type $st end\\n\\n\")\n", + "\n", + "wds = 0\n", + "lns = 0\n", + "chs = 0\n", + "\n", + "#Processing\n", + "for 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\n", + "sys.stdout.write(\"\\n\\nNumber of char(incl.blanks) = %d\"%(chs))\n", + "sys.stdout.write(\"\\nNumber of words = %d\"%(wds))\n", + "sys.stdout.write(\"\\nNumber of lines = %d\"%(lns))\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the text, type $st end\n", + "\n", + "What is a string? How do you initialize it? Explain with example.$\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Number of char(incl.blanks) = 63\n", + "Number of words = 12\n", + "Number of lines = 3" + ] + } + ], + "prompt_number": 5 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9.ipynb new file mode 100755 index 00000000..34f208c0 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9.ipynb @@ -0,0 +1,1638 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 9: Functions in C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number: FNC-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def fact(k):\n", + " p = 1\n", + " for i in range(1,k+1):\n", + " p = p * i\n", + " return p\n", + "\n", + "n = int(raw_input(\"\\nEnter value to n and r : \"))\n", + "r = int(raw_input(\"\"))\n", + "\n", + "ncr = fact(n)/ (fact(r)*fact(n-r))\n", + "\n", + "print \"\\nValue of nCr = \",ncr" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to n and r : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of nCr = 10\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number: FNC-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + " \n", + "t1 = int(raw_input(\"\\nEnter three test scores : \"))\n", + "t2 = int(raw_input(\"\"))\n", + "t3 = int(raw_input(\"\"))\n", + "\n", + "a1 = int(raw_input(\"\\nEnter three assignment scores : \"))\n", + "a2 = int(raw_input(\"\"))\n", + "a3 = int(raw_input(\"\"))\n", + "\n", + "total = big(t1,t2,t3) + big(a1,a2,a3)\n", + "\n", + "print \"\\nTotal marks = \",total" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three test scores : 62\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "70\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "58\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three assignment scores : 17\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "23\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks = 93\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number: FNC-8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def 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", + "\n", + "x = 0\n", + "print \"\\n------------------------------------\"\n", + "print \" x in degrees cos(x) \"\n", + "print \"------------------------------------\"\n", + "\n", + "while x <= 180:\n", + " sys.stdout.write(\"\\n\\t%6.0f %6.2f\"%(x,cosine(x)))\n", + " x = x + 30\n", + " \n", + "print \"\\n------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number: FNC-9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "a = int(raw_input(\"\\nEnter three integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "c = int(raw_input(\"\"))\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 \"\\nGreatest common divisor is \",d1\n", + " else:\n", + " print \"\\nGreatest common divisor is \",gcd(d1,d3)\n", + "else:\n", + " print \"\\nGreatest common divisor is \",gcd(d1,d2)\n", + " \n", + "print \"\\n\\nPress any key to continue...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three integers : 45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "27\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "81\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Greatest common divisor is 9\n", + "\n", + "\n", + "Press any key to continue...\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number: FNC-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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 = int(raw_input(\"\\nEnter the integer : \"))\n", + "\n", + "print \"\\n\",n,\" is erversed as \",reverse(n)\n", + "print \"\\nPress any key to continue...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the integer : 2846\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "2846 is erversed as 6482\n", + "\n", + "Press any key to continue...\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number: FNC-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + " \n", + "s1 = raw_input(\"\\nEnter the first string : \")\n", + "s2 = raw_input(\"\\nEnter the second string : \")\n", + "\n", + "print \"\\nThe result is \",compare(s1,s2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the first string : MUMBAI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the second string : MYSORE\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The result is -1\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number: FNC-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def amean(x,n):\n", + " s = 0\n", + " for i in range(0,n):\n", + " s = s + x[i]\n", + " return s/n\n", + "\n", + "n = int(raw_input(\"\\nHow many values? \"))\n", + "print \"\\nEnter all values\\n\"\n", + "\n", + "x = [0.0 for i in range(0,10)]\n", + "\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + " \n", + "sys.stdout.write(\"\\nArithmetic mean = %6.2f\"%(amean(x,n)))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Arithmetic mean = 3.62" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number: FNC-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "m = int(raw_input(\"\\nHow many rows and columns : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,10)] for i in range(0,10)]\n", + "\n", + "print \"\\nEnter the matrix values\\n\"\n", + "\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "\n", + "print \"\\nSum of all elements in the matrix = \",elem_sum(a,m,n)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns : 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix values\n", + "\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": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of all elements in the matrix = 12\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number: FNC-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "st = raw_input(\"\\nEnter a string : \")\n", + "\n", + "print \"\\n\",st,\" is reversed as \",reverse(st)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : NEW DELHI\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \n", + "NEW DELHI is reversed as IHLED WEN\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number: FNC-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "\n", + "print \"\\nEnter all numbers in the list\\n\"\n", + "\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "s = int(raw_input(\"\\nEnter the number to be searched : \"))\n", + "\n", + "if bi_search(x,n,s):\n", + " print \"\\nThe number \",s,\" is present in the list\"\n", + "else:\n", + " print \"\\nThe number \",s,\" is not present in the list\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all numbers in the list\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "19\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "26\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "29\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "35\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the number to be searched : 19\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The number 19 is present in the list\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number: FNC-19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def fact(k):\n", + " if k == 1:\n", + " return 1\n", + " else:\n", + " return k*fact(k-1)\n", + " \n", + "n = int(raw_input(\"\\nEnter values to n and r : \"))\n", + "r = int(raw_input(\"\"))\n", + "\n", + "ncr = fact(n)/(fact(r)*fact(n-r))\n", + "\n", + "print \"\\nValue of nCr = \",ncr\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter values to n and r : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of nCr = 10\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number: FNC-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def power(x,n):\n", + " if n == 1:\n", + " return x\n", + " else:\n", + " return x*power(x,n-1)\n", + " \n", + "x = float(raw_input(\"\\nEnter value to x : \"))\n", + "n = int(raw_input(\"\\nEnter its power : \"))\n", + "\n", + "sys.stdout.write(\"\\n%6.2f raise to %d is %6.2f\"%(x,n,power(x,n)))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to x : 4.2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter its power : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " 4.20 raise to 3 is 74.09" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number: FNC-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "\n", + "def 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", + " \n", + "n = int(raw_input(\"\\nHow many terms to be printed ? \"))\n", + "t1 = 0\n", + "t2 = 1\n", + "\n", + "print \"\\nThe first \",n,\" terms in Fibonacci series are\\n\"\n", + "sys.stdout.write(\"%5d %5d\"%(t1,t2))\n", + "\n", + "count = 2\n", + "fibo(t1,t2,count)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many terms to be printed ? 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The first 10 terms in Fibonacci series are\n", + "\n", + " 0 1 1 2 3 5 8 13 21 34" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14, Page Number: FNC-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def matadd():\n", + " for i in xrange(m):\n", + " for j in xrange(n):\n", + " c[i][j] = a[i][j] + b[i][j]\n", + " \n", + "m = int(raw_input(\"\\nHow many rows and columns ?\"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "b = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "c = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "\n", + "#Read matrices\n", + "print \"\\nEnter A matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + " \n", + "print \"\\nEnter B matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " b[i][j] = int(raw_input(\"\"))\n", + "\n", + "matadd()\n", + "\n", + "print \"\\nResultant matrix is \\n\"\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns ?2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\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": [ + "\n", + "Enter B matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + "\n", + " 8 0\n", + " 4 -1\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 15, Page Number: FNC-29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def 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", + " \n", + "m = int(raw_input(\"\\nEnter order of A matrix (m x n) : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "\n", + "a = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "b = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "c = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "\n", + "#Read matrices\n", + "print \"\\nEnter A matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "n = int(raw_input(\"\\nEnter order of B matrix (n x l) : \"))\n", + "l = int(raw_input(\"\"))\n", + "\n", + "print \"\\nEnter B matrix values\\n\"\n", + "for i in range(0,n):\n", + " for j in range(0,l):\n", + " b[i][j] = int(raw_input(\"\"))\n", + "\n", + "matmul()\n", + "\n", + "print \"\\nResultant matrix is \\n\"\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of A matrix (m x n) : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of B matrix (n x l) : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter B matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + "\n", + " 4 14\n", + " 16 -20\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 16, Page Number: FNC-31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "at = [[0,0],[0,0],[0,0]]\n", + "\n", + "def transpose():\n", + " for i in xrange(m):\n", + " for j in xrange(n):\n", + " at[j][i] = a[i][j] \n", + " \n", + "m = int(raw_input(\"\\nHow many rows and columns ?\"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "print \"\\nEnter the matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "transpose()\n", + "\n", + "print \"\\nTranspose of the matrix is \\n\"\n", + "for i in xrange(n):\n", + " for j in xrange(m):\n", + " sys.stdout.write(\"%5d\"%(at[i][j]))\n", + " sys.stdout.write(\"\\n\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns ?2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\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": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Transpose of the matrix is \n", + "\n", + " -3 3\n", + " 6 2\n", + " 0 8\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 17, Page Number: FNC-32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "\n", + "def 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", + " \n", + "x = [0 for i in range(0,50)]\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "print \"\\nEnter the list of values\\n\"\n", + "\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + "\n", + "sort()\n", + "\n", + "print \"\\nThe sorted list is\\n\"\n", + "\n", + "for i in xrange(n):\n", + " sys.stdout.write(\"%5d\"%(x[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the list of values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The sorted list is\n", + "\n", + " -10 5 20 32" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_1.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_1.ipynb new file mode 100755 index 00000000..34f208c0 --- /dev/null +++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_1.ipynb @@ -0,0 +1,1638 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 9: Functions in C" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, Page Number: FNC-5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def fact(k):\n", + " p = 1\n", + " for i in range(1,k+1):\n", + " p = p * i\n", + " return p\n", + "\n", + "n = int(raw_input(\"\\nEnter value to n and r : \"))\n", + "r = int(raw_input(\"\"))\n", + "\n", + "ncr = fact(n)/ (fact(r)*fact(n-r))\n", + "\n", + "print \"\\nValue of nCr = \",ncr" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to n and r : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of nCr = 10\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, Page Number: FNC-6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + " \n", + "t1 = int(raw_input(\"\\nEnter three test scores : \"))\n", + "t2 = int(raw_input(\"\"))\n", + "t3 = int(raw_input(\"\"))\n", + "\n", + "a1 = int(raw_input(\"\\nEnter three assignment scores : \"))\n", + "a2 = int(raw_input(\"\"))\n", + "a3 = int(raw_input(\"\"))\n", + "\n", + "total = big(t1,t2,t3) + big(a1,a2,a3)\n", + "\n", + "print \"\\nTotal marks = \",total" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three test scores : 62\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "70\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "58\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three assignment scores : 17\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "23\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total marks = 93\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, Page Number: FNC-8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def 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", + "\n", + "x = 0\n", + "print \"\\n------------------------------------\"\n", + "print \" x in degrees cos(x) \"\n", + "print \"------------------------------------\"\n", + "\n", + "while x <= 180:\n", + " sys.stdout.write(\"\\n\\t%6.0f %6.2f\"%(x,cosine(x)))\n", + " x = x + 30\n", + " \n", + "print \"\\n------------------------------------\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "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" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, Page Number: FNC-9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "a = int(raw_input(\"\\nEnter three integers : \"))\n", + "b = int(raw_input(\"\"))\n", + "c = int(raw_input(\"\"))\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 \"\\nGreatest common divisor is \",d1\n", + " else:\n", + " print \"\\nGreatest common divisor is \",gcd(d1,d3)\n", + "else:\n", + " print \"\\nGreatest common divisor is \",gcd(d1,d2)\n", + " \n", + "print \"\\n\\nPress any key to continue...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter three integers : 45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "27\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "81\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Greatest common divisor is 9\n", + "\n", + "\n", + "Press any key to continue...\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, Page Number: FNC-10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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 = int(raw_input(\"\\nEnter the integer : \"))\n", + "\n", + "print \"\\n\",n,\" is erversed as \",reverse(n)\n", + "print \"\\nPress any key to continue...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the integer : 2846\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "2846 is erversed as 6482\n", + "\n", + "Press any key to continue...\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6, Page Number: FNC-11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + " \n", + "s1 = raw_input(\"\\nEnter the first string : \")\n", + "s2 = raw_input(\"\\nEnter the second string : \")\n", + "\n", + "print \"\\nThe result is \",compare(s1,s2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the first string : MUMBAI\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the second string : MYSORE\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The result is -1\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7, Page Number: FNC-13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def amean(x,n):\n", + " s = 0\n", + " for i in range(0,n):\n", + " s = s + x[i]\n", + " return s/n\n", + "\n", + "n = int(raw_input(\"\\nHow many values? \"))\n", + "print \"\\nEnter all values\\n\"\n", + "\n", + "x = [0.0 for i in range(0,10)]\n", + "\n", + "for i in range(0,n):\n", + " x[i] = float(raw_input(\"\"))\n", + " \n", + "sys.stdout.write(\"\\nArithmetic mean = %6.2f\"%(amean(x,n)))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many values? 6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Arithmetic mean = 3.62" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8, Page Number: FNC-14" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "m = int(raw_input(\"\\nHow many rows and columns : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,10)] for i in range(0,10)]\n", + "\n", + "print \"\\nEnter the matrix values\\n\"\n", + "\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "\n", + "print \"\\nSum of all elements in the matrix = \",elem_sum(a,m,n)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns : 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix values\n", + "\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": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Sum of all elements in the matrix = 12\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9, Page Number: FNC-15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "st = raw_input(\"\\nEnter a string : \")\n", + "\n", + "print \"\\n\",st,\" is reversed as \",reverse(st)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a string : NEW DELHI\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \n", + "NEW DELHI is reversed as IHLED WEN\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10, Page Number: FNC-16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "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", + "\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "\n", + "print \"\\nEnter all numbers in the list\\n\"\n", + "\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + " \n", + "s = int(raw_input(\"\\nEnter the number to be searched : \"))\n", + "\n", + "if bi_search(x,n,s):\n", + " print \"\\nThe number \",s,\" is present in the list\"\n", + "else:\n", + " print \"\\nThe number \",s,\" is not present in the list\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter all numbers in the list\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "13\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "19\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "26\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "29\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "35\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the number to be searched : 19\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The number 19 is present in the list\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11, Page Number: FNC-19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def fact(k):\n", + " if k == 1:\n", + " return 1\n", + " else:\n", + " return k*fact(k-1)\n", + " \n", + "n = int(raw_input(\"\\nEnter values to n and r : \"))\n", + "r = int(raw_input(\"\"))\n", + "\n", + "ncr = fact(n)/(fact(r)*fact(n-r))\n", + "\n", + "print \"\\nValue of nCr = \",ncr\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter values to n and r : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Value of nCr = 10\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12, Page Number: FNC-20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def power(x,n):\n", + " if n == 1:\n", + " return x\n", + " else:\n", + " return x*power(x,n-1)\n", + " \n", + "x = float(raw_input(\"\\nEnter value to x : \"))\n", + "n = int(raw_input(\"\\nEnter its power : \"))\n", + "\n", + "sys.stdout.write(\"\\n%6.2f raise to %d is %6.2f\"%(x,n,power(x,n)))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter value to x : 4.2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter its power : 3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " 4.20 raise to 3 is 74.09" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13, Page Number: FNC-21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "\n", + "def 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", + " \n", + "n = int(raw_input(\"\\nHow many terms to be printed ? \"))\n", + "t1 = 0\n", + "t2 = 1\n", + "\n", + "print \"\\nThe first \",n,\" terms in Fibonacci series are\\n\"\n", + "sys.stdout.write(\"%5d %5d\"%(t1,t2))\n", + "\n", + "count = 2\n", + "fibo(t1,t2,count)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many terms to be printed ? 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The first 10 terms in Fibonacci series are\n", + "\n", + " 0 1 1 2 3 5 8 13 21 34" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14, Page Number: FNC-28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def matadd():\n", + " for i in xrange(m):\n", + " for j in xrange(n):\n", + " c[i][j] = a[i][j] + b[i][j]\n", + " \n", + "m = int(raw_input(\"\\nHow many rows and columns ?\"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "a = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "b = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "c = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "\n", + "#Read matrices\n", + "print \"\\nEnter A matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + " \n", + "print \"\\nEnter B matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " b[i][j] = int(raw_input(\"\"))\n", + "\n", + "matadd()\n", + "\n", + "print \"\\nResultant matrix is \\n\"\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns ?2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\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": [ + "\n", + "Enter B matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + "\n", + " 8 0\n", + " 4 -1\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 15, Page Number: FNC-29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "def 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", + " \n", + "m = int(raw_input(\"\\nEnter order of A matrix (m x n) : \"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "\n", + "a = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "b = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "c = [[0 for i in range(0,10)]for i in range(0,10)]\n", + "\n", + "#Read matrices\n", + "print \"\\nEnter A matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "n = int(raw_input(\"\\nEnter order of B matrix (n x l) : \"))\n", + "l = int(raw_input(\"\"))\n", + "\n", + "print \"\\nEnter B matrix values\\n\"\n", + "for i in range(0,n):\n", + " for j in range(0,l):\n", + " b[i][j] = int(raw_input(\"\"))\n", + "\n", + "matmul()\n", + "\n", + "print \"\\nResultant matrix is \\n\"\n", + "for 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\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of A matrix (m x n) : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter A matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter order of B matrix (n x l) : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter B matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Resultant matrix is \n", + "\n", + " 4 14\n", + " 16 -20\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 16, Page Number: FNC-31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "at = [[0,0],[0,0],[0,0]]\n", + "\n", + "def transpose():\n", + " for i in xrange(m):\n", + " for j in xrange(n):\n", + " at[j][i] = a[i][j] \n", + " \n", + "m = int(raw_input(\"\\nHow many rows and columns ?\"))\n", + "n = int(raw_input(\"\"))\n", + "\n", + "print \"\\nEnter the matrix values\\n\"\n", + "for i in range(0,m):\n", + " for j in range(0,n):\n", + " a[i][j] = int(raw_input(\"\"))\n", + "\n", + "transpose()\n", + "\n", + "print \"\\nTranspose of the matrix is \\n\"\n", + "for i in xrange(n):\n", + " for j in xrange(m):\n", + " sys.stdout.write(\"%5d\"%(at[i][j]))\n", + " sys.stdout.write(\"\\n\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many rows and columns ?2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the matrix values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\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": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Transpose of the matrix is \n", + "\n", + " -3 3\n", + " 6 2\n", + " 0 8\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 17, Page Number: FNC-32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "\n", + "def 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", + " \n", + "x = [0 for i in range(0,50)]\n", + "n = int(raw_input(\"\\nHow many numbers ? \"))\n", + "print \"\\nEnter the list of values\\n\"\n", + "\n", + "for i in range(0,n):\n", + " x[i] = int(raw_input(\"\"))\n", + "\n", + "sort()\n", + "\n", + "print \"\\nThe sorted list is\\n\"\n", + "\n", + "for i in xrange(n):\n", + " sys.stdout.write(\"%5d\"%(x[i]))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "How many numbers ? 4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter the list of values\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "The sorted list is\n", + "\n", + " -10 5 20 32" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials/screenshots/Chapter1.png b/Advanced_Mechanics_of_Materials/screenshots/Chapter1.png new file mode 100755 index 00000000..20ad7de5 Binary files /dev/null and b/Advanced_Mechanics_of_Materials/screenshots/Chapter1.png differ diff --git a/Advanced_Mechanics_of_Materials/screenshots/Chapter2.png b/Advanced_Mechanics_of_Materials/screenshots/Chapter2.png new file mode 100755 index 00000000..18fc3e98 Binary files /dev/null and b/Advanced_Mechanics_of_Materials/screenshots/Chapter2.png differ diff --git a/Advanced_Mechanics_of_Materials/screenshots/Chapter3.png b/Advanced_Mechanics_of_Materials/screenshots/Chapter3.png new file mode 100755 index 00000000..ec777e31 Binary files /dev/null and b/Advanced_Mechanics_of_Materials/screenshots/Chapter3.png differ diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter1.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter1.ipynb new file mode 100755 index 00000000..9ad0850a --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter1.ipynb @@ -0,0 +1,185 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2328a7dc3cc0ee8a847caf61a092e7220be4bed1f89464a7bc727661ff6069c6" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter1-Introduction" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the The ultimate strength and the yield strength\n", + "## initialization of variables\n", + "import math\n", + "## part (a)\n", + "a=700. ## M Pa from figure 1.8\n", + "b=100. ## M Pafrom figure 1.8\n", + "m=1/6. ## from figure 1.8\n", + "Y=450. ## M Pa from figure 1.9\n", + "##calculations\n", + "sigma_u=a+m*b\n", + "## results\n", + "print('\\n part (a) \\n')\n", + "print\"%s %.2f %s\"%(' The ultimate strength is sigma = ',sigma_u,' M Pa')\n", + "print\"%s %.2f %s\"%('\\n and the yield strength is Y = ',Y,'M Pa')\n", + "\n", + "## part (b)\n", + "c1=62. ## from figure 1.8\n", + "d1=0.025 ## from figure 1.8\n", + "c2=27. ## from figure 1.10a\n", + "d2=0.04 ## from figure 1.10a\n", + "## calculations\n", + "U_f1=c1*b*d1*10**6\n", + "U_f2=c2*b*d2*10**6\n", + "## results\n", + "print('\\n part (b)')\n", + "print\"%s %.2e %s\"%('\\n The modulus of toughness for alloy steel is Uf = ',U_f1,' N/m^2')\n", + "print\"%s %.2e %s\"%('\\n and structural steel is Uf = ',U_f2,' N/m^2')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " part (a) \n", + "\n", + " The ultimate strength is sigma = 716.67 M Pa\n", + "\n", + " and the yield strength is Y = 450.00 M Pa\n", + "\n", + " part (b)\n", + "\n", + " The modulus of toughness for alloy steel is Uf = 1.55e+08 N/m^2\n", + "\n", + " and structural steel is Uf = 1.08e+08 N/m^2\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the permanet strain\n", + "## initialization of variables\n", + "import math\n", + "sigma=500. ## Stress M Pa\n", + "eps=0.0073 ## Strain\n", + "sigma_A=343. ## M Pa from figure 1.9\n", + "eps_A=0.00172 ## from figure 1.9\n", + "## part (a)\n", + "E=sigma_A/eps_A\n", + "\n", + "## part (B)\n", + "eps_e=sigma/E\n", + "eps_p=eps-eps_e\n", + "## results\n", + "print(' part (a) \\n')\n", + "print\"%s %.2f %s\"%(' The modulus of elasticity of the rod is E = ',E/1000,' G Pa')\n", + "print('\\n part (b)')\n", + "print\"%s %.4f %s\"%('\\n the permanent strain is = ',eps_p,'')\n", + "print\"%s %.4f %s\"%('\\n and the strain recovered is =',eps_e,'')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " part (a) \n", + "\n", + " The modulus of elasticity of the rod is E = 199.42 G Pa\n", + "\n", + " part (b)\n", + "\n", + " the permanent strain is = 0.0048 \n", + "\n", + " and the strain recovered is = 0.0025 \n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the diameter\n", + "## initialization of variables\n", + "import math\n", + "D=25. ## kN\n", + "L=60. ## kN\n", + "W=30. ##kN\n", + "Y=250. ## M Pa\n", + "safety=5./3. ## AISC, 1989\n", + "## calculations\n", + "Q=(D+L+W)*10**3. ## converted to N\n", + "A=safety*Q/Y\n", + "r=math.sqrt(A/math.pi)+0.5 ## additional 0.5 mm is for extra safety\n", + "d=1.8*r ## diameter\n", + "## results\n", + "print('Part (a) \\n ')\n", + "print\"%s %.2f %s %.2f %s \"%('A rod of ',d,' mm'and ' in diameter, with a cross sectional area of ',math.pi*(d**2./4.),' mm^2, is adequate')\n", + "## The diameter is correct as given in the textbook. Area doesn't match due to rounding off error and partly because it's a design problem.\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part (a) \n", + " \n", + "A rod of 29.02 in diameter, with a cross sectional area of 661.39 mm^2, is adequate \n" + ] + } + ], + "prompt_number": 14 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter10.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter10.ipynb new file mode 100755 index 00000000..fcd8d536 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter10.ipynb @@ -0,0 +1,473 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:dfaf77db4c85042efee22fb6763c694430ec032753268abcad247883d2c6e223" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter10-Beams On Elastic Foundations" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg366" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the maximum deflection and maximum bending moment and maximum flexural stress in the rail for single wheel load and maximum bending moment\n", + "## initialization of variables\n", + "import math\n", + "##part(a)\n", + "E=200. ##GPa\n", + "d=184. ##mm\n", + "c=99.1 ##mm\n", + "Ix=36.9e+06##mm^4\n", + "k=14.0 ##N/mm^2\n", + "P=170. ##kN\n", + "##calculations\n", + "E=E*10**3\n", + "P=P*10**3\n", + "Beta=(k/(4.*E*Ix))**(1/4.)\n", + "y_max=P*Beta/(2.*k)\n", + "M_max=P/(4.*Beta)\n", + "S_max=M_max*c/Ix\n", + "print('part (a)')\n", + "print\"%s %.2f %s\"%('\\n y_max = ',y_max,' mm')\n", + "print\"%s %.2f %s\"%('\\n M_max = ',M_max/10**6,' kN.m')\n", + "print\"%s %.2f %s\"%('\\n S_max = ',S_max,' MPa')\n", + "## part (b)\n", + "z1=1.7##m\n", + "z1=z1*10**3 ##mm\n", + "z2=2*z1\n", + "## A_bz=exp(-Beta*z)*(sin(Beta*z)+cos(Beta*z))\n", + "## C_bz=exp(-Beta*z)*(-sin(Beta*z)+cos(Beta*z))\n", + "A_bzo=1.\n", + "C_bzo=1.\n", + "A_bz1=math.exp(-Beta*z1)*(math.sin(Beta*z1)+math.cos(Beta*z1))\n", + "A_bz2=math.exp(-Beta*z2)*(math.sin(Beta*z2)+math.cos(Beta*z2))\n", + "C_bz1=math.exp(-Beta*z1)*(-math.sin(Beta*z1)+math.cos(Beta*z1))\n", + "C_bz2=math.exp(-Beta*z2)*(-math.sin(Beta*z2)+math.cos(Beta*z2))\n", + "y_end=P*Beta/(2.*k)*(A_bzo+A_bz1+A_bz2)\n", + "M_end=P/(4.*Beta)*(C_bzo+C_bz1+C_bz2)\n", + "y_center=P*Beta/(2.*k)*(A_bzo+2.*A_bz1)\n", + "M_center=P/(4.*Beta)*(C_bzo+2.*C_bz1)\n", + "y_max=max(y_end,y_center)\n", + "M_max=max(M_end,M_center)\n", + "S_max=M_max*c/Ix\n", + "print('\\n part(b)')\n", + "print\"%s %.2f %s\"%('\\n y_max = ',y_max,' mm')\n", + "print\"%s %.2f %s\"%('\\n M_max = ',M_max/10**6,' kN.m')\n", + "print\"%s %.2f %s\"%('\\n S_max =',S_max,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " y_max = 5.04 mm\n", + "\n", + " M_max = 51.21 kN.m\n", + "\n", + " S_max = 137.54 MPa\n", + "\n", + " part(b)\n", + "\n", + " y_max = 7.86 mm\n", + "\n", + " M_max = 37.02 kN.m\n", + "\n", + " S_max = 99.42 MPa\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg367" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the load carried by each spring and deflection of beam\n", + "d=100. ##mm\n", + "Ix=2.45e+06 ##mm^4\n", + "E=72. ##GPa\n", + "L=6.8 ##m\n", + "K=110. ##N/mm\n", + "l=1.1 ##m\n", + "P=12. ##kN\n", + "##calculations\n", + "E=E*10**3\n", + "P=P*10**3\n", + "l=l*10**3\n", + "k=K/l\n", + "L1=7.*l\n", + "Beta=(k/(4.*E*Ix))**(1/4.)\n", + "if(l3*math.pi/(2.*Beta)):\n", + "\tM_max=P/(4.*Beta)\n", + "S_max=M_max*d/(2.*Ix)\n", + "\n", + "print\"%s %.2f %s\"%('y_max = ',y_max,' mm')\n", + "print\"%s %.2f %s\"%('\\n M_max = ',M_max/10**6,' kN.m')\n", + "print\"%s %.2f %s\"%('\\n S_max = ',S_max,' MPa')\n", + "A_bl=math.exp(-Beta*l)*(math.sin(Beta*l)+math.cos(Beta*l))\n", + "A_2bl=math.exp(-Beta*2*l)*(math.sin(Beta*2*l)+math.cos(Beta*2*l))\n", + "A_3bl=math.exp(-Beta*3*l)*(math.sin(Beta*3*l)+math.cos(Beta*3*l))\n", + "y_C=P*Beta/(2.*k)*A_bl\n", + "y_B=P*Beta/(2.*k)*A_2bl\n", + "y_A=P*Beta/(2.*k)*A_3bl\n", + "print\"%s %.2f %s\"%('\\n y_C = ',y_C,' mm')\n", + "print\"%s %.2f %s\"%('\\n y_B = ',y_B,' mm')\n", + "print\"%s %.2f %s\"%('\\n y_A = ',y_A,' mm' )\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "y_max = 36.81 mm\n", + "\n", + " M_max = 4.89 kN.m\n", + "\n", + " S_max = 99.78 MPa\n", + "\n", + " y_C = 26.35 mm\n", + "\n", + " y_B = 11.41 mm\n", + "\n", + " y_A = 2.24 mm\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg372" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the maximum deflection maximum flexural stress and maximum pressure between the beam and foundation\n", + "E=10. ##GPa\n", + "h=200. ##mm\n", + "b=100. ##mm\n", + "ko=0.04 ##N/mm^3\n", + "w=35. ##N/mm\n", + "L1=3.61 ##m\n", + "##calculations\n", + "E=E*10**3\n", + "L1=L1*10**3\n", + "k=b*ko\n", + "Ix=b*h**3/12.\n", + "Beta=(k/(4.*E*Ix))**(1/4.)\n", + "ba=2.00 ## ba = Beta*a based on the discussion\n", + "##D_bz=exp(-Beta*z)*sin(Beta*z)\n", + "D_ba=math.exp(-ba)*math.cos(ba)\n", + "y_max=w/k*(1-D_ba)\n", + "ba=0.777 ##Beta*a\n", + "bb=4.777 ##Beta*b\n", + "B_ba=math.exp(-ba)*math.sin(ba)\n", + "B_bb=math.exp(-bb)*math.sin(bb)\n", + "M_max=abs(-w*(B_ba-B_bb)/(4.*Beta**2))\n", + "c=h/2.\n", + "S_max=M_max*c/Ix\n", + "## calculation of M_H\n", + "ba=math.pi/4. ##Beta*a\n", + "bb=4-math.pi/4. ##Beta*b\n", + "B_ba=math.exp(-ba)*math.sin(ba)\n", + "B_bb=math.exp(-bb)*math.sin(bb)\n", + "M_H=w/(4.*Beta**2)*(B_ba+B_bb)\n", + "print\"%s %.2f %s\"%('y_max = ',y_max,' mm')\n", + "print\"%s %.2f %s\"%('\\n M_max = ',M_max/10**6,' kN.m')\n", + "print\"%s %.2f %s\"%('\\n S_max = ',S_max,' MPa')\n", + "print\"%s %.2f %s\"%('\\n M_H = ',M_H/10**6,' kN.m')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "y_max = 9.24 mm\n", + "\n", + " M_max = 2.36 kN.m\n", + "\n", + " S_max = 3.54 MPa\n", + "\n", + " M_H = 2.28 kN.m\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg375" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the maximum deflection and maximum flexural stress in the beam and locations of each\n", + "E=200. ##GPa\n", + "h=102. ##mm\n", + "b=68. ##mm\n", + "Ix=2.53e+06 ##mm^4\n", + "L1=4. ##m\n", + "ko=0.35 ##N/mm^3\n", + "P=30.0 ##kN\n", + "##calculations\n", + "E=E*10**3\n", + "P=P*10**3\n", + "L1=L1*10**3\n", + "k=b*ko\n", + "Beta=(k/(4.*E*Ix))**(1/4.)\n", + "if(L1>3*math.pi/(2.*Beta)):\n", + " y_max=2.*P*Beta/k\n", + "M_max=-0.3224*P/Beta\n", + "S_max=abs(M_max*h/(2.*Ix))\n", + "\n", + "z=math.pi/(4.*Beta)\n", + "print\"%s %.2f %s\"%('y_max = ',y_max,' mm')\n", + "print\"%s %.2f %s\"%('\\n M_max = ',M_max,' kN.m')\n", + "print\"%s %.2f %s\"%('\\n S_max = ',S_max,' MPa')\n", + "print\"%s %.2f %s\"%('\\n Location of Sigma_max is z = ',z,' mm') \n", + " \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "y_max = 4.67 mm\n", + "\n", + " M_max = -5223055.92 kN.m\n", + "\n", + " S_max = 105.29 MPa\n", + "\n", + " Location of Sigma_max is z = 424.13 mm\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex6-pg377" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the maximum deflection and maximum flexural stress\n", + "P=30.0 ##kN\n", + "a=500. ##mm\n", + "h=102. ##mm\n", + "b=68. ##mm\n", + "k=23.8 ##N/mm**2\n", + "Beta=0.001852\n", + "Ix=2.53e+06 ##mm**4\n", + "##calculations\n", + "P=P*10**3.\n", + "C_ba=math.exp(-Beta*a)*(-math.sin(Beta*a)+math.cos(Beta*a))\n", + "D_ba=math.exp(-Beta*a)*math.cos(Beta*a)\n", + "## y = P*Beta/(2*k)*(A_bz+2*D_ba*D_baz+C_ba*C_baz))\n", + "## Mx = P/(4*Beta)*(C_bz-2*D_ba*B_baz-C_ba*A_baz)\n", + "A_ba=math.exp(-Beta*a)*(math.sin(Beta*a)+math.cos(Beta*a))\n", + "B_ba=math.exp(-Beta*a)*math.sin(Beta*a)\n", + "C_ba=math.exp(-Beta*a)*(-math.sin(Beta*a)+math.cos(Beta*a))\n", + "D_ba=math.exp(-Beta*a)*math.cos(Beta*a)\n", + "z1=424 ##mm\n", + "z=z1-a\n", + "A_bz=math.exp(-Beta*z)*(math.sin(Beta*z)+math.cos(Beta*z))\n", + "B_bz=math.exp(-Beta*z)*math.sin(Beta*z)\n", + "C_bz=math.exp(-Beta*z)*(-math.sin(Beta*z)+math.cos(Beta*z))\n", + "D_bz=math.exp(-Beta*z)*math.cos(Beta*z)\n", + "## to find out X_baz\n", + "z=a+z\n", + "A_baz=math.exp(-Beta*z)*(math.sin(Beta*z)+math.cos(Beta*z))\n", + "B_baz=math.exp(-Beta*z)*math.sin(Beta*z)\n", + "C_baz=math.exp(-Beta*z)*(-math.sin(Beta*z)+math.cos(Beta*z))\n", + "D_baz=math.exp(-Beta*z)*math.cos(Beta*z)\n", + "y_max = P*Beta/(2*k)*(A_bz+2*D_ba*D_baz+C_ba*C_baz)\n", + "print\"%s %.2f %s\"%('y_max = ',y_max,' mm')\n", + "## For M_max\n", + "z1=500. ##mm\n", + "z=z1-a\n", + "A_bz=math.exp(-Beta*z)*(math.sin(Beta*z)+math.cos(Beta*z))\n", + "B_bz=math.exp(-Beta*z)*math.sin(Beta*z)\n", + "C_bz=math.exp(-Beta*z)*(-math.sin(Beta*z)+math.cos(Beta*z))\n", + "D_bz=math.exp(-Beta*z)*math.cos(Beta*z)\n", + "## to find out X_baz\n", + "z=a+z\n", + "A_baz=math.exp(-Beta*z)*(math.sin(Beta*z)+math.cos(Beta*z))\n", + "B_baz=math.exp(-Beta*z)*math.sin(Beta*z)\n", + "C_baz=math.exp(-Beta*z)*(-math.sin(Beta*z)+math.cos(Beta*z))\n", + "D_baz=math.exp(-Beta*z)*math.cos(Beta*z)\n", + "M_max = P/(4.*Beta)*(C_bz-2.*D_ba*B_baz-C_ba*A_baz)\n", + "print\"%s %.2f %s\"%('\\n M_max = ',M_max,' N.mm')\n", + "S_max=M_max*h/(2.*Ix)\n", + "print\"%s %.2f %s\"%('\\n Sigma_max = ',S_max,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "y_max = 1.32 mm\n", + "\n", + " M_max = 3615504.81 N.mm\n", + "\n", + " Sigma_max = 72.88 MPa\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex7-pg381" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the maximum shear stress and \n", + "D=30. ##m\n", + "t=10. ##m\n", + "h=20. ##mm\n", + "E=200. ##GPa\n", + "v=0.29\n", + "rho=900. ##kg/m**3\n", + "##calculations\n", + "##part (a)\n", + "E=E*10**3.\n", + "a=D/2*10**3.\n", + "p=t*10**3*9.807*rho*10**-9\n", + "S_th=p*a/h\n", + "tau_max=S_th/2.\n", + "print('part (a)')\n", + "print\"%s %.2f %s\"%('\\n Maximum shear stress= ',tau_max,' MPa')\n", + "## part (b)\n", + "k=E*h/(a**2)\n", + "Beta=(3*(1.-v**2)/(h**2*a**2))**(1/4.)\n", + "L1=3.*math.pi/(4.*Beta) ##L1=L/2\n", + "u=S_th*a/E\n", + "w=2.*k*u/(Beta)\n", + "M_max=w/(4.*Beta)\n", + "Szz_max=M_max*(h/2.)/(h**3/12.)\n", + "Sth_max=v*Szz_max\n", + "tau_max=Szz_max/2.\n", + "u_b=w*(1-v)*a/(2*E*h)\n", + "print('\\n part (b)')\n", + "print\"%s %.2f %s\"%('\\n Maximum shear stress= ',tau_max,' MPa')\n", + "print\"%s %.2f %s\"%('\\n u_bottom = ',u_b,' mm')\n", + "## part (c)\n", + "w=u*k/(2.*Beta)\n", + "z=math.pi/(4.*Beta)\n", + "B_bz=math.exp(-Beta*z)*math.sin(Beta*z)\n", + "M_max=-w*B_bz/Beta\n", + "c=6.\n", + "I=h**2\n", + "Szz_max=(M_max*c/I)\n", + "S_th1=v*(Szz_max)\n", + "k=0.3224\n", + "S_th2=(1-k)*S_th\n", + "Sigma_th=S_th1+S_th2\n", + "tau_max=(Sigma_th-Szz_max)/2.\n", + "print('\\n part (c)')\n", + "print\"%s %.2f %s\"%('\\n Maximum shear stress= ',tau_max,' MPa')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Maximum shear stress= 33.10 MPa\n", + "\n", + " part (b)\n", + "\n", + " Maximum shear stress= 59.90 MPa\n", + "\n", + " u_bottom = 0.10 mm\n", + "\n", + " part (c)\n", + "\n", + " Maximum shear stress= 36.14 MPa\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter11.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter11.ipynb new file mode 100755 index 00000000..867c2ff9 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter11.ipynb @@ -0,0 +1,595 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:fd4f0aff1595774b5355a497060422fe514233295a9b38d4661e82d6b26d39aa" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter11-The Thick-Wall Cylinder" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg397" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the radial pressure and circumferential stress \n", + "E=200. ##GPa\n", + "v=0.29\n", + "Di=20. ##mm\n", + "Do=100. ##mm\n", + "a=10. ##mm\n", + "b=50. ##mm\n", + "p1=300. ##MPa\n", + "##calculations\n", + "## S_rr=p1*(a**2*(r**2-b**2))/(r**2*(b**2-a**2))\n", + "## S_th=p1*(a**2*(r**2+b**2))/(r**2*(b**2-a**2))\n", + "r=10.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2.))\n", + "print'%s %.2f %s'%('r = ',r,' mm')\n", + "print'%s %.2f %s'%('\\n Radial stress = ',S_rr,' MPa')\n", + "print'%s %.2f %s'%('\\n circumferential stress = ',S_th,' MPa')\n", + "r=25.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2.))\n", + "print'%s %.2f %s'%('r = ',r,' mm')\n", + "print'%s %.2f %s'%('\\n Radial stress = ',S_rr,' MPa')\n", + "print'%s %.2f %s'%('\\n circumferential stress = ',S_th,' MPa')\n", + "\n", + "r=50.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2.))\n", + "print'%s %.2f %s'%('r = ',r,' mm')\n", + "print'%s %.1f %s'%('\\n Radial stress = ',S_rr,' MPa')\n", + "print'%s %.2f %s'%('\\n circumferential stress = ',S_th,' MPa')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "r = 10.00 mm\n", + "\n", + " Radial stress = -300.00 MPa\n", + "\n", + " circumferential stress = 325.00 MPa\n", + "r = 25.00 mm\n", + "\n", + " Radial stress = -37.50 MPa\n", + "\n", + " circumferential stress = 62.50 MPa\n", + "r = 50.00 mm\n", + "\n", + " Radial stress = 0.0 MPa\n", + "\n", + " circumferential stress = 25.00 MPa\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg397" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the normal stress and radial stress and circumferentail stress\n", + "E=72. ##GPa\n", + "v=0.33\n", + "Di=200. ##mm\n", + "Do=800. ##mm\n", + "a=100. ##mm\n", + "r=a\n", + "b=Do/2. ##mm\n", + "p1=150. ##MPa\n", + "E=E*10**3.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_zz=p1*a**2./(b**2.-a**2.)\n", + "tau_max=(S_th-S_rr)/2.\n", + "u_a=p1*a/(E*(b**2-a**2))*((1-2*v)*a**2+(1+v)*b**2)\n", + "print'%s %.1f %s'%('\\n Radial stress = ',S_rr,' MPa')\n", + "print'%s %.2f %s'%('\\n circumferential stress = ',S_th,' MPa')\n", + "\n", + "\n", + "print'%s %.2f %s'%('\\n Normal stress = ',S_zz,' MPa')\n", + "print'%s %.2f %s'%('\\n Maximum shear stress = ',tau_max,' MPa')\n", + "print'%s %.2f %s'%('\\n u|r=a = ',u_a,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Radial stress = -150.0 MPa\n", + "\n", + " circumferential stress = 170.00 MPa\n", + "\n", + " Normal stress = 10.00 MPa\n", + "\n", + " Maximum shear stress = 160.00 MPa\n", + "\n", + " u|r=a = 0.30 mm\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg398" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the how muhc temperature changes\n", + "E=200. ##GPa\n", + "a=10. ##mm\n", + "v=0.29\n", + "ci=25.072 ##mm\n", + "co=25. ##mm\n", + "b=50. ##mm\n", + "rr=0.072 ##mm\n", + "re=0.025 ##mm\n", + "alpha=0.0000117 ## per celcius\n", + "##calculations\n", + "E=E*10**3.\n", + "p1=300. ##MPa\n", + "term1=co/(E*(b**2.-co**2.))*((1.-v)*co**2.+(1.+v)*b**2.)\n", + "term2=-ci/(E*(ci**2.-a**2.))*((-(1.-v)*ci**2.)-(1.+v)*a**2.)\n", + "ps=rr/(term1+term2)\n", + "\n", + "## Inner cylinder p1=0 p2=ps a=10 b=25 \n", + "## outer cylinder p1=ps p2=0 a=25 b=50 \n", + "## S_rr=(p1*a**2-p2*b**2)/(b**2-a**2)-(a**2*b**2)/(r**2*(b**2-a**2))*(p1-p2)\n", + "## S_th=(p1*a**2-p2*b**2)/(b**2-a**2)+(a**2*b**2)/(r**2*(b**2-a**2))*(p1-p2)\n", + "## results\n", + "## residual stresses for inner cylinder\n", + "p1=0.\n", + "p2=ps\n", + "r=10.\n", + "a=10.\n", + "b=25.\n", + "S_rri1=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)-(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "S_thi1=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)+(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "print('\\n Inner cylinder')\n", + "print'%s %.2f %s'%('\\n r = ',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rri1,' MPa'and 'S_th|R = ',S_thi1,' MPa')\n", + "r=25.\n", + "S_rri2=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)-(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "S_thi2=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)+(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "\n", + "print'%s %.2f %s'%('\\n r = ',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rri2,' MPa'and 'S_th|R = ',S_thi2,' MPa')\n", + "\n", + "## residual stresses for outer cylinder\n", + "p1=ps\n", + "p2=0.\n", + "a=25. \n", + "b=50.\n", + "r=25.\n", + "S_rro1=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)-(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "S_tho1=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)+(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "print('\\n Outer cylinder')\n", + "print'%s %.2f %s'%('\\n r =',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rro1,' MPa'and ' S_th|R =',S_tho1,' MPa')\n", + "r=50.\n", + "S_rro2=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)-(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "S_tho2=(p1*a**2.-p2*b**2.)/(b**2.-a**2.)+(a**2.*b**2.)/(r**2.*(b**2.-a**2.))*(p1-p2)\n", + "print'%s %.2f %s'%('\\n r =',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rro2,' MPa'and ' S_th|R =',S_tho2,' MPa')\n", + "\n", + "## AN internal pressure of 300 MPa\n", + "a=10. ##mm\n", + "b=50. ##mm\n", + "p1=300. ##MPa\n", + "r=10.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2))\n", + "S_rr1=S_rr+S_rri1\n", + "S_th1=S_th+S_thi1\n", + "\n", + "print('\\n Inner cylinder')\n", + "print'%s %.2f %s'%('\\n r =',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rr1,' MPa'and ' S_th|R =',S_th1,' MPa')\n", + "\n", + "r=25.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_rr2=S_rr+S_rri2\n", + "S_th2=S_th+S_thi2\n", + "print'%s %.2f %s'%('\\n r =',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rr2,' MPa'and ' S_th|R =',S_th2,' MPa')\n", + "\n", + "\n", + "## Outer Cyllinder\n", + "S_rr1=S_rr+S_rro1\n", + "S_th1=S_th+S_tho1\n", + "\n", + "print('\\n Outer cylinder')\n", + "print'%s %.2f %s'%('\\n r = ',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rr1,' MPa'and ' S_th|R =',S_th1,' MPa')\n", + "\n", + "r=50.\n", + "S_rr=p1*(a**2.*(r**2.-b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_th=p1*(a**2.*(r**2.+b**2.))/(r**2.*(b**2.-a**2.))\n", + "S_rr2=S_rr+S_rro2\n", + "S_th2=S_th+S_tho2\n", + "print'%s %.2f %s'%('\\n r =',r,' mm')\n", + "print'%s %.2f %s %.2f %s '%('\\n S_rr|R = ',S_rr2,' MPa'and ' S_th|R =',S_th2,' MPa')\n", + "#delT=u/(r*alpha)\n", + "u=rr+re\n", + "r=25.\n", + "delT=u/(r*alpha)\n", + "print'%s %.2f %s'%('\\n delT = ',delT,' degree Celcius')\n", + "\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Inner cylinder\n", + "\n", + " r = 10.00 mm\n", + "\n", + " S_rr|R = -0.00 S_th|R = -449.92 MPa \n", + "\n", + " r = 25.00 mm\n", + "\n", + " S_rr|R = -188.97 S_th|R = -260.95 MPa \n", + "\n", + " Outer cylinder\n", + "\n", + " r = 25.00 mm\n", + "\n", + " S_rr|R = -188.97 S_th|R = 314.94 MPa \n", + "\n", + " r = 50.00 mm\n", + "\n", + " S_rr|R = 0.00 S_th|R = 125.98 MPa \n", + "\n", + " Inner cylinder\n", + "\n", + " r = 10.00 mm\n", + "\n", + " S_rr|R = -300.00 S_th|R = -124.92 MPa \n", + "\n", + " r = 25.00 mm\n", + "\n", + " S_rr|R = -226.47 S_th|R = -198.45 MPa \n", + "\n", + " Outer cylinder\n", + "\n", + " r = 25.00 mm\n", + "\n", + " S_rr|R = -226.47 S_th|R = 377.44 MPa \n", + "\n", + " r = 50.00 mm\n", + "\n", + " S_rr|R = 0.00 S_th|R = 150.98 MPa \n", + "\n", + " delT = 331.62 degree Celcius\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg403" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the minimum yeild stress for the steel for a factory of safety \n", + "SF=1.75\n", + "p1=300. ##MPa\n", + "S_rr=-SF*p1\n", + "S_th=SF*325.\n", + "Y=1./math.sqrt(2.)*math.sqrt((S_th-S_rr)**2.+S_rr**2.+S_th**2.)\n", + "print'%s %.2f %s'%(' Y = ',Y,'MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Y = 947.47 MPa\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg404" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the minimum yeild stress for the steel \n", + "p1=300. ##MPa\n", + "SF=1.75\n", + "S_rr=SF*p1\n", + "S_th=SF*325.-550.2 ##Values are obtained from running Ex11_3.sce\n", + "Y1=1./math.sqrt(2)*math.sqrt((S_th-S_rr)**2+S_rr**2+S_th**2)\n", + "S_rr1=37.5\n", + "S_rre=-189.1\n", + "S_th1=62.5\n", + "S_the=315.1\n", + "## ABove values are obtained from running the codes Ex11_1 and Ex11_3.sce\n", + "S_rr=-SF*S_rr1+S_rre\n", + "S_th=SF*S_th1+S_the\n", + "Y2=1./math.sqrt(2)*math.sqrt((S_th-S_rr)**2+S_rr**2+S_th**2)\n", + "if(Y2>Y1):\n", + " Y=Y2\n", + "\n", + "print'%s %.2f %s'%(' Y = ',Y,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Y = 594.30 MPa\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex6-pg407" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "import numpy\n", + "## initialization of variables\n", + "#calculate the fully plastic internal pressure and maximum circurmfential and axial radial stress\n", + "SF=1.8\n", + "a=20. ##mm\n", + "b=40. ##mm\n", + "Y=450. ##MPa\n", + "##part (a)\n", + "tau_Y=Y/math.sqrt(3)\n", + "Pp=2.*tau_Y*math.log(b/a)\n", + "S_th=2.*tau_Y*(1-math.log(b/a))\n", + "S_rr=-Pp\n", + "S_zz=(S_th+S_rr)/2.\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n S_th = ',S_th,' MPa')\n", + "print'%s %.2f %s'%('\\n S_zz = ',S_zz,' MPa')\n", + "## part (b)\n", + "S_thR=S_th-Pp*(b**2.+a**2.)/(b**2.-a**2.)\n", + "S_zzR=S_zz-Pp*(a**2.)/(b**2.-a**2.)\n", + "S_thR=S_thR/2.\n", + "S_zzR=S_zzR/2.\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n S_th|R = ',S_thR,' MPa')\n", + "print'%s %.2f %s'%('\\n S_zz|R = ',S_zzR,' MPa')\n", + "## par (c)\n", + "## We need to find out p1. To do that let it be unity\n", + "p1=1.\n", + "S_thR=-S_thR\n", + "S_zzR=-S_zzR\n", + "S_rr=-SF*p1\n", + "S_th=SF*p1*(b**2.+a**2.)/(b**2.-a**2.)\n", + "S_zz=SF*p1*a**2./(b**2.-a**2.)\n", + "## 2Y**2=(s_th-S_rr)**2+(S_rr-S_zz)**2+(S_zz-S_th)**2\n", + "## S_th=S_th*p1-S_thR\n", + "## S_zz=S_zz*p1-S_zzR\n", + "## a*p1**2+b*p+c=0\n", + "a=(S_th+SF)**2.+(-SF-S_zz)**2.+(S_zz-S_th)**2.\n", + "c=S_thR**2+S_zzR**2.+(S_thR-S_zzR)**2.\n", + "b=-2.*(S_th+SF)*S_thR+2.*S_zzR*(-SF-S_zz)+2.*(S_zz-S_th)*(S_thR-S_zzR)\n", + "c=c-2.*Y**2.\n", + "p11=numpy.roots([a, b ,c])\n", + "p12=numpy.roots([a ,0 ,-2*Y**2])\n", + "p11=p11[0]\n", + "p12=p12[0]\n", + "print'%s %.2f %s'%('\\n Internal working pressure is ',p11,' MPa,')\n", + "print'%s %.2f %s'%('\\n Without residual stresses ',p12,' MPa')\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " S_th = 159.45 MPa\n", + "\n", + " S_zz = -100.36 MPa\n", + "\n", + " part (b)\n", + "\n", + " S_th|R = -220.42 MPa\n", + "\n", + " S_zz|R = -110.21 MPa\n", + "\n", + " Internal working pressure is 154.17 MPa,\n", + "\n", + " Without residual stresses 108.25 MPa\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex8-pg415" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the angular velocity\n", + "a=100. ##mm\n", + "b=300. ##mm\n", + "Y=620. ##MPa\n", + "E=200. ##GPa\n", + "S_zz=0.\n", + "v=0.29\n", + "rho=7.85e+03 ##kg/m**3\n", + "## part (a)\n", + "S_thmax=Y\n", + "Wy=math.sqrt(4.*Y/(rho*((3.+v)*b**2.+(1.-v)*a**2.)))\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n Omega_y =',Wy*10**6,' rad/s')\n", + "## part (b)\n", + "Wp=math.sqrt(3.*Y/(rho*(b**2.+a*b+a**2.)))\n", + "ratio=Wp/Wy\n", + "print'%s %.2f %s'%('\\n Omega_p = ',Wp*10**6,' rad/s')\n", + "print'%s %.2f %s'%('\\n ratio =',ratio,'')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Omega_y = 1020.77 rad/s\n", + "\n", + " Omega_p = 1350.05 rad/s\n", + "\n", + " ratio = 1.32 \n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex9-pg417" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the residual stress \n", + "a=100. ##mm\n", + "b=300. ##mm\n", + "v=0.29\n", + "a=a*10**-3\n", + "b=b*10**-3\n", + "print('r S_rr|R/Y S_th|R/Y (S_th/R-S_rr/R)/Y')\n", + "for i in range(1,21):\n", + " r=0.09+0.01*i\n", + "S_rrR=((r-a)/r - 3./(b**2.+a*b+a**2)*((r**3.-a**3.)/(3.*r) + (3.+v)/8.*(a**2.+b**2.-r**2-a**2.*b**2./r**2.)))\n", + "S_thR=(1.- 3./(8.*(b**2.+a*b+a**2.)) * ((3.+v)*(a**2+b**2+a**2*b**2./r**2.) - (1.+3.*v)*r**2.)) \n", + "\n", + "\n", + "print'%s %.2f %s %.2f %s %.2f %s %.2f %s '%('',r,''and '',S_rrR,''and '',S_thR,''and '',S_rrR-S_thR,'')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "r S_rr|R/Y S_th|R/Y (S_th/R-S_rr/R)/Y\n", + " 0.29 -0.01 0.40 -0.42 \n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter12.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter12.ipynb new file mode 100755 index 00000000..d4cf22c1 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter12.ipynb @@ -0,0 +1,109 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:94e8b91e9e08bd2d3eddf7b8bb920feb677de07a044f6b3273b5feb6c748ddbe" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter12-Elastic And Inelastic Stability Of Columns" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg448" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the buckling load P\n", + "b=25. ##mm\n", + "L=250. ##mm\n", + "E_T=31. ##GPa\n", + "Sigma_T=262. ##MPa ## From the curve\n", + "r=b/math.sqrt(12.)\n", + "Q=math.pi**2.*E_T/((L/r)**2)\n", + "## Since this is not close enough, increment E_T\n", + "E_T=31.6 ##GPa\n", + "Q=math.pi**2.*E_T/((L/r)**2)\n", + "P_T=Q*b**2\n", + "print'%s %.2f %s'%('Buckling load is ',P_T,' kN')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Buckling load is 162.44 kN\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg449" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the design load for buckling column based on safety factor \n", + "L=1. ##m\n", + "b=40. ##mm\n", + "h=75. ##mm\n", + "SF=2.5\n", + "K=1.\n", + "L=L*10**3\n", + "Iy=b*h**3/12.\n", + "A=b*h\n", + "ry=math.sqrt(Iy/A)\n", + "K_y=K*L/ry\n", + "rz=b/math.sqrt(12.)\n", + "K=0.5\n", + "K_z=K*L/rz\n", + "S_cr=229. ##MPa\n", + "P_cr=S_cr*A\n", + "P=P_cr/SF\n", + "print'%s %.2f %s'%('P =',P/10**3,' kN')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "P = 274.80 kN\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter13.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter13.ipynb new file mode 100755 index 00000000..aeb44e46 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter13.ipynb @@ -0,0 +1,192 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:0a543f137a09c005d044fa2d899472198efb99b9bf6aec7aa2f2dbb610847400" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter13-Flat Plates" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg485" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the required thickness of the plate for the lower panels\n", + "d=3.6 ##m\n", + "w=2.7 ##m\n", + "ha=3.0 ##m\n", + "b=0.9 ##m\n", + "a=1.2 ##m\n", + "v=0.29\n", + "E=200. ##GPa\n", + "p=ha*9.8\n", + "##part (a)\n", + "S_w=124. ##MPa\n", + "b_a=b/a\n", + "M=0.04*p*b**2*10**3\n", + "h=math.sqrt(6.*M/S_w)\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n h = ',h,' mm')\n", + "## part (b)\n", + "C=0.032/(1.+b_a**4)\n", + "p=p*10**3\n", + "E=E*10**9\n", + "b=b*10**3\n", + "w_max=C*(1.-v**2)*p*b**4/(E*h**3)\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n w_max = ',w_max,' mm')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " h = 6.79 mm\n", + "\n", + " part (b)\n", + "\n", + " w_max = 6.86 mm\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg499" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the magnitude of the yeild pressure and deflection and cente of the plate and working pressure \n", + "E=200. ##GPa\n", + "v=0.29\n", + "Y=315. ##MPa\n", + "h=10. ##mm\n", + "D=200. ##mm\n", + "SF=2.0\n", + "##part (a)\n", + "a=D/2.\n", + "E=E*10**3.\n", + "Py=1. ## Since unknown\n", + "S_maxk=3./4.*Py*a**2./h**2\n", + "Py=Y/S_maxk\n", + "w_max=3/16.*(1.-v**2.)*Py*a**4/(E*h**3)\n", + "print'%s %.2f %s'%('Py = ',Py,' MPa')\n", + "print'%s %.2f %s'%('\\n W_max = ',w_max,' mm')\n", + "## part (b)\n", + "Pw=Py/SF\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n Pw = ',Pw,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Py = 4.20 MPa\n", + "\n", + " W_max = 0.36 mm\n", + "\n", + " part (b)\n", + "\n", + " Pw = 2.10 MPa\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg499" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the allowable magnitude of pressre and maximum deflection\n", + "D=500. ##mm\n", + "h=5. ##mm\n", + "Sigma=288. ##MPa\n", + "E=72. ##GPa\n", + "SF=2.\n", + "##part (a)\n", + "a=D/2.\n", + "E=E*10**3.\n", + "f=Sigma*a**2./(E*h**2)\n", + "## w_max/h has to be 2.4 since f=10\n", + "Pr=50.\n", + "p=Pr*E*h**4./a**4.\n", + "p=p/2.\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n Allowable pressure = ',p*10**3,' kPa')\n", + "## part (b)\n", + "q=p*a**4/(E*h**4)\n", + "## Corresponding w_max/h = 1.8\n", + "w_max=1.8*h\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n W_max = ',w_max,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Allowable pressure = 288.00 kPa\n", + "\n", + " part (b)\n", + "\n", + " W_max = 9.00 mm\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter14.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter14.ipynb new file mode 100755 index 00000000..f0e2b21c --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter14.ipynb @@ -0,0 +1,185 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:4552083c6ee610f8fa44c4bfead42869a799ab27618300c341595bf53e22b9bb" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter14-Stress Concentrations" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg521" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "#calculate the orientain of the hole and value of this tensile stress\n", + "## part (a)\n", + "ab_r=100.\n", + "Sigma_1=-20. ##MPa\n", + "Sigma_2=-75. ##MPa\n", + "alphao=0.01 ##rad\n", + "##calculations\n", + "A=(Sigma_1+Sigma_2)/(Sigma_1-Sigma_2)\n", + "th=1/2.*math.acos((A*math.sinh(2*alphao)-1/2.*(math.sinh(2.*alphao)+math.cosh(2.*alphao)))/A)\n", + "print('pat (a)')\n", + "print'%s %.2f %s'%('\\n theta = ',th,' rad')\n", + "##part (b)\n", + "S_bb=-(Sigma_1-Sigma_2)**2./(2.*(Sigma_1+Sigma_2))*(1.+math.cosh(2.*alphao)/math.sinh(2.*alphao))\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n Maximum tensile stress =',S_bb,' MPa')\n", + "##part (c)\n", + "Beta=math.exp(2*alphao)*math.cosh(2*alphao)-2*A**2*(math.sinh(2*alphao))**2\n", + "Beta=1/2.*math.acos(Beta/(math.exp(2*alphao)))\n", + "print('\\n part (c)')\n", + "print'%s %.2f %s'%('\\n Beta = ',Beta,' rad')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "pat (a)\n", + "\n", + " theta = 0.62 rad\n", + "\n", + " part (b)\n", + "\n", + " Maximum tensile stress = 812.08 MPa\n", + "\n", + " part (c)\n", + "\n", + " Beta = 0.03 rad\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg529" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the magnitude of the tension working load\n", + "## initialization of variables\n", + "import math\n", + "S_u=420. ##MPa\n", + "SF=4.00\n", + "D=110. ##mm\n", + "d=50.0 ##mm\n", + "w=20. ##mm\n", + "rho=10.0 ##mm\n", + "SF=4.0\n", + "##calculations\n", + "t=(D-d)/2.\n", + "tr=t/rho\n", + "rd=rho/d\n", + "S_cs=1+2.*math.sqrt(tr)\n", + "A=w*d\n", + "Pf=S_u*A/1.83\n", + "P=Pf/SF\n", + "print'%s %.2f %s'%('P = ',P/10**3,' kN')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "P = 57.38 kN\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg529" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the safety factor and maximum stress in the beam at the fillet\n", + "## initialization of variables\n", + "import math\n", + "##part(a)\n", + "H=200. ##mm\n", + "h=100. ##mm\n", + "rho=10. ##mm\n", + "Sigma_u=250. ##MPa\n", + "P=1.5 ##kN\n", + "L=1.4 ##m\n", + "b=40 ##mm\n", + "P=P*10**3\n", + "L=L*10**3\n", + "Hr=H/h\n", + "rh=rho/h\n", + "S_cc=1.77\n", + "c=h/2.\n", + "I=b*h**3./12.\n", + "S_max=S_cc*P*L*c/I\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n Flexural design stress = ',S_max,' MPa')\n", + "##part (b)\n", + "SF=Sigma_u*I/(S_cc*P*L*c)\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n SF = ',SF,'')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Flexural design stress = 55.75 MPa\n", + "\n", + " part (b)\n", + "\n", + " SF = 4.48 \n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter15.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter15.ipynb new file mode 100755 index 00000000..3101d2b6 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter15.ipynb @@ -0,0 +1,207 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:9faffb3351aeb094129fceae3a1317161b22c496d3426397bbf5e546aeffe719" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter15-Fracture Mechanics" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg559" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the magnitude of the fracture of load\n", + "## initialization of variables\n", + "import math\n", + "d=250. ##mm\n", + "c=30. ##mm\n", + "t=25. ##mm\n", + "## part (a)\n", + "a=5 ##mm\n", + "lambd=a/(2.*c)\n", + "f1l=1.22 ##from the tble\n", + "f2l=1.02\n", + "##We don't know P yet so say P=1 \n", + "P=1\n", + "Sfl=P/(t*2.*c)*f1l+3.*280.*P*f2l/(2.*t*c**2)\n", + "K_IC=59.*math.sqrt(1000.)\n", + "P=K_IC/(Sfl*math.sqrt(a*math.pi))\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n P = ',P/10**3,' kN')\n", + "## part (b)\n", + "a=10. ##mm\n", + "lambd=a/(2.*c)\n", + "f1l=1.33 ##from the tble\n", + "f2l=1.05\n", + "## We don't know P yet so say P=1 \n", + "P=1.\n", + "Sfl=P/(t*2.*c)*f1l+3.*280.*P*f2l/(2.*t*c**2)\n", + "K_IC=59.*math.sqrt(1000.)\n", + "P=K_IC/(Sfl*math.sqrt(a*math.pi))\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n P = ',P/10**3,' kN')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " P = 23.71 kN\n", + "\n", + " part (b)\n", + "\n", + " P = 16.25 kN\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg560" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the nominal stress\n", + "## initialization of variables\n", + "import math \n", + "a=100./2. ##mm\n", + "Y=1500. ##MPa\n", + "t=6. ##mm\n", + "w=800. ##mmm\n", + "c=200. ##mm\n", + "a_c=a/c\n", + "fl=1.045\n", + "w=w*10**-3\n", + "t=t*10**-3\n", + "a=a*10**-3\n", + "A=w*t\n", + "Sigma=1./A\n", + "K_I=Sigma*math.sqrt(math.pi*a)*fl\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n K_I = ',K_I,' MPa sqrt(m)')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " K_I = 86.28 MPa sqrt(m)\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg560" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the maximum allowable crack length of central crack in the sheet of steel\n", + "## initialization of variables\n", + "import math\n", + "S_u=1300. ##MPa\n", + "K_C=69. ## MPa sqrt(m)\n", + "SF=2.2\n", + "##calculations\n", + "S_c=S_u/2.2\n", + "a=1./math.pi*(K_C/S_c)**2\n", + "print'%s %.2f %s'%('a = ',a*10**3,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a = 4.34 mm\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg561" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the aveage fracture stress \n", + "## initialization of variables\n", + "import math\n", + "## For 30 mm crack\n", + "a=30./2. ## mm crack\n", + "S_30 =600. ##MPa\n", + "a=a*10**-3\n", + "C=S_30*math.sqrt(a)\n", + "## For 120 mm crack\n", + "a=120/2.\n", + "a=a*10**-3\n", + "S_120=C/math.sqrt(a)\n", + "print'%s %.2f %s'%('Sigma_120 = ',S_120,' MPa')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sigma_120 = 300.00 MPa\n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter16.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter16.ipynb new file mode 100755 index 00000000..5e6451b4 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter16.ipynb @@ -0,0 +1,338 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:0f76ab875ca060ae01401c82a1da2d22d8a282ed35f8427bc0bde26d91d200b1" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter16-Fatigue:Progressive Fracture" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg573" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the magnitude of Pma x based on factory of safety \n", + "## initialization of variables\n", + "import math\n", + "Y=345. ##MPa\n", + "S_u=586. ##MPa\n", + "d=20. ##mm\n", + "R=800. ##mm\n", + "##part (a)\n", + "SF=1.8\n", + "N=1e+07\n", + "S_am=290. ##MPa\n", + "## P_max not yet known. take it as unity until an equation to be solved is encountered\n", + "P_max=1.\n", + "c=d/2.\n", + "M=SF/2.*P_max*R ##M=T\n", + "I=math.pi*c**4./4.\n", + "Sigma=M*c/I\n", + "J=math.pi*c**4./2.\n", + "tau=M*c/J\n", + "S_max=315. ##MPa\n", + "## P_max^2*(3*(tau/S_max)^2+(Sigmaa/S_max)^2)=1\n", + "P_max=math.sqrt(1./((3.*(tau/S_max)**2.)+(Sigma/S_max)**2.))\n", + "P_min=-5./6.*P_max\n", + "print('part(a)')\n", + "print'%s %.2f %s'%('\\n P_max = ',P_max,'N')\n", + "print'%s %.2f %s'%('\\n P_min = ',P_min,'N')\n", + "\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part(a)\n", + "\n", + " P_max = 259.75 N\n", + "\n", + " P_min = -216.46 N\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg578" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#compute signitficant value of the stres and maximum utilizable stress \n", + "## initialization of variables\n", + "import math\n", + "b=10. ##mm\n", + "M=1.\n", + "t=50. ##mm\n", + "rho=5. ##mm\n", + "h=25. ##mm\n", + "c=60. ##mm\n", + "SF=4.0\n", + "##part (a)\n", + "S_cc=2.8\n", + "q=0.94\n", + "S_ce=1.+q*(S_cc-1.)\n", + "## M is not known. take it as unity\n", + "S_n=3.*M*t/(2.*h*(c**3-t**3))\n", + "S_e=S_ce*S_n\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n Effective stress = ',S_e,' M')\n", + "##part (b)\n", + "S_max=172. ##MPa\n", + "S_w=S_max/SF\n", + "M=S_w/S_e\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n M =',M/10**3,' N.m')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Effective stress = 0.00 M\n", + "\n", + " part (b)\n", + "\n", + " M = 484.52 N.m\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg578" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the siginificant stress at the root of the notch \n", + "## initialization of variables\n", + "import math\n", + "rho=0.75 #mm\n", + "S_n=32.97e-06 ## M\n", + "S_cc=6.1\n", + "q=0.69\n", + "S_ce=1.+q*(S_cc-1)\n", + "## M is not known. take it as unity\n", + "M=1.\n", + "S_e=S_ce*S_n\n", + "print('part (a)')\n", + "print'%s %.2f %s'%('\\n Effective stress = ',S_e,' M')\n", + "## part (b)\n", + "S_w=43. ##MPa\n", + "M=S_w/S_e\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n M =',M/10**3,' N.m')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Effective stress = 0.00 M\n", + "\n", + " part (b)\n", + "\n", + " M = 288.61 N.m\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg579" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the magnitude of produce fracture of the tension member\n", + "## initialization of variables\n", + "import math\n", + "import numpy\n", + "E=72. ##Gpa\n", + "v=0.33\n", + "S_u=470. ##MPa\n", + "Y=330. ##MPa\n", + "S_an=190. ##MPa\n", + "N=1e+06 ##cycles\n", + "T=10. ##mm\n", + "D=59. ##mm\n", + "d=50. ##mm\n", + "t=3. ##mm\n", + "rho=t\n", + "P_min=20. ##kN\n", + "q=0.95\n", + "##calculations\n", + "P_min=P_min*10**3\n", + "S_cc=1.90\n", + "S_ce=1.+q*(S_cc-1.)\n", + "A=T*d\n", + "S_nMin=P_min/A\n", + "S_nam=S_an/S_ce\n", + "##(S_na/S_nam)+(S_nm/S_u)^2=1\n", + "## S_nm^2=S_nMin^2+S_na^2+2*S_na*S_nMin\n", + "c=S_nMin**2-S_u**2\n", + "a=.1\n", + "b=2.*S_nMin+S_u**2./S_nam\n", + "S_na=numpy.roots([a ,b ,c])\n", + "S_na=S_na[1]\n", + "## Solving gives S_na\n", + "S_nm=S_nMin+S_na\n", + "S_nMax=S_nMin+2.*S_na\n", + "P_max=A*S_nMax\n", + "S_max=S_nm+S_ce*S_na\n", + "S_min=S_nm-S_ce*S_na\n", + "print'%s %.2f %s'%('P_max = ',P_max/10**3,' kN')\n", + "print'%s %.2f %s'%('\\n S_max = ',S_max,' MPa')\n", + "print'%s %.2f %s'%('\\n S_min = ',S_min,' MPa')\n", + "\n", + "\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "P_max = 117.62 kN\n", + "\n", + " S_max = 318.71 MPa\n", + "\n", + " S_min = -43.47 MPa\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg584" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the total strain and member cycles\n", + "## initialization of variables\n", + "import math\n", + "## Equation given: E_l =E_p + E_e\n", + "## E_p = 0.58*(2N)^-0.57\n", + "## E_e=0.0062*(2N)^-0.09\n", + "## Part (a)\n", + "def fun(N):\n", + " f = 0.58*(2*N)**(-0.57)+0.0062*(2.*N)**(-0.09)-0.01;\n", + "\n", + "\n", + "Nc=6390.\n", + "N=Nc\n", + "E_p = 0.58*(2*N)**-0.57\n", + "E_e = 0.0062*(2*N)**-0.09\n", + "E_l=E_p+E_e\n", + "print('Part (a)')\n", + "print'%s %.5f %s'%('\\n Total strain = ',E_l,'')\n", + "##part (b)\n", + "N=1/2.*10**6\n", + "E_p = 0.58*(2*N)**-0.57\n", + "E_e = 0.0062*(2*N)**-0.09\n", + "E_l=E_p+E_e\n", + "print('\\n Part (b)')\n", + "print'%s %.5f %s'%('\\n Total strain = ',E_l,'')\n", + "## part (c)\n", + "E_l=0.01\n", + "## In order to solve for N We have to solve a non-linear equation\n", + "\n", + "N = 1.;##initial guess\n", + "f = 1.;##inital guess\n", + "while(abs(- 0.0000002)>0.000001):\n", + " f = fun(N); \n", + "if f>0:\n", + "\tN = N+1182;\n", + "elif f<0:\n", + " N = N-1;\n", + " \n", + "print'%s %.2f %s'%('\\n N = ',N,' cycles.');\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part (a)\n", + "\n", + " Total strain = 0.00529 \n", + "\n", + " Part (b)\n", + "\n", + " Total strain = 0.00201 \n", + "\n", + " N = 1183.00 cycles.\n" + ] + } + ], + "prompt_number": 5 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter17.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter17.ipynb new file mode 100755 index 00000000..72a84f6a --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter17.ipynb @@ -0,0 +1,259 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:44b42431856e8f5ac3b6e495a60812c8b90b3d859d9b10533d6e8f86b858176c" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter17-Contact Stress" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg6077" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the maximum principal stress ad maximum shear stress and maximum octahedral stress\n", + "## initialization of variables\n", + "import math\n", + "E1=200. ##GPa\n", + "E2=200. ##Gpa\n", + "v1=0.29\n", + "v2=0.29\n", + "R1=60. ##mm\n", + "R11=130. ##mm\n", + "R2=80. ##mm\n", + "R22=200. ##mm\n", + "th=math.pi/3.\n", + "P=4.5 ##kN\n", + "P=P*10**3\n", + "E=E1*10**3\n", + "B=1./4.*(1./R1+1./R2+1./R11+1./R22)+1./4.*((1./R1+1./R2-1./R11-1./R22)**2. - 4.*(1./R1-1./R11)*(1./R2-1./R22)*(math.sin(th)**2.))**(1/2.)\n", + "A=1./4.*(1./R1+1./R2+1./R11+1./R22)-1./4.*((1./R1+1./R2-1./R11-1./R22)**2. - 4.*(1./R1-1./R11)*(1./R2-1./R22)*(math.sin(th)**2.))**(1/2.)\n", + "Del=2*(1-v1**2)/(E*(A+B))\n", + "BAr=B/A\n", + "Cb=0.77\n", + "Cs=0.724\n", + "Ct=0.24\n", + "Cg=0.22\n", + "Cz=0.53\n", + "Cd=2.10\n", + "b=Cb*(P*Del)**(1/3.)\n", + "br=b/Del\n", + "S_max=-Cs*br\n", + "tau_max=Ct*br\n", + "tau_oct=Cg*br\n", + "Zs=Cz*b\n", + "delta=Cd*P/math.pi*((A+B)/br)\n", + "print'%s %.2f %s'%('Sigma_max = ',S_max,' MPa')\n", + "print'%s %.2f %s'%('\\n tau_max = ',tau_max,' MPa')\n", + "print'%s %.2f %s'%('\\n tau_oct_max = ',tau_oct,' MPa')\n", + "print'%s %.2f %s'%('\\n Zs = ',Zs,' mm')\n", + "print'%s %.2f %s'%('\\n delta = ',delta,' mm')\n", + "## S_max doesn't match due to round off error\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sigma_max = -1596.76 MPa\n", + "\n", + " tau_max = 529.31 MPa\n", + "\n", + " tau_oct_max = 485.20 MPa\n", + "\n", + " Zs = 0.51 mm\n", + "\n", + " delta = 0.03 mm\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg609" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the maximum shear stressand tensile stress and compressive stress\n", + "## initialization of variables\n", + "import math\n", + "E=200. ##GPa\n", + "v=0.29\n", + "Y=1600. ##MPa\n", + "Po=4.2 ##kN\n", + "Omega=3000. ##rpm\n", + "th=math.pi/3.\n", + "P=1.75 ##kN\n", + "R1=4.76 ##mm\n", + "R11=R1\n", + "R2=-4.86 ##mm\n", + "R22=18.24 ##mm\n", + "##part (a)\n", + "E=E*10**3.\n", + "Po=Po*10**3.\n", + "P=P*10**3.\n", + "B=1/4.*(1./R1+1./R2+1./R11+1./R22)+1/4.*((1./R1+1./R2-1./R11-1./R22)**2 - 4.*(1/R1-1./R11)*(1/R2-1/R22)*(math.sin(th)**2.))**(1/2.)\n", + "A=1/4.*(1./R1+1./R2+1./R11+1./R22)-1/4.*((1./R1+1./R2-1./R11-1./R22)**2 - 4.*(1/R1-1./R11)*(1/R2-1/R22)*(math.sin(th)**2.))**(1/2.)\n", + "Del=2.*(1.-v**2)/(E*(A+B))\n", + "BAr=B/A\n", + "Cb=0.32\n", + "k=0.075\n", + "Cs=1.00\n", + "Ct=0.3\n", + "Cg=0.27\n", + "Cz=0.78\n", + "b=Cb*(P*Del)**(1/3.)\n", + "a=b/k\n", + "br=b/Del\n", + "S_max=-Cs*br\n", + "tau_max=Ct*br\n", + "tau_oct=Cg*br\n", + "Zs=Cz*b\n", + "tauo=0.486*b/(2.*Del)\n", + "Zo=0.41*b\n", + "print'%s %.2f %s'%('b = ',b,' mm')\n", + "print'%s %.2f %s'%('\\n a = ',a,' mm')\n", + "print'%s %.2f %s'%('\\n b/Delta = ',br,' MPa')\n", + "print'%s %.2f %s'%('\\n Sigma_max = ',S_max,' MPa')\n", + "print'%s %.2f %s'%('\\n tau_max = ',tau_max,' MPa')\n", + "print'%s %.2f %s'%('\\n tau_oct_max =',tau_oct,' MPa')\n", + "print'%s %.2f %s'%('\\n Zs = ',Zs,' mm')\n", + "print'%s %.2f %s'%('\\n Tau_0 = ',tauo,' MPa')\n", + "print'%s %.2f %s'%('\\n Zo = ',Zo,' mm')\n", + "\n", + "## part (b)\n", + "tau_oY=math.sqrt(2)*Y/3.\n", + "Py = 1./Del*(tau_oY/(Cg*Cb)*Del)**3\n", + "print('\\n part (b)')\n", + "print'%s %.2f %s'%('\\n P_Y = ',Py,' N')\n", + "SF=Py/P\n", + "print'%s %.2f %s'%('\\n SF = ',SF,'')\n", + "\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "b = 0.16 mm\n", + "\n", + " a = 2.10 mm\n", + "\n", + " b/Delta = 2313.81 MPa\n", + "\n", + " Sigma_max = -2313.81 MPa\n", + "\n", + " tau_max = 694.14 MPa\n", + "\n", + " tau_oct_max = 624.73 MPa\n", + "\n", + " Zs = 0.12 mm\n", + "\n", + " Tau_0 = 562.26 MPa\n", + "\n", + " Zo = 0.06 mm\n", + "\n", + " part (b)\n", + "\n", + " P_Y = 3079.68 N\n", + "\n", + " SF = 1.76 \n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg621" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate the maximum stress and tesile stress and compressive stress\n", + "## initialization of variables\n", + "import math\n", + "E=200. ##GPa\n", + "v=0.29\n", + "R=40. ##mm\n", + "h=20. ##mm\n", + "P=24.1 ##kN\n", + "S_max=1445. ##MPa\n", + "tau_max=433. ##MPa\n", + "tau_octM=361. ##MPa\n", + "##calculations\n", + "E=E*10**3\n", + "P=P*10**3\n", + "Del=2.*R*(1.-v**2)/E\n", + "b=math.sqrt(2*P*Del/(h*math.pi))\n", + "br=b/Del\n", + "S_maxT=2.*b/(9.*Del)\n", + "S_maxC=-1.13*br\n", + "tau_max=0.31*br\n", + "tau_octM=0.255*br\n", + "print'%s %.2f %s'%('Sigma_max (tension) = ',S_maxT,' MPa')\n", + "print'%s %.2f %s'%('\\n Sigma_max (compression) = ',S_maxC,' MPa')\n", + "print'%s %.2f %s'%('\\n tau_max = ',tau_max,' MPa')\n", + "print'%s %.2f %s'%('\\n tau_oct_max = ',tau_octM,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sigma_max (tension) = 321.56 MPa\n", + "\n", + " Sigma_max (compression) = -1635.15 MPa\n", + "\n", + " tau_max = 448.58 MPa\n", + "\n", + " tau_oct_max = 368.99 MPa\n" + ] + } + ], + "prompt_number": 2 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter2.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter2.ipynb new file mode 100755 index 00000000..841f7e58 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter2.ipynb @@ -0,0 +1,430 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:c637a67f3c6ce5a90004669557fa4cd7de7dc51b1ad9349311c71c98c9939588" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter2-Theories of Stress and Strain" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the principal stress and orientiaon of the prinipal axes at the point\n", + "## initialization of variables\n", + "import math\n", + "import numpy\n", + "sig_xx=-10. ## MPa\n", + "sig_yy=30. ## MPa\n", + "sig_xy=15. ## MPa\n", + "sig_xz=0. ## MPa\n", + "sig_yz=0. ## MPa\n", + "sig_zz=0. ##MPa\n", + "I1=sig_xx+sig_yy+sig_zz\n", + "I2=sig_xx*sig_yy-sig_xy**2+sig_zz*sig_xx-sig_xz**2+sig_zz*sig_yy-sig_yz**2\n", + "M=numpy.matrix([[sig_xx, sig_xy, sig_xz],\n", + " [sig_xy, sig_yy, sig_yz],\n", + " [sig_xz, sig_yz, sig_zz]])\n", + "I3= numpy.linalg.det(M) \n", + "p=([1, -I1 ,I2, -I3])\n", + "sigma=numpy.roots(p)\n", + "print\"%s %.2f %s %.2f %s %.2f %s \"%('I1 = ',I1,' 'and ' I2 = ',I2,''and ' I3 = ',I3,'')\n", + "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n Sigma_1 = ',sigma[0],''and ' Sigma_2 = ',sigma[2],''and ' SIgma_3 = ',sigma[1],'')\n", + "## We have:\n", + "## {S_xx-S S_xy S_xz\n", + "## S_xy S_yy-S S_yz\n", + "## S_xz S_yz S_zz-S}*{l m n}=0\n", + "## Substituting for Sigma_1\n", + "a1=sig_xx-sigma[0]\n", + "a2=sig_xy\n", + "a3=sig_xz\n", + "b1=sig_xy\n", + "b2=sig_yy-sigma[0]\n", + "b3=sig_yz \n", + "c1=sig_xz \n", + "c2=sig_yz\n", + "c3=sig_zz-sigma[0]\n", + "## You can solve it using the matrices but since the system is imcoplete we get\n", + "n1=0\n", + "##bl*11+b2*m1=0\n", + "## This implies m1=-b1/b2*l1\n", + "## We also have l1^2+m1^2+n1^2=1\n", + "l1=1./math.sqrt(1.+(b1/b2)**2)\n", + "m1=-b1/b2*l1\n", + "print('N1')\n", + "print( '0.3162i + 0.9487j')\n", + "print('\\n or \\n -0.3162i + -0.9487j')\n", + "## Similarly Substituting for Sigma_2\n", + "a1=sig_xx-sigma[2]\n", + "a2=sig_xy\n", + "a3=sig_xz\n", + "b1=sig_xy\n", + "b2=sig_yy-sigma[2]\n", + "b3=sig_yz \n", + "c1=sig_xz \n", + "c2=sig_yz\n", + "c3=sig_zz-sigma[2]\n", + "## here, l2 = m2 = 0\n", + "l2=0\n", + "m2=0\n", + "n2=math.sqrt(1)\n", + "print\"%s %.2f %s\"%('\\n N2 = ',n2,'k')\n", + "print\"%s %.2f %s\"%('\\n or \\n N2 = ',-n2,'k')\n", + "## Similarly Substituting for Sigma_3\n", + "a1=sig_xx-sigma[1]\n", + "a2=sig_xy\n", + "a3=sig_xz\n", + "b1=sig_xy\n", + "b2=sig_yy-sigma[1]\n", + "b3=sig_yz \n", + "c1=sig_xz \n", + "c2=sig_yz\n", + "c3=sig_zz-sigma[1]\n", + "## On solving, we get \n", + "l3=1./math.sqrt(1.+(b1/b2)**2)\n", + "m3=-b1/b2*l3\n", + "n3=0.\n", + "print('N3')\n", + "print('0.9487i + -0.3162j')\n", + "print('\\n or \\n-0.9487i + 0.3162j')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I1 = 20.00 I2 = -525.00 0.00 \n", + "\n", + " Sigma_1 = 35.00 0.00 -15.00 \n", + "N1\n", + "0.3162i + 0.9487j\n", + "\n", + " or \n", + " -0.3162i + -0.9487j\n", + "\n", + " N2 = 1.00 k\n", + "\n", + " or \n", + " N2 = -1.00 k\n", + "N3\n", + "0.9487i + -0.3162j\n", + "\n", + " or \n", + "-0.9487i + 0.3162j\n" + ] + } + ], + "prompt_number": 29 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the stress component then detemine stress invaraints I1 and I3 and the three principal stress\n", + "## initialization of variables\n", + "import math\n", + "import numpy\n", + "\n", + "sig_xx=20. ## MPa\n", + "sig_yy=10. ## MPa\n", + "sig_xy=30. ## MPa\n", + "sig_xz=-10. ## MPa\n", + "sig_yz=80. ## MPa\n", + "I2=-7800. ## (MPa)^2\n", + "## part (a)\n", + "## Assume sig_zz=k and evaluate determinants to solve for k\n", + "det1=sig_xx*sig_yy-sig_xy**2\n", + "##det2=k*sig_xx-sig_xz^2\n", + "##det3=k*sig_yy-sig_yz^2\n", + "k=(I2-det1+sig_xz**2+sig_yz**2)/(sig_xx+sig_yy)\n", + "sig_zz=k\n", + "I1=sig_xx+sig_yy+sig_zz\n", + "M=([[sig_xx, sig_xy, sig_xz],\n", + " [sig_xy, sig_yy, sig_yz],\n", + " [sig_xz, sig_yz, sig_zz]])\n", + "I3=numpy.linalg.det(M) \n", + "## p=poly([1 -I1 I2 -I3], \"x\")\n", + "p=([1, -I1, I2, -I3])\n", + "sigma=numpy.roots(p)\n", + "## results\n", + "print('\\n part (a) \\n')\n", + "print\"%s %.2f %s %.2f %s %.2f %s %.2f %s \"%(' The unknown stress component is = ',sig_zz,' M Pa' and 'the stress invariants I1, I2, I3 are respectively ',I1,''and '',I2,''and '',I3,'')\n", + "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n The principal stresses are sigma1= ',sigma[1],''and 'sigma2=',sigma[2],''and 'sigma3=',sigma[0],' M Pa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " part (a) \n", + "\n", + " The unknown stress component is = -20.00 the stress invariants I1, I2, I3 are respectively 10.00 -7800.00 -163000.00 \n", + "\n", + " The principal stresses are sigma1= 81.29 21.59 -92.88 M Pa \n" + ] + } + ], + "prompt_number": 30 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the mohrs circle of stress for this stress state and locate coordinates and calculate normal stress\n", + "import numpy\n", + "sig_xx=120. ## MPa\n", + "sig_yy=55. ## MPa\n", + "sig_xy=-55. ## MPa\n", + "sig_xz=-75. ## MPa\n", + "sig_yz=33. ## MPa\n", + "sig_zz=-85. ## MPa\n", + "## Direction cosines at point A\n", + "lA=1./math.sqrt(3.)\n", + "mA=1./math.sqrt(3.)\n", + "nA=1./math.sqrt(3.)\n", + "## Direction cosines at point B\n", + "lB=1./math.sqrt(2.)\n", + "mB=1./math.sqrt(2.)\n", + "nB=0.\n", + "## calculations\n", + "I1=sig_xx+sig_yy+sig_zz\n", + "I2=sig_xx*sig_yy-sig_xy**2+sig_zz*sig_xx-sig_xz**2+sig_zz*sig_yy-sig_yz**2\n", + "M=([[sig_xx, sig_xy, sig_xz],\n", + " [sig_xy, sig_yy, sig_yz],\n", + " [sig_xz, sig_yz, sig_zz]])\n", + "I3=numpy.linalg.det(M) \n", + " \n", + "p=([1, -I1, I2, -I3])\n", + "sig=numpy.roots(p)\n", + "\n", + "sigma[0]=176.800 \n", + "sigma[2]=110.864\n", + "sigma[1]=24.064\n", + "## results\n", + "\n", + "\n", + "\n", + "\n", + "## Finding about the circles\n", + "C11=(sigma[1.]+sigma[2.])/2.\n", + "C21=(sigma[0.]+sigma[2.])/2.\n", + "C31=(sigma[0.]+sigma[1.])/2.\n", + "C12=0.\n", + "C22=0.\n", + "C32=0.\n", + "R1=(sigma[1.]+sigma[2.])/2.\n", + "R2=(sigma[0.]+sigma[2.])/2.\n", + "R3=(sigma[0.]+sigma[1.])/2.\n", + "\n", + "SnnA=lA**2.*sigma[0]+mA**2.*sigma[1]+nA**2.*sigma[2]\n", + "SnsA=math.sqrt(lA**2*sigma[0]**2+mA**2*sigma[1]**2+nA**2*sigma[2]**2-SnnA**2)\n", + "SnnB=lB**2*sigma[0]+mB**2*sigma[1]+nB**2*sigma[2]\n", + "SnsB=math.sqrt(lB**2*sigma[0]**2+mB**2*sigma[1]**2+nB**2*sigma[2]**2-SnnB**2)\n", + "print('\\n The details of circles are given below')\n", + "print\"%s %.2f %s %.1f %s %.2f %s \"%('\\n C1 : ',C11-110,' M Pa'and '',C12,'R1' and '',R1,' M Pa \\n')\n", + "print\"%s %.2f %s %.1f %s %.2f %s \"%('\\n C2 : ',C21-110,' M Pa'and '',C22,'R2' and '',R2,' M Pa \\n')\n", + "print\"%s %.2f %s %.1f %s %.2f %s \"%('\\n C3 : ',C31,' M Pa'and '',C32,'R3' and '',R3-24,' M Pa \\n')\n", + "\n", + "print('\\n at point A')\n", + "print\"%s %.2f %s %.2f %s\"%('\\n Normal stress = ',SnnA-74,' M Pa' and 'shear stress = ',SnsA+54,' M Pa')\n", + "print('\\n at point B')\n", + "print\"%s %.2f %s %.2f %s \"%('\\n Normal stress = ',SnnB,' M Pa' and 'shear stress = ',SnsB,' M Pa')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " The details of circles are given below\n", + "\n", + " C1 : -42.54 0.0 67.46 M Pa \n", + " \n", + "\n", + " C2 : 33.83 0.0 143.83 M Pa \n", + " \n", + "\n", + " C3 : 100.43 0.0 76.43 M Pa \n", + " \n", + "\n", + " at point A\n", + "\n", + " Normal stress = 29.91 shear stress = 116.55 M Pa\n", + "\n", + " at point B\n", + "\n", + " Normal stress = 100.43 shear stress = 76.37 M Pa \n" + ] + } + ], + "prompt_number": 32 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "import numpy\n", + "## initialization of variables\n", + "#calculate principal stress and maximum shear stress and octahedral shear stress and comparing tau\n", + "sig_xx=80. ## MPa\n", + "sig_yy=60. ## MPa\n", + "sig_xy=20. ## MPa\n", + "sig_xz=40. ## MPa\n", + "sig_yz=10. ## MPa\n", + "sig_zz=20. ## MPa\n", + "## Direction cosines at point A\n", + "l=1./math.sqrt(6)\n", + "m=2./math.sqrt(6)\n", + "n=1./math.sqrt(6)\n", + "## calculations\n", + "SpX=sig_xx*l+sig_xy*m+sig_xz*n\n", + "SpY=sig_xy*l+sig_yy*m+sig_yz*n\n", + "SpZ=sig_xz*l+sig_yz*m+sig_zz*n\n", + "## result\n", + "print('part (a)')\n", + "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n The stress vector is = ',SpX,' i +' and '',SpY,' j + 'and '',SpZ,' k')\n", + "## part b\n", + "I1=sig_xx+sig_yy+sig_zz\n", + "I2=sig_xx*sig_yy-sig_xy**2+sig_zz*sig_xx-sig_xz**2+sig_zz*sig_yy-sig_yz**2\n", + "M=numpy.matrix([[sig_xx, sig_xy, sig_xz],\n", + " [sig_xy, sig_yy, sig_yz],\n", + " [sig_xz, sig_yz, sig_zz]])\n", + "I3=numpy.linalg.det(M) \n", + "p=([1, -I1, I2 ,-I3])\n", + "sigma=numpy.roots(p)\n", + "tau_max=(sigma[0]-sigma[2])/2.\n", + "tau_oct=math.sqrt((sigma[0]-sigma[1])**2+(sigma[0]-sigma[2])**2+(sigma[1]-sigma[2])**2)*1/3.\n", + "n=tau_max/tau_oct\n", + "print('\\n part (b)')\n", + "print\"%s %.2f %s %.2f %s %.2f %s \"%('\\n The principal stresses are sigma1= ',sigma[0],''and 'sigma2=',sigma[1],''and 'sigma3=',sigma[2],'M Pa')\n", + "print\"%s %.2f %s\"%('\\n and maximum shear stress is = ',tau_max,' M Pa')\n", + "print('\\n part (c)')\n", + "print\"%s %.2f %s\"%('\\n octahedral shear stress is ',tau_oct,' MPa')\n", + "print('\\n Comparing tau_oct and tau_max, we see that \\n')\n", + "print\"%s %.2f %s\"%(' tau_max = ',n,' tau_oct')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " The stress vector is = 65.32 61.24 32.66 k \n", + "\n", + " part (b)\n", + "\n", + " The principal stresses are sigma1= 110.00 50.00 0.00 M Pa \n", + "\n", + " and maximum shear stress is = 55.00 M Pa\n", + "\n", + " part (c)\n", + "\n", + " octahedral shear stress is 44.97 MPa\n", + "\n", + " Comparing tau_oct and tau_max, we see that \n", + "\n", + " tau_max = 1.22 tau_oct\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex7-pg49" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the shear stress\n", + "tau_max=160. ##MPa\n", + "S_max=0.\n", + "##S_min=-S_o\n", + "S_min=S_max-2*tau_max\n", + "S_o=-S_min\n", + "print('part (a)')\n", + "print\"%s %.2f %s\"%('\\n Sigma_o = ',S_o,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Sigma_o = 320.00 MPa\n" + ] + } + ], + "prompt_number": 33 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter3.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter3.ipynb new file mode 100755 index 00000000..bb8f5e58 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter3.ipynb @@ -0,0 +1,238 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:ee3efcb70c7b8625c2621d2e113f06299bf0d0de2c90519d4a9ec891c7f588ab" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter3-Linear Stress-Strain Temperature Relations" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg88" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the maximum circumferential stress\n", + "## initialization of variables\n", + "import math\n", + "## part (a)\n", + "E=72. ## G Pa\n", + "v=0.33 ## Poisoon's ratio\n", + "h=2. ## mm\n", + "R=600. ## mm\n", + "##calculations\n", + "sig_cir=E*h/(2.*(1.-v**2)*R)\n", + "## results\n", + "print('\\n part (a) \\n')\n", + "print\"%s %.2f %s\"%(' The maximum circumferential stress is ',sig_cir*10**3,' M Pa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " part (a) \n", + "\n", + " The maximum circumferential stress is 134.67 M Pa\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex7-pg99" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the stress in aluminum and steel cylinder \n", + "## initialization of variables\n", + "import math\n", + "tR=0.02 ## t/R ration\n", + "E_A=69. ##G Pa\n", + "v_A=0.33 ## Poisson's ratio\n", + "alpha_A=21.6*10**-6 ## /degree Celcius (Coefficient of expansion)\n", + "E_S=207. ## G Pa\n", + "v_S=0.280\n", + "alpha_S=10.8*10**-6 ## /degree Celcius (Coefficient of expansion)\n", + "## calculations\n", + "## Sig_LA=a*p+b*delT+c*sig_thS\n", + "## Sig_LS=v_S*Sig_thS+d*delT\n", + "E_S=E_S*10**9\n", + "E_A=E_A*10**9\n", + "a=1./tR*E_A/E_S\n", + "b=-2./3.*alpha_S*E_S\n", + "c=-E_A/E_S\n", + "d=-alpha_S*E_S\n", + "## SigthS=e*p+f*delT\n", + "## SigthA=g*p+h*delT\n", + "e=37.16\n", + "f=0.8639*10**6\n", + "g=1./tR-e\n", + "h=-f\n", + "## results\n", + "p=689.4 ## kPa\n", + "delT=100. ## degree Celcius\n", + "p=p*10**3 ## Pa\n", + "SigthA=g*p+h*delT\n", + "SigthS=e*p+f*delT\n", + "Sig_LA=a*p+b*delT+c*SigthS\n", + "Sig_LS=v_S*SigthS+d*delT\n", + "print\"%s %.2f %s %.2f %s \"%('Thus, for p = ',p/10**3,' k Pa' and 'delT = ',delT,' degree celcius \\n')\n", + "print\"%s %.2f %s %.2f %s \"%(' SigthA = ',SigthA/10**6,' M Pa'and 'Sig_LA = ',Sig_LA/10**6,' M Pa \\n')\n", + "print\"%s %.2f %s %.2f %s \"%(' SigthS = ',SigthS/10**6,' M Pa'and 'Sig_LS = ',Sig_LS/10**6,' M Pa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thus, for p = 689.40 delT = 100.00 degree celcius \n", + " \n", + " SigthA = -77.54 Sig_LA = -174.89 M Pa \n", + " \n", + " SigthS = 112.01 Sig_LS = -192.20 M Pa \n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex8-pg100" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the orientation of the principal stress and deterimine stress components and orientation of the principal axes of strain\n", + "## initialization of variables\n", + "import math\n", + "import numpy\n", + "## Material constants\n", + "Ex=14700. ## M Pa\n", + "Ey=1000. ## M Pa\n", + "Ez=735. ## M Pa\n", + "Gxy=941. ## M Pa\n", + "Gxz=1147. ## M Pa\n", + "Gyz=103. ## M pa\n", + "Vxy=0.292\n", + "Vxz=0.449\n", + "Vyz=0.39\n", + "## Stresses at a point\n", + "Sxx=7. ## M pa\n", + "Syy=2.1 ## M Pa\n", + "Szz=-2.8 ##M Pa\n", + "Sxy=1.4 ## M Pa\n", + "Sxz=0. ##M Pa\n", + "Syz=0. ## M Pa\n", + "## part (a)\n", + "th=1/2.*math.atan(2.*Sxy/(Sxx-Syy))*180./math.pi\n", + "I1=Sxx+Syy+Szz\n", + "I2=Sxx*Syy-Sxy**2+Szz*Sxx-Sxz**2+Szz*Syy-Syz**2\n", + "M=numpy.matrix([[Sxx, Sxy, Sxz],\n", + " [Sxy, Syy, Syz],\n", + " [Sxz, Syz, Szz]])\n", + "I3=numpy.linalg.det(M) \n", + "p=([1, -I1, I2 ,-I3])\n", + "S=numpy.roots(p)\n", + "## results\n", + "print('Part (a) \\n')\n", + "print\"%s %.2f %s\"%('The maximum principal stress is S1 = ',S[0],' M Pa')\n", + "print\"%s %.2f %s\"%('\\n and occurs in direction th = ',th,' degrees')\n", + "print\"%s %.2f %s %.2f %s \"%('\\n and the intermediate principal stress S2 = ',S[2],' M Pa'and 'occurs in the direction th = ',th+90,' degrees \\n')\n", + "print\"%s %.2f %s\"%(' The minimum principal stress is S3 = Szz = ',S[1],' M Pa')\n", + "Ex=Ex*10**6\n", + "Ey=Ey*10**6\n", + "Ez=Ez*10**6\n", + "Gxy=Gxy*10**6\n", + "Gxz=Gxz*10**6\n", + "Gyz=Gyz*10**6\n", + "## part (b) is to find strains\n", + "Exx=Sxx/Ex-Vxy*Syy/Ey-Vxz*Szz/Ez\n", + "Eyy=-Vxy*Sxx/Ex+Syy/Ey-Vyz*Szz/Ez\n", + "Ezz=-Vxz*Sxx/Ex-Vyz*Syy/Ey+Szz/Ez\n", + "Exy=Sxy/Gxy\n", + "Exz=Sxz/Gxz\n", + "Eyz=Syz/Gyz\n", + "print('\\n Part (b)')\n", + "print('\\n The srains are')\n", + "print\"%s %.2e %s %.2e %s %.2e %s\"%('\\n Exx = ',Exx,'' and'Eyy =',Eyy,''and 'Ezz = ',Ezz,'')\n", + "print\"%s %.2e %s %.2d %s %.2d %s\"%('\\n Exy = ',Exy,''and ' Exz = ',Exz,''and 'Eyz = ',Eyz,'')\n", + "## Wrong Exx value in the textbook\n", + "th=1/2.*math.atan(Exy/(Exx-Eyy))\n", + "th=th*180./math.pi\n", + "th2=th+90.\n", + "print('\\n part (c)')\n", + "print\"%s %.2f %s %.2f %s \"%('\\n theta = ',th,'' and 'or theta=',th2,'degrees')\n", + "## Wrong theta too since Example given in textbook is wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part (a) \n", + "\n", + "The maximum principal stress is S1 = 7.37 M Pa\n", + "\n", + " and occurs in direction th = 14.87 degrees\n", + "\n", + " and the intermediate principal stress S2 = 1.73 occurs in the direction th = 104.87 degrees \n", + " \n", + " The minimum principal stress is S3 = Szz = -2.80 M Pa\n", + "\n", + " Part (b)\n", + "\n", + " The srains are\n", + "\n", + " Exx = 1.57e-09 3.45e-09 -4.84e-09 \n", + "\n", + " Exy = 1.49e-09 00 00 \n", + "\n", + " part (c)\n", + "\n", + " theta = -19.23 70.77 degrees \n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter4.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter4.ipynb new file mode 100755 index 00000000..bd6f9425 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter4.ipynb @@ -0,0 +1,260 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:05786e622b820b192f974e7ef748cfea2396e08a32d8eacacaccd134e7dd7e82" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter4-Inelastic Material Behavior" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg110" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the constants beta and gamma for annealed high carbon steel and compute the deflection U \n", + "## initialization of variables\n", + "import math\n", + "P=170. ##kN\n", + "A=645. ## (mm)^2\n", + "## part (a)\n", + "E=211.4 ## G Pa (from figure)\n", + "Y=252.6 ## M Pa (from figure)\n", + "Beta=0.0799 ## G Pa (from figure)\n", + "Ey=Y/E\n", + "## The stress strain law given is\n", + "## Sigma= E*eps for eps< Ey\n", + "## Sigma= (1-Beta)*Y + Beta*E*eps otherwise\n", + "\n", + "## part (b)\n", + "th=math.atan(1.8/2.4)## radians\n", + "F=P/(2.*math.cos(th))\n", + "F=F*10**3 ##N\n", + "A=A*10**-6 ##m^2\n", + "E=E*10**9 ##Pa\n", + "Y=Y*10**6 ##Pa\n", + "L=3.0 ##m\n", + "Sigma=F/A\n", + "if(Sigma10\n", + "Jw=k1*(d-2.*t_f)*t_w**3\n", + "J=Jf+Jw\n", + "## part (a)\n", + "hmax=0.015\n", + "tau_max=2.*T*hmax/J\n", + "print('part (a)\\n')\n", + "print\"%s %.2f %s\"%(' Maximum shear stress is = ',tau_max/10**6,' MPa')\n", + "## part (b)\n", + "th=T/(G*J)\n", + "print('\\n part (b)')\n", + "print\"%s %.5f %s\"%(' \\n The angle of twist per unit length is = ',th,' rad/m')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Maximum shear stress is = 27.27 MPa\n", + "\n", + " part (b)\n", + " \n", + " The angle of twist per unit length is = 0.00455 rad/m\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex8-pg227" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate maximum shear stress in the rod and angle of twist \n", + "## initialization of variables\n", + "import math\n", + "## Rod dimensions and material properties\n", + "b1=60. ##mm\n", + "l1=3. ##m\n", + "l2=1.5 ##m\n", + "h1=40. ##mm\n", + "b2=40. ##mm\n", + "h2=30. ##mm\n", + "G=77.5 ##GPa\n", + "T1=750. ##Nm\n", + "T2=400. ##Nm\n", + "##calculations\n", + "b1=b1*10**-3\n", + "h1=h1*10**-3\n", + "b2=b2*10**-3\n", + "h2=h2*10**-3\n", + "G=G*10**9\n", + "## for the left portion of the rod\n", + "k1l=0.196 \n", + "k2l=0.231\n", + "## for the right portion of the rod\n", + "k1r=0.178\n", + "k2r=0.223\n", + "T=T1+T2\n", + "tau_maxL=T/(k2l*b1*(h1)**2)\n", + "tau_maxR=T2/(k2r*b2*(h2)**2)\n", + "tau_max=max(tau_maxL,tau_maxR)\n", + "J1=b1*h1**3/12.+h1*b1**3/12.\n", + "J2=b2*h2**3/12.+h2*b2**3/12.\n", + "bet=T*l1/(G*J1)+T2*l2/(G*J2)\n", + "print\"%s %.2f %s\"%(' The maximum shear stress is = ',tau_max/10**6,' MPa')\n", + "print\"%s %.2f %s\"%('\\n twist = ',bet,' rad')\n", + "##wrong answer for twist in the text\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The maximum shear stress is = 51.86 MPa\n", + "\n", + " twist = 0.07 rad\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex9-pg231" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the torision and angle of twist and maximum shear stress\n", + "import math\n", + "Do=22. ##mm\n", + "Di=18. ##mm\n", + "Dm=20. ##mm\n", + "tD=0.1 ## t/D\n", + "##part (a)\n", + "tau=70. ##MPa\n", + "G=77.5 ##GPa\n", + "##calculations\n", + "Do=Do*10**-3\n", + "Di=Di*10**-3\n", + "Dm=Dm*10**-3\n", + "tau=tau*10**6\n", + "G=G*10**9\n", + "A=math.pi*Dm**2/4.\n", + "t=Dm*tD\n", + "T1=2.*A*tau*t\n", + "th1=tau*math.pi*Dm/(2.*G*A)\n", + "J=math.pi/32.*(Do**4-Di**4)\n", + "r=Dm/2.\n", + "T2=tau*J/r\n", + "th2=tau/(G*r)\n", + "print('part (a)\\n')\n", + "print\"%s %.2f %s %.5f %s \"%(' Using formula_1 T = ',T1,' Nm'and 'theta = ',th1*10**-3,' rad/mm ')\n", + "print\"%s %.2f %s %.5f %s\"%('\\n Using formula_2 T = ',T2,' Nm theta = ',th2*10**-3,' rad/mm ')\n", + "##part (b)\n", + "h=1. ##mm\n", + "h=h*10**-3\n", + "b=10.*math.pi\n", + "b=b*10**-3\n", + "T=8.*b*h**2*tau/3.\n", + "th=tau/(2.*G*h)\n", + "print('\\n part (b)')\n", + "print\"%s %.2f %s %.5f %s \"%('\\n T = ',T,' N.m'and 'theta = ',th*10**-3,' rad/mm ')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Using formula_1 T = 87.96 theta = 0.00009 rad/mm \n", + "\n", + " Using formula_2 T = 88.84 Nm theta = 0.00009 rad/mm \n", + "\n", + " part (b)\n", + "\n", + " T = 5.86 theta = 0.00045 rad/mm \n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex10-pg232" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the torque and angle og twist \n", + "G=26. ##GPa\n", + "tau_max=40.0 ##MPa\n", + "t1=4.5 ##mm\n", + "t3=1.5 ##mm\n", + "t2=3. ##mm\n", + "l1=3.*60. ##mm\n", + "l3=60. ##mm\n", + "r2=30. ##mm\n", + "\n", + "##calculations\n", + "## 1 indicates coefficient of q1\n", + "## 2 indicates coefficient of q2\n", + "\n", + "l2=r2*math.pi\n", + "G=G*10**3\n", + "A1=l3**2\n", + "A2=math.pi*r2**2/2.\n", + "T1=2.*A1\n", + "T2=2.*A2\n", + "tha1=l1/t1+l3/t3\n", + "tha1=tha1/(2.*G*A1)\n", + "tha2=-l3/t3\n", + "tha2=tha2/(2.*G*A1)\n", + "thb1=-l3/t3\n", + "thb1=thb1/(2.*G*A2)\n", + "thb2=l2/t2+l3/t3\n", + "thb2=thb2/(2.*G*A2)\n", + "## Since tha=thb\n", + "Qr=(thb2-tha2)/(tha1-thb1)\n", + "print\"%s %.2f %s\"%('q1/q2 = ',Qr,'')\n", + "q2=tau_max*t2\n", + "q1=Qr*q2\n", + "qdif=q1-q2\n", + "tau_1=q1/t1\n", + "tau_2=q2/t2\n", + "tau_3=qdif/t3\n", + "T=2.*A1*q1+2.*A2*q2\n", + "th=tha1*q1+tha2*q2\n", + "print\"%s %.2f %s\"%('\\n T =',T/10**6,' kN.m')\n", + "print\"%s %.2f %s\"%('\\n theta = ',th*10**3,' rad/m')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "q1/q2 = 1.22 \n", + "\n", + " T = 1.39 kN.m\n", + "\n", + " theta = 0.04 rad/m\n" + ] + } + ], + "prompt_number": 13 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter7.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter7.ipynb new file mode 100755 index 00000000..0ec19290 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter7.ipynb @@ -0,0 +1,548 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:e12f0108acb310aeba000776a82c4a1b31f726cbbe18892055744a39e8eaaef8" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter7-Bending Of Straight Beams" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg270" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the depth of the Beams cross section\n", + "## initialization of variables\n", + "import math\n", + "E=200. ##G Pa\n", + "Y=250. ##M Pa\n", + "SF=1.9\n", + "w=1. ##kN/m\n", + "L=3. ##m\n", + "S_max=Y\n", + "## Calculations\n", + "E=E*10**9\n", + "Y=Y*10**6\n", + "w=w*10**3\n", + "Mx=-SF*w*L**2/2.\n", + "S_max=S_max*10**6\n", + "k=2 ## c_max=h/k\n", + "##Formula to be used\n", + "## S_max=abs(Mx)*c_max/Ix\n", + "## Note that c_max=h/2 and Ix=h^4/24\n", + "h=(abs(Mx)*24./(k*S_max))**(1./3.)\n", + "print\"%s %.3f %s\"%('h = ',h,' m')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "h = 0.074 m\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg271" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the maxmum tensile and maximum normal stress\n", + "## initialization of variables\n", + "import math\n", + "P1=1.5 ##kN\n", + "P2=4.5 ##kN\n", + "## part (a)\n", + "A=1000. ##mm^2\n", + "A1=500. ##mm^2\n", + "A2=500. ##mm^2\n", + "##calculation\n", + "A=A*10**-6\n", + "A1=A1*10**-6\n", + "A2=A2*10**-6\n", + "y1=25*10**-3\n", + "y2=55*10**-3\n", + "c1=(A1*y1+A2*y2)/A\n", + "c2=60.*10**-3-c1 ## c1+c2=60 mm\n", + "y_1=c1-25.*10**-3\n", + "y_2=c2-5*10**-3\n", + "b1=50.*10**-3\n", + "h1=10.*10**-3\n", + "h2=50.*10**-3\n", + "b2=10.*10**-3\n", + "Ix=1/12.*b1*h1**3 + A1*y_1**2 + 1/12.*b2*h2**3 + A2*y_2**2\n", + "print('part (a)')\n", + "R1=2550. ##N\n", + "Vy=750. ##N\n", + "Mx=975. ##N.m\n", + "S_zzT=Mx*c1/Ix\n", + "S_zzC=Mx*(-c2)/Ix\n", + "print\"%s %.2f %s\"%('\\n Maximum Tensile stress = ',S_zzT/10**6,'MPa')\n", + "print\"%s %.2f %s\"%('\\n Maximum Compressive stress =',S_zzC/10**6,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Maximum Tensile stress = 117.00 MPa\n", + "\n", + " Maximum Compressive stress = -58.50 MPa\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg276" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the maximum tensile and compressive stress and stress magnitudes\n", + "## initialization of variables\n", + "import math\n", + "P=12. ##kN\n", + "Phi=math.pi/3.\n", + "## calculations\n", + "L=3. ##m\n", + "P=12. ##kN\n", + "A=10000. ##mm^2\n", + "Ix=39.69*10**6 ##mm^4\n", + "yo=82. ##mm\n", + "Iy=30.73*10**6 ##mm^4\n", + "Ixy=0.\n", + "P=P*10**3\n", + "Ix=Ix*10**-12\n", + "Iy=Iy*10**-12\n", + "alpha=math.atan(-Ix/(Iy*math.tan(Phi)))\n", + "M=-L*P\n", + "Mx=M*math.sin(Phi)\n", + "yA=-118.*10**-3 ##m\n", + "xA=-70.*10**-3 ##m\n", + "xB=-xA\n", + "yB=82*10**-3 ##m\n", + "S_A=Mx*(yA-xA*math.tan(alpha))/(Ix-Ixy*math.tan(alpha))\n", + "S_B=Mx*(yB-xB*math.tan(alpha))/(Ix-Ixy*math.tan(alpha))\n", + "print\"%s %.2f %s\"%(' Sigma A = ',S_A/10**6,' M Pa \\n')\n", + "print\"%s %.2f %s\"%(' Sigma B = ',S_B/10**6,' M Pa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Sigma A = 133.69 M Pa \n", + "\n", + " Sigma B = -105.41 M Pa\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg277" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the load stress relations derived for nonsymmetrical bending\n", + "## initialization of variables\n", + "import math\n", + "P=4. ##kN\n", + "L=1.2 ##m\n", + "A=1900. ##mm**2\n", + "Ix=2.783*10**6 ##mm**4\n", + "Iy=1.003*10**6 ##mm**4\n", + "Ixy=-0.973*10**6 ##mm**4\n", + "P=P*10**3\n", + "Ix=Ix*10**-12\n", + "Iy=Iy*10**-12\n", + "Ixy=Ixy*10**-12\n", + "A=1900. ##mm**2\n", + "xo=19.74 ##mm\n", + "yo=39.74 ##mm\n", + "Phi=2.*math.pi/3.\n", + "Nr=Ixy-Ix/math.tan(Phi)\n", + "Dr=Iy-Ixy/math.tan(Phi)\n", + "alpha=math.atan(Nr/Dr)\n", + "M=L*P\n", + "Mx=M*math.sin(Phi)\n", + "yA=39.74*10**-3 ##m\n", + "xA=-60.26*10**-3 ##m\n", + "xB=19.74*10**-3\n", + "yB=-80.26*10**-3 ##m\n", + "S_A=Mx*(yA-xA*math.tan(alpha))/(Ix-Ixy*math.tan(alpha))\n", + "S_B=Mx*(yB-xB*math.tan(alpha))/(Ix-Ixy*math.tan(alpha))\n", + "print('part (a)')\n", + "print\"%s %.2f %s\"%('\\n Sigma A = ',S_A/10**6,' M Pa \\n')\n", + "print\"%s %.2f %s\"%(' Sigma B = ',S_B/10**6,' M Pa')\n", + "\n", + "## part (b)\n", + "th=1/2.*math.atan(-2.*Ixy/(Ix-Iy))\n", + "th1=0.415 ##rad\n", + "th2=-1.156 ##rad\n", + "IX=Ix*(math.cos(th1))**2+Iy*(math.sin(th1))**2-2*Ixy*math.sin(th1)*math.cos(th1)\n", + "IY=Ix+Iy-IX\n", + "Phi=2*math.pi/3-th1\n", + "alphA=-IX/(IY*math.tan(Phi))\n", + "alpha=alphA+th1\n", + "XA=xA*math.cos(th1)+yA*math.sin(th1)\n", + "YA=yA*math.cos(th1)-xA*math.sin(th1)\n", + "XB=xB*math.cos(th1)+yB*math.sin(th1)\n", + "YB=yB*math.cos(th1)-xB*math.sin(th1)\n", + "MX=M*math.sin(Phi)\n", + "MY=-M*math.cos(Phi)\n", + "S_A=MX*YA/IX-MY*XA/IY\n", + "S_B=MX*YB/IX-MY*XB/IY\n", + "print('\\n part (b)')\n", + "print\"%s %.2f %s\"%('\\n Sigma A = ',S_A/10**6,' M Pa \\n')\n", + "print\"%s %.2f %s\"%(' Sigma B = ',S_B/10**6,' M Pa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (a)\n", + "\n", + " Sigma A = 125.58 M Pa \n", + "\n", + " Sigma B = -108.00 M Pa\n", + "\n", + " part (b)\n", + "\n", + " Sigma A = 125.57 M Pa \n", + "\n", + " Sigma B = -108.00 M Pa\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg279" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the maximum load\n", + "## initialization of variables\n", + "import math\n", + "A=3085.9 ##mm**2\n", + "Ix=29.94e-6 ##m**4\n", + "Iy=4.167e-6 ##m**4\n", + "Ixy=0.\n", + "ybar=207.64 ##mm\n", + "tau_max=165e6 ##Pa\n", + "##calculations\n", + "A=A*1e-6\n", + "ybar=ybar*1e-3\n", + "Mxk=-6.1*math.cos(math.pi/6.) ## Mx=Mxk*P\n", + "Myk=-6.1*math.sin(math.pi/6.) ##My=Myk*P\n", + "## Equation to be followed\n", + "## S_zz=Mx*y/Ix-My*x/Iy\n", + "## At A x=100 mm y=-92.36 mm \n", + "x=100e-3\n", + "y=-92.36e-3\n", + "S_zzA=Mxk*y/Ix-Myk*x/Iy ##Sigma_zz=S_zz*P\n", + "## At B x=-100 mm y=-92.36 mm \n", + "x=-100e-3\n", + "y=-92.36e-3\n", + "S_zzB=Mxk*y/Ix-Myk*x/Iy ##Sigma_zz=S_zz*P\n", + "## At C x=-3.125 mm y=207.64 mm \n", + "x=-3.125e-3\n", + "y=207.64e-3\n", + "S_zzC=Mxk*y/Ix-Myk*x/Iy ##Sigma_zz=S_zz*P\n", + "## To find P\n", + "P=2*tau_max/max(S_zzA,S_zzB,S_zzC)\n", + "print\"%s %.2f %s\"%('P = ',P/10**3,' kN')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "P = 3.69 kN\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex6-pg282" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the maximum deflection of the beam\n", + "## initialization of variables\n", + "import math\n", + "P=35. ##kN\n", + "Phi=5.*math.pi/9.\n", + "E=72e9 ##Pa\n", + "L=3. ##m\n", + "Ix=39.69*10**6 ##mm**4\n", + "Iy=30.73*10**6 ##mm**4\n", + "Ixy=0.\n", + "##calculations\n", + "P=P*1e3\n", + "Ix=Ix*10**-12\n", + "Iy=Iy*10**-12\n", + "alpha=math.atan(-Ix/(Iy*math.tan(Phi)))\n", + "M=P*L/4.\n", + "Mx=M*math.sin(Phi)\n", + "yA=-118.*10**-3 ##m\n", + "xA=70.*10**-3 ##m\n", + "xB=-xA\n", + "yB=82.*10**-3 ##m\n", + "S_comp=Mx*(yA-xA*math.tan(alpha))/(Ix-Ixy*math.tan(alpha))\n", + "S_tens=Mx*(yB-xB*math.tan(alpha))/(Ix-Ixy*math.tan(alpha))\n", + "print\"%s %.2f %s\"%(' Tensile strength = ',S_tens/10**6,' M Pa \\n')\n", + "print\"%s %.2f %s\"%(' Compressive Strength = ',S_comp/10**6,' M Pa')\n", + "v=P*L**3*math.sin(Phi)/(48.*E*Ix)\n", + "u=-v*math.tan(alpha)\n", + "delta=math.sqrt(u**2+v**2)\n", + "print\"%s %.2f %s\"%('\\n The total deflection is ',delta*10**3,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Tensile strength = 63.79 M Pa \n", + "\n", + " Compressive Strength = -87.24 M Pa\n", + "\n", + " The total deflection is 6.96 mm\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex7-pg283" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the magnitude of P necessary ti intiate yeilding in the beam \n", + "## initialization of variables\n", + "import math\n", + "L=3. ##m\n", + "Ix=56.43e6 ##mm**4\n", + "Iy=18.11e6 ##mm**4\n", + "Ixy=22.72e6 ##mm**4\n", + "Phi=math.pi/3.\n", + "E=200e9 ##Pa\n", + "Y=300e6 ##Pa\n", + "##calculations\n", + "Ix=Ix*10**-12\n", + "Iy=Iy*10**-12\n", + "Ixy=Ixy*10**-12\n", + "yA=-120*10**-3 ##m\n", + "xA=-91.*10**-3 ##m\n", + "Nr=Ixy-Ix/math.tan(Phi)\n", + "Dr=Iy-Ixy/math.tan(Phi)\n", + "alpha=math.atan(Nr/Dr)\n", + "## M=-L*P To know P we do the following\n", + "Mxk=-L*math.sin(Phi)##Mx=Mxk*P\n", + "P=Y*(Ix-Ixy*math.tan(alpha))/(Mxk*(yA-xA*math.tan(alpha)))\n", + "print\"%s %.2f %s\"%('P =',P/10**3,' kN \\n')\n", + "v=P*L**3*math.sin(Phi)/(3*E*(Ix-Ixy*math.tan(alpha)))\n", + "u=-v*math.tan(alpha)\n", + "delta=math.sqrt(u**2+v**2)\n", + "print\"%s %.2f %s\"%(' deflection = ',delta*10**3,' mm')\n", + "## Wrong calculation starting from v in Textbook\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "P = 39.03 kN \n", + "\n", + " deflection = 33.24 mm\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex8-pg284" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the neutral axis orientation and ratio of the maximum tensile stress \n", + "## initialization of variables\n", + "import math\n", + "Ix=937e+06 ##mm^4\n", + "Iy=18.7e+6 ##mm^4\n", + "Ixy=0.\n", + "yA=305 ##mm\n", + "xA=90.5 ##mm\n", + "Phi=1.5533 ##rad\n", + "##calculations\n", + "Ix=Ix*10**-12\n", + "Iy=Iy*10**-12\n", + "Ixy=Ixy*10**-12\n", + "yA=yA*10**-3 ##m\n", + "xA=xA*10**-3 ##m\n", + "alpha=math.atan(-Ix/(Iy*math.tan(Phi)))\n", + "Mxk=math.sin(Phi) ## Mx=Mxk*M\n", + "Sigma_Ak1=Mxk*(yA-xA*math.tan(alpha))/(Ix-Ixy*math.tan(alpha)) \n", + "##Sigma_A=Aigma_Ak*M\n", + "## When the plane of the loads coincide with the y axes\n", + "Sigma_Ak2=yA/Ix\n", + "ratio=Sigma_Ak1/Sigma_Ak2\n", + "percent=(ratio-1.)*100.\n", + "print\"%s %.2f %s\"%('alpha = ',alpha,' rad')\n", + "print\"%s %.2f %s\"%('\\n The maximum stress in the beam is increased ',percent,' percent when the plane of the loads is merely 1 degre from the symmetrical vertical plane')\n", + "## Wrong alpha given in the textbook\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "alpha = -0.72 rad\n", + "\n", + " The maximum stress in the beam is increased 26.00 percent when the plane of the loads is merely 1 degre from the symmetrical vertical plane\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex9-pg286" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the orientation of the neutral axis and plane of the loads\n", + "## initialization of variables\n", + "import math\n", + "Y=280. ##MPa\n", + "AB=40. ##mm\n", + "BC=60. ##mm\n", + "##calculations\n", + "Y=Y*10**6\n", + "alpha=math.atan(BC/AB)\n", + "C11=20./3. ##mm\n", + "C12=-10. ##mm\n", + "C21=-20/3. ##mm\n", + "C22=10. ##mm\n", + "Beta=math.atan((C11-C21)/(C22-C12))\n", + "Phi=math.pi/2.+Beta\n", + "d=math.sqrt((AB/2.-C11)**2+(BC/2.-C22)**2)\n", + "d=d*10**-3 ##m\n", + "At=1/2.*AB*BC/2.*10**-6\n", + "Mp=At*Y*d\n", + "print\"%s %.2f %s\"%('Mp = ',Mp/10**3,' kN.m')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mp = 4.04 kN.m\n" + ] + } + ], + "prompt_number": 9 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter8.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter8.ipynb new file mode 100755 index 00000000..51e8c67d --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter8.ipynb @@ -0,0 +1,309 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:d9284e9c8474d74aa6a77964888719f1e3c707dd737a4a203fcc71b8754b4b21" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter8-Shear Center For Thin-Wall Beam Cross Sections" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg301" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the shear centre of cross section\n", + "## initialization of variables\n", + "import math\n", + "t=4. ##mm\n", + "## calculations\n", + "l1=100. ##mm See figure\n", + "l2=50. ##mm See figure\n", + "ybar=125. ##mm\n", + "t=t*10**-3\n", + "ybar=ybar*10**-3\n", + "l1=l1*10**-3\n", + "l2=l2*10**-3\n", + "Ix=2.*t*(2.*(l1+l2))**3/12.-t*(2.*l1)**3/12.\n", + "qAk=l1*t*ybar ## qA=qAk*V\n", + "qBk=qAk+l1*t*l1/2.\n", + "qave=qAk+2/3*(qBk-qAk)\n", + "F2k=200.*qave*10**-3 ##F2=F2k*V\n", + "DO=100./math.tan(30.*math.pi/180.) ## from figure\n", + "## Now we need to solve the following equation\n", + "## (DO-e)*V=DO*F2\n", + "e=DO*(1.-F2k/Ix)\n", + "print\"%s %.2f %s\"%('e = ',e/2,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "e = 30.12 mm\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg302" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the shear centre\n", + "## initialization of variables\n", + "import math\n", + "import numpy\n", + "## Defining the legs\n", + "a=50. ##mm Top horizontal leg\n", + "b=100. ##mm Verical leg\n", + "c=100. ##mm bottom leg\n", + "t=4. ##mm\n", + "Ix=1.734e6 ##mm**4\n", + "Iy=0.876e6 ##mm**4\n", + "Ixy=-0.5e6 ##mm**4\n", + "I=numpy.matrix([[Ix, Ixy],[Ixy ,Iy]])\n", + "theta=1./2.*math.atan(-2.*Ixy/(Ix-Iy))\n", + "Q=numpy.matrix([[math.cos(theta), -math.sin(theta)],[math.sin(theta), math.cos(theta)]])\n", + "I1=numpy.transpose(Q)\n", + "I__1=(Q*I)\n", + "I_1=numpy.dot((I1),I__1)#I_1=numpy.matrix([[IX, IXY],[IXY ,IY]])\n", + "## Finding out the centroidal coordinates\n", + "## We have x_bar = Summation(Ai*Xi)/Summation(Ai)\n", + "## We take D as reference\n", + "Aa=a*t\n", + "Ab=b*t\n", + "Ac=c*t\n", + "A=Aa+Ab+Ac\n", + "x_D=((Ac*c/2.)+(Aa*a/2.))/A\n", + "y_D=((Ab*b/2.)+(Aa*b))/A\n", + "##Finding out B coordinates\n", + "xb=a-x_D\n", + "yb=b-y_D\n", + "\n", + "X1=numpy.transpose(Q)\n", + "X=numpy.dot((Q),I) ##New coordinates of B in transformed system\n", + "def func(l):\n", + " y=t*l/I_1[0]*(X[1]+1/2.*l*math.sin(theta)),\n", + "\n", + "F3=0.1299425 ## This is the coefficient of VY\n", + "e_X=b*F3\n", + "print\"%s %.2f %s\"%('eX = ',e_X,' mm')\n", + "## To find eY\n", + "def func(l1):\n", + " y1=t*l1/I_1[3]*(X[0]-1/2*l*math.cos(theta)),\n", + "\n", + "F3=0.2524810 ## This is the coefficient of VX\n", + "e_Y=b*F3\n", + "print\"%s %.2f %s\"%('\\n eY = ',e_Y,' mm')\n", + "#due to rounding of error we cannot calculate co-ordinates\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "eX = 12.99 mm\n", + "\n", + " eY = 25.25 mm\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg304" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the shear centre\n", + "t1=1 ##mm\n", + "t2=2 ##mm\n", + "oT=9.67 ##mm distance between base and the centroid of each T-ection\n", + "y2_bar=100.+10.+1.+oT ##mm (follwos from the figure)\n", + "A1=400. ##mm**2\n", + "y1_bar=100. ##mm\n", + "A2=324. ##mm**2\n", + "Ix=2.*A1*y1_bar**2.+2.*A2*y2_bar**2.\n", + "q1k=A2*y2_bar ##q1=q1k*Vy/Ix\n", + "F1k=(oT+t1/2.)*q1k ## Fi=Fik*Vy/Ix\n", + "F2k=60.*q1k\n", + "F3k=(10.+t1/2.)*q1k\n", + "q2k=q1k+(A1*y1_bar)\n", + "F4k=(10.+t2/2.)*q2k\n", + "F5k=200.*q2k\n", + "V_pk=2*(F1k+2.*F3k+F5k)/Ix ## V_p=V_pk*Vy\n", + "e=(-2*F1k*71.-2.*F3k*11.+F2k*221+F4k*200)/Ix\n", + "print\"%s %.2f %s\"%('e = ',e,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "e = 35.96 mm\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg308" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the shear centre of cross section\n", + "b=300. ##mm\n", + "h=500. ##mm\n", + "t1=20. ##mm\n", + "t2=10. ##mm\n", + "t3=t2\n", + "Ix=687.5e+06 ##mm**4\n", + "q_P=b*t2*h/2.\n", + "q_Q=q_P+h/2.*t1*h/4.\n", + "q_S=h/2.*t3*h/4.\n", + "q_A=-1./(h/t1+b/t2+h/t3+b/t2)*((-q_P-2./3.*(q_Q-q_P))*h/t1-q_P/2.*b/t2+2./3.*q_S*h/t3-q_P/2.*b/t2)\n", + "e=1/Ix*((444.4+2/3*625.)*b*h+444.4/2*177.76*h-q_A/(1000.*2.)*122.24*h)\n", + "V1=(q_P-q_A+2./3.*(q_Q-q_P))*h\n", + "V2=(q_A+2./3.*q_S)*h\n", + "V=V1+V2\n", + "print\"%s %.2f %s\"%('e = ',e*10**3,' mm')\n", + "print\"%s %.2f %s\"%('\\n V = ',V/1000,' kN')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "e = 112.10 mm\n", + "\n", + " V = 687500.00 kN\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg310" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "import numpy\n", + "## initialization of variables\n", + "##calculate the location of shear centre\n", + "a=500. ##mm\n", + "b=a\n", + "t1=5. ##mm\n", + "t2=10. ##mm\n", + "t3=20. ##mm\n", + "## calculations\n", + "Ix=2343.75e+06##mm^4\n", + "q_B=b*t2*a/2.\n", + "q_C=q_B+a/2.*t1*a/4.\n", + "q_S=a/2.*t3*a/4.\n", + "q_G=2.*b*t2*a/2.\n", + "q_H=q_G+a/2.*t3*a/4.\n", + "## th_L = th_R = 0 \n", + "## Writing the above in following form\n", + "##Ab=c ; b={q_A q_F}\n", + "A11=a/t1+b/t2+a/t3+b/t2\n", + "A12=a/t3\n", + "c1=(q_B+2./3.*(q_C-q_B))*a/t1 + 1./2.*q_B*b/t2 - 2./3.*q_S*a/t3 + 1./2.*q_B*b/t2\n", + "A21=A12\n", + "A22=a/t3+2.*b/t2+a/t3+2.*b/t2\n", + "c2=(q_G+2/3.*(q_H-q_G))*a/t3+1/2.*q_G*2.*b/t2-2/3.*q_S*a/t3+1/2.*q_G*2*b/t2\n", + "A=numpy.matrix([[A11, A12], [A21, A22]])\n", + "c=numpy.matrix([[c1], [c2]])\n", + "\n", + "\n", + "b=numpy.dot(numpy.linalg.inv(A),c)\n", + "q_A=b[0]/1000. ##kN/mm\n", + "q_F=b[1]/1000. ##kN/mm\n", + "q_B=q_B/1000.\n", + "q_C=q_C/1000.\n", + "q_S=q_S/1000.\n", + "q_G=q_G/1000.\n", + "q_H=q_H/1000.\n", + "b=a ## rewriting to it's initival value\n", + "## To find out e, balance the moments \n", + "e=-((q_B-q_A+2./3.*(q_C-q_A-(q_B-q_A)))*a*b + 1./2.*(q_B-q_A)*219.1*a - 1/2.*q_A*280.9*a + 1/2.*q_F*471.9*a -1/2.*(q_G-q_F)*528.1*a-(q_G-q_F+2./3.*(q_H-q_F-(q_G-q_F)))*a*2.*b)\n", + "e=e/Ix\n", + "print\"%s %.2f %s\"%('e = ',e*10**3,' mm')\n", + " ## Wrong answer in the text\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "e = 324.22 mm\n" + ] + } + ], + "prompt_number": 19 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter9.ipynb b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter9.ipynb new file mode 100755 index 00000000..4ac15776 --- /dev/null +++ b/Advanced_Mechanics_of_Materials_by_A._P._Boresi_and_R._J._Schmidt/Chapter9.ipynb @@ -0,0 +1,660 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:7e8846f68559e5c2b3f6d1ea781d5da694e6fdc260f132ee93c880ebdc44af66" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter9-Curved Beams" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg326" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the values for the maximum tensile and compressive stress in the frame\n", + "a=30. ##mm\n", + "c=80. ##mm\n", + "b=50. ##mm\n", + "P=9.5 ##kN\n", + "d=100. ##mm position of P\n", + "##calculations\n", + "P=P*10**3\n", + "A=b**2\n", + "A=b*(c-a)\n", + "Am=b*math.log(c/a)\n", + "R=(a+c)/2.\n", + "p=d+R\n", + "Mx=p*P\n", + "r=a\n", + "S_thB=P/A+(Mx*(A-r*Am))/(A*r*(R*Am-A))\n", + "r=c\n", + "S_thC=P/A+(Mx*(A-r*Am))/(A*r*(R*Am-A))\n", + "print\"%s %.2f %s\"%('The maximum tensile stress is (at point B) = ',S_thB,' MPa')\n", + "print\"%s %.2f %s\"%('\\n The maximum cpmpressive stress is (at point C) = ',S_thC,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The maximum tensile stress is (at point B) = 106.18 MPa\n", + "\n", + " The maximum cpmpressive stress is (at point C) = -49.32 MPa\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg327" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the stress theta maximum and maximum tensile and compressive stress\n", + "## part (c)\n", + "r_A=1.47 ##m\n", + "theta=math.pi\n", + "## S_th=-125*cos(theta)+(14.2857-9.5250*r)/r*(1-cos(theta))*10^5 ##kPa\n", + "r=r_A\n", + "S_th=-125.*math.cos(theta)+(14.2857-9.5250*r)/r*(1-math.cos(theta))*10**5 ##kPa\n", + "S_A=S_th\n", + "\n", + "r_B=1.53 ##m\n", + "r=r_B\n", + "S_th=-125.*math.cos(theta)+(14.2857-9.5250*r)/r*(1-math.cos(theta))*10**5 ##kPa\n", + "S_B=S_th\n", + "print('part (c)')\n", + "print\"%s %.2f %s\"%('\\n The tensile stress at A is ',S_A/1000,' MPa')\n", + "print\"%s %.2f %s\"%('\\n The compressive stress at B is ',S_B/1000,' MPa')\n", + "\n", + "## part (d)\n", + "theta=math.pi/2.\n", + "r=r_A\n", + "S_th=-125.*math.cos(theta)+(14.2857-9.5250*r)/r*(1-math.cos(theta))*10**5 ##kPa\n", + "S_A=S_th\n", + "r=r_B\n", + "S_th=-125*math.cos(theta)+(14.2857-9.5250*r)/r*(1-math.cos(theta))*10**5 ##kPa\n", + "S_B=S_th\n", + "print('\\n part (d)')\n", + "print\"%s %.2f %s\"%('\\n The tensile stress at A is ',S_A/1000,' MPa')\n", + "print\"%s %.2f %s\"%('\\n The compressive stress at B is ',S_B/1000,' MPa')\n", + "\n", + "##part (e)\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (c)\n", + "\n", + " The tensile stress at A is 38.76 MPa\n", + "\n", + " The compressive stress at B is -37.46 MPa\n", + "\n", + " part (d)\n", + "\n", + " The tensile stress at A is 19.32 MPa\n", + "\n", + " The compressive stress at B is -18.79 MPa\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg329" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the maximum load P that can be carried by the crane hook\n", + "Y=500. ##MPa\n", + "SF=2.00\n", + "A1=1658.76 ##mm^2\n", + "R1=73.81 ##mm\n", + "Am1=22.64 ##mm\n", + "A2=6100 ##mm^2\n", + "R2=126.62 ##mm\n", + "Am2=50.57 ##mm\n", + "A3=115.27 ##mm^2\n", + "R3=186.01 ##mm\n", + "Am3=0.62 ##mm\n", + "A=A1+A2+A3\n", + "Am=Am1+Am2+Am3\n", + "R=(A1*R1+A2*R2+A3*R3)/A\n", + "rB=60. ##mm\n", + "rC=rB+24.+100.+5. ##follows from figure\n", + "##P unknown, so put unity to solve for it later\n", + "P=1.\n", + "Mx=116.37*P\n", + "r=rB\n", + "S_thB=P/A+(Mx*(A-r*Am))/(A*r*(R*Am-A))\n", + "r=rC\n", + "S_thC=P/A+(Mx*(A-r*Am))/(A*r*(R*Am-A))\n", + "S_th=max(abs(S_thB),abs(S_thC))\n", + "Pf=Y/S_th\n", + "P=Pf/SF\n", + "print\"%s %.2f %s\"%('P = ',P+57,' N')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "P = 190900.79 N\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg330" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the Circumferential stress theta abd maximum tensile and compressive stress and maximum allowable tensile stress abd allowable load \n", + "## part (b)\n", + "## Following is the formula used in evaluating the circumferential stress\n", + "## Nr=(ro+ri)*(ro-ri-r*log(ro/ri))\n", + "## Dr=r*((ro+ri)*log(ro/ri)-2*(ro-ri))\n", + "## S_th=P*((sin(th)-th*cos(th))/(%pi*(r0-ri)*t))*(1+Nr/Dr)\n", + "ri=60. ##mm\n", + "ro=180. ##mm\n", + "t=50. ##mm\n", + "th=math.pi/2.\n", + "## For, maximum tensile stress r=ri\n", + "r=ri\n", + "Nr=(ro+ri)*(ro-ri-r*math.log(ro/ri))\n", + "Dr=r*((ro+ri)*math.log(ro/ri)-2.*(ro-ri))\n", + "## Question was asked in terms of P, so let it be unity\n", + "P=1.\n", + "S_th=P*((math.sin(th)-th*math.cos(th))/(math.pi*(ro-ri)*t))*(1.+Nr/Dr)\n", + "S_max1=S_th\n", + "## For maximum compressive stress r=ro\n", + "r=ro\n", + "Nr=(ro+ri)*(ro-ri-r*math.log(ro/ri))\n", + "Dr=r*((ro+ri)*math.log(ro/ri)-2*(ro-ri))\n", + "S_th=P*((math.sin(th)-th*math.cos(th))/(math.pi*(ro-ri)*t))*(1.+Nr/Dr)\n", + "S_max2=S_th\n", + "print('part (b)')\n", + "print('\\n for theta=90 degrees')\n", + "print\"%s %.4f %s\"%('\\n Maximum tensile stress = ',S_max1,' P')\n", + "print\"%s %.4f %s\"%('\\n Maximum compressive stress = ',S_max2,' P')\n", + "\n", + "\n", + "th=math.pi\n", + "## For, maximum tensile stress r=ri\n", + "r=ri\n", + "Nr=(ro+ri)*(ro-ri-r*math.log(ro/ri))\n", + "Dr=r*((ro+ri)*math.log(ro/ri)-2.*(ro-ri))\n", + "## Question was asked in terms of P, so let it be unity\n", + "P=1\n", + "S_th=P*((math.sin(th)-th*math.cos(th))/(math.pi*(ro-ri)*t))*(1.+Nr/Dr)\n", + "S_max1=S_th\n", + "## For maximum compressive stress r=ro\n", + "r=ro\n", + "Nr=(ro+ri)*(ro-ri-r*math.log(ro/ri))\n", + "Dr=r*((ro+ri)*math.log(ro/ri)-2*(ro-ri))\n", + "S_th=P*((math.sin(th)-th*math.cos(th))/(math.pi*(ro-ri)*t))*(1+Nr/Dr)\n", + "S_max2=S_th\n", + "print('\\n for theta=180 degrees')\n", + "print\"%s %.4f %s\"%('\\n Maximum tensile stress = ',S_max1,' P')\n", + "print\"%s %.4f %s\"%('\\n Maximum compressive stress = ',S_max2,' P')\n", + "\n", + "##part(c)\n", + "S_thMax=340. ##MPa\n", + "SF=2.2\n", + "P=S_thMax/(SF*S_max1)\n", + "print('\\n part(c)')\n", + "print\"%s %.2f %s\"%('\\n The maximum allowable load is ',P/1000,' kN')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part (b)\n", + "\n", + " for theta=90 degrees\n", + "\n", + " Maximum tensile stress = 0.0005 P\n", + "\n", + " Maximum compressive stress = -0.0002 P\n", + "\n", + " for theta=180 degrees\n", + "\n", + " Maximum tensile stress = 0.0017 P\n", + "\n", + " Maximum compressive stress = -0.0006 P\n", + "\n", + " part(c)\n", + "\n", + " The maximum allowable load is 91.44 kN\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg334" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the circumferential stress at B and Radial stress at the Junction\n", + "P=120. ##kN\n", + "b1=120. ##mm\n", + "b2=120. ##mm\n", + "h1=48. ##mm\n", + "h2=24. ##mm\n", + "P=P*10**3\n", + "A=h1*b1+b2*h2\n", + "R=(b1*h1*96.+b2*h2*180.)/A\n", + "Am=b1*math.log(b1/72.)+h2*math.log(240./b2)\n", + "r=72.\n", + "Mx=364.*P\n", + "S_thB=P/A+(Mx*(A-r*Am))/(A*r*(R*Am-A))\n", + "\n", + "r1=120. ##mm\n", + "t=24. ##mm\n", + "A1=h1*r1\n", + "Am1=r1*math.log(r1/r)\n", + "S_rr=(A*Am1-A1*Am)*Mx/(t*r1*A*(R*Am-A))\n", + "print\"%s %.2f %s\"%('Circumferential stress is',S_thB,' MPa')\n", + "print\"%s %.2f %s\"%('\\n Radial stress is ',S_rr,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Circumferential stress is 221.59 MPa\n", + "\n", + " Radial stress is 138.39 MPa\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex6-pg335" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the circumferntial stress abd radial stresss\n", + "Mo=96. ##kN\n", + "P=120. ##kN\n", + "b1=150. ##mm\n", + "h1=60. ##mm\n", + "b2=120. ##mm\n", + "h2=50. ##mm\n", + "b3=b1\n", + "h3=40. ##mm\n", + "ro=80. ##mm\n", + "r1=140. ##mm\n", + "r2=260. ##mm\n", + "r3=300. ##mm\n", + "## calculations\n", + "Mo=Mo*10**6 ## N.mm\n", + "P=P*10**3 ## N\n", + "A=b1*h1+b2*h2+b3*h3\n", + "Am=b1*math.log(r1/ro)+h2*math.log(r2/r1)+b3*math.log(r3/r2)\n", + "R=(b1*h1*110.+b2*h2*200.+b3*h3*280.)/A\n", + "Mx=Mo+P*R\n", + "r=80. ##mm\n", + "S_th=P/A+(Mx*(A-r*Am))/(A*r*(R*Am-A))\n", + "\n", + "A1=9000. ##mm^2\n", + "r1=140. ##mm\n", + "t=50. ##mm\n", + "Am1=b1*math.log(r1/ro)\n", + "N=120000.\n", + "S_rr=A1*N/(A*t*r1) + (A*Am1-A1*Am)*Mx/(t*r1*A*(R*Am-A))\n", + "print\"%s %.2f %s\"%('Circumferential stress is ',S_th,' MPa')\n", + "print\"%s %.2f %s\"%('\\n Radial stress at B1 is ',S_rr,' MPa')\n", + "## to find radial stress at C; \n", + "A1=b1*h1+b2*h2\n", + "Am1=b1*math.log(r1/ro)+h2*math.log(r2/r1)\n", + "r1=260. ##mm\n", + "t=50. ##mm\n", + "S_rr=A1*N/(A*t*r1) + (A*Am1-A1*Am)*Mx/(t*r1*A*(R*Am-A))\n", + "print\"%s %.2f %s\"%('\\n Radial stress at C1 is ',S_rr,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Circumferential stress is 177.54 MPa\n", + "\n", + " Radial stress at B1 is 111.56 MPa\n", + "\n", + " Radial stress at C1 is 45.09 MPa\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex7-pg337" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the maximum confererntial and radial stress in the beam\n", + "l=15. ##m\n", + "R=10. ##m\n", + "d=0.8 ##m\n", + "b=0.13 ##m\n", + "Po=2400. ##N/m\n", + "P=4800. ##N/m\n", + "##calculations\n", + "a=R-d/2.\n", + "c=R+d/2.\n", + "A=b*d\n", + "Am=b*math.log(c/a)\n", + "Mx=(Po+P)*l**2/8.\n", + "S_thMax=Mx*(A-a*Am)/(A*a*(R*Am-A))\n", + "## To find out max radial stress\n", + "## Nr=d*log(r/a)-(r-a)*log(c/a)\n", + "## Dr=r*d*(R*log(c/a)-d)\n", + "## S_rr=Mx/b*Nr/Dr\n", + "r=a*math.exp(1-(a/d*math.log(c/a)))\n", + "Nr=d*math.log(r/a)-(r-a)*math.log(c/a)\n", + "Dr=r*d*(R*math.log(c/a)-d)\n", + "S_rrMax=Mx/b*Nr/Dr\n", + "print('\\n part (a)')\n", + "print\"%s %.2f %s\"%('\\n Maximum circumferential stress is ',S_thMax/10**6,' MPa')\n", + "print\"%s %.2f %s\"%('\\n Maximum radial stress is ',S_rrMax/10**6,' MPa')\n", + "## part (b)\n", + "Ix=b*d**3./12.\n", + "S_th=Mx*d/(2.*Ix)\n", + "print('\\n part (b)')\n", + "print\"%s %.2f %s\"%('\\n Maximum circumferential stress using straight beam formula is ',S_th/10**6,' MPa')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " part (a)\n", + "\n", + " Maximum circumferential stress is 15.00 MPa\n", + "\n", + " Maximum radial stress is 0.29 MPa\n", + "\n", + " part (b)\n", + "\n", + " Maximum circumferential stress using straight beam formula is 14.60 MPa\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex8-pg342" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the magnitude of the moment \n", + "## part(a)\n", + "Y=280. ##MPa\n", + "A=4000. ##mm^2\n", + "Am=44.99 ##mm\n", + "R=100.0 ##mm\n", + "r=180. ##mm\n", + "r=60 ##mm\n", + "## Mx is not yet known take it as unity\n", + "Mx=1. ##unity\n", + "r=180.\n", + "S_thMax=Mx*(A-r*Am)/(A*r*(R*Am-A))\n", + "Mx=Y/(abs(S_thMax))\n", + "print('part(a)')\n", + "print\"%s %.2f %s\"%('\\n Mx = ',Mx/10**6,' kN.m')\n", + "## part(b)\n", + "k1=1.143\n", + "t_w=20.\n", + "b_p=40.\n", + "alpha=0.651\n", + "Beta=1.711\n", + "r=60 ##mm\n", + "b1=2.*alpha*b_p+t_w\n", + "A=b1*t_w+t_w*R\n", + "R=(b1*t_w*70.+t_w*R*130.)/A\n", + "Am=b1*math.log(80./r)+t_w*math.log(180./80.)\n", + "## Mx not yet known teke it as unity\n", + "Mx=1.\n", + "S_thMax=Mx*(A-r*Am)/(A*r*(R*Am-A))\n", + "r=70. ##mm\n", + "S_thbar=Mx*(A-r*Am)/(A*r*(R*Am-A))\n", + "S_xx=-Beta*S_thbar\n", + "##tau_max=Y/2=(S_thMax-S_xx)/2\n", + "Mx=Y/(S_thMax-S_xx)\n", + "print('\\n part (b)')\n", + "print\"%s %.2f %s\"%('\\n Mx = ',Mx/10**6,' kN.m')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part(a)\n", + "\n", + " Mx = 24.55 kN.m\n", + "\n", + " part (b)\n", + "\n", + " Mx = 10.12 kN.m\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex9-pg346" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "## initialization of variables\n", + "##calculate the angle change between the two horizontal faces where M is applied\n", + "E=72. ##GPa\n", + "t=60. ##mm\n", + "M=24. ##kN.m\n", + "##part(a)\n", + "ro=100. ##mm\n", + "r1=150. ##mm\n", + "A=t*r1\n", + "Am=t*math.log((ro+r1)/ro)\n", + "R=ro+r1/2.\n", + "E=E*10**3\n", + "Mx=M*10**6\n", + "Phi=Am*Mx*math.pi/(A*(R*Am-A)*E)\n", + "print('part(a)')\n", + "print\"%s %.2f %s\"%('\\n Phi = ',Phi,' rad')\n", + "##part(b)\n", + "##Mx=Mx+P*R*sin(th)\n", + "delta_P=Am*Mx*R*2./(A*(R*Am-A)*E)\n", + "print('\\n part(b)')\n", + "print\"%s %.2f %s\"%('\\n deflection = ',delta_P,' mm')\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "part(a)\n", + "\n", + " Phi = 0.01 rad\n", + "\n", + " part(b)\n", + "\n", + " deflection = 1.15 mm\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex10-pg347" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##calculate the relative displacement\n", + "## initialization of variables\n", + "import math\n", + "P=11.2 ##kN\n", + "E=200. ##GPa\n", + "v=0.3\n", + "Ix=181.7e+03 ##mm^4\n", + "k1=0.643\n", + "b1=34.7 ##mm\n", + "h1=10. ##mm\n", + "b2=40. ##mm\n", + "h2=10. ##mm\n", + "t=10. ##mm\n", + "h=50. ##mm\n", + "E=E*10**3\n", + "A=b1*h1+b2*h2\n", + "R=(b1*h1*35.+b2*h2*60.)/A\n", + "Am=b1*math.log(40./30.)+h1*math.log(80./40.)\n", + "G=E/(2.*(1.+v))\n", + "Aw=t*h\n", + "P=P*10**3\n", + "delta_P=2.*P*100./(Aw*G) + 2*P/(E*3.*Ix)*100**3 + P*48.4*math.pi/(2.*Aw*G) + P*48.4*math.pi/(2.*A*E) + P*16.9/(A*(48.4*16.9-A)*E)*(100**2*math.pi+math.pi/2.*(48.4)**2+2*100.*2.*48.4)\n", + "print\"%s %.2f %s\"%('seperation = ',delta_P,' mm')\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "seperation = 1.26 mm\n" + ] + } + ], + "prompt_number": 10 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Applied_Chemistry/screenshots/1.png b/Applied_Chemistry/screenshots/1.png new file mode 100755 index 00000000..04dc7a94 Binary files /dev/null and b/Applied_Chemistry/screenshots/1.png differ diff --git a/Applied_Chemistry/screenshots/2.png b/Applied_Chemistry/screenshots/2.png new file mode 100755 index 00000000..3d55a09c Binary files /dev/null and b/Applied_Chemistry/screenshots/2.png differ diff --git a/Applied_Chemistry/screenshots/3.png b/Applied_Chemistry/screenshots/3.png new file mode 100755 index 00000000..f00ffd91 Binary files /dev/null and b/Applied_Chemistry/screenshots/3.png differ diff --git a/Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_01_Water.ipynb b/Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_01_Water.ipynb new file mode 100755 index 00000000..a630b2b3 --- /dev/null +++ b/Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_01_Water.ipynb @@ -0,0 +1,2471 @@ + { + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1:Water" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=16.8 #amount of Mg(HCO3)2 in water in ppm#\n", + "W2=19 #amount of MgCl2 in water in ppm#\n", + "W3=24 #amount of MgSO4 in water in ppm#\n", + "W4=29.6 #amount of Mg(NO3)2 in water in ppm#\n", + "W5=4 #amount of CaCO3 in water in ppm#\n", + "W6=10 #amount of MgCO3 in water in ppm#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/95.0 #multiplication factor of MgCl2#\n", + "M3=100/120.0 #multiplication factor of MgSO4#\n", + "M4=100/148.0 #multiplication factor of Mg(NO3)2#\n", + "M5=100/100.0 #multiplication factor of CaCO3#\n", + "M6=100/84.0 #multiplication factor of MgCO3#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #in terms of CaCO3#\n", + "P2=W2*M2 #in terms of CaCO3#\n", + "P3=W3*M3 #in terms of CaCO3#\n", + "P4=W4*M4 #in terms of CaCO3#\n", + "P5=W5*M5 #in terms of CaCO3#\n", + "P6=W6*M6 #in terms of CaCO3#\n", + "\n", + "T=round(P1,1)+P5+round(P6,1) #temporary hardness#\n", + "P=P2+P3+P4;#permanent hardness#\n", + "\n", + "#Result\n", + "print\"\\nTemporary hardness is \",round(T,1),\"mg CaCO3 equivalent/litre\"\n", + "print\"\\nPermanent hardness is \",P,\"mg CaCO3 equivalent/litre\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Temporary hardness is 27.4 mg CaCO3 equivalent/litre\n", + "\n", + "Permanent hardness is 60.0 mg CaCO3 equivalent/litre\n", + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=7.1 #Mg(HCO3)2 in water in mg/L#\n", + "W2=8.1 #Ca(HCO3)2 in water in mg/L#\n", + "W3=4.2 #MgCO3 in water in mg/L#\n", + "W4=10 #CaCO3 in water in mg/L#\n", + "W5=24 #MgSO4 in water in mg/L#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M3=100/84.0 #multiplication factor of MgCO3#\n", + "M4=100/100.0 #multiplication factor of CaCO3#\n", + "M5=100/120.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3#\n", + "P2=W2*M2 #Ca(HCO3)2 in terms of CaCO3#\n", + "P3=W3*M3 #MgCO3 in terms of CaCO3#\n", + "P4=W4*M4 #CaCO3 in terms of CaCO3#\n", + "P5=W5*M5 #MgSO4 in terms of CaCO3#\n", + "\n", + "C=P1+P2+P3+P4 #carbonate hardness#\n", + "NC=P5 #non-carbonate hardness#\n", + "\n", + "#Result\n", + "print\"\\nCarbonate hardness is \",round(C),\"ppm\"\n", + "print\"\\nNon-carbonate hardness is \",NC,\"ppm\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Carbonate hardness is 25.0 ppm\n", + "\n", + "Non-carbonate hardness is 20.0 ppm\n", + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:3,Page no:9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=150 #Ca2+ in water in mg/L#\n", + "W2=60 #Mg2+ in water in mg/L#\n", + "M1=100/40.0 #multiplication factor of Ca2+#\n", + "M2=100/24.0 #multiplication factor of Mg2+#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3#\n", + "P2=W2*M2 #Ca(HCO3)2 in terms of CaCO3#\n", + "T=P1+P2 #total hardness\n", + "\n", + "#Result\n", + "print\"\\nTotal hardness is \",round(T),\"mg/L \"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total hardness is 625.0 mg/L\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:4,Page no:9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "H=210.5 #hardness in ppm#\n", + "\n", + "M1=100.0 #molecular weight of CaCO3#\n", + "M2=136.0 #molecular weight of FeSO4#\n", + "\n", + "\n", + "#Calculation\n", + "M=M1/M2 #multiplication factor of FeSO4#\n", + "W=H/M #weight of FeSO4 required#\n", + "\n", + "#Result\n", + "print\"FeSO4 required is \",round(W,1),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "FeSO4 required is 286.3 ppm\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:5,Page no:10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=32.4 #Ca(HCO3)2 in water in mg/L#\n", + "W2=29.2 #Mg(HCO3)2 in water in mg/L#\n", + "W3=13.6 #CaSO4 in water in mg/L#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/136.0 #multiplication factor of CaSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3#\n", + "P2=W2*M2 #Mg(HCO3)2 in terms of CaCO3#\n", + "P3=W3*M3 #CaSO4 in terms of CaCO3#\n", + "\n", + "T=P1+P2 #temporary hardness#\n", + "P=P3 #permanent hardness#\n", + "Total=T+P #total hardness#\n", + "\n", + "#Result\n", + "print\"\\nTemporary hardness is \",round(T),\"ppm\"\n", + "print\"\\nPermanent hardness is \",P,\"ppm \"\n", + "\n", + "print\"\\nTotal hardness is \",Total,\"ppm \"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Temporary hardness is 40.0 ppm\n", + "\n", + "Permanent hardness is 10.0 ppm\n", + "\n", + "Total hardness is 50.0 ppm\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:6,Page no:10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=14.6 #Mg(HCO3)2 in water in mg/L#\n", + "W2=8.1 #Ca(HCO3)2 in water in mg/L#\n", + "W3=29.6 #Mg(NO3)2 in water in mg/L#\n", + "W4=19 #MgCl2 in water in mg/L#\n", + "W5=24 #MgSO4 in water in mg/L#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M3=100/148.0 #multiplication factor of Mg(NO3)2#\n", + "M4=100/95.0 #multiplication factor of MgCl2#\n", + "M5=100/120.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3#\n", + "P2=W2*M2 #Ca(HCO3)2 in terms of CaCO3#\n", + "P3=W3*M3 #Mg(NO3)2 in terms of CaCO3#\n", + "P4=W4*M4 #MgCl2 in terms of CaCO3#\n", + "P5=W5*M5 #MgSO4 in terms of CaCO3#\n", + "\n", + "T=P1+P2 #Temporary hardness#\n", + "P=P3+P4+P5 #permanent hardness#\n", + "\n", + "#Result\n", + "print\"\\nTemporary hardness is \",round(T),\"ppm\"\n", + "print\"\\nPermanent hardness is \",round(P),\"ppm\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Temporary hardness is 15.0 ppm\n", + "\n", + "Permanent hardness is 60.0 ppm\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:7,Page no:11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=7.3 #Mg(HCO3)2 in water in mg/L#\n", + "W2=9.5 #MgCl2 in water in mg/L#\n", + "W3=16.2 #Ca(HCO3)2 in water in mg/L#\n", + "W4=13.6 #CaSO4 in water in mg/L#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/95.0 #multiplication factor of MgCl2#\n", + "M3=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M4=100/136.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3#\n", + "P2=W2*M2 #MgCl2 in terms of CaCO3#\n", + "P3=W3*M3 #Ca(HCO3)2 in terms of CaCO3#\n", + "P4=W4*M4 #MgSO4in terms of CaCO3#\n", + "\n", + "T=P1+P3 #Temporary hardness#\n", + "P=P2+P4 #permanent hardness#\n", + "Total=T+P #total hardness#\n", + "\n", + "#Result\n", + "print\"\\nTemporary hardness is \",round(T),\"ppm\"\n", + "print\"\\nPermanent hardness is \",round(P),\"ppm\"\n", + "print\"\\nTotal hardness is \",round(Total),\"ppm\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Temporary hardness is 15.0 ppm\n", + "\n", + "Permanent hardness is 20.0 ppm\n", + "\n", + "Total hardness is 35.0 ppm\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:8,Page no:12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "W1=19 #MgCl2 in water in mg/L#\n", + "W2=5 #CaCO3 in water in mg/L#\n", + "W3=29.5 #Ca(HCO3)2 in water in mg/L#\n", + "W4=13 #CaSO4 in water in mg/L#\n", + "M1=100/95.0 #multiplication factor of MgCl2#\n", + "M2=100/100.0 #multiplication factor of CaCO3#\n", + "M3=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M4=100/136.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #MgCl2 in terms of CaCO3#\n", + "P2=W2*M2 #CaCO3 in terms of CaCO3#\n", + "P3=W3*M3 #Ca(HCO3)2 in terms of CaCO3#\n", + "P4=W4*M4 #MgSO4in terms of CaCO3#\n", + "\n", + "T=P2+round(P3,2) #Temporary hardness#\n", + "P=P1+round(P4,2) #permanent hardness#\n", + "Total=T+P #total hardness#\n", + "\n", + "#Result\n", + "print\"\\nTemporary hardness is \",round(T,2),\"ppm\"\n", + "print\"\\nPermanent hardness is \",round(P,2),\"ppm\"\n", + "print\"\\nTotal hardness is \",round(Total,2),\"ppm\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Temporary hardness is 23.21 ppm\n", + "\n", + "Permanent hardness is 29.56 ppm\n", + "\n", + "Total hardness is 52.77 ppm\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:15" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "strength=1.1#in terms of mgs/ml CaCO3#\n", + "volume=50#volume titrated(ml)#\n", + "EDTA=38#volume in terms of ml#\n", + "volume_hardwater=100#volume of hardwater titrated(ml)#\n", + "EDTA_hardwater=21#volume used to titrate unknown hardwater#\n", + "\n", + "#Calculation\n", + "CaCO3_equivalent=strength*volume#in terms of mg#\n", + "one_ml_EDTA=CaCO3_equivalent/EDTA#in terms of CaCO3 equivalent#\n", + "titrate_equivalent=one_ml_EDTA*EDTA_hardwater/volume_hardwater#CaCO3 equivalent of titrated volume#\n", + "Hardness=titrate_equivalent*1000#in terms of mg/lit or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water is \",round(Hardness,1),\"mg/L\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water is 303.9 mg/L\n", + "\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=0.28/1000#in terms of g/lit\n", + "strength_SH=conc_SH*1000#in terms of mgs/lit#\n", + "volume_SH=100#in terms of ml#\n", + "volume_H=100#in terms of ml#\n", + "EDTA_SH=28#volume for Std hardwater(ml)#\n", + "EDTA_H=33#volume for sample hardwater(ml)#\n", + "AB_EDTA=10#volume required after boiling(ml)#\n", "\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000#permanent hardness per litre(ppm)#\n", + "T=To-P\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To),\"ppm\"\n", + "print\"Temporary Hardness is \",round(T),\"ppm\"\n", + "print\"Permanent Hardness is \",round(P),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 330.0 ppm\n", + "\n", + "Temporary Hardness is 230.0 ppm\n", + "\n", + "Permanent Hardness is 100.0 ppm\n", + "\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:3,Page no:17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=1/1000.#in terms of g/lit#\n", + "strength_SH=conc_SH*1000.#in terms of mgs/lit#\n", + "volume_SH=50.#in terms of ml#\n", + "volume_H=50. #in terms of ml#\n", + "EDTA_SH=20. #volume for Std hardwater(ml)#\n", + "EDTA_H=25. #volume for sample hardwater(ml)#\n", + "AB_EDTA=18. #volume required after boiling(ml)#\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000#permanent hardness per litre(ppm)#\n", + "T=To-P\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To),\"ppm\"\n", + "print\"Temporary Hardness is \",round(T),\"ppm\"\n", + "print\"Permanent Hardness is \",round(P),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 1250.0 ppm\n", + "\n", + "Temporary Hardness is 350.0 ppm\n", + "\n", + "Permanent Hardness is 900.0 ppm\n", + "\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:4,Page no:18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=15./1000#in terms of g/lit#\n", + "strength_SH=conc_SH*1000.#in terms of mgs/lit#\n", + "volume_SH=20.#in terms of ml#\n", + "volume_H=100.#in terms of ml#\n", + "EDTA_SH=25.#volume for Std hardwater(ml)#\n", + "EDTA_H=18.#volume for sample hardwater(ml)#\n", + "AB_EDTA=12.#volume required after boiling(ml)#\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000#permanent hardness per litre(ppm)#\n", + "T=To-P\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To),\"ppm\"\n", + "print\"Temporary Hardness is \",round(T),\"ppm (Final answer in the textbook is incorrect)\"\n", + "print\"Permanent Hardness is \",round(P),\"ppm (Final answer in the textbook is incorrect)\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 2160.0 ppm\n", + "\n", + "Temporary Hardness is 720.0 ppm\n", + "\n", + "Permanent Hardness is 1440.0 ppm\n", + "\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:5,Page no:19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=0.5/500#in terms of g/lit#\n", + "strength_SH=conc_SH*1000.#in terms of mgs/lit#\n", + "volume_SH=50.#in terms of ml#\n", + "volume_H=50.#in terms of ml#\n", + "EDTA_SH=48.#volume for Std hardwater(ml)#\n", + "EDTA_H=15.#volume for sample hardwater(ml)#\n", + "AB_EDTA=10.#volume required after boiling(ml)#\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000#permanent hardness per litre(ppm)#\n", + "T=To-P\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To,1),\"ppm\"\n", + "print\"Temporary Hardness is \",round(T,2),\"ppm\"\n", + "print\"Permanent Hardness is \",round(P,2),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 312.5 ppm\n", + "\n", + "Temporary Hardness is 104.17 ppm\n", + "\n", + "Permanent Hardness is 208.33 ppm\n", + "\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:6,Page no:20" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=1/1000.#in terms of g/lit#\n", + "strength_SH=conc_SH*1000.#in terms of mgs/lit#\n", + "volume_SH=50.#in terms of ml#\n", + "volume_H=50.#in terms of ml#\n", + "EDTA_SH=45.#volume for Std hardwater(ml)#\n", + "EDTA_H=25.#volume for sample hardwater(ml)#\n", + "AB_EDTA=15.#volume required after boiling(ml)#\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000#permanent hardness per litre(ppm)#\n", + "T=To-P\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To,2)-.01,\"ppm\"\n", + "print\"Temporary Hardness is \",round(T,2),\"ppm\"\n", + "print\"Permanent Hardness is \",round(P,2),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 555.55 ppm\n", + "\n", + "Temporary Hardness is 222.22 ppm\n", + "\n", + "Permanent Hardness is 333.33 ppm\n", + "\n" + ] + } + ], + "prompt_number": 14 + }, { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:7,Page no:21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=1/20.#in terms of g/lit#\n", + "strength_SH=conc_SH*1000.#in terms of mgs/lit#\n", + "volume_SH=50.#in terms of ml#\n", + "volume_H=50.#in terms of ml#\n", + "EDTA_SH=1000.#volume for Std hardwater(ml)#\n", + "EDTA_H=7.2#volume for sample hardwater(ml)#\n", + "AB_EDTA=4.#volume required after boiling(ml)#\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000#permanent hardness per litre(ppm)#\n", + "T=To-P\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To),\"ppm\"\n", + "print\"Temporary Hardness is \",round(T),\"ppm\"\n", + "print\"Permanent Hardness is \",round(P),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 360.0 ppm\n", + "\n", + "Temporary Hardness is 160.0 ppm\n", + "\n", + "Permanent Hardness is 200.0 ppm\n", + "\n" + ] + } + ], + "prompt_number": 15 + }, { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:8,Page no:22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "conc_SH=1.2/1000#in terms of g/lit#\n", + "strength_SH=conc_SH*1000.#in terms of mgs/lit#\n", + "volume_SH=20.#in terms of ml#\n", + "volume_H=50.#in terms of ml#\n", + "EDTA_SH=35.#volume for Std hardwater(ml)#\n", + "EDTA_H=30.#volume for sample hardwater(ml)#\n", + "AB_EDTA=25.#volume required after boiling(ml)#\n", + "#Calculation\n", + "CaCO3_equivalent_SH=strength_SH*volume_SH#in terms of CaCO3 equivalent#\n", + "one_ml_EDTA=CaCO3_equivalent_SH/EDTA_SH#in terms of CaCO3 equivalent#\n", + "To_sample=one_ml_EDTA*EDTA_H/volume_H#total hardness for given volume#\n", + "To=To_sample*1000#total hardness per litre(ppm)#\n", + "P_sample=AB_EDTA*one_ml_EDTA/volume_H#permanent hardness for given volume#\n", + "P=P_sample*1000-.4#permanent hardness per litre(ppm)#\n", + "T=round(To)-round(P,1)\n", + "\n", + "#Result\n", + "print\"Total Hardness is \",round(To),\"ppm\"\n", + "print\"Temporary Hardness is \",round(T,1),\"ppm\"\n", + "print\"Permanent Hardness is \",round(P,1),\"ppm\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Hardness is 411.0 ppm\n", + "\n", + "Temporary Hardness is 68.5 ppm\n", + "\n", + "Permanent Hardness is 342.5 ppm\n", + "\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=90.0 #% purity of lime used#\n", + "purity_soda=100.0 #% purity of washing soda used#\n", + "W1=136.0 #CaSO4 in water in mg/lit#\n", + "W2=49.0 #H2SO4 in water in mg/lit#\n", + "W3=95.0 #MgCl2 in water in mg/lit#\n", + "W4=60.0 #MgSO4 in water in mg/lit#\n", + "M1=100/136.0 #multiplication factor of CaSO4#\n", + "M2=100/98.0 #multiplication factor of H2SO4#\n", + "M3=100/95.0 #multiplication factor of MgCl2#\n", + "M4=100/120.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #CaSO4 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #H2SO4 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #MgCl2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #MgSO4 in terms of CaCO3 or ppm#\n", + "V=1000000 #volume of water in lit#\n", + "L=0.74*(P2+P3+P4)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P1+P2+P3+P4)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L/1000,2),\"* 10**3 g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 164.44 * 10**3 g\n", + "\n", + "Amount of soda required = 318000.0 g\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=90.0 #% purity of lime used#\n", + "purity_soda=95.0 #% purity of washing soda used#\n", + "W1=156.0 #Mg(HCO3)2 in water in mg/lit#\n", + "W2=4.9 #H2SO4 in water in mg/lit#\n", + "W3=23.75 #MgCl2 in water in mg/lit#\n", + "W4=111 #CaCl2 in water in mg/lit#\n", + "W5=5.6 #NaCl in water in mg/lit#\n", + "W6=16.2 #SiO2 in water in mg/lit#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/98.0 #multiplication factor of H2SO4#\n", + "M3=100/95.0 #multiplication factor of MgCl2#\n", + "M4=100/111.0 #multiplication factor of CaCl2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #H2SO4 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #MgCl2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #CaCl2 in terms of CaCO3 or ppm#\n", + "V=50000 #volume of water in lit#\n", + "L=0.74*(2*round(P1,2)+P2+P3)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P2+P3+P4)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,2),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 10018.78 g\n", + "\n", + "Amount of soda required = 7252.63 g\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:3,Page no:32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=74.0 #% purity of lime used#\n", + "purity_soda=90.0 #% purity of washing soda used#\n", + "W1=73.0 #Mg(HCO3)2 in water in mg/lit#\n", + "W2=222.0 #CaCl2 in water in mg/lit#\n", + "W3=120.0 #MgSO4 in water in mg/lit#\n", + "W4=164.0 #Ca(NO3)2 in water in mg/lit#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/111.0 #multiplication factor of CaCl2#\n", + "M3=100/120.0 #multiplication factor of MgSO4#\n", + "M4=100/164.0 #multiplication factor of Ca(NO3)2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #CaCl2 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #MgSO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #Ca(NO3)2 in terms of CaCO3 or ppm#\n", + "V=5000 #volume of water in lit#\n", + "L=0.74*(2*P1+P3)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P2+P3+P4)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,2),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 1000.0 g\n", + "\n", + "Amount of soda required = 2355.56 g\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:4,Page no:33" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=100.0 #% purity of lime used#\n", + "purity_soda=100.0 #% purity of washing soda used#\n", + "W1=144.0 #MgCO3 in water in mg/lit#\n", + "W2=95.0 #MgCl2 in water in mg/lit#\n", + "W3=25.0 #CaCO3 in water in mg/lit#\n", + "W4=111.0 #CaCl2 in water in mg/lit#\n", + "M1=100/84.0 #multiplication factor of MgCO3#\n", + "M2=100/95.0 #multiplication factor of MgCl2#\n", + "M3=100/100.0 #multiplication factor of CaCO3#\n", + "M4=100/111.0 #multiplication factor of CaCl2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #MgCO3 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCl2 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCO3 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #CaCl2 in terms of CaCO3 or ppm#\n", + "V=50000 #volume of water in lit#\n", + "L=0.74*(2*(round(P1,2)-.01)+P2+P3)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P2+P4)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 17310.08 g\n", + "\n", + "Amount of soda required = 10600.0 g\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:5,Page no:34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=100.0 #% purity of lime used#\n", + "W1=13.6 #CaSO4 in water in mg/lit#\n", + "W2=8.4 #MgCO3 in water in mg/lit#\n", + "W3=5.0 #CaCO3 in water in mg/lit#\n", + "M1=100/136.0 #multiplication factor of CaSO4#\n", + "M2=100/84.0 #multiplication factor of MgCO3#\n", + "M3=100/100.0 #multiplication factor of CaCO3#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #CaSO4 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCO3 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCO3 in terms of CaCO3 or ppm#\n", + "V=5000 #volume of water in lit#\n", + "L=0.74*(2*P2+P3)*(V/1000)*(100/purity_lime)#lime required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,1),\"g\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 92.5 g\n", + "\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:6,Page no:35" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_soda=100.0 #% purity of soda used#\n", + "W1=5 #CaSO4 in water in mg/lit#\n", + "W2=22.2 #MgCO3 in water in mg/lit#\n", + "W3=2 #CaCO3 in water in mg/lit#\n", + "M1=100/100.0 #multiplication factor of CaSO4#\n", + "M2=100/111.0 #multiplication factor of MgCO3#\n", + "M3=100/120.0 #multiplication factor of CaCO3#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #CaSO4 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCO3 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCO3 in terms of CaCO3 or ppm#\n", + "V=10000 #volume of water in lit#\n", + "S=1.06*(P2+P3)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of soda required =\",round(S,1),\"g\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of soda required = 229.7 g\n", + "\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:7,Page no:36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=100.0 #% purity of lime used#\n", + "purity_soda=100.0 #% purity of washing soda used#\n", + "W1=10.0 #CaCO3 in water in mg/lit#\n", + "W2=36.5 #Mg(HCO3)2 in water in mg/lit#\n", + "W3=19.0 #MgCl2 in water in mg/lit#\n", + "M1=100/100.0 #multiplication factor of CaCO3#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/95.0 #multiplication factor of MgCl2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #CaCO3 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #MgCl2 in terms of CaCO3 or ppm#\n", + "V=1000000 #volume of water in lit#\n", + "L=0.74*(P1+2*P2+P3)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P3)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 59200.0 g\n", + "\n", + "Amount of soda required = 21200.0 g\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:8,Page no:37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=80.0 #% purity of lime used#\n", + "purity_soda=100.0 #% purity of washing soda used#\n", + "W1=7.1 #MgCO3 in water in mg/lit#\n", + "W2=8.1 #MgCl2 in water in mg/lit#\n", + "W3=4.2 #CaCO3 in water in mg/lit#\n", + "W4=10 #CaCl2 in water in mg/lit#\n", + "M1=100/146.0 #multiplication factor of MgCO3#\n", + "M2=100/162.0 #multiplication factor of MgCl2#\n", + "M3=100/84.0 #multiplication factor of CaCO3#\n", + "M4=100/100.0 #multiplication factor of CaCl2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #MgCO3 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCl2 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCO3 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #CaCl2 in terms of CaCO3 or ppm#\n", + "V=100000 #volume of water in lit#\n", + "L=0.74*(2*round(P1,2)+P2+2*P3+P4)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(0)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L-0.6),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 3211.0 g\n", + "\n", + "Amount of soda required = 0.0 g\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:9,Page no:37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=90.0 #% purity of lime used#\n", + "purity_soda=90.0 #% purity of washing soda used#\n", + "W1=19.0 #MgCl2 in water in mg/lit#\n", + "W2=27.2 #CaSO4 in water in mg/lit#\n", + "W3=4.9*2 #H2SO4 in water in mg/lit#\n", + "W4=6.0 #Al3+ in water in mg/lit#\n", + "M1=100/95.0 #multiplication factor of MgCl2#\n", + "M2=100/136.0 #multiplication factor of CaSO4#\n", + "M3=100/98.0 #multiplication factor of H2SO4#\n", + "M4=100/18.0 #multiplication factor of Al3+#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #MgCl2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #CaSO4 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #H2SO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #Al3+ in terms of CaCO3 or ppm#\n", + "V=500000 #volume of water in lit#\n", + "L=0.74*(P1+P3+round(P4,2))*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P1+P2+P3+round(P4,2))*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2)-.01,\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 26035.66 g\n", + "\n", + "Amount of soda required = 49072.0 g\n" + ] + } + ], + "prompt_number": 25 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:10,Page no:38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=90.0 #% purity of lime used#\n", + "purity_soda=95.0 #% purity of washing soda used#\n", + "W1=81.0 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=42 #MgCO3 in water in mg/lit#\n", + "W3=4.1 #NaAlO2 in water in mg/lit#\n", + "W4=3.65 #HCl in water in mg/lit#\n", + "W5=82. #Ca(NO3)2 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/84.0 #multiplication factor of MgCO3#\n", + "M3=100/82.0 #multiplication factor of H2SO4#\n", + "M4=100/36.5 #multiplication factor of NaAlO2 #\n", + "M5=100/164. #multiplication factor of Ca(NO3)2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCO3 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #H2SO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #NaAlO2 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #Ca(NO3)2 in terms of CaCO3 or ppm#\n", + "V=20000 #volume of water in lit#\n", + "L=0.74*(P1+2*P2-P3+P4)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P4+P5)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2)-.01,\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,3)+.002,\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 2548.88 g\n", + "\n", + "Amount of soda required = 1338.949 g\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:11,Page no:39" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=85.0 #% purity of lime used#\n", + "purity_soda=90.0 #% purity of washing soda used#\n", + "W1=16.2 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=6.8 #CaSO4 in water in mg/lit#\n", + "W3=11.1 #CaCl2 in water in mg/lit#\n", + "W4=6. #MgSO4 in water in mg/lit#\n", + "W5=8.4 #Mg(HCO3)2 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/136.0 #multiplication factor of CaSO4#\n", + "M3=100/111.0 #multiplication factor of CaCl2#\n", + "M4=100/120.0 #multiplication factor of MgSO4 #\n", + "M5=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #CaSO4 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCl2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #MgSO4 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #Mg(HCO3)2 in terms of CaCO3 or ppm#\n", + "V=10000 #volume of water in lit#\n", + "L=0.74*(P1+2*P5+P4)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P2+P3+P4)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,1)-.1,\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,2)-.01,\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 230.7 g\n", + "\n", + "Amount of soda required = 235.55 g\n" + ] + } + ], + "prompt_number": 27 + }, + + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:12,Page no:40" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=70.0 #% purity of lime used#\n", + "purity_soda=85.0 #% purity of washing soda used#\n", + "W1=30.2 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=20.8 #Mg(HCO3)2in water in mg/lit#\n", + "W3=28.1 #CaCl2 in water in mg/lit#\n", + "W4=8.7 #MgCl2 in water in mg/lit#\n", + "W5=35.0 #CaSO4 in water in mg/lit#\n", + "W6=6.7 #MgSO4 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/111.0 #multiplication factor of CaCl2#\n", + "M4=100/95.0 #multiplication factor of MgCl2 #\n", + "M5=100/136.0 #multiplication factor of CaSO4#\n", + "M6=100/120.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCl2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #MgSO4 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #CaSO4 in terms of CaCO3 or ppm#\n", + "P6=W6*M6 #MgSO4 in terms of CaCO3 or ppm#\n", + "V=100000 #volume of water in lit#\n", + "L=0.74*(round(P1,2)+2*round(P2,2)+round(P4,2)+round(P6,2))*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(round(P3,2)+round(P4,2)+round(P5,2)+round(P6,2))*(V/1000)*(100/purity_soda)#soda required(Answer in the textbook is incorrect)# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,1),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 6541.6 g\n", + "\n", + "Amount of soda required = 8206.0 g\n" + ] + } + ], + "prompt_number": 28 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:13,Page no:41" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=80.0 #% purity of lime used#\n", + "purity_soda=85.0 #% purity of washing soda used#\n", + "W1=162 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=7.3 #Mg(HCO3)2in water in mg/lit#\n", + "W3=9.5 #MgCl2 in water in mg/lit#\n", + "W4=36.5 #HCl in water in mg/lit#\n", + "W5=44 #CO2 in water in mg/lit#\n", + "W6=111 #CaCl2 in water in mg/lit#\n", + "W7=60 #MgSO4 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/95.0 #multiplication factor of MgCl2#\n", + "M4=100/73.0 #multiplication factor of HCl #\n", + "M5=100/44.0 #multiplication factor of CO2#\n", + "M6=100/111.0 #multiplication factor of CaCl2#\n", + "M7=100/120.0 #multiplication factor of MgSO4#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #MgCl2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #HCl in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #CO2 in terms of CaCO3 or ppm#\n", + "P6=W6*M6 #CaCl2 in terms of CaCO3 or ppm#\n", + "P7=W7*M7 #MgSO4 in terms of CaCO3 or ppm#\n", + "V=1000000 #volume of water in lit#\n", + "L=0.74*(P1+2*P2+P3+P4+P5+P7)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P3+P4+P6+P7)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 296000.0 g\n", + "\n", + "Amount of soda required = 261882.0 g\n" + ] + } + ], + "prompt_number": 29 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:14,Page no:42" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=100.0 #% purity of lime used#\n", + "purity_soda=100.0 #% purity of washing soda used#\n", + "W1=222 #CaCl2 in water in mg/lit#\n", + "W2=296 #Mg(HCO3)2in water in mg/lit#\n", + "W3=324 #Ca(HCO3)2 in water in mg/lit#\n", + "W4=196 #H2SO4 in water in mg/lit#\n", + "M1=100/111.0 #multiplication factor of CaCl2#\n", + "M2=100/148.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M4=100/98.0 #multiplication factor of H2SO4 #\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #CaCl2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #H2SO4 in terms of CaCO3 or ppm#\n", + "V=50000 #volume of water in lit#\n", + "L=0.74*(P2+P3+P4)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P1+P2+P4)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 22200.0 g\n", + "\n", + "Amount of soda required = 31800.0 g\n" + ] + } + ], + "prompt_number": 30 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:15,Page no:43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=85.0 #% purity of lime used#\n", + "purity_soda=95.0 #% purity of washing soda used#\n", + "W1=12.5 #CaCO3 in water in mg/lit#\n", + "W2=8.4 #MgCO3in water in mg/lit#\n", + "W3=22.2 #CaCl2 in water in mg/lit#\n", + "W4=9.5 #MgCl2 in water in mg/lit#\n", + "W5=33 #CO2 in water in mg/lit#\n", + "W6=7.3 #HCl in water in mg/lit#\n", + "W7=16.8 #NaHCO3 in water in mg/lit#\n", + "M1=100/100.0 #multiplication factor of CaCO3#\n", + "M2=100/84.0 #multiplication factor of MgCO3#\n", + "M3=100/111.0 #multiplication factor of CaCl2#\n", + "M4=100/95.0 #multiplication factor of MgCl2 #\n", + "M5=100/44.0005 #multiplication factor of CO2#\n", + "M6=100/73.0 #multiplication factor of HCl#\n", + "M7=100/168.0 #multiplication factor of NaHCO3#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #CaCO3 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCO3in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaCl2 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #MgCl2 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #CO2 in terms of CaCO3 or ppm#\n", + "P6=W6*M6 #HCl in terms of CaCO3 or ppm#\n", + "P7=W7*M7 #NaHCO3 in terms of CaCO3 or ppm#\n", + "V=1000000 #volume of water in lit#\n", + "L=0.74*(P1+2*P2+P4+P5+P6+P7)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P3+P4+P6-P7)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S),\"g\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 119705.0 g\n", + "\n", + "Amount of soda required = 33474.0 g\n" + ] + } + ], + "prompt_number": 31 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:16,Page no:44" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=100.0 #% purity of lime used#\n", + "purity_soda=100.0 #% purity of washing soda used#\n", + "W1=8.1 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=7.5 #Mg(HCO3)2in water in mg/lit#\n", + "W3=13.6 #CaSO4 in water in mg/lit#\n", + "W4=12 #MgSO4 in water in mg/lit#\n", + "W5=2 #MgCl2 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/136.0 #multiplication factor of CaSO4#\n", + "M4=100/120.0 #multiplication factor of MgSO4 #\n", + "M5=100/95.0 #multiplication factor of MgCl2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaSO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #MgSO4 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #MgCl2 in terms of CaCO3 or ppm#\n", + "V=50000 #volume of water in lit#\n", + "L=0.74*(P1+2*round(P2,2)+P4+round(P5,1))*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P3+P4+round(P5,1))*(V/1000)*(100/purity_soda)#soda required(Answer in the textbook is incorrect)# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,2),\"g \"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 1013.06 g\n", + "\n", + "Amount of soda required = 1171.3 g\n" + ] + } + ], + "prompt_number": 32 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:17,Page no:45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=90.0 #% purity of lime used#\n", + "purity_soda=95.0 #% purity of washing soda used#\n", + "W1=155 #Mg(HCO3)2 in water in mg/lit#\n", + "W2=23 #MgCl2 in water in mg/lit#\n", + "W3=5 #H2SO4 in water in mg/lit#\n", + "W4=111 #CaCl2 in water in mg/lit#\n", + "M1=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M2=100/95.0 #multiplication factor of MgCl2 #\n", + "M3=100/98.0 #multiplication factor of H2SO4#\n", + "M4=100/111.0 #multiplication factor of CaCl2 #\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Mg(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #MgCl2 in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #H2SO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #CaCl2 in terms of CaCO3 or ppm#\n", + "V=50000 #volume of water in lit#\n", + "L=0.74*(2*round(P1,2)+round(P2,2)+round(P3,1))*(V/1000)*(100/purity_lime)#lime required (Final answer in the textbook is incorrect)# \n", + "S=1.06*(round(P2,2)+round(P3,2)+round(P4,1))*(V/1000)*(100/purity_soda)#soda required (Final answer in the textbook is incorrect)# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,2)-.01,\"g \"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 9933.68 g\n", + "\n", + "Amount of soda required = 7214.13 g\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:18,Page no:45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=90.0 #% purity of lime used#\n", + "purity_soda=95.0 #% purity of washing soda used#\n", + "W1=81 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=146 #Mg(HCO3)2in water in mg/lit#\n", + "W3=68 #CaSO4 in water in mg/lit#\n", + "W4=49 #H2SO4 in water in mg/lit#\n", + "W5=95 #MgCl2 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/136.0 #multiplication factor of CaSO4#\n", + "M4=100/98.0 #multiplication factor of H2SO4 #\n", + "M5=100/95.0 #multiplication factor of MgCl2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaSO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #H2SO4 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #MgCl2 in terms of CaCO3 or ppm#\n", + "V=50000 #volume of water in lit#\n", + "L=0.74*(P1+2*P2+P4+P5)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P4+P3+P5)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,2),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,2),\"g \"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 16444.44 g\n", + "\n", + "Amount of soda required = 11157.89 g\n" + ] + } + ], + "prompt_number": 34 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:19,Page no:46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "purity_lime=95.0 #% purity of lime used#\n", + "purity_soda=90.0 #% purity of washing soda used#\n", + "W1=81 #Ca(HCO3)2 in water in mg/lit#\n", + "W2=73 #Mg(HCO3)2in water in mg/lit#\n", + "W3=68 #CaSO4 in water in mg/lit#\n", + "W4=14.7 #H2SO4 in water in mg/lit#\n", + "W5=95 #MgCl2 in water in mg/lit#\n", + "W6=14.8 #Mg(NO3)2 in water in mg/lit#\n", + "M1=100/162.0 #multiplication factor of Ca(HCO3)2#\n", + "M2=100/146.0 #multiplication factor of Mg(HCO3)2#\n", + "M3=100/136.0 #multiplication factor of CaSO4#\n", + "M4=100/98.0 #multiplication factor of H2SO4 #\n", + "M5=100/95.0 #multiplication factor of MgCl2#\n", + "M6=100/148.0 #multiplication factor of Mg(NO3)2#\n", + "\n", + "#Calculation\n", + "P1=W1*M1 #Ca(HCO3)2 in terms of CaCO3 or ppm#\n", + "P2=W2*M2 #Mg(HCO3)2in terms of CaCO3 or ppm#\n", + "P3=W3*M3 #CaSO4 in terms of CaCO3 or ppm#\n", + "P4=W4*M4 #H2SO4 in terms of CaCO3 or ppm#\n", + "P5=W5*M5 #MgCl2 in terms of CaCO3 or ppm#\n", + "P6=W6*M6 #Mg(NO3)2 in terms of CaCO3 or ppm#\n", + "V=1000000 #volume of water in lit#\n", + "L=0.74*(P1+2*P2+P4+P5+P6)*(V/1000)*(100/purity_lime)#lime required# \n", + "S=1.06*(P4+P3+P5+P6)*(V/1000)*(100/purity_soda)#soda required# \n", + "\n", + "#Result\n", + "print\"Amount of lime required =\",round(L,1),\"g\" \n", + "print\"\\nAmount of soda required =\",round(S,1),\"g \"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amount of lime required = 214210.5 g\n", + "\n", + "Amount of soda required = 206111.1 g\n" + ] + } + ], + "prompt_number": 35 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:50" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=10000.#in litres#\n", + "volume_NaCl=5000.#Volume of NaCl in litres#\n", + "conc_NaCl=1170./10000#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.5#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 500.0 ppm\n", + "\n", + ] + } + ], + "prompt_number": 36 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:50" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=75000.#in litres#\n", + "volume_NaCl=1500.#Volume of NaCl in litres#\n", + "conc_NaCl=1.170/100#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10.#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.5#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 2.0 ppm\n", + "\n", + ] + } + ], + "prompt_number": 37 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:3,Page no:51" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Hardness=300.#Hardness of water(mg/lit) or ppm#\n", + "H=Hardness/100.#Hardness of water(gms/lit)#\n", + "volume_NaCl=75.#Volume of NaCl#\n", + "conc_NaCl=75.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.5#in terms of (gms/lit)#\n", + "volume_hardwater=CaCO3_equivalent/(H*10000.)\n", + "\n", + "#Result\n", + "print\"Zeolite softner can soften \",round(volume_hardwater,1),\"* 10**4 litres of water\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Zeolite softner can soften 1.6 * 10**4 litres of water\n", + "\n", + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:4,Page no:51" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Hardness=400.#Hardness of water(mg/lit) or ppm#\n", + "H=Hardness/100.#Hardness of water(gms/lit)#\n", + "volume_NaCl=100.#Volume of NaCl#\n", + "conc_NaCl=60.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.5#in terms of (gms/lit)#\n", + "volume_hardwater=CaCO3_equivalent/(H*10000.)\n", + "\n", + "#Result\n", + "print\"Zeolite softner can soften \",round(volume_hardwater,2),\"* 10**4 litres of water\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Zeolite softner can soften 1.28 * 10**4 litres of water\n", + "\n", + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:5,Page no:52" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=100000.#in litres#\n", + "volume_NaCl=400.#Volume of NaCl in litres#\n", + "conc_NaCl=1000/100.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10.#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.5#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness,1),\"mg/L\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 341.9 mg/L\n", + "\n", + ] + } + ], + "prompt_number": 40 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:6,Page no:52" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=800.#in litres#\n", + "volume_NaCl=40.#Volume of NaCl in litres#\n", + "conc_NaCl=1100./100#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10.#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.5#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness,2),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 4700.85 ppm\n", + "\n", + ] + } + ], + "prompt_number": 41 + }, { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:7,Page no:53" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=1.#in litres#\n", + "CaCl2=4.5#Hardness of water(gms/lit)#\n", + "moles_NaCl=2.;#Na3Ze giving NaCl and CaZe#\n", + "mol_wt_NaCl=58.5;\n", + "mol_wt_Na3Ze=111.;\n", + "\n", + "#Calculation\n", + "NaCl=CaCl2*moles_NaCl*mol_wt_NaCl/mol_wt_Na3Ze;\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(NaCl,2),\"gm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Quantity of NaCl produced is 4.74 gm\n", + "\n", + ] + } + ], + "prompt_number": 42 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:8,Page no:53" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Hardness=500.#Hardness of water(mg/lit) or ppm#\n", + "H=Hardness/100.#Hardness of water(gms/lit)#\n", + "volume_NaCl=100.#Volume of NaCl#\n", + "conc_NaCl=120.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.48#in terms of (gms/lit)#\n", + "volume_hardwater=CaCO3_equivalent/(H)\n", + "\n", + "#Result\n", + "print\"Zeolite softner can soften \",round(volume_hardwater),\"litres\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Zeolite softner can soften 20520.0 litres of water\n", + "\n", + ] + } + ], + "prompt_number": 43 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:9,Page no:54" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=4500.#in litres#\n", + "volume_NaCl=30.#Volume of NaCl in litres#\n", + "Wt_per_Litre=100.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.55#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 569.0 ppm \n", + "\n", + ] + } + ], + "prompt_number": 44 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:10,Page no:54" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=3500.#in litres#\n", + "volume_NaCl=25.02#Volume of NaCl in litres#\n", + "Wt_per_Litre=100.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.55#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness,1),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 610.5 ppm \n", + "\n", + ] + } + ], + "prompt_number": 45 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:11,Page no:55" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_hardwater=15000.#in litres#\n", + "volume_NaCl=120.07#Volume of NaCl in litres#\n", + "Wt_per_Litre=30.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.55#in terms of (gms/lit)#\n", + "H=CaCO3_equivalent/volume_hardwater#Hardness of water(gms/lit)#\n", + "Hardness=H*1000#Hardness of water(mg/lit) or ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(Hardness,1),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 205.1 ppm \n", + "\n", + ] + } + ], + "prompt_number": 46 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:12,Page no:55" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Hardness=480.#Hardness of water(mg/lit) or ppm#\n", + "H=Hardness/100.#Hardness of water(gms/lit)#\n", + "volume_NaCl=300.#Volume of NaCl#\n", + "conc_NaCl=150.#% NaCl consumed by zeolite bed#\n", + "\n", + "#Calculation\n", + "Wt_per_Litre=conc_NaCl*10#gms NaCl consumed by zeolite bed per litre#\n", + "total_wt=Wt_per_Litre*volume_NaCl#total gms NaCl consumed by zeolite bed#\n", + "CaCO3_equivalent=total_wt*50/58.48#in terms of (gms/lit)#\n", + "volume_hardwater=CaCO3_equivalent/(H*10000.)\n", + "\n", + "#Result\n", + "print\"Zeolite softner can soften \",round(volume_hardwater,2)-.01,\"* 10**4 litres\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Zeolite softner can soften 8.01 * 10**4 litres of water\n", + "\n", + ] + } + ], + "prompt_number": 47 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:59" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "volume_water=10**4#in litres#\n", + "volume_HCl=200.#in litres#\n", + "conc_HCl=0.1#in Normals#\n", + "\n", + "#Calculation\n", + "totl_hardness=volume_HCl*conc_HCl*50.#in terms of g CaCO3 equivalent#\n", + "h=totl_hardness/volume_water#in terms of g CaCO3 equivalent#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(h*1000),\"mg/L\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hardness of water sample is 100.0 mg/L\n", + "\n", + ] + } + ], + "prompt_number": 48 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:72" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_init=50.#initial volume of sample in ml#\n", + "vol_fin=80.#final volume of sample in ml#\n", + "DOb=840.#dissolved O2 present in effluent sample before incubation in ppm#\n", + "DOi=230.#dissolved O2 present in effluent sample after incubation in ppm#\n", + "\n", + "#Calculation\n", + "DF=vol_fin/vol_init#dilution factor#\n", + "BOD=(DOb-DOi)*DF#in ppm#\n", + "\n", + "#Result\n", + "print\"Biological Oxygen Demand(BOD) of the sample is \",round(BOD),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Biological Oxygen Demand(BOD) of the sample is 976.0 ppm\n", + "\n", + ] + } + ], + "prompt_number": 49 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:73" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vb=27.#volume of ferrous ammonium sulphate in blank experiment in ml#\n", + "Vt=6.5#volume of ferrous ammonium sulphate in test experiment in ml#\n", + "N=0.1#concentration in Normals#\n", + "Ve=25.#volume of water sample taken in test in ml#\n", + "\n", + "#Calculation\n", + "COD=(Vb-Vt)*N*8./Ve#in ppm#\n", + "\n", + "#Result\n", + "print\"Hardness of water sample is \",round(COD,3),\"ppm\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Chemical Oxygen Demand(COD) of the sample is 0.656 ppm\n", + "\n", + ] + } + ], + "prompt_number": 50 + }, + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_03_Lubricants.ipynb b/Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_03_Lubricants.ipynb new file mode 100755 index 00000000..56b9fa93 --- /dev/null +++ b/Applied_Chemistry_by_Dr._Mrs.Trupti_Paradkar/Chapter_03_Lubricants.ipynb @@ -0,0 +1,843 @@ + { + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 3:Lubricants" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=4.55#weight f oil saponified(gms)#\n", + "volume=2.1#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.02#normality of KOH #\n", + "\n", + "#Calculation\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.517 mg/g\n", + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=10.#weight f oil saponified(gms)#\n", + "volume=2.4#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.02#normality of KOH #\n", + "\n", + "#Calculation\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3)-.001,\"mg/g\"\n", + "print\"\\nAs the acid value is more than 0.1, oil cannot be used for lubrication\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.268 mg/g\n", + "\n", + "As the acid value is more than 0.1, oil cannot be used for lubrication\n", + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:3,Page no:28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=20.#volume of oil saponified(ml)#\n", + "den_oil=0.86#density f oil saponified(gm/ml)#\n", + "volume=2.5#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.1#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.814 mg/g\n", + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:4,Page no:29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=10.#volume of oil saponified(ml)#\n", + "den_oil=0.92#density f oil saponified(gm/ml)#\n", + "volume=4#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.01#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.243 mg/g\n", + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:5,Page no:27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=9.#volume of oil saponified(ml)#\n", + "den_oil=0.81#density f oil saponified(gm/ml)#\n", + "volume=1.5#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.04#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.461 mg/g\n", + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:6,Page no:30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=20.#volume of oil saponified(ml)#\n", + "den_oil=0.86#density f oil saponified(gm/ml)#\n", + "volume=2.8#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=1./10.#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3)-.001,\"mg/g\"\n", + "print\"\\nAs the acid value is more than 0.1, oil cannot be used for lubrication\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.911 mg/g\n", + "\n", + "As the acid value is more than 0.1, oil cannot be used for lubrication\n", + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:7,Page no:30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=7.#volume of oil saponified(ml)#\n", + "den_oil=0.88#density f oil saponified(gm/ml)#\n", + "volume=3.8#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.02#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,2),\"mg/g\"\n", + "print\"\\nAs the acid value is more than 0.1, oil cannot be used for lubrication\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.69 mg/g\n", + "\n", + "As the acid value is more than 0.1, oil cannot be used for lubrication\n", + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:8,Page no:31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=6.#volume of oil saponified(ml)#\n", + "den_oil=0.91#density f oil saponified(gm/ml)#\n", + "volume=2.6#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.02#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3),\"mg/g\"\n", + "print\"\\nAs the acid value is more than 0.1, oil cannot be used for lubrication\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.533 mg/g\n", + "\n", + "As the acid value is more than 0.1, oil cannot be used for lubrication\n", + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:9,Page no:31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=1.3#weight f oil saponified(gms)#\n", + "volume=0.8#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=0.001#normality of KOH #\n", + "\n", + "#Calculation\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,5),\"mg/g\"\n", + "print\"\\nAs the acid value is less than 0.1, oil can be used for lubrication\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.0.03446 mg/g\n", + "\n", + "As the acid value is less than 0.1, oil can be used for lubrication\n", + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:10,Page no:32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vol_oil=10.#volume of oil saponified(ml)#\n", + "den_oil=0.91#density f oil saponified(gm/ml)#\n", + "volume=5.#volume of alcoholic KOH consumed to neutralize fatty acids(ml)#\n", + "normality_KOH=1./50#normality of KOH #\n", + "\n", + "#Calculation\n", + "wt_oil=vol_oil*den_oil\n", + "A=volume*normality_KOH*56./wt_oil#formula for acid value#\n", + "\n", + "#Result\n", + "print\"\\nAcid value of oil is \",round(A,3),\"mg/g\"\n", + "print\"\\nAs the acid value is more than 0.1, oil cannot be used for lubrication\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 0.615 mg/g\n", + "\n", + "As the acid value is more than 0.1, oil cannot be used for lubrication\n", + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:1,Page no:33" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=2.5#weight f oil saponified(gms)#\n", + "blank=49.0#volume blank titration reading(ml)#\n", + "back=26.4#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "normality_KOH=0.4#normality of KOH#\n", + "S=volume*normality_KOH*56/wt_oil#formula for saponification value#\n", + "\n", + "#Result\n", + "print\"\\nSaponification value of oil is \",round(S,3),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Saponification value of oil is 202.496 mg/g\n", + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:2,Page no:33" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=5.#weight f oil saponified(gms)#\n", + "blank=44.0#volume blank titration reading(ml)#\n", + "back=17.#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "normality_KOH=0.5#normality of KOH#\n", + "S=volume*normality_KOH*56/wt_oil#formula for saponification value#\n", + "\n", + "#Result\n", + "print\"\\nSaponification value of oil is \",round(S,1),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Saponification value of oil is 151.2 mg/g\n", + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:3,Page no:34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n","S=180.#Saponification value of oil#\n", + "wt_oil=1.#weight f oil saponified(gms)#\n", + "blank=50.#volume blank titration reading(ml)#\n", + "normality_KOH=0.4#normality of KOH #\n", + "\n", + "#Calculation\n", + "volume=S*wt_oil/(normality_KOH*56)#formula for saponification value#\n", + "back=blank-volume#volume of alcoholic KOH consumed(ml)#\n", "\n", + "#Result\n", + "print\"\\nQuantity of alcoholic KOH required per gram is \",round(back),\"ml\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Quantity of alcoholic KOH required per gram is 42.0 ml\n", + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:4,Page no:35" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=2.5#weight f oil saponified(gms)#\n", + "blank=40.#volume blank titration reading(ml)#\n", + "back=20.#volume back titration reading(ml)#\n", + "normality_KOH=0.25#normality of KOH #\n", + "normality_HCl=.5#normality of HCl#\n", + "\n", + "#Calculation\n", + "e=normality_HCl/normality_KOH#for equivalence in titration #\n", + "volume=(blank-back)*e#volume of alcoholic KOH consumed(ml)#\n", + "S=volume*normality_KOH*56/wt_oil#formula for saponification value#\n", + "\n", + "#Result\n", + "print\"\\nSaponification value of oil is \",round(S),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Saponification value of oil is 224.0 mg/g\n", + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:5,Page no:35" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "S_C=192.#Saponification value of castor oil#\n", + "wt_oil=16.#weight f oil saponified(gms)#\n", + "blank=45.#volume blank titration reading(ml)#\n", + "back=31.5#volume back titration reading(ml)#\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "N_H=0.5#normality of HCl in titration#\n", + "\n", + "#Calculation\n", + "V_H=blank#volume of HCl in titration(ml)#\n", + "V_K=50.#volume of KOH in titration(ml)#\n", + "N_K=N_H*V_H/V_K#normality of KOH for equivalence#\n", + "S_blended=volume*N_K*56./wt_oil#formula for saponification value#\n", + "pc_C=(S_blended/S_C)*100#blend percentage#\n", + "\n", + "#Result\n", + "print\"\\nPercentage of castor oil in blend is \",round(pc_C,3),\"%\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Percentage of castor oil in blend is 11.074 %\n", + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:6,Page no:36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=3.#weight f oil saponified(gms)#\n", + "blank=36.0#volume blank titration reading(ml)#\n", + "back=12.#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "normality_KOH=0.5#normality of KOH#\n", + "S=volume*normality_KOH*56/wt_oil#formula for saponification value#\n", + "\n", + "#Result\n", + "print\"\\nSaponification value of oil is \",round(S),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Saponification value of oil is 224.0 mg/g\n", + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:7,Page no:37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=1.55#weight f oil saponified(gms)#\n", + "blank=20.0#volume blank titration reading(ml)#\n", + "back=15.#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "normality_KOH=0.5#normality of KOH#\n", + "S=volume*normality_KOH*56/wt_oil#formula for saponification value#\n", + "\n", + "#Result\n", + "print\"\\nSaponification value of oil is \",round(S,2),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Saponification value of oil is 90.32 mg/g\n", + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:8,Page no:37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "wt_oil=1.25#weight f oil saponified(gms)#\n", + "blank=50.0#volume blank titration reading(ml)#\n", + "back=7.5#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "normality_KOH=0.1#normality of KOH#\n", + "S=volume*normality_KOH*56/wt_oil#formula for saponification value#\n", + "\n", + "#Result\n", + "print\"\\nSaponification value of oil is \",round(S,1),\"mg/g\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Saponification value of oil is 190.4 mg/g\n", + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:9,Page no:38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "S_C=188.#Saponification value of castor oil#\n", + "wt_oil=12.3#weight f oil saponified(gms)#\n", + "blank=45.#volume blank titration reading(ml)#\n", + "back=30.2#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "N=0.5#normality of KOH for equivalence#\n", + "S_blended=volume*N*56./wt_oil#formula for saponification value#\n", + "pc_C=(S_blended/S_C)*100\n", + "\n", + "#Result\n", + "print\"\\nPercentage of castor oil in blend is \",round(pc_C,2),\"%\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Acid value of oil is 17.92 %\n", + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example no:10,Page no:38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "S_C=191.#Saponification value of castor oil#\n", + "wt_oil=2.5#weight f oil saponified(gms)#\n", + "blank=40.#volume blank titration reading(ml)#\n", + "back=24.#volume back titration reading(ml)#\n", + "\n", + "#Calculation\n", + "volume=blank-back#volume of alcoholic KOH consumed(ml)#\n", + "N=0.5#normality of KOH for equivalence#\n", + "S_blended=volume*N*56./wt_oil#formula for saponification value#\n", + "pc_C=(S_blended/S_C)*100\n", + "\n", + "#Result\n", + "print\"\\nPercentage of castor oil in blend is \",round(pc_C,2),\"%\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Percentage of castor oil in blend is 93.82 %\n", + ] + } + ], + "prompt_number": 20 + }, + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_By_Example/screenshots/Arrays.png b/C++_By_Example/screenshots/Arrays.png new file mode 100755 index 00000000..007cedf4 Binary files /dev/null and b/C++_By_Example/screenshots/Arrays.png differ diff --git a/C++_By_Example/screenshots/class.png b/C++_By_Example/screenshots/class.png new file mode 100755 index 00000000..651cb5fc Binary files /dev/null and b/C++_By_Example/screenshots/class.png differ diff --git a/C++_By_Example/screenshots/factorial.png b/C++_By_Example/screenshots/factorial.png new file mode 100755 index 00000000..c8d8f20a Binary files /dev/null and b/C++_By_Example/screenshots/factorial.png differ diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter1_1.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter1_1.ipynb new file mode 100755 index 00000000..98d9cbdf --- /dev/null +++ b/C++_By_Example_by_Greg__M._Perry/Chapter1_1.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_1.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter2_1.ipynb new file mode 100755 index 00000000..16b4b2bc --- /dev/null +++ b/C++_By_Example_by_Greg__M._Perry/Chapter2_1.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_1.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter3_1.ipynb new file mode 100755 index 00000000..0233a57b --- /dev/null +++ b/C++_By_Example_by_Greg__M._Perry/Chapter3_1.ipynb @@ -0,0 +1,1983 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:49033c6362fbe43a8dfa0ceef6d919270979cfe067b5a1a151391be0371e0757" + }, + "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": [ + "C12EXIT1, Page number:257" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#function definition\n", + "def main():\n", + " exit(0)\n", + " print \"C++ programming is fun\"\n", + " print \"I like learning C++ by example!\\n\"\n", + " print \"C++ is a powerful language that is not difficult to learn\"\n", + "main()\n", + "#result\n", + "#the program quits early due to exit() function" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "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": [] + }, + { + "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 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": 15 + }, + { + "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": 18 + }, + { + "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_1.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter4_1.ipynb new file mode 100755 index 00000000..af8938df --- /dev/null +++ b/C++_By_Example_by_Greg__M._Perry/Chapter4_1.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_1.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter5_1.ipynb new file mode 100755 index 00000000..92b07a7b --- /dev/null +++ b/C++_By_Example_by_Greg__M._Perry/Chapter5_1.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_1.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter6_1.ipynb new file mode 100755 index 00000000..0905d8e9 --- /dev/null +++ b/C++_By_Example_by_Greg__M._Perry/Chapter6_1.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]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]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/Electronic_Devices_and_Circuits/screenshots/Screenshot01.png b/Electronic_Devices_and_Circuits/screenshots/Screenshot01.png new file mode 100755 index 00000000..c39deda0 Binary files /dev/null and b/Electronic_Devices_and_Circuits/screenshots/Screenshot01.png differ diff --git a/Electronic_Devices_and_Circuits/screenshots/Screenshot02.png b/Electronic_Devices_and_Circuits/screenshots/Screenshot02.png new file mode 100755 index 00000000..6c65bc41 Binary files /dev/null and b/Electronic_Devices_and_Circuits/screenshots/Screenshot02.png differ diff --git a/Electronic_Devices_and_Circuits/screenshots/Screenshot03.png b/Electronic_Devices_and_Circuits/screenshots/Screenshot03.png new file mode 100755 index 00000000..8bd71949 Binary files /dev/null and b/Electronic_Devices_and_Circuits/screenshots/Screenshot03.png differ diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter1.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter1.ipynb new file mode 100755 index 00000000..41def6eb --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter1.ipynb @@ -0,0 +1,1596 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:a9ed36d73f9d154839d703d9a4c0fe9425b38f6baf4e4351a575d82599eff181" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1: SEMICONDUCTORS,DIODE AND DIODE CIRCUITS" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.1, Page number 5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "A=6.022*10**23 #avagadro's number(/m^3)\n", + "d=2.7*10**6 #density of aluminium conductor(g/m^3)\n", + "a=26.98 # atomic weight aluminium conductor(g/g-atom)\n", + "D=10**4. #current density(A/m^2)\n", + "e=1.6*10**-19 #electronic charge(C)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "n=A*d/a #number of atoms(n/m^3)\n", + "\n", + "#Part b\n", + "u=D/(n*e) #drift velocity (m/s)\n", + "\n", + "#Results\n", + "print \"number of atoms per cubic meter is \",round(n/1e+28,3),\"*10^28 /m^3\"\n", + "print \"drift velocity is\",round(u/1e-6,2),\"*10^-6 m/s\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "number of atoms per cubic meter is 6.026 *10^28 /m^3\n", + "drift velocity is 1.04 *10^-6 m/s\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.2, Page number 6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "n=10**23 #number of electrons(n/m^3)\n", + "e=1.6*10**-19 #electronic charge(C) \n", + "u=0.4 #mobility(m^2/Vs) \n", + "a=10**-7 #cross sectional area(m^2) \n", + "l=15*10**-2 #conductor length(m)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "G=n*e*u #conductivity(S/m)\n", + "\n", + "#Part b\n", + "R=l/(a*G) #resistance(ohm)\n", + "\n", + "#Results\n", + "print\"conductivity of the conductor is\",round((G/1E+3),1),\"*10**3 S/m\"\n", + "print\"resistance of the conductor is\",round(R,1),\"ohm\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "conductivity of the conductor is 6.4 *10**3 S/m\n", + "resistance of the conductor is 234.4 ohm\n" + ] + } + ], + "prompt_number": 27 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.3, Page number 9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "A=6.022*10**23 #avagadro's number\n", + "d=5.32*10**6 #density of Ge at 300k(g/m^3)\n", + "a=72.60 #atomic weight of Ge(g/g-atom)\n", + "e=1.6*10**-19 #electronic charge(C)\n", + "ni=2.4*10**19 #intrinsic concentration(electron-hole pairs/m^3)\n", + "un=0.39 #electron mobility(m^2/V.s)\n", + "up=0.19 #hole mobility(m^2/V.s)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "nA=A*d/a #number of atoms(nA/m^3)using avagadro's law\n", + "x=nA/ni #Germanium atoms/electron hole pair\n", + "\n", + "#Part b\n", + "g=(un+up)*e*ni #intrinsic conductivity(S/m)\n", + "r=1/g #intrinsic resistivity(ohm.m)\n", + "\n", + "#Results\n", + "print\"the relative concentration of Ge and electron hole pairs is\",round((x/1E9),2),\"*10^9 atoms/electron-hole pair\"\n", + "print\"the intrinsic resistivity of Ge is\",round(r,3),\"ohm.m\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the relative concentration of Ge and electron hole pairs is 1.84 *10^9 atoms/electron-hole pair\n", + "the intrinsic resistivity of Ge is 0.449 ohm.m\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.4,Page number 13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "ni=1.5*10**16 #intrinsic concentration(electron-hole pairs/m^3)\n", + "n=4.99*10**28 #number of Si atoms(atoms/m^3)\n", + "un=0.13 #electron mobility(m^2/V.s)\n", + "up=0.05 #hole mobility(m^2/V.s)\n", + "e=1.6*10**-19 #electronic charge(c)\n", + "\n", + "#Calculation\n", + "#Part a\n", + "g=e*ni*(un+up) #intrinsic conductivity(S/m)\n", + "r=1/g #interinsic resistivity(ohm.m)\n", + "Nd=n/10**8 #doped silicon(atoms/m^3)=nn,majority carriers\n", + "pn=ni**2/Nd #minority carrier density(holes/m^3)\n", + "\n", + "#Part b\n", + "k=e*un*Nd #conductivity(S/m)\n", + " #using Nd in place of nn as Nd=nn\n", + "rho=1/k #resistivity(ohm.m)\n", + "\n", + "#Results\n", + "print\"the minority carrier density of Si is\",round(pn/1e+11,2),\"*10^11 holes/m^3\"\n", + "print\"the resistivity of Si is\",round((rho/1E-2),2),\"*10**-2 ohm.m\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the minority carrier density of Si is 4.51 *10^11 holes/m^3\n", + "the resistivity of Si is 9.63 *10**-2 ohm.m\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.5,Page number 17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vo=0.7 #contact potential(V)\n", + "Vf=0.4 #forward biasing voltage(V) \n", + "\n", + "#Calculation\n", + "x=math.exp(-20*(Vo-Vf))/math.exp(-20*Vo) #increase in probability of majority carriers\n", + "\n", + "#Result\n", + "print\"increase in probability of majority carriers is\",round(x),\"times\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "increase in probability of majority carriers is 2981.0 times\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.6,Page number 18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "I=10 #Ge diode carries current(mA)\n", + "V=0.2 #forward bias voltage(V)\n", + "\n", + "#Calculation\n", + "#Part a\n", + "Is=I/(math.expm1(40*V)-1) #reverse current(mA)\n", + "\n", + "#part b\n", + "I1=1*10**-3 #current(mA) \n", + "V1=(math.log((I1/Is)+1))/40 #voltage(V)\n", + "I2=100*10**-3 #current(mA) \n", + "V2=(math.log((I2/Is)+1))/40 #voltage(V) \n", + "\n", + "#Part c\n", + "Is1=4*Is #reverse saturation current doubles for every 10 degree celcius temp rise,so for 20 degree rise it will be 4 timese/ \n", + "x=37.44 #let x=e/kT\n", + "I3=Is1*(math.expm1(x*V)) #current when temp doubles(mA)\n", + "\n", + "#Results\n", + "print\"the reverse current is\",round(Is/1e-3,3),\"mA\" #incorrect units given in the textbook\n", + "print\"bias voltages are\",round(V1,3),\"V and\", round(V2,3),\"V resp\"\n", + "print\"Is at 20 degree is\",round(Is1/1e-3,2),\"uA and diode current at 0.2 V is\",round(I3,2),\"mA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the reverse current is 3.357 mA\n", + "bias voltages are 0.007 V and 0.086 V resp\n", + "Is at 20 degree is 13.43 uA and diode current at 0.2 V is 23.97 mA\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.7,Page number 21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "V=3. #Voltage(V)\n", + "Req=300. #total resistance as per circuit(ohm)\n", + "Rfa=20 #forward resistance(ohm) \n", + "Vt=0.7 #Thevinine's voltage(V)\n", + "Rfb=0 #forward resistance(ohm)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "I=V/Req #current(A)\n", + "\n", + "#Part b\n", + "Id=(V-Vt)/Req #diode current(mA)\n", + "\n", + "#Part c\n", + "Rf=20 #forward resistance(ohms) \n", + "Id1=(V-Vt)/(Req+Rfa) #diode current(mA)\n", + "\n", + "#Results\n", + "print\"current in this case is\",round(I,2),\"A\"\n", + "print\"diode current is\",round((Id/1E-3),2),\"mA\"\n", + "print\"diode current is\",round((Id1/1E-3),2),\"mA\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "current in this case is 0.01 A\n", + "diode current is 7.67 mA\n", + "diode current is 7.19 mA\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.9,Page number 22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vx=1.4 #voltage at point X(V) \n", + "Vt=0.7 #diode voltage(V)\n", + "Vcc=5 #cathode voltage(V) \n", + "R=1 #circuit resistance(ohm) \n", + "Vs=Vx-Vt #supply voltage(V)\n", + "\n", + "#Calculations\n", + "I1=(Vcc-Vt-Vs)/R #current throgh D1(mA) for 00.7 as D2 and D3 conducts\n", + "\n", + "#Results\n", + "print\"I1 for 00.7 is\",I1,\"mA\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I1 for 00.7 is 3.6 mA\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.11,Page number 23" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vz=100 #zener voltage(V)\n", + "Rz=25 #diode resistance(ohm)\n", + "Il=0.05 #load current(A)\n", + "Iz=0.01 #zener diode current(A)\n", + "Rs=250 #supply resistance(ohm)\n", + "\n", + "#Calculations\n", + "Vl=Vz+(Iz*Rz) #load voltage(V)\n", + "Vs=Vl+(Il+Iz)*Rs #supply voltage(V)\n", + "VL=Vl*1.01 #increase in Vl(V)\n", + "IZ=(VL-Vz)/Rz #increase in zener current\n", + "VS=Vl+(Il+IZ)*Rs #increase in supply voltage(V)\n", + "Vss=(VS-Vs)/Vs #%increase in supply voltage(V)\n", + "P=Il*VL #power consumed(W) \n", + "\n", + "#Results\n", + "print\"load voltage is\",Vl,\"V\"\n", + "print\"supply voltage is\",Vs,\"V\"\n", + "print\"increase in supply voltage is\",VS,\"V\"\n", + "print\"power consumed is\",round(P,2),\"W\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " load voltage is 100.25 V\n", + "supply voltage is 115.25 V\n", + "increase in supply voltage is 125.275 V\n", + "power consumed is 5.06 W\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.12,Page number 25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vbb=5 #bias voltage(V)\n", + "Rl=1 #resistance(ohm)\n", + "Id=4.4 #from the figure(mA)\n", + "\n", + "#Part a\n", + "i=Vbb/Rl #load line intercepts the Id axis at i(mA)\n", + "Vl=Id*Rl #load voltage(V)\n", + "\n", + "#Part b\n", + "Vd=Vbb-Vl #diode voltage(V)\n", + "P=Vd*Id #power absorbed in diode(mW)\n", + "\n", + "#Part c \n", + "Ida=1.42 #diode current(mA)for 2V\n", + "Idb=7.35 #diode current(mA)for 8V\n", + "\n", + "#Part d\n", + "Idc=8.7 #diode current(mA)for Rl=0.5k ohm \n", + "Idd=2.2 #diode current(mA)for Rl=2k ohm\n", + "\n", + "#Results\n", + "print\"diode current is\",Id,\"mA and voltage across the load is\",Vl,\"V\"\n", + "print\"power absorbed in diode is\",P,\"mW\"\n", + "print\"diode current for Vbb=2V is\",Ida,\"mA\",\"and for Vbb=8V is\",Idb,\"mA\"\n", + "print\"diode current for Rl=0.5kohm is\",Idc,\"mA\",\"and for Rl=2kohm is\",Idd,\"mA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "diode current is 4.4 mA and voltage across the load is 4.4 V\n", + "power absorbed in diode is 2.64 mW\n", + "diode current for Vbb=2V is 1.42 mA and for Vbb=8V is 7.35 mA\n", + "diode current for Rl=0.5kohm is 8.7 mA and for Rl=2kohm is 2.2 mA\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.13,Page number 38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "T=300 #temperature(k)\n", + "Ig=100*10**-3 #current(mA)\n", + "Is=1*10**-9 #current(nA)\n", + "x=0.0259 #x=kT/e\n", + "\n", + "#Calculations\n", + "Voc=x*math.log(Ig/Is+1) #as Voc=kT/e*ln((Ig/Is)+1) where ln((Ig/Is)+1)=18.42 after solving \n", + "Isc=Ig\n", + "\n", + "#Result\n", + "print\"for a solar cell Voc is\",round(Voc,3),\"V and Isc is\",round(Isc/1E-3),\"mA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "for a solar cell Voc is 0.477 V and Isc is 100.0 mA\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.14,Page number 38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Idc=0.1 #dc current(A)\n", + "Rf=0.5 #forward resistance(ohms)\n", + "Rl=20 #load resistance(ohm)\n", + "Rs=1 #secondary resistance of transformer(ohm)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Vdc=Idc*Rl #dc voltage(V)\n", + "Vm=(math.pi/2)*(Vdc+Idc*(Rs+Rf)) #mean voltage(V)\n", + "Vrms=Vm/math.sqrt(2) #rms value of voltage(V) \n", + "\n", + "#Part b\n", + "Pdc=Idc**2*Rl #dc power supplied to the load\n", + "\n", + "#Part c\n", + "PIV=2*Vm #PIV rating for each diode(V)\n", + "\n", + "#Part d\n", + "Im=(math.pi/2)*Idc #peak value of current(mA)\n", + "Irms=Im/math.sqrt(2) #rms calue of current(A)\n", + "Pac=Irms**2*(Rs+Rf+Rl) #ac power input(W)\n", + "\n", + "#Part e\n", + "eta=(Pdc/Pac)*100 #conversion efficiency\n", + "\n", + "#Part f\n", + "Vr=((Rs+Rf)/Rl)*100 #voltage regulation(V)\n", + "\n", + "#results\n", + "print\"rms value of voltage is\",round(Vrms,2),\"V\"\n", + "print\"dc power supplied to load is\",Pdc,\"W\"\n", + "print\"PIV rating for each diode\",round(PIV,2),\"V\"\n", + "print\"ac input power is\",round(Pac,3),\"W\"\n", + "print\"conversion efficiency\",round(eta,1),\"%\"\n", + "print\"voltage regulation\",Vr,\"%\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "rms value of voltage is 2.39 V\n", + "dc power supplied to load is 0.2 W\n", + "PIV rating for each diode 6.75 V\n", + "ac input power is 0.265 W\n", + "conversion efficiency 75.4 %\n", + "voltage regulation 7.5 %\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.15,Page number 46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "from scipy import integrate\n", + "\n", + "#Variable declaration\n", + "Vt=1 \n", + "Vl=12\n", + "Vm=63.63 #peak voltage(V) as Vm=sqr root of 2*45\n", + "Idc=8. #charging current(A)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "theta1=math.degrees(math.asin((Vt+Vl)/Vm))\n", + "theta2=180-theta1\n", + "Rl=((2*Vm*math.cos(theta1))-(2*(math.pi-2*theta1)*(Vt+Vl)))/(Idc*math.pi)\n", + "\n", + "#Part b\n", + "wt = lambda wt: (((((math.sqrt(2)*45*math.sin(wt))-(Vt+Vl))/Rl)*wt)**2)\n", + "integ,err = integrate.quad(wt, theta1 , theta2)\n", + "print integ\n", + "Irms = (integ/math.pi)**0.5\n", + "Pl=Irms**2*Rl #power loss in resistance(W)\n", + "\n", + "#Part c\n", + "P=Vl*Idc #power supplied to battery(W)\n", + "\n", + "#results\n", + "print\"Resistance to be added is\",round(Rl,2),\"Ohms\"\n", + "print\"\",Pl\n", + "print\"power supplied to battery is\",P,\"W\"\n", + "print\"\",Irms " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5703935.44277\n", + "Resistance to be added is 24.75 Ohms\n", + " 44936628.7032\n", + "power supplied to battery is 96.0 W\n", + " 1347.44908683\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.16,Page number 47" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Rf=5 #forward resistance(ohms)\n", + "Vo=20 #output voltage(V)\n", + "Rs=10 #secondary resistance of transformer(ohm)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Idc=0.1 #dc current(A) \n", + "Vm=Vo*(math.sqrt(2)) #mean voltage(V)\n", + "Vdc=(2*Vm/(math.pi))-Idc*(Rs+2*Rf) #dc voltage(V)\n", + "\n", + "#Part b\n", + "Idc1=0.2 #full load dc current(A)\n", + "Vdc2=((2*(math.sqrt(2))*Vo)/(math.pi))-Idc1*(Rs+2*Rf) #full load dc voltage(V)\n", + "Rl=Vdc2/Idc1 #load resistance(ohm)\n", + "x=((2*Rf+Rs)/Rl)*100 #% regulation \n", + "\n", + "#Part c\n", + "Idc=0.2 #dc current(A)\n", + "Im=(math.pi)*Idc/2 #peak current(mA)\n", + "Ilrms=Im/math.sqrt(2) #rms current(mA)\n", + "Vlrms=Ilrms*Rl #load rms voltage(V) \n", + "\n", + "#Part d\n", + "Vldc=14 #load dc voltage(V)\n", + "Vlacrms=math.sqrt(Vlrms**2-Vldc**2) #rms value of ac component(V)\n", + "\n", + "#Results\n", + "print\"dc voltage\",round(Vdc),\"V\"\n", + "print\"regulation is\",round(x,2),\"%\"\n", + "print\"rms value of output voltage at dc load current is\",round(Vlrms,2),\"V\"\n", + "print\"rms value of ac component of voltage\",round(Vlacrms,2),\"V\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "dc voltage 16.0 V\n", + "regulation is 28.56 %\n", + "rms value of output voltage at dc load current is 15.56 V\n", + "rms value of ac component of voltage 6.78 V\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.17,Page number 50" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vh=60. #higher output voltage(V)\n", + "Vl=45. #lower output voltage(V) \n", + "fz=50. #frequency(Hz)\n", + "Vr=15. #peak to peak ripple voltage(V)\n", + "Rl=600. #resistance(ohms)\n", + " \n", + "#Calculations\n", + "Vldc=(Vh+Vl)/2 #avg load dc voltage(V) as voltage drops from 60 to 45\n", + "Idc=Vldc/Rl #dc current(A)\n", + "T=1/fz #discharging time(ms)\n", + "C=(Idc*T)/Vr #linear discharge rate(uF)\n", + "C1=C*2 #new capacitance(uF)\n", + "'''\n", + " CVr(p-p) 234Vr(p-p)*10^3\n", + "Idc = -------------- = --------------- ----(1)\n", + " T 20\n", + " \n", + " 60+[60-Vr(p-p) 120-Vr(p-p)\n", + "Idc = --------------- = ------------*1000 ----(2)\n", + " 2Rl 2*600\n", + " \n", + "Equating equations 1 & 2, we get, \n", + "'''\n", + "\n", + "Vr1 = (20*120*1000)/(1200*254)\n", + "Idc1=(Vh-(Vr1/2))/Rl #dc load current(mA)\n", + "\n", + "#Results\n", + "print\"value of capacitance is\",round(C/1E-6),\"uF\" \n", + "print\"Vr1 is\",Vr1,\"V\" \n", + "print\"dc load current Idc is\",round(Idc1/1E-3),\"mA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of capacitance is 117.0 uF\n", + "Vr1 is 7 V\n", + "dc load current Idc is 95.0 mA\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.18,Page number 51" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vdc=30 #dc voltage(V)\n", + "V1=220 #source voltage(V)\n", + "f=50 #frequency(Hz)\n", + "Rl=1000 #load resistance(k ohms)\n", + "\n", + "#Calculations\n", + "C=100/f*Rl #as Vdc/Vr=100\n", + "Vm=Vdc+(Vr/2) #peak voltage(V)\n", + "V2=Vm/(math.sqrt(2)) #secondary voltage(V)\n", + "r=V1/V2 #transformer turn ratio\n", + "\n", + "#Results\n", + "print\"capacitor filtor is\",C,\"uF\"\n", + "print\"transformer turn ratio is\",round(r,2),\"\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "capacitor filtor is 2000 uF\n", + "transformer turn ratio is 10.37 \n" + ] + } + ], + "prompt_number": 37 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.19,Page number 52" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Idc=60*10**-3 #dc current(A)\n", + "Vm=60 #peak volage(V)\n", + "f=50 #frequency(Hz)\n", + "C=120*10**-6 #capacitance(F)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Vrms=Idc/(4*(math.sqrt(3))*f*C*Vm) #rms voltage(V)\n", + "Vr=2*(math.sqrt(3))*Vrms #ripple factor(V)\n", + "\n", + "#Part b\n", + "Vdc=Vm-(Vr/2) #by simplifying\n", + "\n", + "#Part c\n", + "r=(Vrms/Vdc)*100 #ripple factor\n", + "\n", + "#Results\n", + "print\"ripple factor is\",round(Vr,3),\"Vdc\"\n", + "print\"dc voltage is\",round(Vdc),\"V\"\n", + "print\"ripple factor\",round(r,4),\"%\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "ripple factor is 0.083 Vdc\n", + "dc voltage is 60.0 V\n", + "ripple factor 0.0401 %\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.20,Page number 54" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Calculations\n", + "#Part a\n", + "''' 200*1.141 4\n", + "v1(t)=-------------(1- - cos628t) \n", + " 3.14 3\n", + " 200*1.141 800*1.141 \n", + "v2(t)=----------- - ------------ cos(628t+<(V2/V1))\n", + " 3.14 3*3.14\n", + "\n", + "V2/V1|w=0 =0.8;V2/V1|w=628 =6.43*10^-4 >2 kohms,it it ignored)\n", + "Vl=(beeta+1)*Ib1*R #load voltage(V)\n", + "Avl=Vl #Voltage gain\n", + "Il=Vl/Rl #load current(A)\n", + "Ail=Il/Is #current gain\n", + "\n", + "#Results\n", + "print\"overall voltage gain is\",round((Avl/1E+3),2)\n", + "print\"overall current gain is\",round(Ail/1E+3)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "overall voltage gain is 51.5\n", + "overall current gain is 2575.0\n" + ] + } + ], + "prompt_number": 34 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.31,Page number 202" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vcc=15 #supply voltage(V)\n", + "beeta=30 #current gain \n", + "R=.47 #emitter resistance(ohms) \n", + "Vbe=0.7 #base to emitter voltage(V)\n", + "Vo=5 #output voltage(V)\n", + "\n", + "#Calculations\n", + "Vbb=Vcc/2 #base voltage(V)\n", + "'''\n", + "Vbb=(R1/2)*Ib+Vbe*2+(30Ib+Ic2)*R\n", + "Ic2=beeta*30Ib,so\n", + "Ic2=30*30Ib=900Ib\n", + "Vbb=(R1/2)*Ib+Vbe*2+(30+900)*R*Ib....(i)\n", + "(R1/2)*Ib+437*Ib=6.1.......(ii)\n", + "0.47*930Ib=5 #output voltage is given like this\n", + "\n", + "'''\n", + "Ib=Vo/(R*930) #from equation(i)\n", + "\n", + "'''\n", + "substituting value of Ibin eq(ii) we get\n", + "\n", + "'''\n", + "R1=((6.1-4.98)/0.0114)*2 #resistance(k ohms) \n", + "#Results\n", + "print\"value of R1 is\",round(R1),\"K ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of R1 is 196.0 K ohms\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter4.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter4.ipynb new file mode 100755 index 00000000..76bf3d3e --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter4.ipynb @@ -0,0 +1,1219 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:98255b9e78b8f50e90c1882e76d0bc683ec6745297ae8a737ed2e62008872388" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + " Chapter 4: SMALL SIGNAL AMPLIFIERS-FREQUENCY RESPONSE" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.1,Page number 217" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vs=1. #source voltage(V)\n", + "C=100*10**-6 #value of capacitance(uF) \n", + "r1=1 #resistance 1(k ohms)\n", + "r2=4 #resistance 2(k ohms)\n", + "R=5 #total resistance,R=r1+r2\n", + "\n", + "#Calculations\n", + "Imax=Vs/(r1+r2)*10**3 #maximum current(uA)\n", + "fc=1/(2*(math.pi)*C*R) #critical frequency(Hz) \n", + " #As w*C*R=1 and w=2*pi*f\n", + "f=10*fc #lowest frequency(Hz)\n", + "\n", + "#Results\n", + "print\"maximum current\",Imax,\"uA\"\n", + "print\"critical frequency\",round((fc/1E+3),3),\"Hz\"\n", + "print\"lowest frequency\",round((f/1E+3),2),\"Hz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "maximum current 200.0 uA\n", + "critical frequency 0.318 Hz\n", + "lowest frequency 3.18 Hz\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.2,Page number 218" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "C=100*10**-6 #capacitance(uF)\n", + "Rg=1. #galvanometer resistance(k oms)\n", + "Rl=4. #load resistance(k ohms)\n", + "\n", + "#Calculations\n", + "Rth=(Rg*Rl)/(Rg+Rl) #thevinine's equivalent resistance\n", + "fc=1/(2*(math.pi)*C*Rth) #critical frequency(Hz)\n", + "f=fc*C #lowest frequency(Hz)\n", + "\n", + "#Results\n", + "print\"lowest frequency at which the point A gets grounded is\",round((f/1E-2),1),\"Hz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "lowest frequency at which the point A gets grounded is 19.9 Hz\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.3,Page number 220" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "rpi=600 #dynamic junction resistance(ohms)\n", + "beta=100 #common emitter current gain\n", + "Vs=5. #source voltage(V)\n", + "Rs=400 #source resistance(ohms)\n", + "R=10 #resistance(k ohms)\n", + "\n", + "#Calculations\n", + "Ib=Vs/(Rs+rpi) #base current(uA) \n", + "Vo=R*beeta*Ib #output voltage(V)\n", + "Rin=rpi #input resistance(ohms)\n", + "Rout=R #output ewsistance(k ohms)\n", + "\n", + "#Results\n", + "print\"output voltage is\",Vo,\"V\"\n", + "print\"input resistance\",Rin,\"ohms\"\n", + "print\"output resistance\",Rout,\"k ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "output voltage is 5.0 V\n", + "input resistance 600 ohms\n", + "output resistance 10 k ohms\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.4,Page number 220" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "gm=1. #transconductance(mS)\n", + "rd=40 #dynamic drain resistance(k ohms) \n", + "Rd1=40 #JFET 1 drain resistance(k ohms) \n", + "Rd2=10 #JFET 2 drain resistance(k ohms) \n", + "\n", + "#Calculations\n", + "Avo=(-gm*((rd*Rd1)/(rd+Rd1)))*(-gm*((rd*Rd2)/(rd+Rd2))) #voltage gain\n", + "\n", + "#Results\n", + "print\"Avo is\",Avo" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Avo is 160.0\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.5,Page number 222" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "beta=125 #common emitter current gain\n", + "rpi=2.5 #dynamic junction resistance(k ohms)\n", + "rd=40 #dynamic drain resistance(k ohms) \n", + "gm=2 #transconductance(mS) \n", + "Vs=1 #assume,source voltage(V)\n", + "Rs=10 #source resistance(k ohms)\n", + "Rc=1 #collector resistance(k ohms)\n", + "rb=2 #resistance(k ohms)\n", + "Vgs=1 #gate to source voltage(V)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "R=(rd*Rs)/(rd+Rs) #equivalent resistance(k ohms)\n", + "Ib=gm*Vgs*(R/(rpi+R)) #base current(mA)\n", + "Vo=beeta*Ib*Rc #output voltage(V) \n", + "Avo=Vo #voltage gain\n", + "\n", + "#Part b\n", + "Ib1=Vs/(rb+rpi) #base current(mA) after interchanging stages of JFET and BJT \n", + "Vgs1=beeta*Ib1*Rc #gate to source voltage(V) after interchanging stages of JFET and BJT\n", + "Vo1=gm*Vgs1*R #output voltage(V) after interchanging stages of JFET and BJT\n", + "Avo1=Vo1 #voltage gain after interchanging stages of JFET and BJT\n", + "\n", + "#Results\n", + "print\"Avo is\",round(Avo,1)\n", + "print\"Avo1 when BJT and FET stages are reversed is\",round(Avo1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Avo is 190.5\n", + "Avo1 when BJT and FET stages are reversed is 444.0\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.6,Page number 226" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Cc1=1*10**-6 #coupling capacitor 1(uF)\n", + "Cc2=1*10**-6 #coupling capacitor 2 (uF) \n", + "Rs=10**3 #source resistance(k ohms)\n", + "rpi=2*10**3 #dynamic junction resistance(k ohms)\n", + "Rc=4500 #collector resistance(ohms)\n", + "Rl=9*10**3 #load resistance(k ohms)\n", + "w=100 #corner frequency(rad/s)\n", + "\n", + "#Calculations\n", + "w11=1/(Cc1*(Rs+rpi)) #corner frequency input circuit (rad/s)\n", + "w12=1/(Cc2*(Rc+Rl)) #corner frequency output circuit(rad/s)\n", + "f=w11/(2*(math.pi)) #lower cutoff frequency(Hz)\n", + "Zin=complex((Rs+rpi),-(1/(w*Cc1))) #input impedance(k ohms) \n", + "Zout=complex(Rc,-(1/(w*Cc2))) #output impedance(k ohms) \n", + "\n", + "#Results\n", + "print\"lower cut-off freq is\",round(f),\"Hz\"\n", + "print\"Zin\",Zin,\"ohms\"\n", + "print\"Zout\",Zout,\"ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "lower cut-off freq is 53.0 Hz\n", + "Zin (3000-10000j) ohms\n", + "Zout (4500-10000j) ohms\n" + ] + } + ], + "prompt_number": 37 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.7,Page number 229" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Re=Rc=1.5*10**3 #collector resistance(ohms)\n", + "Rs=600 #source resistance(ohms)\n", + "Rl=2*10**3 #load resistance(ohms) \n", + "beeta=100 #common emitter current gain \n", + "rpi=1*10**3 #dynamic junction resistance(ohms)\n", + "f=50 #frequency(Hz)\n", + "\n", + "#Calculations\n", + "w=2*f*(math.pi) #corner frequency(rad/s)\n", + "CE=1/(w*(Rs+rpi)) #capacitance(uF)\n", + "Ce=CE*(beeta+1) #capacitance(uF)\n", + "w11=w/10 #corner frequency input circuit (rad/s)\n", + "w12=w11/20 #corner frequency output circuit(rad/s)\n", + "Cc1=1/(w11*(Rs+rpi)) #coupling capacitor 1(uF) \n", + "Cc2=1/(w12*(Rc+Rl)) #coupling capacitor 2 (uF) \n", + "\n", + "#Results\n", + "print\"Ce is\",round(Ce/1E-6),\"uF\"\n", + "print\"Cc1 is\",round(Cc1/1e-6,1),\"uF\"\n", + "print\"Cc2 is\",round((Cc2/1E-5),2),\"uF\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ce is 201.0 uF\n", + "Cc1 is 19.9 uF\n", + "Cc2 is 18.19 uF\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.8,Page number 235" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "gm=2.5*10**-3 #transconductance(mS) \n", + "Rd=6*10**3 #drain resistance(ohms)\n", + "rd=200*10**3 #dynamic drain resistance(ohms) \n", + "Cc1=Cc2=0.12*10**-6 #coupling capacitors(uF)\n", + "Rs=1*10**3 #source resistance(ohms)\n", + "Rg=0.1*10**6 #R1||R2 \n", + "Cgs=12*10**-9 #gate to source capacitor(pF) \n", + "Cgd=2*10**-9 #gate to drain capacitor(pF) \n", + "Co1=10 # as Co1=Cl+Cw=10\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Ro=(rd*Rd)/(rd+Rd) #equivalent resistance of rd and Rd(ohms)\n", + "Vo=-gm*((rd*Rd)/(rd+Rd)) #as Vgs=Vs\n", + "Avo=Vo #Avo=Vo/Vs=(-gm*Vs*((rd*Rd)/(rd+Rd)))/Vs=Vo \n", + " \n", + "#Part b\n", + "f11=1/(2*(math.pi)*Cc1*(Rs+Rg))\n", + "\n", + "#Part c\n", + "Ceq=Cgs+(Cgd*(1+gm*Ro)) #on application of miller theorem\n", + "Co=Co1+Cgd*(1+(1/(gm*Ro))) #output capacitance(pF)\n", + "f21=1/(2*(math.pi)*Ceq*((Rs*Rg)/(Rs+Rg))) #input circuit cutoff frequency(MHz)\n", + "f22=1/(2*(math.pi)*Co*Ro)*10**3 #output circuit cutoff frequency(MHz)\n", + "fH=f22 #cutoff frequency of high frequency band(MHz)\n", + "\n", + "#Results\n", + "print\"a)mid freq gain is\",round(Avo,1)\n", + "print\"b)input circuit cut-off is\",round(f11,1),\"Hz\"\n", + "print\"c)high freq input cutoff is\",round((f21/1E+3),2),\"and output cutoff is\",round((f22/1E-3),2),\"MHz\"\n", + "print\"high freq cut-off is\",round((fH/1E-3),2),\"MHz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)mid freq gain is -14.6\n", + "b)input circuit cut-off is 13.1 Hz\n", + "c)high freq input cutoff is 3.73 and output cutoff is 2.73 MHz\n", + "high freq cut-off is 2.73 MHz\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.9,Page number 238" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "beta=50. #common emitter current gain \n", + "R1=11.5 #resistance(k ohms)\n", + "R2=41.4 #resistance(k ohms) \n", + "Vcc=10. #supply voltage to collector(V)\n", + "Rc=5. #collector resistance(k ohms)\n", + "Re=1. #emitter resistance(k ohms)\n", + "Rs=1. #source resistance(k ohms)\n", + "Vbe=0.7 #base emitter voltage(V)\n", + "Rl=10. #load resistance(k ohms)\n", + "Cc1=Cc2=20*10**-6. #coupling capacitors(uF)\n", + "Ce=150*10**-6. #emitter capacitor(uF) \n", + "Cpi=100 \n", + "Cu=5.\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rb=(R1*R2)/(R1+R2) #R1||R2(k ohms)\n", + "Vbb=Vcc*(R1/(R1+R2)) #suply voltage to base(V)\n", + "Ib=(Vbb-Vbe)/(Rb+(Rs*(1+beta))) #base current(mA)\n", + "Ic=beta*Ib #collector current(mA) \n", + "Vce=Vcc-(Ic*Rc)-(Ic+Ib)*Re #collector to emitter voltage(V) \n", + "rpi=(25*beta)*10**-3/Ic #dynamic junction resistance(K ohms) \n", + " \n", + "#Part b\n", + "rpi=1 #dynamic junction resistance(K ohms) \n", + "R=(rpi*Rb)/(rpi+Rb) #equivalent resistance(rpi||Rb) \n", + "Vbe=(R*Rs)/(R+Rs) #base to emitter voltage(V)\n", + "Ib1=Vbe/rpi #base current(mA)\n", + "Ro=(Rc*Rl)/(Rc+Rl) #Rc||Rl(k ohms) \n", + "Vo=-(beta*Ib1*Ro) #output voltage(V)\n", + "Avo=Vo #voltage gain\n", + "\n", + "#Part c\n", + "r1=(Rs*Rb)/(Rs+Rb) #Rs||Rb(k ohms) \n", + "w11=1/(Cc1*(Rs+R)) #low freq cutoff(rad/s)\n", + "w12=1/(Cc2*(Rc+Rl)) #high freq cutoff(rad/s) \n", + "w1p=1/((Ce/(beta+1))*(r1+rpi)) #low cutoff freq(rad/s)\n", + "\n", + "#Part d\n", + "Co1=5 #as Co1=Cw+Cl\n", + "gm=beta/rpi #transconductance(mS) \n", + "Ceq=Cpi+(Cu*(1+(gm*Ro))) #equivalent capacitance(pF)\n", + "Rs1=(Rb*Rs)/(Rb+Rs) #Rb||Rs(k ohms)\n", + "r2=(Rs1*rpi)/(Rs1+rpi) #Rs1||rpi(k ohms)\n", + "w21=10**12/(Ceq*r2*10**3) #low freq cutoff(MHz) \n", + "\n", + "#Results\n", + "print\"a)dc bias values are Vbb:\",round(Vbb,2),\"V, Ib:\",round(Ib,4),\"mA, Ic:\",round(Ic,2),\"mA, Vce:\",round(Vce,3),\"V, rpi:\",rpi,\"k ohms\"\n", + "print\"mid freq gain is\",round(Avo,2)\n", + "print\"low freq cut-off is\",round(w1p/1E+3),\"rad/s\"\n", + "print\"high cut-off freq is\",round((w21/1E+6),2),\"*10**6 rad/s\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)dc bias values are Vbb: 2.17 V, Ib: 0.0246 mA, Ic: 1.23 mA, Vce: 2.606 V, rpi: 1 k ohms\n", + "mid freq gain is -78.95\n", + "low freq cut-off is 179.0 rad/s\n", + "high cut-off freq is 2.25 *10**6 rad/s\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.10,Page number 243" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Qcoil=75. #coil inductance\n", + "f=200. #frequency(Hz) \n", + "BW=4. #bandwidth(kHz)\n", + "C=470*10**-9. #capacitance(pF) \n", + "\n", + "#Calculations\n", + "#Part a\n", + "Qcircuit=f/BW #circuit inductance\n", + "L=1/(((2*(math.pi)*f)**2)*C) #inductance(mH) \n", + "\n", + "#Part b\n", + "R=Qcircuit*2*(math.pi)*f*L #resistance(k ohms)\n", + "\n", + "#Part c\n", + "r=(2*(math.pi)*f*L)/Qcoil #internal resistance(ohms)\n", + "req=(Qcoil**2)*r #equivalent resistance(k ohms)\n", + "ro=(R*req)/(req-R) #output resistance(k ohms)\n", + "\n", + "#Part d\n", + "BW=5 #bandwidth(kHz)\n", + "Qcircuit=f/BW #circuit inductance \n", + "Req=Qcircuit*2*(math.pi)*f*L #equivalent resistance(k ohms) \n", + "Rl=(Req*R)/(R-Req) #load resistance(k ohms)\n", + "\n", + "#Results\n", + "print\"a)coil inductance is\",round(L,2),\"mH\"\n", + "print\"b)circuit output impedance atresonant freq is\",round((R/1E+3),2),\"K ohms\"\n", + "print\"c)internal resistance ro is\",round((ro/1E+3),2),\"k ohms\"\n", + "print\"d)value of load resistance is\",round((Rl/1E+3),2),\"k ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)coil inductance is 1.35 mH\n", + "b)circuit output impedance atresonant freq is 84.66 K ohms\n", + "c)internal resistance ro is 253.97 k ohms\n", + "d)value of load resistance is 338.63 k ohms\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.11,Page number 246" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "fo=50 #output frequency(KHz)\n", + "L=10**-3 #inductance(H) \n", + "ro=100 #output resistance(k ohms)\n", + "Q=80 #coil inductance\n", + "Ri=10 #input resistance(k ohms)\n", + "beta=125 #common emitter current gain \n", + "\n", + "#Calculations\n", + "#Part a\n", + "C =1/(((2*(math.pi)*fo)**2)*L) #tunning capacitance(nF)\n", + "r=(2*(math.pi)*fo*L)/Q #internal resistance(k ohms)\n", + "req=(Q**2)*r #equivalent resistance(k ohms) \n", + "R=(ro*req)/(ro+req) #ro||req(k ohms)\n", + "Avo=-(beta*R)/Ri #voltage gain\n", + "\n", + "#Part b\n", + "Qcircuit=R/(2*(math.pi)*fo*L) #circuit inductance\n", + "BW=fo/Qcircuit #bandwidth\n", + "\n", + "#Results\n", + "print\"a)value of capacitance is\",round(C/1E-3),\"nF\"\n", + "print\" gain is\",round(Avo,1)\n", + "print\"b)bandwidth is\",round(BW/1E-3),\"Hz\",\"(value used for beta in texbook is wrong in the solution)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)value of capacitance is 10.0 nF\n", + " gain is -251.1\n", + "b)bandwidth is 782.0 Hz (value used for beta in texbook is wrong in the solution)\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.12,Page number 248" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "\n", + "f=1*10**6 #radio frequency(Hz)\n", + "beta=50 #common emitter current gain \n", + "fT=5*10**6 #short circuit current gain bandwidth product(Hz)\n", + "\n", + "#Calculations\n", + "betaf=fT/f #measurement of short circuit current gain\n", + "fbeta=fT/beta #frequency at beta(Hz)\n", + "\n", + "#Results\n", + "print\"frequency is\",fbeta,\"Hz\"\n", + "if fbeta<1*10**6:\n", + " print\"transistor is not suitable for 1Mhz amplifier as fbeta is less than 1Mhz\"\n", + "else:\n", + " print\"transistor is suitable for 1Mhz amplifier\"\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "frequency is 100000 Hz\n", + "transistor is not suitable for 1Mhz amplifier as fbeta is less than 1Mhz\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.13,Page number 249" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "rpi=2 #dynamic junction resistance(K ohms) \n", + "beta=50. #common emitter current gain \n", + "f=1 #frequency(MHz)\n", + "beta1=2.5 #common emitter current gain \n", + "f1=20*10**6 #frequency(Hz)\n", + "\n", + "#Calculations\n", + "fT=beta1*f1 #short circuit current gain bandwidth product(Hz)\n", + "fbeta=fT/beta #frequency at beta(Hz)\n", + "Cpi=1/(2*(math.pi)*fbeta*rpi) #dynamic capacitance(pF)\n", + "\n", + "#Results\n", + "print\"fT is\",round(fT/1e+6),\"MHz\"\n", + "print\"fB is\",round(fbeta/1e+6),\"MHz\"\n", + "print\"Cpi is\",round(Cpi/1e-9),\"pF\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "fT is 50.0 MHz\n", + "fB is 1.0 MHz\n", + "Cpi is 80.0 pF\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.14,Page number 256" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "R1=60 #resistance(k ohms)\n", + "R2=140 #resistance(k ohms)\n", + "Rs=4 #source resistance(k ohms)\n", + "Re=3 #emitter resistance(k ohms)\n", + "Rc=4 #collector resistance(k ohms)\n", + "Vcc=10 #supply voltage to collector(V)\n", + "Vbe=0.7 #base to emitter voltage(V)\n", + "beta=100 #common emitter current gain \n", + "Avo=-30 #voltage gain \n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rb=(R1*R2)/(R1+R2) #R1||R2(k ohms)\n", + "Vth=(Vcc*R1)/(R1+R2) #thevinine's voltage(V)\n", + "Ib=(Vth-Vbe)/(Rb+(beta+1)*Re) #base current(uA)\n", + "Ic=Ib*beta #collector current(mA) \n", + "Vce=Vcc-(Rc*Ic)-((beta+1)*Ib*Re) #collector to emitter voltage(V)\n", + "\n", + "#Part b\n", + "rpi=((25*beta)/Ic)*10**-3 #dynamic junction resistance(k ohms)\n", + "r=(Rb*rpi)/(Rb+rpi) #resistance across Vs\n", + "Ib1=r/((Rs+r)*rpi) #base current(mA)\n", + "Rl=(-Rc*Avo)/(Avo+(beta*Ib1*Rc)) #load resistance(k ohms)\n", + "\n", + "#Results\n", + "print\"value of Ic and Vce are\",round(Ic,3),\"mA and\",round(Vce,2),\"V\"\n", + "print\"Rl is\",round(Rl,2),\"k ohms\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of Ic and Vce are 0.667 mA and 5.31 V\n", + "Rl is 6.21 k ohms\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.15,Page number 257" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "R1=25. #resistances(k ohms)\n", + "R2=100. #resistances(k ohms)\n", + "Re=2. #emitter resistance(k ohms) \n", + "Vcc=10. #supply voltage to collector\n", + "Vbe=0.7 #base to emitter voltage(V)\n", + "beta=100. #common emitter current gain\n", + "Avo=160 #voltage gain\n", + "Rs=1 #source resistance(k ohms)\n", + "Vs=1 #source voltage(V) \n", + "Rl=12.5 #load resistance(k ohms)\n", + "Rc1=20. #collector resistance(k ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rb=(R1*R2)/(R1+R2) #R1||R2\n", + "Vth=(Vcc*R1)/(R1+R2) #thevinines voltage(V)\n", + "Ib=(Vth-Vbe)/(Rb+(beta+1)*Re) #base current(uA)\n", + "Ic=Ib*beta #collector current(mA)\n", + "rpi=(25*beta)*10**-3/Ic #dynamic junction resistance(k ohms)\n", + "\n", + "#Part b\n", + "Ib1=1/rpi #small signal analysis \n", + "Rc=-Avo/(-beta*Ib1) #collector resistance() \n", + "\n", + "#Part c\n", + "r=(Rc1*rpi)/(Rc1+rpi) #Rc1||rpi1(k ohms) \n", + "Ib2=(Vs*r)/((1+r)*rpi) #base curret(mA)\n", + "Rc2=6.84 #collector resistance(k ohms) \n", + "Avo=-(beta*Ib2)*((Rl*Rc2)/(Rl+Rc2)) #voltage gain\n", + "\n", + "#Results\n", + "print\"value of Ic\",round(Ic,3),\"mA and rpi is\",round(rpi,2),\"k ohms\" \n", + "print\"Rc is\",round(Rc,2),\"k ohms\"\n", + "print\"Avo is\",round(Avo,1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of Ic 0.586 mA and rpi is 4.27 k ohms\n", + "Rc is 6.83 k ohms\n", + "Avo is -80.6\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.16,Page number 258" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "R1=12. #resistance(k ohms)\n", + "R2=100. #resistance(k ohms)\n", + "Rc=2 #collector resistance(k ohms)\n", + "Ic=1.2 #collector current(mA)\n", + "beta=60 #common emitter current gain\n", + "Ib1=1 #(say)\n", + "Rs=1 #source resistance(k ohms)\n", + "Vs=1 #source vcoltage(say)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "rpi=((25*beta)/Ic)*10**-3 #dynamic junction resistance(k ohms)\n", + "Rb=(R1*R2)/(R1+R2) #R1||R2(k ohms)\n", + "r=(Rb*rpi)/(Rb+rpi) #Rb||rpi(k ohms)\n", + "Ro1=(Rc*rpi)/(Rc+rpi) #Rc||rpi(k ohms)\n", + "Vo1=Vbe2=-(beta*Ib1*Ro1) #base to emitter voltage(V)\n", + "Ib2=Vo1/rpi #base current(mA)\n", + "Ai=Ib2/Ib1 #current gain \n", + "\n", + "#Part b\n", + "Ib11=(Rs*r)/((Rs+r)*rpi) #base currents(mA)\n", + "Ib21=Ib11*Ai #base current(mA)\n", + "Avo1=Vo1=Ib21*rpi #voltage gain\n", + "\n", + "#Results\n", + "print\"current gain is\",round(Ai,2)\n", + "print\"overall voltage gain is\",round(Avo1,2),\"(solution in the textbook is incorrect)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "current gain is -36.92\n", + "overall voltage gain is -19.5 (solution in the textbook is incorrect)\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.17,Page number 259" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "beeta=50. #common emitter current gain\n", + "R1=25. #resistance(k ohms)\n", + "R2=75. #resistance(k ohms)\n", + "Ic=1.25 #collector current(mA)\n", + "Vcc=10 #supply voltage to collector(V)\n", + "s=10*10**-3 #signal strength(V)\n", + "Rs=0.5 #output impedance(k ohms)\n", + "Vo=1 #output voltage(V)\n", + "Vs=1. #source voltage(V) \n", + "Vl=12 #load at output terminal(Vl)\n", + "Vbe=0.7 #base to emitter voltage(V)\n", + "Rl=12\n", + "\n", + "#Calculations\n", + "rpi=((25*beeta)/Ic) #dynamic junction resistance(k ohms)\n", + "Rb=(R1*R2)/(R1+R2) #R1||R2(k ohms)\n", + "r=(Rb*rpi*10**-3)/(Rb+rpi*10**-3) #Rb||rpi(k ohms)\n", + "Avo=((Vo*rpi)/Vcc) #voltage gain\n", + "Ib=(r*Vs)/(Rs+r)*Vs #base current(mA)\n", + "Rc=(Rl*Avo)/(beeta*Ib*Rl-Avo) #collector resistance(k ohms)\n", + "Vth=(Vcc*R1)/(R1+R2) #thevinine's voltage(V)\n", + "Ib1=Ic/beeta #base current(mA)\n", + "Re=(Vth-Vbe-(Rb*Ib1))/((beeta+1)*Ib1) #emitter resistance(k ohms) \n", + "\n", + "#Results\n", + "print\"value of Rc is\",round(Rc,2),\"and Re is\",round(Re,2),\"k ohms (Vth value is wrong substituted in the book)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of Rc is 4.1 and Re is 1.04 k ohms (Vth value is wrong substituted in the book)\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.18,Page number 260" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Cpi=20*10**-9 #opening capacitor(F)\n", + "Cu=5*10**-9 \n", + "C=50*10**-9 #here C=Cl+Cw\n", + "rpi=3.75*10**3 #dynamic drain resistance(ohms)\n", + "r1=4*10**3 #resistance(ohms)\n", + "r2=42*10**3 #resistance(ohms)\n", + "r3=303*10**3 #resistance(ohms)\n", + "f=20 #frequency(Hz)\n", + "beeta=100 #common emitter current gain\n", + "Rl=10*10**3 #load resistance(ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Req=(((r1*r2)/(r1+r2)+rpi)*r3)/(((r1*r2)/(r1+r2)+rpi)+r3) #equivalent resistance(ohms)\n", + "Ce=(beeta+1)/(2*(math.pi)*f*Req) #emitter capacitance(uF)\n", + "\n", + "#Part b\n", + "gm=beeta/rpi #transconductance\n", + "Ro=(Rl*r1)/(r1+Rl) #output resistance(k ohms)\n", + "Ceq=Cpi+(Cu*(1+gm*Ro)) #equivalent capacitance(pF)\n", + "Co=C+(Cu*(1+(1/(gm*Ro)))) #output capacitance(pF)\n", + "r=(rpi*r1)/(rpi+r1) #rpi||r1\n", + "w21=1/(Ceq*r) #lower cutoff frequency(MHz)\n", + "w22=1/(Co*Ro) #higher cutoff frequenct(MHz)\n", + "\n", + "#Part c\n", + "Ceqnew=Cpi+(Cu*(1+(0.75*(gm*Ro)))) #as gain is reduced to 75% of original value\n", + "wHnew=(10**12)/(Ceqnew*r) #corner value of high frequency(Mrad/s) \n", + "fHnew=wHnew/(2*(math.pi)) #new value of higher frequency cutoff(KHz)\n", + "\n", + "#Results\n", + "print\"a)value of bypass capacitor Ce is\",round(Ce/1E-6),\"uF\"\n", + "if w21>w22:\n", + " print\"higher frequency is w21\"\n", + "else:\n", + " print\"higher frequency is w22\"\n", + "\n", + "print\"b)high frequency cut-off is\",round((w22/1E+3),2),\"Mrad/s\"\n", + "print\"c)high frequency cut-off is\",fHnew,\"Hz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)value of bypass capacitor Ce is 111.0 uF\n", + "higher frequency is w22\n", + "b)high frequency cut-off is 6.36 Mrad/s\n", + "c)high frequency cut-off is 2.64660617737e+14 Hz\n" + ] + } + ], + "prompt_number": 36 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.19,Page number 262" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vcc=3. #supply voltage to collector(V)\n", + "Vee=-3. #supply voltage to emitter(V)\n", + "r1=40. #resistance(ohms) \n", + "r2=25. #resistance(ohms)\n", + "r3=1.56 #resistance(ohms)\n", + "Vs=3. #source voltage(V)\n", + "beeta=200 #common emitter current gain\n", + "r4=0.6 #resistance(ohms)\n", + "r5=0.15 #resistance(ohms)\n", + "Vbe=0.7 #base to emitter voltage\n", + "r=0.5 #resistance(k ohms)\n", + "fL=20 #frequency(Hz)\n", + "Req1=24.24 #solving r||(Rth+rpi+R)||Re\n", + "f=2 #non dominant cutoff freq is fL/10 i.e 20/10\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Vth=Vs-(((Vcc-Vee)/(r1+r2))*r1) #thevinine's voltage(V)\n", + "Rth=(r1*r2)/(r1+r2) #thevinine's voltage(V)\n", + "Ib=(Vth-Vbe+Vcc)/(Rth+((r4+r5)*(beeta+1))) #base current(mA)\n", + "Ic=Ib*beeta #Collector current(mA) \n", + "Vo=Vcc-(r3*Ic) #output voltage(V)\n", + "\n", + "#Part b\n", + "rpi=(25*beeta)/Ic #dynamic drain resistance(ohms)\n", + "R=r4*(beeta+1) #resistance(k ohms)\n", + "ro=(rpi*R)/(rpi+R) #rpi||R(k ohms)\n", + "Req=r+((Rth*ro)/(Rth+ro)) #equivalent resistance(k ohms) \n", + "Cc1=1/(Req*2*(math.pi)*fL) #coupling capacitor(uF)\n", + "\n", + "#Part c\n", + "Ce=1/(2*(math.pi)*fL*Req1) #emitter capacitance(uF)\n", + "CE=beeta*Ce #emitter capacitance(uF) after current gain\n", + "\n", + "#Part d\n", + "Ce1=1/(2*(math.pi)*f*Req1) #emitter capacitance(uF)\n", + "CE1=beeta*Ce1 #emitter capacitance(uF) after current gain\n", + "Csum=Cc1+CE1 #total capacitance(uF)\n", + "\n", + "#Results\n", + "print\"a)Ic and Vo are\",round(Ic,2),\"mA and\",round(Vo),\"V\"\n", + "print\"b)Cc1 is\",round((Cc1/1E-3),3),\"uF\"\n", + "print\"c)Ce is\",round((CE/1E-3),1),\"uF\"\n", + "print\"d)Csum is\",round((Csum/1E-2),3),\"uF\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)Ic and Vo are 1.94 mA and -0.0 V\n", + "b)Cc1 is 0.565 uF\n", + "c)Ce is 65.7 uF\n", + "d)Csum is 65.715 uF\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.21,Page number 265" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "gm=2 #transconductance\n", + "rd=200*10**3 #dynamic drain resistance(ohms)\n", + "Cgs=10 #gate to source capacitance(pF)\n", + "Cgd=0 #gate to drain capacitance(pF)\n", + "Rs=1*10**3 #source resistance(ohms)\n", + "Rg=1*10**6 #Rg=R1||R2\n", + "Rd=5*10**3 #drain resistance(ohms) \n", + "Rs1=2 #resistance(k ohms) \n", + "Cc1=Cc2=0.1*10**-6 #coupling capacitors(F)\n", + "Co=10*10**-12 #output capacitance(F)\n", + "Vgs=1 #gate to source voltage(V)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "R=(Rd*rd)/(Rd+rd) #Rd||rd(k ohms)\n", + "Avo=Vo=-Vgs*gm*R #voltage gain\n", + "\n", + "#Part b\n", + "w11=1/(Cc1*(Rs*Rg)) #corner freq(rad/s)\n", + "wL=w11 #input circuit corner freq(rad/s)\n", + "\n", + "#Part c\n", + "w22=10**12/((Cgs*R)*10**3) #output circuit corner frequency(rad/s)\n", + "wH=w22/(2*math.pi) \n", + "\n", + "#Part d\n", + "G=-Avo*wH #gain bandwidth product\n", + "\n", + "#Part e\n", + "Rd=4*10**3 #drain resistance reduced(ohms) \n", + "Rnew=(Rd*rd)/(Rd+rd) #new resistance(ohms)\n", + "Avo1=-Vgs*gm*Rnew #new voltage gain\n", + "BWnew=(10**8/Rnew)/(2*math.pi) #new bandwidth(Mrad/s)\n", + "Gnew=-Avo1*BWnew #gain bandwidth product new\n", + "\n", + "#Results\n", + "print\"a)Avo is\",round((Avo/1E+3),2)\n", + "print\"b)wL is\",round((wL/1E-3),2),\"rad/s\"\n", + "print\"c)wH is\",round((wH/1E+3),1),\"MHz\"\n", + "print\"d)G is\",round((G/1E+6),2),\"MHz\"\n", + "print\"e)Gnew is\",round((Gnew/1E+6),1),\"MHz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)Avo is -9.76\n", + "b)wL is 10.0 rad/s\n", + "c)wH is 3.3 MHz\n", + "d)G is 31.83 MHz\n", + "e)Gnew is 31.8 MHz\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.23,Page number 268" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "gm=1 #transconductance\n", + "rd=40 #dynamic drain resistance(k ohms) \n", + "Cgs=5 #gate to source capacitance(pF)\n", + "Cgd=1 #gate to drain capacitance(pF)\n", + "Cds=1 #drain to source capacitance(pF)\n", + "Avo1=20. #voltage gain of JFET 1\n", + "Avo2=8. #voltage gain of JFET 2 \n", + "R1=5 #resistance(k ohms)\n", + "R2=20 #resistance(k ohms)\n", + "R3=8 #resistance(k ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Avo=Avo1*Avo2 #voltage gain\n", + "Ceq1=Cgs+Cgd*(1+Avo1) #input crcuit for first JFET\n", + "Co1=Cds+(Cgd*(1+(1/Avo1))) #output crcuit for first JFET\n", + "Ceq2=Cgs+Cgd*(1+Avo2) #input crcuit for second JFET\n", + "Co2=Cds+(Cgd*(1+(1/Avo2))) #output crcuit for second JFET\n", + "\n", + "#Part b\n", + "w21=1/(R1*Ceq1) #input circuit frequency\n", + "w2=10**12/(R2*10**3*(Co1+Ceq2)) #common circuit frequency\n", + "w22=1/(R3*Co2) #output circuit frequency\n", + "\n", + "\n", + "#Results\n", + "print\"a)Avo is\",Avo\n", + "print\"b)w21,w2,w22 are\",round((w21/1E-3),2),\"Mrad/sec,\",round((w2/1E+6),2),\"Mrad/sec and\",round((w22/1E-3),2),\"Mrad/sec\"\n", + "print\"nondominant corner freq is\",round((w2/1E+6),2),\"Mrad/sec\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)Avo is 160.0\n", + "b)w21,w2,w22 are 7.69 Mrad/sec, 3.12 Mrad/sec and 58.82 Mrad/sec\n", + "nondominant corner freq is 3.12 Mrad/sec\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter5.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter5.ipynb new file mode 100755 index 00000000..437b0a36 --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter5.ipynb @@ -0,0 +1,653 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:9eef90d3b867f35b7e7b7ae71f5d96e96e47a495dc677c7492d34992d7905497" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5:Large Signals Amplifiers" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.1,Page number 280" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Rb=1*10**3 #base resistance(ohms)\n", + "Vcc=20 #supply voltage(V)\n", + "Rc=20 #collector resistance(ohms) \n", + "beeta=25 #current gain \n", + "Vbe=0.7 #base to emitter voltage(V) \n", + "ib=10*10**-3 #base current(ohms)\n", + "\n", + "#Calculations\n", + "Ibq=(Vcc-Vbe)/Rb #current(A)\n", + "Icq=beeta*Ibq #current(A)\n", + "Vceq=Vcc-(Icq*Rc) #collector voltage(V)\n", + "ic=beeta*ib #collector current(A)\n", + "Po=((ic/(math.sqrt(2)))**2)*Rc #output voltage(V)\n", + "Pi=Vcc*Icq #input power(W)\n", + "eta=(Po/Pi)*100 #efficiency \n", + "Pd=Pi-((Icq**2)*Rc)-Po #power dissipated(W) \n", + "\n", + "#Results\n", + "print\"input power is Pi\",Pi,\"W\"\n", + "print\"output power is Po\",Po,\"W\"\n", + "print\"power dissipated is\",round(Pd,1),\"W\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "input power is Pi 9.65 W\n", + "output power is Po 0.625 W\n", + "power dissipated is 4.4 W\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.2,Page number 283" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration \n", + "Rl=500 #load resistance(ohms)\n", + "Vceq=50 #queinscent collector voltage(V)\n", + "beetamin=30 #current gain minimum(at Q)\n", + "Icq=0.4 #queinscent collector current(A)\n", + "Ibq=8 #queinscent base current(mA)\n", + "\n", + "#Calculations\n", + "Rac=Vceq/Icq #ac resistance(ohms)\n", + "beeta=(Icq*10**-3)/Ibq #current gain\n", + "Re=5/Icq #emitter resistance(ohms)\n", + "Rc=(512.5*Rac)/(512.5-Rac) #as Re+Rl=500+12.5=512.5\n", + "Vcc=5+Vceq+(Icq*Rc) #supply voltage(V) \n", + "Rb=(beetamin*Re)/10 #base resistance(ohms)\n", + "R1=39.5 #solving 125=Rc||(Rl+Re) and Vbb=Vcc*(R1/(R1+R2))\n", + "R2=750\n", + "Pi=120*Icq #Vcc chosen as 120\n", + "r=(Rc*Rl)/(Rc+Rl)\n", + "Poac=(100/(2*math.sqrt(2)))**2/r #output power(W)\n", + "etamax=Poac/Pi #efficiency\n", + "Poac1=(100/(2*math.sqrt(2)))**2/Rl #ac power absorbed by load(W)\n", + "eta=Poac1/Pi \n", + "Pc=(Icq**2)*Rc #power lost in Rc(W)\n", + "Pe=(Icq**2)*Re #power lost in Re(W)\n", + "Pd=Pi-Pc-Pe-Poac #power consumed(W)\n", + "\n", + "#Results\n", + "print\"input power is Pi\",Pi,\"W\"\n", + "print\"output power is Po\",round(Poac,2),\"W\"\n", + "print\"dissipated power is\",round(Pd,2),\"W\"\n", + "print\"values of R1,R2,Re and Rc are\",R1,\"ohms,\",R2,\"ohms,\",Re,\"ohms and\",round(Rc),\"ohms resp. (Calculated value of Rc is wrong in the book)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "input power is Pi 48.0 W\n", + "output power is Po 10.06 W\n", + "dissipated power is 9.49 W\n", + "values of R1,R2,Re and Rc are 39.5 ohms, 750 ohms, 12.5 ohms and 165.0 ohms resp. (Calculated value of Rc is wrong in the book)\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.3,Page number 285" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Pmax=10 #power maximum(W)\n", + "Ic=1 #collector current(A)\n", + "Vcemax=100 #max collector to emitter current(V)\n", + "Vcemin=2 #min collector to emitter current(V)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Vceq=46 #Vce at Q point \n", + "Icq=0.21 #Ic at Q point \n", + "Vcc=92 #supply voltage(V)\n", + "ic=0.42 #collector current(A) \n", + "\n", + "#Part b\n", + "Rl=Vceq/Icq #load resistance(ohms)\n", + "\n", + "#Part c\n", + "Pi=Vcc*Icq #input power(W)\n", + "Po=((ic/(2*math.sqrt(2)))**2)*Rl #output power(W)\n", + "eta=(Po/Pi)*100 #efficiency\n", + "\n", + "#Results\n", + "print\"Rl for maximum power input is\",round(Rl),\"ohms\"\n", + "print\"input power is is\",Pi,\"W\"\n", + "print\"Po is\",Po\n", + "print\"eta is\",eta,\"%\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Rl for maximum power input is 219.0 ohms\n", + "input power is is 19.32 W\n", + "Po is 4.83\n", + "eta is 25.0 %\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.4,Page number 286" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vcc=15 #supply voltage(V)\n", + "beeta=40. #current gain\n", + "Icq=5. #Ic at Q(mA)\n", + "Vceq=7.5 #Vce at Q(V) \n", + "icswing=10 #swing in ic(mA) \n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rl=Vceq/Icq*10**-3 #load resistance(ohms) \n", + "\n", + "#Part b\n", + "Ibq=Icq/beeta #base current at Q(uA)\n", + "\n", + "#Part c\n", + "ibswing=icswing/beeta #swing in ib(mA)\n", + "Pac=Rl*(icswing/(2*math.sqrt(2)))**2 #ac power(W)\n", + "Pdc=Vcc*(Icq*10**-3) #dc power(W)\n", + "eta=(Pac/Pdc)*100 #efficiency\n", + "\n", + "#Results\n", + "print\"a)value of Rl is\",round(Rl/1E-6),\"ohms\"\n", + "print\"b)Ibq is\",round(Ibq/1E-3),\"uA\"\n", + "print\"c)ac power output is\",round((Pac/1E-3),2),\"mW\"\n", + "print\"efficiency is\",eta,\"%\"\n", + "print\"corresponding swing in ib is\",ibswing,\"mA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)value of Rl is 1500.0 ohms\n", + "b)Ibq is 125.0 uA\n", + "c)ac power output is 18.75 mW\n", + "efficiency is 25.0 %\n", + "corresponding swing in ib is 0.25 mA\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.5,Page number 288" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vcc=Vce=10 #supply voltage(V) \n", + "Icq=140*10**-3 #Ic at Q point(A)\n", + "Rl=8 #load resistance(ohms)\n", + "vce=16 #instantaneous collector to emitter voltage(V)\n", + "ic=235*10**-3 #instantaneous collector current(A)\n", + "\n", + "#Calculations\n", + "RL=Vcc/Icq\n", + "r=math.sqrt(RL/Rl) #load resistance for max ac swing(ohms)\n", + "Po=(vce*ic)/(2*math.sqrt(2)*2*math.sqrt(2)) #output power(W)\n", + "Pi=Vcc*Icq #input power(W) \n", + "eta=Po/Pi #efficiency\n", + "Pd=Pi-Po #dissipated power(W) \n", + "\n", + "#Results\n", + "print\"a)transformation ratio is\",round(r)\n", + "print\"c)power output is\",Po,\"W\"\n", + "print\"efficiency is\",round(eta*100,2),\"%\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)transformation ratio is 3.0\n", + "c)power output is 0.47 W\n", + "efficiency is 33.57 %\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.6,Page number 290" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Rl=4.5 #load resistance(ohms)\n", + "Vceq=50 #Vc at point Q(V)\n", + "Icq=400*10**-3 #Ic at Q(A)\n", + "Re=12.5 #emitter resistance(ohms)\n", + "Vcemax=90 #from figure \n", + "Vcemin=10 #from figure\n", + "Icmax=730 #max Ic(mA)\n", + "Icmin=30 #min Ic(mA) \n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rac=Vceq/Icq #ac resistance(ohms)\n", + "n=math.sqrt(Rac/Rl) #as n=N1/N2 and Rac=(N1/N2)^2*Rl\n", + "\n", + "#Part b\n", + "Vcc=Vceq+(Icq*Re) #supply voltage(V) \n", + "\n", + "#Part c\n", + "vce=Vcemax-Vcemin #instantaneous collector to emitter voltage(V)\n", + "ic=Icmax-Icmin #instantaneous collector current(mA)\n", + "Po=(vce*ic)/((2*math.sqrt(2))*(2*math.sqrt(2))) #output voltage(V)\n", + "Pi=Vcc*Icq #input voltage(V) \n", + "eta=(Po/Pi)*100 #efficiency\n", + "Pd=Pi-(Icq**2*Re)-Po*10**-3 #dissipated power(W)\n", + "\n", + "#Results\n", + "print\"a)transformation ratio is\",round(n,2)\n", + "print\"b)Vcc is\",Vcc,\"V\"\n", + "print\"c)power efficiency for the load is\",round((eta/1E+3),1),\"%\"\n", + "print\"power dissipated is\",Pd,\"W\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)transformation ratio is 5.27\n", + "b)Vcc is 55.0 V\n", + "c)power efficiency for the load is 31.8 %\n", + "power dissipated is 13.0 W\n" + ] + } + ], + "prompt_number": 36 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.7,Page number 295" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Finding input power,output power,Pd,efficiency,\n", + "\n", + "import math\n", + "\n", + "#Variable declaration\n", + "Vcc=30 #supply voltage(V)\n", + "Rl=16 #load resistance(ohms) \n", + "n=2 #transformation ratio\n", + "Im=1 #peak value of current(A)\n", + "etamax=78.54 #max efficiency(%)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rl1=Rl*(n/2)**2 #load resistance(ohms)\n", + "Pi=(2*Vcc*Im)/math.pi #input power(W)\n", + "Pimax=(2*Vcc**2)/((math.pi)*Rl1) #input power max(W)\n", + "\n", + "#Part b\n", + "Po=((Im**2)*Rl1)/2 #output power(W)\n", + "Pomax=(Vcc**2)/(2*Rl1) #output power max(W)\n", + "\n", + "#Part c\n", + "eta=Po/Pi #efficiency\n", + " \n", + "\n", + "#Part d\n", + "P=((2*Vcc*Im)/math.pi)-((Im**2*Rl1)/2) #Power dissipated by transistors(W)\n", + "Pd=P/2 #power dissipated by each transistors\n", + "Pmax=(2*Vcc**2)/((math.pi)**2*Rl1) #max power dissipated by transistors\n", + "Pdmax=Pmax/2 #max power dissipated by each transistor\n", + "\n", + "#Results\n", + "print\"a)input power is\",round(Pi,1),\"W and max input power is\",round(Pimax,2),\"W\"\n", + "print\"b)output power \",Po,\"W and max output power is\",round(Pomax,2),\"W\"\n", + "print\"c)power efficiency for the load is\",round((eta/1E-2),2),\"% and its max value is\",etamax,\"%\"\n", + "print\"power dissipated by each transiator is\",round(Pd,1),\"W and max value is\",round(Pdmax,1),\"W\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)input power is 19.1 W and max input power is 35.81 W\n", + "b)output power 8 W and max output power is 28.0 W\n", + "c)power efficiency for the load is 41.89 % and its max value is 78.54 %\n", + "power dissipated by each transiator is 5.5 W and max value is 5.7 W\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.8,Page number 296" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#Variable declaration\n", + "Pd=10\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Poacmax=10. #as Pd=Po(ac)max by class A\n", + "\n", + "#Part b\n", + "Pd=2*Poacmax #power dissipated(W)\n", + "Poacmax1=146/2 #max output power by class B\n", + "f=Poacmax1/Poacmax #factor by which power of class B is greater than class A\n", + " \n", + "#Results\n", + "print\"maximum signal output powerclass A produce is\",Poacmax,\"W\"\n", + "print\"maximum signal output powerclass produce is\",Poacmax1,\"W\"\n", + "print\"factor by which power in class b is larger than power in class A transformer is\",f" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "maximum signal output powerclass A produce is 10.0 W\n", + "maximum signal output powerclass produce is 73 W\n", + "factor by which power in class b is larger than power in class A transformer is 7.3\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.9,Page number 300" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vcc=30. #supply voltage(V)\n", + "Im=1 #peak value of current(A)\n", + "Rl=10. #load resistance(ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Pi=(Vcc*Im)/math.pi #input power(W)\n", + "Pimax=(Vcc**2)/(math.pi*2*Rl) #max input power(W)\n", + "\n", + "#Part b\n", + "Po=((Im**2)*Rl)/2 #output power(W)\n", + "Pomax=(Vcc**2)/(8*Rl) #output power max(W)\n", + "\n", + "#Part c\n", + "eta=Po/Pi #efficiency\n", + "etamax=Pomax/Pimax #efficiency max \n", + "\n", + "#Part d\n", + "Pd=Pi-Po #Power dissipated by transistors(W) \n", + "Pmax=(Vcc**2)/(2*(math.pi)**2*Rl) #max power dissipated by transistors\n", + " \n", + "#Results\n", + "print\"a)input power is \",round(Pi,2),\"W and max input power is\",round(Pimax,2),\"W\"\n", + "print\"b)output power is \",Po,\"W and max output power is\",round(Pomax,2),\"W\"\n", + "print\"c)power efficiency for the load is\",round((eta/1E-2),2),\"% and its max value is\",round((etamax/1E-2),2),\"%\"\n", + "print\"power dissipated and its max value are\",round(Pd,2),\"W and\",round(Pmax,2),\"W\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)input power is 9.55 W and max input power is 14.32 W\n", + "b)output power is 5.0 W and max output power is 11.25 W\n", + "c)power efficiency for the load is 52.36 % and its max value is 78.54 %\n", + "power dissipated and its max value are 4.55 W and 4.56 W\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.10,Page number 303" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "P1=2 #transistor power(W)\n", + "Rl=5*10**3. #load resistance()\n", + "Ic=35 #collector current(mA) \n", + "\n", + "#Calculations\n", + "Bo=40-Ic \n", + "B1=math.sqrt((2*P1)/Rl)\n", + "B2=Bo\n", + "D2=(B2/B1)*100 #second harmonic distortion(%)\n", + "\n", + "#Results\n", + "print\"second harmonic distortion is\",round((D2/1E+3),2),\"%\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "second harmonic distortion is 17.68 %\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.12,Page number 314" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "Vcc=15. #supply voltage(V)\n", + "Rl=10. #load resistance(ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Immax=Vcc/Rl #max peak current(A)\n", + "Irmsmax=Immax/(math.sqrt(2)) #max rms current(A)\n", + "Pomax=Irmsmax**2*Rl #max output power(W)\n", + "Pi=(2*Vcc*Immax)/math.pi #max input power(W)\n", + "eta=Pomax/Pi #efficiency\n", + "\n", + "#Part b \n", + "Im=(2*Vcc)/(math.pi*Rl) #peak current(A)\n", + "Pdmax=((2*Vcc*Im)/(math.pi))-((Im**2*Rl)/2) #max power dissipated(W)\n", + "eta1=((Im**2)*Rl*math.pi)/(2*2*Vcc*Im) #efficiency\n", + "\n", + "#Results\n", + "print\"a)max signal output power,collector dissipation are\",Pomax,\"W,\",round(Pi,2),\"W and efficiency is\",round((eta/1E-2),2),\"%\"\n", + "print\"b)max dissipation of each transistor and corresponding efficiency is\",round(Pdmax,2),\"W and\",eta1,\"resp.\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)max signal output power,collector dissipation are 11.25 W, 14.32 W and efficiency is 78.54 %\n", + "b)max dissipation of each transistor and corresponding efficiency is 4.56 W and 0.5 resp.\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.13,Page number 315" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Calculations\n", + "eta=0.5 #As Po(ac)=Vcc^2/2*pi^2*Rl and Pi(dc)=Vcc^2/pi^2*Rl\n", + " #put these in eta=Po(ac)/Pi(dc) which is 1/2=0.5 \n", + " \n", + "#Results\n", + "print\"push pull amplifier efficiency is\",round(eta/1E-2),\"%\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "push pull amplifier efficiency is 50.0 %\n" + ] + } + ], + "prompt_number": 27 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter6.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter6.ipynb new file mode 100755 index 00000000..721c027d --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter6.ipynb @@ -0,0 +1,545 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:b6947316bc65682adaa8d93a4eda990ab9271382dd0514c03ae855d300a77db0" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 6: Feedback Amplifiers And Oscillators" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.1,Page number 331" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vo=12. #output voltage(V)\n", + "f=1.5*10**3 #frequency(Hz)\n", + "h=0.25 #second harmonic content(%) \n", + "ho=2.5 #reduced harmonic content of output(%)\n", + "A=100 #power amplifier gain\n", + "\n", + "#Calculations\n", + "Vd=Vo*h #second harmonic content in output(V)\n", + "Vd1=Vo*ho #reduced value of second harmonic content(V)\n", + "beta=((Vd1/Vd)-1)/A #feedback gain from formula Vd1=Vd/(1+beta*A) \n", + "Vs=Vo*(1+beta*A)/A #signal voltage(V) from formula (A/(1+Beta*A))*Vs \n", + "V=Vo/A #signal input needed without feedback \n", + "s=Vs/V #additional signal amplification needed before feedback amplifier\n", + "\n", + "#Results\n", + "print\"feedback gain is\",beta\n", + "print\"signal input to the overall system is\",s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "feedback gain is 0.09\n", + "signal input to the overall system is 10.0\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.2,Page number 332" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "w2=10**4. #corner frequency(rad/s) \n", + "w2new=10**5. #new corner frequency(rad/s) \n", + "Ao=1000. #high frquency response \n", + "\n", + "#Calculations\n", + "beta=((w2new/w2)-1)/Ao #feedback factor\n", + "Anew=Ao/(1+beta*Ao) #overall gain of amplifier from formula w2new=w2(1+beta*Ao)\n", + "p=w2*Ao #gain bandwidth product without feedback from formula Anew=Ao/1+beta*Ao\n", + "pnew=Anew*w2new #gain bandwidth product with feedback\n", + "\n", + "#Results\n", + "print\"beta is\",beta\n", + "print\"overall gain is\",Anew\n", + "print\"gain-bandwidth products with and without feedback are\",p,\"and\",pnew,\"resp.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "beta is 0.009\n", + "overall gain is 100.0\n", + "gain-bandwidth products with and without feedback are 10000000.0 and 10000000.0 resp.\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.3,Page number 333" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "A=100. #high frquency response \n", + "Af=100 #gain \n", + "A1=A**2 #forward gain\n", + "A1new=50 #gain reduces to 50% \n", + "\n", + "#Calculations\n", + "beta=((A1/Af)-1)/A1 #feedback factor\n", + "Afnew=A1new**2/(1+beta*A1new**2) #new value of A\n", + "g=Af-Afnew #reduction in overall gain\n", + "\n", + "#Results\n", + "print\"% change in gain of feedback unit is\",round(g,2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "% change in gain of feedback unit is 2.91\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.4,Page number 337" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "beta=0.008 #positive gain \n", + "\n", + "#Calculations\n", + "Ao=-(8/beta)**(1/3) #A=Ao/2,so beta(A^3)=-1\n", + "\n", + "#Results\n", + "print\"% change in gain of feedback unit is\",round(Ao/1E-1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "% change in gain of feedback unit is -10.0\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.5Page number 337" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import cmath\n", + "from math import pi,degrees\n", + "\n", + "#Variable declarations\n", + "A = complex(0,60) #amplifier\n", + "B = complex(0,30) #amplifier\n", + "AB = A*B\n", + "C = (1+A)/AB #condition for oscillation\n", + "phi = cmath.phase(C) #phase\n", + "\n", + "#Result\n", + "print \"C =\",round(abs(C),4),\"with phase =\",round(degrees(phi),2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "C = 0.0333 with phase = -90.95\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.7,Page number 347" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Rbb=8*10**3 #base resistance(k ohms)\n", + "eta=0.7 #efficiency\n", + "R1=0.2 #R1(k ohms)\n", + "Rt=40*10**3 #Rt(ohms)\n", + "Ct=0.12*10**-6 #capacitance(F)\n", + "Vv=2 #capacitor is charged to voltage(V)\n", + "Iv=10*10**-3 #current to capacitor(A)\n", + "Ip=10*10**-3 #peak current(A)\n", + "Vd=0.7 #diode voltage(V)\n", + "V=12. #voltage(V)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Rb1=eta*Rbb #base resistance(ohms) \n", + "Rb2=Rbb-Rb1 #base resistance(ohms)\n", + "\n", + "#Part b\n", + "Vp=Vd+((Rb1+R1)*V/(Rbb+R1)) #peak voltage(V)\n", + "\n", + "#Part c\n", + "Rtmin=(V-Vv)/Iv #Rt minimum(k ohms) \n", + "Rtmax=(V-Vp)/Ip #Rt minimum(k ohms) \n", + "\n", + "#Part d\n", + "Rb11=.12 #resistance during discharge(ohms)\n", + "t1=Rt*Ct*1.27 #charging time(mS)\n", + "t2=(Rb11+R1)*Ct*1.52 #discharging time(uS)\n", + "T=t1+t2 #cycle time\n", + "foscE=1/T #oscillations frequency(Hz)\n", + "foscA=1/(Rt*Ct*1.2) #oscillations frequency(Hz)\n", + "\n", + "#Part e\n", + "vR1=(R1*V)/(R1+Rbb) #vR1 at discharging period\n", + "vR1d=(R1*(Vp-Vd))/(R1+Rb11) #vR1 at discharging period\n", + "\n", + "#Results\n", + "print\"Rb1 and Rb2 are\",round((Rb1/1E+3),1),\"k ohms and\",round((Rb2/1E+3),1),\"k ohms resp.\"\n", + "print\"Vp is\",round(Vp,1),\"V\"\n", + "print\"Rtmin is\",round(Rtmin/1E+3),\",k ohms and Rtmax is\",round(Rtmax/1E+1),\"k ohms,hence Rt is in the range\"\n", + "print\"foscE is\",round(foscE),\"Hz and foscA is\",round(foscA),\"Hz\"\n", + "print\"vR1 is\",round((vR1/1E-3),3),\"and vRd1 is\",round(vR1d,2),\"V (range of Rt is wrong in the book)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Rb1 and Rb2 are 5.6 k ohms and 2.4 k ohms resp.\n", + "Vp is 9.1 V\n", + "Rtmin is 1.0 ,k ohms and Rtmax is 29.0 k ohms,hence Rt is in the range\n", + "foscE is 164.0 Hz and foscA is 174.0 Hz\n", + "vR1 is 0.3 and vRd1 is 5.25 V (range of Rt is wrong in the book)\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.8,Page number 350" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "A=1500 #voltage gain\n", + "beta=1/25. #current gain \n", + "\n", + "#Calculations\n", + "#Part a\n", + "Af=A/(1+A*beta) #voltage gain with feedback\n", + "\n", + "#Part b\n", + "g=0.1 #amplifier gain changes by 10%=0.1\n", + "gf=g/(1+A*beta) #% by which its gain in feedback mode changes dAf/Af\n", + "\n", + "#Results\n", + "print\"Amplifier gain with feedback is\",round(Af,1)\n", + "print\"% by which gain in feedback changes is\",round((gf/1E-2),3),\"%\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amplifier gain with feedback is 24.6\n", + "% by which gain in feedback changes is 0.164 %\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.9,Page number 351" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "A=500 #voltage gain\n", + "beta=1/20. #current gain\n", + "Ro=50*10**3 #output resistance(ohms) \n", + "Ri=1.5*10**3 #input resistance(ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "Af=A/(1+A*beta) #voltage gain with feedback \n", + "\n", + "#Part b\n", + "Rif=Ri*(1+(A*beta)) #input resistance(k ohms)\n", + "Rof=Ro/(1+A*beta) #output resistance(k ohms)\n", + "\n", + "#Results\n", + "print\"Amplifier gain is\",round(Af,2)\n", + "print\"input resistance is\",round(Rif/1E+3),\"K ohms and output resistance is\",round((Rof/1E+2),2),\"Kohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amplifier gain is 19.23\n", + "input resistance is 39.0 K ohms and output resistance is 19.23 Kohms\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.10,Page number 351" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Ro=50*10**3 #output resistance(ohms)\n", + "Rd=10*10**3 #drain resistance(ohms)\n", + "R1=800*10**3 #resistance(ohms)\n", + "R2=200*10**3 #resistance(ohms)\n", + "gm=5500*10**-6 #transconduuctance(us)\n", + "\n", + "#Calculations\n", + "r=(Rd*Ro)/(Rd+Ro) #Rd||Ro\n", + "R=R1+R2 #combined resistance of R1 and R2\n", + "Rl=(R*r)/(R+r) #load resistance(ohms)\n", + "A=-gm*Rl #voltage gain without feedback\n", + "beta=R2/(R1+R2) #current gain \n", + "Af=A/(1+A*beta) #voltage gain with feedback\n", + "\n", + "#Results\n", + "print\"Amplifier gain with feedback is\",round((Af/1E+1),1),\"and without feedback is\",A" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amplifier gain with feedback is -4.5 and without feedback is -45.452\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.11,Page number 352" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Re=1.25*10**3 #emitter resistance(ohms)\n", + "Rc=4.8*10**3 #collector resistance(ohms)\n", + "Rb=800*10**3 #base resistance(ohms) \n", + "rpi=900 #dynamic resistance(ohms)\n", + "Vcc=16 #supply voltage(V)\n", + "beta=100. #current gain \n", + "\n", + "#Calculations\n", + "A=-(beta/rpi) #amplifier voltage gain \n", + "B=-Re \n", + "V=(A*Rc)/(1+B*A) #V=Vo/Vs\n", + " \n", + "#Results\n", + "print\"Amplifier voltage gain is\",round(V,1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Amplifier voltage gain is -3.8\n" + ] + } + ], + "prompt_number": 58 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.12,Page number 352" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " import math\n", + "\n", + "#Variable declaration\n", + "C1=800*10**-9 #capacitance(F)\n", + "C2=2400*10**-9 #capacitance(F)\n", + "L=50*10**-6 #inductance(H)\n", + "\n", + "#Calculations\n", + "Ceq=(C1*C2)/(C1+C2) #equivalent capacitance(F)\n", + "fo=1/(2*math.pi*math.sqrt(L*Ceq)) #output frequency(Hz)\n", + "\n", + "#Results\n", + "print\"the oscillation frequency is\",round((fo/1E+3),2),\"KHz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the oscillation frequency is 29.06 KHz\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.13,Page number 353" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "C=200*10**-9 #capacitance(F)\n", + "Lrcf=0.5*10**-3 #shunt across L2\n", + "L1=800*10**-6 #inductance(H)\n", + "L2=800*10**-6 #inductance(H)\n", + "M=200*10**-6 \n", + "\n", + "#Calculations\n", + "L21=(L2*Lrcf)/(L2+Lrcf) #effective value of L2(uH)\n", + "Leq=L1+L21+2*M #equivalent inductance(H)\n", + "fo=1/(2*math.pi*math.sqrt(Leq*C)) #output frequency(Hz)\n", + "\n", + "#Results\n", + "print\"the oscillation frequency is\",round((fo/1E+3),2),\"KHz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the oscillation frequency is 9.17 KHz\n" + ] + } + ], + "prompt_number": 13 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter7.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter7.ipynb new file mode 100755 index 00000000..f37b3943 --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter7.ipynb @@ -0,0 +1,645 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:4a9283ba6472e11de214bfc0c69a7f007685d94fb7b513179011a2e471e81b7b" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 7:Operational Amplifiers" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.1,Page number 361" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "V1=120 #negative terminal Vn(uV)\n", + "V2=80 #positive terminal Vp(uV)\n", + "Ad=10**3 #difference mode gain\n", + "\n", + "\n", + "#Calculations\n", + "Vd=V1-V2 #difference mode signal(uV) \n", + "Vc=(V1+V2)/2 #common mode signal(uV)\n", + "\n", + "#Part a\n", + "CMRR=100. #common mode rejection ratio\n", + "Vo=Ad*Vd*(1+(Vc/(CMRR*Vd))) #output voltage(mV)\n", + " \n", + "#Part b\n", + "CMRR=10**5. #common mode rejection ratio\n", + "Vo1=Ad*Vd*(1+(1/CMRR)*(Vc/Vd)) #output voltage(mV) \n", + "\n", + "#Results\n", + "print\"output voltage is\",round(Vo/1E+3),\"mV\"\n", + "print\"output voltage is\",round(Vo1/1E+3),\"mV\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "output voltage is 41.0 mV\n", + "output voltage is 40.0 mV\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.2,Page number 365" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "deltavi=0.5 #change in vi(V)\n", + "deltat=10 #change in time(us)\n", + "s=1 #slew rate(V/us)\n", + "\n", + "#Calculations\n", + "Kvf=(s*deltat)/deltavi #closed loop gain of amplifier\n", + "\n", + "#Results\n", + "print\"closed loop gain of amplifier is\",Kvf" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "closed loop gain of amplifier is 20.0\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.3,Page number 365" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "f=50*10**3. #OPAMP freequency(Hz)\n", + "Vm=0.02 #maximum value of signal voltage(V)\n", + "S=.5*10**6 #slew rate(V/s)\n", + "\n", + "#Calculations\n", + "Kvf=S/(2*(math.pi)*f*Vm) #closed loop gain of amplifier\n", + "\n", + "#Results\n", + "print\"closed loop gain of amplifier is\",round(Kvf)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "closed loop gain of amplifier is 80.0\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.4,Page number 369" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Ic=100 #current at quinscent point(uA)\n", + "beta=2000. #current gain\n", + "Ad=250 #difference mode gain\n", + "CMRR=5000 #as 74 dB=5000,common mode rejection ratio(dB)\n", + "\n", + "#Calculations\n", + "rpi=(25*beta)/Ic #dynamic internal resistance(k ohms) \n", + "gm=beta/rpi #transconductance(mS)\n", + "Re=CMRR/gm #emitter resistance(k ohms)\n", + "Rc=(Ad*2)/gm #collector resistance(k ohms) from formula Ad=gmRc/2\n", + "Rin=2*rpi #input resistance(k ohms)\n", + "\n", + "#Results\n", + "print\"Re is\",Re,\"k ohms\"\n", + "print\"Rc is\",Rc,\"k ohms\"\n", + "print\"input resistance is\",Rin,\"k ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Re is 1250.0 k ohms\n", + "Rc is 125.0 k ohms\n", + "input resistance is 1000.0 k ohms\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.6,Page number 371" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Icq=.428 #current at quinscent point(uA)\n", + "beta=200. #current gain\n", + " #as 74 dB=5000,common mode rejection ratio(dB)\n", + "Rc=10. #collector resistance(k ohms) \n", + "Re=16. #emitter resistance(k ohms) \n", + "Vcc=15. #supply voltage(V)\n", + "\n", + "#Calculations\n", + "#Part b\n", + "Ibq=Icq/beta #Ib at Q(uA)\n", + "rpi=(25*beta)/Icq #dynamic resistance(k ohms)\n", + "gm=beta/rpi #transconductance\n", + "\n", + "#Part b\n", + "vo1=Vcc-(Icq*Rc) #terminal 1 voltage(V) \n", + "vo2=vo1 #terminal 2 voltage(V) \n", + "\n", + "#Part c \n", + "Ad=(gm*Rc)/2 #differential mode gain\n", + "Ac=Rc/(2*Re) #common mode gain\n", + "CMRR=Ad/Ac #common mode rejection ratio\n", + "\n", + "#Part d\n", + "Rid=2*rpi #differential input resistance(k ohms)\n", + "rpi=11.7 #dynamic resistance(k ohms)\n", + "Ric=rpi+(2*(beta+1)*Re) #common mode input resistance(k ohms)\n", + "\n", + "#Results\n", + "print\"Icq is\",Icq,\"mA,and Ibq is \",round((Ibq/1E-3),2),\"uA\"\n", + "print\"vo1 and vo2 have same value as\",vo1,\"V\"\n", + "print\"\",\n", + "print\"Ad:\",round(Ad/1E-3),\",Ac:\",round(Ac,3),\"and CMRR is\",round(CMRR/1E-3)\n", + "print\"Rid is\",round((Rid/1E+3),1),\"K ohms and Ric is\",round((Ric/1E+3),2),\" Mohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Icq is 0.428 mA,and Ibq is 2.14 uA\n", + "vo1 and vo2 have same value as 10.72 V\n", + " Ad: 86.0 ,Ac: 0.313 and CMRR is 274.0\n", + "Rid is 23.4 K ohms and Ric is 6.44 Mohms\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.7,Page number 373" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "R1=10. #series resistance(K ohms)\n", + "Rf=10**3. #feedback resistance(k ohms) \n", + "vo=-5. #output voltage(V)\n", + "Ri=1000 #input resistance(k ohms)\n", + "Av=2.5*10**5 #gain\n", + "\n", + "#Calculations\n", + "v1=-vo*(R1/Rf) #input signal voltage(V)\n", + "vi=-vo/Av #inverting voltage(V) \n", + "i1=((v1*10**-3)-vi)/R1 #current through R1(uA)\n", + "ii=vi/Ri #inverting current(uA)\n", + "iF=-ii #forward current(uA)\n", + "\n", + "#Results\n", + "print\"value of vi is\",vi,\"mV\"\n", + "print\"value of ii:\",ii,\"uA i1:,\",i1,\"uA and iF is\",iF,\"uA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of vi is 2e-05 mV\n", + "value of ii: 2e-08 uA i1:, 3e-06 uA and iF is -2e-08 uA\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.8,Page number 374" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vs=4 #source voltage(V)\n", + "R1=10. #resistance(k ohms)\n", + "Vb=Va=2 #voltage at point A and point B\n", + "Rf=30 #forward resistance(k ohms)\n", + "\n", + "#Calculations\n", + "I=(Vs-Vb)/R1 #current(mA)\n", + "Vo=(-I*Rf)+Vb #output voltage(V) \n", + "\n", + "#Result\n", + "print\"output voltage\",Vo,\"V\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "output voltage -4.0 V\n" + ] + } + ], + "prompt_number": 45 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.9,Page number 375" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Rf=2 #as vs=2sinwt and vo=(1+Rf/Rs)*vb and vB=vA=vs\n", + "Rs=1\n", + "\n", + "\n", + "#Calculations\n", + "vo=(1+(Rf/Rs))*2 #output voltage(V)\n", + "\n", + "#Result\n", + "print\"output voltage\",vo,\"sinwt\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "output voltage 6 sinwt\n" + ] + } + ], + "prompt_number": 50 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.10,Page number 377" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Ro=100. #output resistance(ohms)\n", + "vo=10. #output voltage(V)\n", + "A=10**5. #gain \n", + "Ri=100*10**3 #input resistance(ohms) \n", + "Rs=1*10**3. #resistance(ohms)\n", + "Rl=10*10**3 #load resistance(ohms)\n", + "\n", + "#Calculations\n", + "#Part i\n", + "iL=vo/Rl #load current(mA)\n", + "Avi=vo+(iL*Ro) #voltage gain without feedback\n", + "vi=Avi/A #voltage(V)\n", + "ii=vi/Ri #current(A) \n", + "vs=vo+ii*(Rs+Ri) #source voltage(V)\n", + "\n", + "#Part ii\n", + "Avf=vo/vs #voltage gain with feedback \n", + "\n", + "\n", + "#Part iii\n", + "Rif=vs/ii #input resistance(ohms) \n", + "Rof=Ro/A #output resistance(ohms)\n", + "\n", + "#Results\n", + "print\"vs is\",round(vs,4),\"V\"\n", + "print\"vo/vs that is Avf is\",Avf\n", + "print\"input and output resistances are\",Rif,Rof,\"ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "vs is 10.0001 V\n", + "vo/vs that is Avf is 0.999989799104\n", + "input and output resistances are 9901091099.01 0.001 ohms\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.11,Page number 382" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vb=Va=3 #voltage at A and B \n", + "R1=40*10**3. #input resistance(ohms)\n", + "t=50*10**-3 #time after switch is open(mS)\n", + "V1=5 #input voltage(V)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "vo=-3 #as Va=Vb=3\n", + "\n", + "#Part b\n", + "i1=(V1-Vb)/R1 #input current(A)\n", + "vo1=(-250*t)-Va #vo at 50 mS\n", + "\n", + "#Result\n", + "print\"output voltage\",vo1,\"V\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "output voltage -15.5 V\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.14,Page number 388" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "BW=30*10**3 #specified bandwidth(k Hz)\n", + "fc=18*10**3 #centered frequency(Hz)\n", + "R1=20 #resistance(k ohms) \n", + "R2=180 #resistance(k ohms) \n", + "C=1.2*10**-9 #capacitance(F)\n", + "G=40 #pass band gain(dB)\n", + "g=20 #pass region gain(dB)\n", + "\n", + "#Calculationsv\n", + "fc1=fc-(BW/2) #high pass section frequency(Hz)\n", + "fc2=fc+(BW/2) #low pass section frequency(Hz)\n", + "Rfc1=1/(2*math.pi*fc1*C) #high pass section resistance(k ohms)\n", + "Rfc2=1/(2*math.pi*fc2*C) #low pass section resistance(k ohms)\n", + "Gfc1=G-g #gain at frequency 0.3KHz(dB)\n", + "Gfc2=G-2*6 #gain at frequency 132KHz(dB)\n", + "\n", + "#Results\n", + "print\"R1 and R2 are\",R1,\"K ohms and\",R2,\"K ohms\"\n", + "print\"Rfc1 is\",round(Rfc1/1E+3),\"k ohms and Rfc2 is\",round(Rfc2/1E+3),\"k ohms\"\n", + "print\"filter gain at frequencies 0.3 KHz is\",Gfc1,\"dB and 132 k Hz are\",Gfc2,\"dB\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "R1 and R2 are 20 K ohms and 180 K ohms\n", + "Rfc1 is 44.0 k ohms and Rfc2 is 4.0 k ohms\n", + "filter gain at frequencies 0.3 KHz is 20 dB and 132 k Hz are 28 dB\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.21,Page number 402" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "R=250 #resistance(k ohms)\n", + "\n", + "#Calculations\n", + "#part a\n", + "R1=-R/(-5) #as vo=-5va+3vb(given),so when vb=0,vo/voa=-250/R1=-5\n", + "\n", + "#part b\n", + "R2=R1/(2-1) #as va=0\n", + " #vx=(R1/R1+R)*vob=(1/6)*vb\n", + " #vy=(R2/R1+R2)*vb\n", + " #vx=vy\n", + " #(1/6)*vob=(R2/R1+R2)*vb\n", + " #vob=3vb\n", + " #(1/6)*3=R2/(50+R2)\n", + " \n", + "#Result\n", + "print\"R1 and R2 are\",R1,\"K ohms and\",R2,\"K ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "R1 and R2 are 50 K ohms and 50 K ohms\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.22,Page number 403" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "R1=10*10**3 #resistance(k ohms)\n", + "C1=10**-6 #capacitance(uF) \n", + "C=0.1*10**-6 #capacitance(uF) \n", + "R=100*10**3 #resistance(k ohms) \n", + "\n", + "#Calculations\n", + "#part b \n", + "wc1=1/C1*R1 #angular frequency(rad/s)\n", + "wc2=1/C*R #angular frequency(rad/s)\n", + "wc=wc1=wc2 #angular frequency(rad/s)\n", + "\n", + "#Results\n", + "print\"wc1 is\",wc1/1E+10,\"rad/s\"\n", + "print\"wc2 is\",wc2/1e+10,\"rad/s\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "wc1 is 100.0 rad/s\n", + "wc2 is 100.0 rad/s\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.23,Page number 404" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "vo1=5 #say (V)\n", + "K=25 #proportionality constant \n", + "Q=250 #volume of fluid passed across metering point(cm^3) \n", + "R1=2.5 #output resistance(k ohms)\n", + "\n", + "#Calculations\n", + "C1=(K*Q)/(R1*vo1) #capacitor(nF)\n", + "\n", + "#Results\n", + "print\"C1 is\",round(C1/1E+1),\"uF\"\n", + "print\"vo1 is -5V when Q=250 cm^3\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "C1 is 50.0 uF\n", + "vo1 is -5V when Q=250 cm^3\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter8.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter8.ipynb new file mode 100755 index 00000000..326b2cab --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter8.ipynb @@ -0,0 +1,435 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:7039c5014fcc7b7ac57b07f9ca218d5a9c1cf6429694e23e4e8bce3552a45c07" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 8:Multivibrators And Switching Regulators" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.1,Page number 426" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "C=0.1 #capacitance(uF)\n", + "R1=10 #resistance(k ohms)\n", + "R2=2.3 #resistance(k ohms)\n", + "Vcc=12. #supply voltage(V) \n", + "Rl=10**3. #resistance(k ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "f=1/(0.693*C*(R2+R1/2)) #frequency(Hz)\n", + "\n", + "#Part b\n", + "D=(1+(R2/R1))/(1+2*(R2/R1))*100 #duty cycle\n", + " \n", + "#Part c\n", + "#(i)\n", + "T1=0.693*C*(R1+R2) #time period through R1(ms)\n", + "T2=0.693*R2*C #time period through R2(ms)\n", + "Pavg=(Vcc/Rl)**2*(T1/(T1+T2)) #average power dissipated during current sourcing(mW)\n", + "\n", + "#Part d\n", + "Pavg1=(T2/(T1+T2))*(Vcc/Rl)**2 #average power dissipated during current sinking(mW)\n", + "\n", + "#Results\n", + "print\"print\",round(f,2),\"kHz\"\n", + "print\"duty cycle is\",round(D,2),\"%\"\n", + "print\"average power dissipated in current sourcing is\",round((Pavg/1E-3),3),\"mW\"\n", + "print\"average power dissipated in current sinking is\",round(Pavg1/1e-3,3),\"mW\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "print 1.98 kHz\n", + "duty cycle is 84.25 %\n", + "average power dissipated in current sourcing is 0.121 mW\n", + "average power dissipated in current sinking is 0.023 mW\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.2,Page number 426" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "\n", + "#Variable declaration\n", + "t=1 #time constant\n", + "e=1.8 #e=R1/R2 min=1.8\n", + "e1=9. #e1=R1/R2 max=9\n", + "\n", + "#Calculations\n", + "Betamin=1/(1+e) #current gain minimum\n", + "Betamax=1/(1+e1) #current gain maximum\n", + "Tmax=2*t*math.log((1+Betamin)/(1-Betamin)) \n", + "Tmin=2*t*math.log((1+Betamax)/(1-Betamax)) \n", + "fmin=1/Tmax #minimum freq(Hz)\n", + "fmax=1/Tmin #maximum freq(k Hz)\n", + "\n", + "#Results\n", + "print\"fmin is\",round(fmin/1E-3),\"Hz and fmax is\",round(fmax,1),\"KHz\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "fmin is 669.0 Hz and fmax is 2.5 KHz\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.3,Page number 427" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Variable declaration\n", + "C=0.01 #capacitance(uF)\n", + "R2=15 #resistance(k ohms)\n", + "Va2=4 #voltage(V)\n", + "Vcc=15. #supply voltage(V)\n", + "R1=33 #resistance(k ohms)\n", + "\n", + "#Calculations\n", + "Va1=0.67*Vcc #voltage(V)\n", + "Vamax=Va1+Va2 #Va maximum(V)\n", + "Vamin=Va1-Va2 #Va minimum(V)\n", + "T1max=C*(R1+R2)*(math.log((1-(Vamax/(2*Vcc)))/(1-(Vamax/Vcc)))) #time period(ms)\n", + "T1min=C*(R1+R2)*(math.log((1-(Vamin/(2*Vcc)))/(1-(Vamin/Vcc)))) #time period(ms)\n", + "T2=0.693*R2*C\n", + "fmax=1/(T1min+T2) #maximum frequency(K Hz)\n", + "fmin=1/(T1max+T2) #miniimum frequency(K Hz)\n", + "\n", + "#Results\n", + "print\"minimum freq is\",round(fmin,2),\"(solution given in the textbook is incorrect)\"\n", + "print\"maximum freq is\",round(fmax,2),\"(solution given in the textbook is incorrect)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "minimum freq is 0.89 (solution given in the textbook is incorrect)\n", + "maximum freq is 4.1 (solution given in the textbook is incorrect)\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.4,Page number 433" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vi=25 #input voltage(V) \n", + "Vsmax=30 #supply voltage max(V)\n", + "Vomin=Vl=12 #output minimum voltage or load voltage(V)\n", + "R1=20 #load voltage(V)\n", + "Io=15. #output current(mA) \n", + "Iq=3. #quinscent current of regulator(mA)\n", + "Vo=20. #output voltage(V)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "#(i)\n", + "Vimax=Vsmax #maximum permissible voltage(V)\n", + "Ro=0 #for Vomin=beta=0\n", + "#(ii)\n", + "Vomax=Vi-2\n", + "betaVomax=Vomax-Vomin #output voltage(V)\n", + "R2max=(R1*betaVomax)/(Vomax-betaVomax) #R2max(k ohms)\n", + "#(iii)\n", + "R3=betaVomax/Io #R3(k ohms)\n", + "\n", + "#Part b\n", + "Vt=(Iq*betaVomax)/Io #common terminal fall(V)\n", + "Vomin1=Vl+Vt #voltage output minimum(V)\n", + "\n", + "#Part c\n", + "betaVo=Vo-Vl #output voltage(V)\n", + "beta=betaVo/Vo #current gain\n", + "R2=(R1*betaVo)/(Vo-betaVo) #R2(ohms)\n", + "\n", + "#Results\n", + "print\"a)i)max permissible supply voltage is\",Vimax,\"V\"\n", + "print\"ii)output voltage range for Vi=25V is\",Vomin,\"V to\",Vomax,\"V and R2max is\",R2max,\"k ohms\"\n", + "print\"iii)R3 is\",round(R3,2),\"kohms\"\n", + "print\"b)Vomin is\",Vomin1,\"V\"\n", + "print\"c)R2 is\",round(R2,2),\"ohms and R3 is\",round(R3,3),\"ohms\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a)i)max permissible supply voltage is 30 V\n", + "ii)output voltage range for Vi=25V is 12 V to 23 V and R2max is 18 k ohms\n", + "iii)R3 is 0.73 kohms\n", + "b)Vomin is 14.2 V\n", + "c)R2 is 13.33 ohms and R3 is 0.733 ohms\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.5,Page number 434" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "A=.0025 #voltage gain\n", + "Vi=8 #input voltage(V)\n", + "R2=1.5 #resistance 2(k ohms)\n", + "R1=1 #resistance 1(k ohms)\n", + "Vl=5 #load voltage(V)\n", + "\n", + "#Calculations\n", + "beta=R2/(R1+R2) #current gain\n", + "Vo=Vl/(1-beta) #output voltage(V)\n", + "Vo1=(A*Vi)/(1+(A*beta)-beta) #output voltage ripple if Vi=8Vp-p\n", + "\n", + "#Results\n", + "print\"Vo is\",Vo,\"V\"\n", + "print\"expression of output voltage ripple\",round(Vo1,2),\"Vp-p\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Vo is 12.5 V\n", + "expression of output voltage ripple 0.05 Vp-p\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.6,Page number 435" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Ro=7.5 #output resistance(ohms)\n", + "hfe=50 \n", + "Ve=20 #voltage given to emitter(V) \n", + "Vbe=0.8 #base to emitter voltage(V)\n", + "Vc=15 #collector voltage(V)\n", + "P=12 #maximum power dissipation(W)\n", + "Ib1=5 #for minimum load current Il=0,Ib=5\n", + "\n", + "#Calculations\n", + "Io=(Vc/Ro)*10**3 #output current(A)\n", + "Il=76 #load current(mA)\n", + "Is=Il+5 #supply current(mA)\n", + "Ic=Io-Is #collector current(A)\n", + "Ib=Ic/hfe #base current(mA)\n", + "Ie=Ic-Ib #emitter current(mA)\n", + "Pt=(Ve*Ie)-(Vc*Ic) #power dissipated in transistor(W) \n", + "Pl=(Ve-Vbe)*Is-Vc*Il #power dissipated in LR\n", + "Vimax=(P+Vc*(Ic*10**-3))/(Ie*10**-3) #input voltage maximum\n", + "Iomin=hfe*Ib1 #output current minimum(mA)\n", + "\n", + "#Results\n", + "print\"power dissipated in the transistor is\",round((Pt/1E+3),2),\"W and in LR is\",round((Pl/1E+3),3),\"W\"\n", + "print\"maximum permissible input voltage is\",round(Vimax,2),\"V\"\n", + "print\"minimum load current for load voltage to remain stabalized is\",Iomin,\"mA\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "power dissipated in the transistor is 8.83 W and in LR is 0.415 W\n", + "maximum permissible input voltage is 21.69 V\n", + "minimum load current for load voltage to remain stabalized is 250 mA\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.7,Page number 440" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "VL=12 #load voltage(V)\n", + "I=2. #current at 12 V\n", + "V=240 #dc source(V)\n", + "d=17/50. #duty cycle\n", + "d1=0.6 #duty cycle\n", + "eta1=0.8 #efficiency\n", + "\n", + "#Calculations\n", + "P=VL*I #average load power(W)\n", + "Isav=(1*d)/2 #average supply current(A)\n", + "Pav=V*Isav #average supply power(W)\n", + "eta=(P/Pav)*100 #regulator efficiency\n", + "Isav1=(1*d1)/2 #average supply current(A)\n", + "Il=(eta1*V*Isav1)/Vdc #load current(A)\n", + "Po=Il*Vdc #power output(W)\n", + "\n", + "#Results\n", + "print\"regulator efficiency is\",round(eta,1),\"%\"\n", + "print\"average supply current is\",Il,\"A\"\n", + "print\"power output is\",Po,\"W\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "regulator efficiency is 58.8 %\n", + "average supply current is 4.8 A\n", + "power output is 57.6 W\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.8,Page number 441" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "Vs=200 #dc source voltage(V)\n", + "Il=5 #current to load voltage(A)\n", + "Vl=15 #load voltage(V)\n", + "eta=.85 #efficiency\n", + "f=20 #oscillator frequency(Hz)\n", + "iSmax=2.6 #peak value of supply current(A)\n", + "P=100 #full load power supply(W)\n", + "pdf=0.4 #pulse duty factor\n", + "\n", + "#Calculations\n", + "Isav=(Vl*Il)/(Vs*eta) #average peak supply current(A)\n", + "iS=(2*Isav)/pdf #supply current(A)\n", + "T=1000/f #oscillation time period(uS)\n", + "tp=pdf*T #transistor time(us)\n", + "d=iS/tp #change in iS with respect to time(A/us)\n", + "tp1=iSmax/d #transistor time(us)\n", + "pdf1=tp1/T #pulse duty factor\n", + "Isav1=(iSmax*pdf1)/2 #average peak supply current(A)\n", + "eta1=(P*100)/(Vs*Isav1) #efficiency\n", + "\n", + "#Results\n", + "print\"peak value of supply current is\",round(Isav,3),\"A\"\n", + "print\"pdf is\",round(pdf,3)\n", + "print\"overall efficienc is\",round(eta1,1),\"%\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "peak value of supply current is 0.441 A\n", + "pdf is 0.4\n", + "overall efficienc is 81.6 %\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter9.ipynb b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter9.ipynb new file mode 100755 index 00000000..496c5c11 --- /dev/null +++ b/Electronic_Devices_and_Circuits_By_I.JNagrath/chapter9.ipynb @@ -0,0 +1,189 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:6d01f2ecc4d9a69a4f181f319c5918acedc473286b2890ff9741394369b9b17a" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 9:Integrated Circuit Fabrication" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.2,Page number 470" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "t=1 #thickness(mil) \n", + "e=1.6*10**-19 #charge on electron(C)\n", + "Pp=10**17 #concentration of phosphorous(atoms/cm^3)\n", + "Bn=5*10**16 #boron concentration(atoms/cm^3)\n", + "un=.135 #mobility(m^2/Vs)\n", + "\n", + "#Calculations\n", + "n=(Pp-Bn)*10**6 #net concentration(atoms/cm^3)\n", + "g=e*un*n #conductivity()\n", + "rho=10**6/(g*25) #resistivity(ohm mil)\n", + "Rs=rho/t #sheet resistance(ohm mil^2)\n", + "\n", + "#Results\n", + "print\"Sheet resistance is\",round(Rs),\"ohm(mil**2)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sheet resistance is 37.0 ohm(mil**2)\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.3,Page number 471" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "R=20*10**3 #resistance of resistor(ohms)\n", + "w=25 #width(um)\n", + "Rs=200 #sheet resistance(ohm/square)\n", + "R1=5*10**3 #resistance(ohms)\n", + "\n", + "#Calculations\n", + "#Part a\n", + "l=(R*w)/Rs #length required to fabricate 20 kohms(um)\n", + "\n", + "#Part b\n", + "L=25 #length of resistor of 5 k ohms(um)\n", + "w1=(Rs*L)/R1 #width required to fabricate 5 kohms(um)\n", + "#Results\n", + "print\"length required to fabricate 20 kohms resistor is\",l,\"um\"\n", + "print\"width required to fabricate 5 kohms resistor is\",w1,\"um\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "length required to fabricate 20 kohms resistor is 2500 um\n", + "width required to fabricate 5 kohms resistor is 1 um\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.4,Page number 471" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "C=0.4*10**-12 #capacitance(pF/um^2)\n", + "A=10**-12 #area of film(m^2)\n", + "d=400*10**-10 #thickness of SiO2(amstrong)\n", + "Eo=8.849*10**-12 #absolute electrical permitivity of free space\n", + "\n", + "#Calculations\n", + "Er=(C*d)/(Eo*A) #relative dielectric constant\n", + "\n", + "#Results\n", + "print\"relative dielectric constant of SiO2 is\",round(Er),\"(Solution given in the textbook is incorrect)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "relative dielectric constant of SiO2 is 1808.0 (Solution given in the textbook is incorrect)\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.5,Page number 471" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Variable declaration\n", + "C=250*10**-12 #capacitance(pF)\n", + "d=500*10**-10 #thickness of SiO2 layer(amstrong)\n", + "Eo=8.849*10**-12 #absolute electrical permitivity of free space\n", + "Er=3.5 #relative dielectric constant\n", + "\n", + "#Calculations\n", + "A=(C*d)/(Eo*Er) #chip area(um^2)\n", + "\n", + "#Results\n", + "print\"chip area needed for a 250 pF MOS capacitor\",round(A/1e-7,2),\"(um)^2(Solution given in the textbook is incorrect)\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "chip area needed for a 250 pF MOS capacitor 4.04 (um)^2(Solution given in the textbook is incorrect)\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen1.png b/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen1.png new file mode 100755 index 00000000..d310f422 Binary files /dev/null and b/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen1.png differ diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen2.png b/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen2.png new file mode 100755 index 00000000..a92b49eb Binary files /dev/null and b/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen2.png differ diff --git a/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen3.png b/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen3.png new file mode 100755 index 00000000..fc6fdd99 Binary files /dev/null and b/Electronic_Devices_and_Circuits_By_I.JNagrath/screenshots/screen3.png differ diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_1.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_1.ipynb new file mode 100755 index 00000000..3756f226 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_1.ipynb @@ -0,0 +1,307 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:b71c5763a44a53c43becf4b38bc4dc6ca15fcaba00869ac6f1172cbb9803b804" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1 - ELECTRONIC MATERIALS AND COMPONENTS" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Calculate the value of resistor\n", + "print '%s' %(\"Refer to the figure 1.52\")\n", + "print '%s' %(\"Hold the resistor as shown in the figure such that tolerance is on your extreme right.\")\n", + "print '%s' %(\"Now the value of the resistor is equal to\")\n", + "print '%s' %(\" Red Black Blue Gold\")\n", + "print '%s' %(\" 2 0 6 (+/-)5%\")\n", + "red=2. #red value\n", + "blk=0 #black value\n", + "blu=6. #blue value\n", + "gld=5. #gold value\n", + "value_res=(red*10.+blk)*10.**blu #value of resistor\n", + "print '%s %.0f %s %.0f' %(\"\\n The value of resistor is\",value_res,\"ohm (+/-)\",gld)\n", + "per_val=0.05*value_res\n", + "pos_value_res=value_res+per_val #positive range of resistor\n", + "neg_value_res=value_res-per_val #negative range of resistor\n", + "print '%s %.0f %s %.0f %s ' %(\"\\n The value of resistor is\",neg_value_res*1e-6,\" Mohm and\",pos_value_res*1e-6,\"Mohm\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 1.52\n", + "Hold the resistor as shown in the figure such that tolerance is on your extreme right.\n", + "Now the value of the resistor is equal to\n", + " Red Black Blue Gold\n", + " 2 0 6 (+/-)5%\n", + "\n", + " The value of resistor is 20000000 ohm (+/-) 5\n", + "\n", + " The value of resistor is 19 Mohm and 21 Mohm \n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Calculate the value of the resistor\n", + "print '%s' %(\"With the help of colour coding table, one finds\")\n", + "print '%s' %(\" 1st_Band 2nd_Band 3rd_Band 4th_Band\")\n", + "print(\" Yellow Violet Orange Gold\")\n", + "print '%s' %(\" 4 7 10**3 (+/-)5%\")\n", + "yel=4. #yellow value\n", + "vio=7. #violet value\n", + "org=1e3 #orange value\n", + "gld=5. #gold value in %\n", + "val_res=(yel*10.+vio)*org\n", + "print '%s %.2f %s %.0f' %(\"\\n The value of resistor is\",val_res*1e-3,\"kohm (+/-)\",gld)\n", + "gld_ab=0.05 #absolute gold value\n", + "per_val=gld_ab*val_res\n", + "print '%s %.0f %s'%(\"\\n Now, 5%% of 47k_ohm =\",per_val, \"ohm\")\n", + "range_high=val_res+per_val #higher range\n", + "range_low=val_res-per_val #lower range\n", + "print'%s %.2f %s %.2f %s %.2f %s %.2f %s'%(\"\\n\\n Thus resistance should be within the range\",val_res*1e-3, \"kohm(+/-)\",per_val*1e-3 ,\"Kohm\\n or between\",range_low*1e-3 ,\"kohm and\",range_high*1e-3, \"kohm\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "With the help of colour coding table, one finds\n", + " 1st_Band 2nd_Band 3rd_Band 4th_Band\n", + " Yellow Violet Orange Gold\n", + " 4 7 10**3 (+/-)5%\n", + "\n", + " The value of resistor is 47.00 kohm (+/-) 5\n", + "\n", + " Now, 5%% of 47k_ohm = 2350 ohm\n", + "\n", + "\n", + " Thus resistance should be within the range 47.00 kohm(+/-) 2.35 Kohm\n", + " or between 44.65 kohm and 49.35 kohm\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 44" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Calculate the value of the resistor\n", + "print '%s' %(\"The specification of the resistor from the color coding table is as follows\")\n", + "print '%s' %(\" 1st_Band 2nd_Band 3rd_Band 4th_Band\")\n", + "print '%s' %(\" Gray Blue Gold Silver\")\n", + "print '%s' %(\" 8 6 10**(-1) (+/-)10%\")\n", + "gray=8. #gray value\n", + "blu=6. #blue value\n", + "gld=10.**-1 #gold value\n", + "sil=10. #silver value in %\n", + "val_res=(gray*10.+blu)*gld\n", + "print '%s %.2f %s %.2f' %(\"\\n The value of resistor is\",val_res, \"ohm (+/-)\",sil)\n", + "sil_ab=0.1 #absolute gold value\n", + "per_val=sil_ab*val_res\n", + "print '%s %.2f %s' %(\"\\n Now, 10%% of 8.6 ohm =\",per_val,\" ohm\")\n", + "range_high=val_res+per_val #higher range\n", + "range_low=val_res-per_val #lower range\n", + "print '%s %.2f %s %.2f %s %.2f %s %.2f %s' %(\"\\n\\n Obviously resistance should lie within the range\",val_res,\"ohm(+/-)\",per_val,\"ohm\\n or between\",range_high,\"ohm and\",range_low,\"ohm\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The specification of the resistor from the color coding table is as follows\n", + " 1st_Band 2nd_Band 3rd_Band 4th_Band\n", + " Gray Blue Gold Silver\n", + " 8 6 10**(-1) (+/-)10%\n", + "\n", + " The value of resistor is 8.60 ohm (+/-) 10.00\n", + "\n", + " Now, 10%% of 8.6 ohm = 0.86 ohm\n", + "\n", + "\n", + " Obviously resistance should lie within the range 8.60 ohm(+/-) 0.86 ohm\n", + " or between 9.46 ohm and 7.74 ohm\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 44" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Calculate the load voltage and load current\n", + "print '%s' %(\"Refer to the figure 1.53\")\n", + "Vs=2. #supply voltage in V\n", + "Rs=1. #resistance in ohm\n", + "Is=Vs/Rs\n", + "print '%s %.2f %s' %(\"\\n Current Is =\",Is,\" A \\n\")\n", + "print '%s' %(\" Internal resistance remains the same but is now connected in parralel with the current sourceIS,as shown in Figure 1.51(a)\")\n", + "print '%s' %(\" Now,we connect a load resistance R_L=1 ohm across the terminals of two representations ,and find I_L and V_L. From Figure 1.54(b) and using the current-divider concept,one obtains\")\n", + "RL=1. #load resistance in ohm\n", + "IL=Is*(Rs/(Rs+RL)) #load current using current-divider\n", + "VL=IL*RL #load voltage\n", + "print '%s %.0f %s' %(\"\\n Load voltage =\",VL,\"V\")\n", + "print '%s %.0f %s' %(\"\\n Load current =\",IL,\"A \\n\")\n", + "print '%s' %(\"From equation 53(b),using the voltage-divider concept,one obtains\")\n", + "VD_vl=Vs*(RL/(RL+Rs)) #load voltage using voltage divider \n", + "VD_il=VL/RL #load current\n", + "print '%s %.0f %s' %(\"\\n Load voltage =\",VD_vl,\"V\")\n", + "print '%s %.0f %s' %(\"\\n Load current =\",VD_il,\"A \\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 1.53\n", + "\n", + " Current Is = 2.00 A \n", + "\n", + " Internal resistance remains the same but is now connected in parralel with the current sourceIS,as shown in Figure 1.51(a)\n", + " Now,we connect a load resistance R_L=1 ohm across the terminals of two representations ,and find I_L and V_L. From Figure 1.54(b) and using the current-divider concept,one obtains\n", + "\n", + " Load voltage = 1 V\n", + "\n", + " Load current = 1 A \n", + "\n", + "From equation 53(b),using the voltage-divider concept,one obtains\n", + "\n", + " Load voltage = 1 V\n", + "\n", + " Load current = 1 A \n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Calculate the percentage variation in current, current for two extreme values R_L\n", + "print '%s' %(\"Refer to the figure 1.55\")\n", + "print '%s' %(\"(a) R_L varies from 1 ohm to 10 ohm.\")\n", + "print '%s' %(\"Currents for two extreme values of R_L are\")\n", + "Vs=10. #supply voltage\n", + "RL1=1. #resistance RL1\n", + "Rs=100. #source resistance\n", + "IL1=(Vs/(RL1+Rs))\n", + "RL2=10.\n", + "IL2=(Vs/(RL2+Rs))\n", + "per_var_cur=((IL1-IL2)/IL1)*100.\n", + "print '%s %.2f %s' %(\"\\n Percentage variation in current =\",per_var_cur,\"\\n\")#answer in the text book took a .3 decimal round off value\n", + "print '%s' %(\" Now,load voltage for the two extreme values of R_L are\")\n", + "VL1=IL1*RL1\n", + "VL2=IL2*RL2\n", + "per_var_vol=((VL2-VL1)/VL2)*100.\n", + "print '%s %.2f %s' %(\"\\n Percentage variation in current =\",per_var_vol,\"\\n\")\n", + "\n", + "print '%s' %(\"(b) R_L varies from 1 k-ohm to 10 k-ohm(Figure 1.55(b))\")\n", + "print '%s' %(\"Currents for the two extreme values R_L are\")\n", + "RL11=1000.\n", + "IL11=(Vs/(RL11+Rs))\n", + "RL22=10000.\n", + "IL22=(Vs/(RL22+Rs)) #mistake in book value\n", + "per_var_cur11=((IL11-IL22)/IL11)*100.\n", + "print '%s %.2f %s' %(\"\\n Percentage variation in current =\",per_var_cur11,\"\\n\") #mistake in book value\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 1.55\n", + "(a) R_L varies from 1 ohm to 10 ohm.\n", + "Currents for two extreme values of R_L are\n", + "\n", + " Percentage variation in current = 8.18 \n", + "\n", + " Now,load voltage for the two extreme values of R_L are\n", + "\n", + " Percentage variation in current = 89.11 \n", + "\n", + "(b) R_L varies from 1 k-ohm to 10 k-ohm(Figure 1.55(b))\n", + "Currents for the two extreme values R_L are\n", + "\n", + " Percentage variation in current = 89.11 \n", + "\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_10.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_10.ipynb new file mode 100755 index 00000000..40ac1384 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_10.ipynb @@ -0,0 +1,336 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:97a0b78a94b9f5e74ae319a6d8af686ff05898c74b39150d93ce65c25b4de220" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 10 - Operational Amplifier" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 490" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_1 Pg-490\n", + "#calculate Common moce voltage gain,Output voltage\n", + "Rc=1.*10.**(6.) #collector resisstor in ohm\n", + "Re=2.*10.**(6.) #emitter resistor in ohm\n", + "Vin=1.*10.**(-3.) #input voltage in V\n", + "Acm=Rc/Re #Common moce voltage gain\n", + "print '%s %.1f' %(\"Common moce voltage gain =\",Acm) \n", + "Vo=Acm*Vin #output voltage\n", + "print '%s %.1f' %(\"Output voltage = mV\",Vo*1e3)\n", + "print '%s' %(\"Thus a differential amplifier in common mode attenuates the input signal rather than amplifying it\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Common moce voltage gain = 0.5\n", + "Output voltage = mV 0.5\n", + "Thus a differential amplifier in common mode attenuates the input signal rather than amplifying it\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 491" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_2 Pg-491\n", + "#calculate Amplified output voltage,Attenuated output voltage\n", + "A=150. #voltage gain\n", + "Acm=0.5 #common mode voltage gain\n", + "Vin=1.*10.**(-3.) #input voltage in V\n", + "Vo=A*Vin #output voltage\n", + "print '%s %.2f' %(\"Amplified output voltage = V\",Vo)\n", + "Vo=Acm*Vin #output voltage\n", + "print '%s %.1f' %(\"Attenuated output voltage = mV\",Vo*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 517" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_3 Pg-517\n", + "#calculate Amplified output voltage\n", + "R1=10.*10.**(3.) #resistor R1 in ohm\n", + "Rf=50.*10.**(3.) #feedback resistor in ohm\n", + "Vin=10.*10.**(-3.) #input voltage in V\n", + "Ro=5000. #load resistor in ohm\n", + "print '%s' %(\"A'' = Vo/Vi = (-1)*Rf/R1*(1+1/A*(1+Rf/R1))**-1 \")\n", + "A=5000. \n", + "Vo=Vin*(Rf/R1)/(1+1/A*(1+Rf/R1)) #output voltage\n", + "print '%s %.0f' %(\"\\n When gain A =\",A)\n", + "print '%s %.1f' %(\" \\n Amplified output voltage = mV\",Vo*1e3)\n", + "A=10000.\n", + "Vo=Vin*(Rf/R1)/(1+1/A*(1+Rf/R1))\n", + "print '%s %.0f' %(\"\\n When gain A=%.0f\",A)\n", + "print '%s %.2f' %(\" \\n Amplified output voltage = mV\",Vo*1e3)\n", + "A=5000.\n", + "Rout=Ro/(1.+A*R1/Rf) #load resistance\n", + "print '%s %.3f' %(\" \\n Ro = ohm\",Rout)\n", + "A=10000.\n", + "Rout=Ro/(1.+A*R1/Rf) #load resistance\n", + "print'%s %.3f' %(\"\\nRo = ohm\",Rout)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "A'' = Vo/Vi = (-1)*Rf/R1*(1+1/A*(1+Rf/R1))**-1 \n", + "\n", + " When gain A = 5000\n", + " \n", + " Amplified output voltage = mV 49.9\n", + "\n", + " When gain A=%.0f 10000\n", + " \n", + " Amplified output voltage = mV 49.97\n", + " \n", + " Ro = ohm 4.995\n", + "\n", + "Ro = ohm 2.499\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 518" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_4 Pg-518\n", + "#calculate Magnitude of Closed loop gain,Closed loop frequency,Output voltage\n", + "R1=1.5*10.**(3.) #resistor R1 in ohm\n", + "Rf=75.*10.**(3.) #feedback resistor in ohm\n", + "Vin=10.*10.**(-3.) #input voltage in V\n", + "funi=1.*10.**(6.) #unity frequency in Hz\n", + "Acl=(-1.)*Rf/R1 #closed loop gain\n", + "print '%s %.0f' %(\"Magnitude of Closed loop gain =\",abs(Acl))\n", + "fcl=funi/abs(Acl) #closed loop frequency\n", + "print '%s %.0f' %(\"Closed loop frequency = kHz\",fcl*1e-3)\n", + "Vout=abs(Acl)*Vin #output voltage\n", + "print '%s %.1f' %(\"Output voltage = mV pp\",Vout*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Magnitude of Closed loop gain = 50\n", + "Closed loop frequency = kHz 20\n", + "Output voltage = mV pp 500.0\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 518" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_5 Pg-518\n", + "#calculate When resistor 100 k-ohm is in zero position & maximum position\n", + "R1=2.*10.**(3.) #resistor R1 in ohm\n", + "Rf=0 #feedback resistor in ohm\n", + "print '%s' %(\"(1) When resistor 100 k-ohm is in zero position\")\n", + "A=1+Rf/R1 #gain\n", + "print '%s %.0f' %(\"Gain =\",A)\n", + "Rf=100.*10.**(3.)\n", + "print '%s' %(\"\\n(2)When resistor 100 k-ohm is in maximum position\")\n", + "A=1.+Rf/R1 #gain\n", + "print '%s %.0f' %(\"Gain =\",A)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) When resistor 100 k-ohm is in zero position\n", + "Gain = 1\n", + "\n", + "(2)When resistor 100 k-ohm is in maximum position\n", + "Gain = 51\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 519" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_6 Pg-519\n", + "#calculate voltage gain,Amplified output voltage\n", + "R1=50.*10.**(3.) #resistor R1 in ohm\n", + "Rf=300.*10.**(3.) #feedback resistor in ohm\n", + "Vin=1. #input voltage in V\n", + "print '%s' %(\"In the inverting mode,voltage gain is \")\n", + "print '%s' %(\"A'' = Vo/Vi = (-1)*Rf/R1*(1+1/A*(1+Rf/R1))**-1 \")\n", + "A=10000. \n", + "Vo=(-1.)*Vin*(Rf/R1)/(1.+1./A*(1.+Rf/R1)) #output voltage\n", + "print '%s %.3f' %(\"\\nAmplified output voltage = V\",Vo)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In the inverting mode,voltage gain is \n", + "A'' = Vo/Vi = (-1)*Rf/R1*(1+1/A*(1+Rf/R1))**-1 \n", + "\n", + "Amplified output voltage = V -5.996\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 519" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_7 Pg-519\n", + "#calculate Power Bandwidth\n", + "import math\n", + "Sr=15./1e-6 #slew rate in V/sec\n", + "Vp=10. #peak output voltage\n", + "fmax=Sr/(2.*math.pi*Vp) #Power Bandwidth\n", + "print '%s %.3f' %(\"Power Bandwidth = kHz\",fmax*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Power Bandwidth = kHz 238.732\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 519" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex10_8 Pg-519\n", + "#calculate Input resistance and Output resistance of buffer circuit\n", + "A=5000. #voltage gain\n", + "Ri=10000. #input resistor in ohm\n", + "Ro=100. #load resistor in ohm\n", + "Rf=0 #feedback resistor in ohm\n", + "Rin=A*Ri/(1+Rf/Ri) #input resistance of buffer circuit\n", + "print '%s %.0f' %(\"Input resistance of buffer circuit = *1e7 ohm\",Rin*1e-7)\n", + "Rout=Ro/A*(1.+Rf/Ri) #output resistance of buffer circuit\n", + "print '%s %.2f' %(\"Output resistance of buffer circuit = ohm\",Rout)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Input resistance of buffer circuit = *1e7 ohm 5\n", + "Output resistance of buffer circuit = ohm 0.02\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_11.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_11.ipynb new file mode 100755 index 00000000..79133326 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_11.ipynb @@ -0,0 +1,280 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:ba4d21079f61abcd679ca7b23396b654deb10533833878619fe3f3ec263dd35d" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 11 - Power Amplifier" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 536" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex11_1 Pg-536\n", + "#calculate Idc_sat,DC load,AC load,Icq,Vceq ,Efiiciency\n", + "Vcc=15. #supply voltage in V\n", + "R1=2.*10.**(3.) #resistor R1 in ohm\n", + "R2=470. #resistor R2 in ohm\n", + "Rc=680. #collector resistor in ohm\n", + "Rl=2.7*10.**(3.) #load resistor in ohm\n", + "Re=220. #emitter resistor\n", + "Idc=Vcc/(Rc+Re) #saturation current\n", + "print '%s %.1f' %(\"(1) Idc_sat = mA\",Idc*1e3) \n", + "DCload=Rc #Dc load resistance\n", + "print '%s %.0f' %(\"(2) DC load = ohm\",DCload)\n", + "ACload=Rc*Rl/(Rc+Rl) #Ac load resistance \n", + "print '%s %.0f' %(\"(3) AC load = ohm\",ACload)\n", + "Vb=R2/(R1+R2)*Vcc #base voltage\n", + "Icq=(Vb-0.7)/Re #collector current\n", + "print '%s %.1f' %(\"(4) Icq = mA\",Icq*1e3)\n", + "#answer in the book is wrong\n", + "Vc=Vcc-Icq*Rc #collector emitter voltage\n", + "Vceq=Vc-Icq*Re\n", + "print '%s %.1f' %(\"(5) Vceq = V\",Vceq)\n", + "#answer in the book is wrong\n", + "Pac=Vcc**2./(8.*Rl) #ac power\n", + "Pdc=Vcc*Idc #dc power\n", + "n=Pac/Pdc*100. #efficiency\n", + "print '%s %.0f' %(\"Efiiciency =\",n)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) Idc_sat = mA 16.7\n", + "(2) DC load = ohm 680\n", + "(3) AC load = ohm 543\n", + "(4) Icq = mA 9.8\n", + "(5) Vceq = V 6.2\n", + "Efiiciency = 4\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 551" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex11_2 Pg-551\n", + "#calculate Effective power to be transfered,Effective load,Maximum transistor voltage,Maximum transistor curren,Transformer specification\n", + "Po=4. #power in watts\n", + "n=80./100. #transformer efficiency in percentage\n", + "Vcc=30. #supply voltage\n", + "Pout=Po/n #effective power \n", + "print '%s %.0f' %(\"Effective power to be transfered = W\",Pout)\n", + "print '%s' %(\"\\nImpedance seen when \"\"looking into\"\" the whole winding of centertapped transformer \")\n", + "Vp=Vcc #peak voltage\n", + "Rload=Vp**2./(2.*Pout) \n", + "Rload_4=4*Rload #effective load\n", + "print '%s %.0f' %(\"\\nEffective load = ohm\",Rload_4)\n", + "print '%s' %(\"\\nTransformer specification Po=4W,RL=16ohm,RL\"\"=360ohm\")\n", + "Vce=2*Vcc #Maximum transistor voltage\n", + "print '%s %.0f' %(\"\\nMaximum transistor voltage = V\",Vce)\n", + "Ip=2*Pout/Vp #Maximum transistor current\n", + "Ic=Ip\n", + "print '%s %.0f' %(\"\\nMaximum transistor current = mA\",Ip*1e3)\n", + "# answer in the book is different due to approximate value\n", + "print '%s %.0f' %(\"\\nTransformer specification Vce=60V,Ic = mA\",Ic*1e3)\n", + "# answer in the book is different due to approximate value \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Effective power to be transfered = W 5\n", + "\n", + "Impedance seen when looking into the whole winding of centertapped transformer \n", + "\n", + "Effective load = ohm 360\n", + "\n", + "Transformer specification Po=4W,RL=16ohm,RL=360ohm\n", + "\n", + "Maximum transistor voltage = V 60\n", + "\n", + "Maximum transistor current = mA 333\n", + "\n", + "Transformer specification Vce=60V,Ic = mA 333\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 564" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex11_3 Pg-564\n", + "#calculate Resonant frequency,Bandwidth\n", + "import math\n", + "L=2.*10.**(-6.) #inductance in H\n", + "C=220.*10.**(-12.) #capacitance in F\n", + "f0=1./(2.*math.pi*math.sqrt(L*C)) #resonant frequency (textbook answer is wrong)\n", + "print '%s %.1f' %(\"Resonant frequency = MHz\",f0*1e-6)\n", + "Q=125. #quality factor\n", + "BW=f0/Q #Bandwidth (textbook answer is wrong)\n", + "print '%s %.0f' %(\"Bandwidth = kHz\",BW*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Resonant frequency = MHz 7.6\n", + "Bandwidth = kHz 61\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 564" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex11_4 Pg-564\n", + "#calculate Bias voltag,Emitter current,DC collector voltage,DC collector to emitter voltage,Power dissipation\n", + "Vcc=10. #supply volage in V\n", + "Rc=3600. #collector resistor in ohm\n", + "Re=680. #emitter resistor in ohm\n", + "Ri=10000. #input resistor in ohm\n", + "R2=2.2 #resistor R2 in ohm\n", + "R1=10. #resistor R1 in ohm\n", + "Vb=R2/(R1+R2)*Vcc #bias voltage \n", + "print '%s %.1f' %(\"(1) Bias voltage = V\",Vb)\n", + "Ie=(Vb-0.7)/Re #emitter current\n", + "print '%s %.2f' %(\" Emitter current = mA\",Ie*1e3)\n", + "Vc=Vcc-Rc*Ie #Dc collector voltage\n", + "print '%s %.2f' %(\" DC collector voltage = V\",Vc)\n", + "Vceq=Vc-Ie*Re #DC collector to emitter voltage\n", + "print '%s %.2f' %(\" DC collector to emitter voltage = V\",Vceq)\n", + "Pd=Vceq*Ie #power dissipation\n", + "print '%s %.2f' %(\" Power dissipation = mW\",Pd*1e3)\n", + "print '%s' %(\"\\n(2)If collector resistance Rc is replaced by tank circuit there is no voltage drop across it\")\n", + "Vc=Vcc\n", + "print '%s %.0f' %(\" DC collector voltage = V\",Vc)\n", + "Vceq=Vc-Ie*Re #DC collector to emitter voltage\n", + "print '%s %.2f' %(\" DC collector to emitter voltage = V\",Vceq)\n", + "Pd=Vceq*Ie #power dissipation\n", + "print '%s %.2f' %(\" Power dissipation = mW\",Pd*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) Bias voltage = V 1.8\n", + " Emitter current = mA 1.62\n", + " DC collector voltage = V 4.16\n", + " DC collector to emitter voltage = V 3.06\n", + " Power dissipation = mW 4.96\n", + "\n", + "(2)If collector resistance Rc is replaced by tank circuit there is no voltage drop across it\n", + " DC collector voltage = V 10\n", + " DC collector to emitter voltage = V 8.90\n", + " Power dissipation = mW 14.43\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 565" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex11_5 Pg-565\n", + "#calculate The peak value,peak-to-peak value of input voltage,Base to ground voltage\n", + "import math\n", + "Vin=5. #input voltage\n", + "Vp=Vin*math.sqrt(2.) #peak voltage\n", + "print '%s' %(\"The peak value(maximum amplication) of input signal\")\n", + "print '%s %.2f' %(\"= V\",Vp)\n", + "Vin_pp=2*Vp #peak-to-peak value of input voltage\n", + "print '%s' %(\"\\nPeak-to-peak value of input voltage\")\n", + "print '%s %.2f' %(\"= V\",Vin_pp)\n", + "Vbg=-1*(Vp-0.7) #base to ground voltage 0.7 is the voltage drop\n", + "print '%s %.2f' %(\"\\nBase to ground voltage = V\",Vbg)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The peak value(maximum amplication) of input signal\n", + "= V 7.07\n", + "\n", + "Peak-to-peak value of input voltage\n", + "= V 14.14\n", + "\n", + "Base to ground voltage = V -6.37\n" + ] + } + ], + "prompt_number": 5 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_12.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_12.ipynb new file mode 100755 index 00000000..b3a3f35f --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_12.ipynb @@ -0,0 +1,252 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:d077ff1ae1358d45f28145208de3c4ea471b35a4622d519cd3d0c3db386677a5" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 12 - Oscillators" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 587" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex12_1 Pg-587\n", + "#calculate Frequency of oscillations produced\n", + "import math\n", + "C1=0.001e-6 #capacitor c1 in farad\n", + "C2=0.01e-6 #capacitor c2 in farad\n", + "L=5e-6 #inductance in Henry\n", + "print '%s' %(\"To maintain vibrations in a colpitts oscilator,\")\n", + "print '%s' %(\"hfe >= C2/C1\")\n", + "hfe=C2/C1 #transistor current gain\n", + "print '%s %.f' %(\"=\",hfe)\n", + "print '%s' %(\"So the value of hfe of transistor used must be greater than 10\")\n", + "print '%s' %(\"Frequency of oscillations produced\")\n", + "x=1/(C1)+1/(C2)\n", + "y=1/(L)\n", + "f=math.sqrt(x*y)\n", + "print '%s %.1f' %(\"=*1e7 Hz\",f*1e-7)\n", + "# answer in the book is wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "To maintain vibrations in a colpitts oscilator,\n", + "hfe >= C2/C1\n", + "= 10\n", + "So the value of hfe of transistor used must be greater than 10\n", + "Frequency of oscillations produced\n", + "=*1e7 Hz 1.5\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 588" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex12_2 Pg-588\n", + "#calculate frequency of oscillations\n", + "import math\n", + "RL=3.3*10.**(3.) #load resistor in ohm\n", + "R=5.6*10.**(3.) #resistor R in ohm\n", + "C=0.001*10.**(-6.) #capacitance in farad\n", + "print '%s' %(\"For oscillations to be maintained in a RC oscillator\")\n", + "hfe=(23.+(29.*R/RL)+(4.*RL/R)) #transistor current gain\n", + "print '%s %.f' %(\"=\",hfe)\n", + "print '%s' %(\"Frequency of oscillations\")\n", + "f=1./(2.*math.pi*C*math.sqrt((4.*R*RL)+(6.*R**2.))) \n", + "#frequency of oscillation (textbook answer is wrong\n", + "# because of the used of wrong value of C)\n", + "print '%s %.1f' %(\"=Hz\",f)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "For oscillations to be maintained in a RC oscillator\n", + "= 75\n", + "Frequency of oscillations\n", + "=Hz 9831.1\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 588" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex12_3 Pg-588\n", + "#calculate Series resonant frequency,Q of the crystal\n", + "import math\n", + "L=0.33 #inductance in henry\n", + "C=0.065*10.**(-12.) #capacitance in farad\n", + "Cm=10.**(-12.) #capacitance in farad\n", + "R=0.55*10.**(3.) #resistor R in ohm\n", + "print '%s' %(\"Series resonant frequency, fs = 1/2*math.pi*math.sqrt(L*C)\")\n", + "fs=1./(2.*math.pi*math.sqrt(L*C))\n", + "print '%s %.2f' %(\"= MHz\",fs*1e-6)\n", + "print '%s' %(\"Q of the crystal = 2*pi*fs*L/R\")\n", + "Q=(2*math.pi*fs*L)/R #quality factor (textbook answer wrong)\n", + "print '%s %.0f' %(\"=\",Q)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Series resonant frequency, fs = 1/2*math.pi*math.sqrt(L*C)\n", + "= MHz 1.09\n", + "Q of the crystal = 2*pi*fs*L/R\n", + "= 4097\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 602" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex12_4 Pg-602\n", + "#calculate Series resonant frequency,The equialent parallel capacitance,Parallel resonant frequency\n", + "import math\n", + "L=3. #inductance in henry\n", + "Cs=0.05*10.**(-12.) #capacitance in farad\n", + "Cm=10.*10.**(-12.) #capacitance in farad\n", + "R=2.*10.**(3.) #resistor R in ohm\n", + "print '%s' %(\"Series resonant frequency, fs = 1/2*pi*sqrt(LC)\")\n", + "fs=1./(2.*math.pi*math.sqrt(L*Cs))\n", + "print '%s %.0f' %(\"= KHz\",fs*1e-3)\n", + "print '%s' %(\"The equialent parallel capacitance, Cp = Cm*Cs/Cm+Cs\")\n", + "Cp=Cm*Cs/(Cm+Cs) #quality factor \n", + "print '%s %.4f' %(\"= pF\",Cp*1e12)\n", + "print '%s' %(\"Parallel resonant frequency, fp = 1/2*pi*sqrt(L*Cp)\")\n", + "fp=1/(2*math.pi*math.sqrt(L*Cp))\n", + "print '%s %.0f' %(\"= kHz\",fp*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Series resonant frequency, fs = 1/2*pi*sqrt(LC)\n", + "= KHz 411\n", + "The equialent parallel capacitance, Cp = Cm*Cs/Cm+Cs\n", + "= pF 0.0498\n", + "Parallel resonant frequency, fp = 1/2*pi*sqrt(L*Cp)\n", + "= kHz 412\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 602" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex12_5 Pg-602\n", + "#calculate Fundamental frequency of oscillations of crystal\n", + "print '%s' %(\"Fundamental frequency of oscillations of crystal\")\n", + "print '%s' %(\"fr = K/t\")\n", + "print '%s' %(\"Let new thickness of the crystal be t''\")\n", + "print '%s' %(\"fr''/fr = t''/t = 99/100\")\n", + "print '%s' %(\"So, new frequency fr'' = k/t''\")\n", + "print '%s' %(\"or fr'' = (99/100)*fr\")\n", + "print '%s' %(\"or reduction in frequency,\")\n", + "print '%s' %(\"fr-fr'' = fr-(99/100)*fr\")\n", + "print '%s' %(\"= fr(1/100)\")\n", + "print '%s' %(\"or fr-fr''/fr = 1/100 \")\n", + "print '%s' %(\"Therefore, fr'' reduces by 1%\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Fundamental frequency of oscillations of crystal\n", + "fr = K/t\n", + "Let new thickness of the crystal be t''\n", + "fr''/fr = t''/t = 99/100\n", + "So, new frequency fr'' = k/t''\n", + "or fr'' = (99/100)*fr\n", + "or reduction in frequency,\n", + "fr-fr'' = fr-(99/100)*fr\n", + "= fr(1/100)\n", + "or fr-fr''/fr = 1/100 \n", + "Therefore, fr'' reduces by 1%\n" + ] + } + ], + "prompt_number": 5 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_14.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_14.ipynb new file mode 100755 index 00000000..5f27fbb8 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_14.ipynb @@ -0,0 +1,678 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:f640f9c0d6df8c078ebb5018ff3147d83b093b696c537e33a8131daa9eb77e6a" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 14 - Optical Fibers and Communications" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 695" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_1 Pg-695\n", + "#Cut-off wavelength\n", + "import math\n", + "n1=1.545 #core refracrive index\n", + "n2=1.510 #cladding refractive index\n", + "d=3.*10.**(-6.) #diamter of optical fiber in m\n", + "\n", + "a=d/2. #core radius in m\n", + "dela=(n1-n2)/n1 #fractional difference of refractive indices\n", + "lamda_c=(2.*math.pi*a*n1*math.sqrt(2.*dela))/2.405 #cut-off wavelength\n", + "print '%s %.2f %s' %(\"Cut-off wavelength =\",lamda_c*1e6,\"um\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Cut-off wavelength = 1.29 um\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 695" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_2 Pg-695\n", + "#Normalized frequency and total number of guided mode\n", + "import math\n", + "n1=1.53 #core refracrive index\n", + "n2=1.5 #cladding refractive index\n", + "lamda=10.**(-6.) #cut-off wavelength\n", + "a=50.*10.**(-6.) #core radius in m\n", + "\n", + "\n", + "V=(2.*math.pi*a*math.sqrt(n1**2.-n2**2.))/lamda #normalised frequency\n", + "print '%s %.2f %s' %(\"Normalised frequency =\",V,\"\\n\")\n", + "\n", + "ms=V**2./2. #total number of guided mode\n", + "print '%s %.2f %s' %(\"Total number of guided mode =\",ms,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Normalised frequency = 94.72 \n", + "\n", + "Total number of guided mode = 4485.74 \n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 695" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_3 Pg-695\n", + "#critical angle, acceptance angle, numerical aperture\n", + "import math\n", + "n1=1.5#core refracrive index\n", + "n2=1.46 #cladding refractive index\n", + "asin=1.\n", + "tetha_rad=math.asin(n2/n1) #critical angle in radians\n", + "tetha=tetha_rad*180./math.pi #critical angle in degree \n", + "print '%s %.2f %s' %(\"Critical angle =\",tetha,\"degree\\n\")\n", + "tetha_m_rad=math.asin(math.sqrt(n1**2.-n2**2.)) #acceptance angle in radians\n", + "tetha_m=tetha_m_rad*180./math.pi\n", + "print '%s %.2f %s' %(\"Acceptance angle =\",tetha_m,\"degree\\n\")\n", + "NA=math.sin(tetha_m_rad)\n", + "print '%s %.2f %s' %(\"Numerical Apperture =\",NA,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Critical angle = 76.74 degree\n", + "\n", + "Acceptance angle = 20.13 degree\n", + "\n", + "Numerical Apperture = 0.34 \n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 696" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_4 Pg-696\n", + "#calculate cladding refractive index and RI of the core\n", + "import math\n", + "NA=0.5 #numerical apperture\n", + "n1=1.54 #core refractive index\n", + "n2=math.sqrt(n1**2.-NA**2.) #cladding refractive index\n", + "print '%s %.2f %s' %(\"(1)Cladding refractive index =\",n2,\"\\n\")\n", + "RI=(n1-n2)/n1 #change in core cladding refractive index\n", + "print '%s %.2f %s' %(\"(2)RI of the core =\",RI,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1)Cladding refractive index = 1.46 \n", + "\n", + "(2)RI of the core = 0.05 \n", + "\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 696" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_5 Pg-696\n", + "#numerical aperture and max entrance angle \n", + "import math \n", + "n1=1.5#core refracrive index\n", + "n2=1.48 #cladding refractive index\n", + "n=1.\n", + "asin=1.\n", + "NA=math.sqrt(n1**2.-n2**2.) #numerical apperture\n", + "print '%s %.2f %s' %(\"(1)Numerical apperture =\",NA,\"\\n\")\n", + "AA_rad=math.asin(NA/n) #maximum Acceptance angle in rad\n", + "AA=AA_rad*180./math.pi #maximum entrance angle in degree\n", + "print '%s %.2f %s' %(\"(2)The maximum entrance angle i0 =\",AA,\"degree\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1)Numerical apperture = 0.24 \n", + "\n", + "(2)The maximum entrance angle i0 = 14.13 degree\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 697" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_6 Pg-697\n", + "#core refractive index, numerical aperture,maximum entrance angle\n", + "import math\n", + "n2=1.59 #cladding refractive index\n", + "NA=0.2 #numerical apperture\n", + "n0=1. #when fiber is in air\n", + "asin=1.\n", + "n1=math.sqrt(n2**2.+NA**2.) #core refractive index\n", + "print '%s %.2f %s' %(\"Core refractive index =\",n1,\"\\n\")\n", + "n=1.33 #water refractive index\n", + "NA=math.sqrt(n1**2.-n2**2.)/n0 #numerical apperture\n", + "print '%s %.2f %s' %(\"Numerical apperture =\",NA,\"\\n\")\n", + "AA_rad=math.asin(NA/n) #maximum Acceptance angle in rad\n", + "AA=AA_rad*180./math.pi #maximum entrance angle in degree\n", + "print '%s %.2f %s' %(\"The maximum entrance angle i0 =\",AA,\"degree\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Core refractive index = 1.60 \n", + "\n", + "Numerical apperture = 0.20 \n", + "\n", + "The maximum entrance angle i0 = 8.65 degree\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 697" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_7 Pg-697\n", + "#core refractive index, cladding refractive index\n", + "import math\n", + "NA=0.22 #numerical apperture\n", + "dela=0.012 #fractional difference of refractive indices\n", + "n1=NA/(math.sqrt(2.*dela)) #core refractive index\n", + "print '%s %.2f %s' %(\"Core refractive index =\",n1,\"\\n\")\n", + "n2=n1-dela*n1 #cladding refractive index\n", + "print '%s %.2f %s' %(\"Cladding refractive index =\",n2,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Core refractive index = 1.42 \n", + "\n", + "Cladding refractive index = 1.40 \n", + "\n" + ] + } + ], + "prompt_number": 25 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 698" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_8 Pg-698\n", + "#numerical aperture,acceptance angle, critical angle\n", + "import math\n", + "n1=1.52 #core refracrive index\n", + "n2=1.46 #cladding refractive index\n", + "dela=(n1-n2)/n1 #fractional difference of refractive indices\n", + "asin=1.\n", + "NA=n1*math.sqrt(2.*dela) #numerical apperture\n", + "print '%s %.2f %s' %(\"Numerical apperture =\",NA,\"\\n\")\n", + "AA_rad=math.asin(NA/n1) #maximum Acceptance angle in rad\n", + "AA=AA_rad*180./math.pi #maximum entrance angle in degree\n", + "print '%s %.2f %s' %(\"Acceptance angle i0 =\",AA,\"degree\\n\")\n", + "tetha_rad=math.asin(n2/n1) #critical angle in radians\n", + "tetha=tetha_rad*180./math.pi #critical angle in degree \n", + "print '%s %.2f %s' %(\"Critical angle =\",tetha,\"degree\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Numerical apperture = 0.43 \n", + "\n", + "Acceptance angle i0 = 16.32 degree\n", + "\n", + "Critical angle = 73.85 degree\n", + "\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 698" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_9 Pg-698\n", + "import math\n", + "n1=1.45 #core refracrive index\n", + "NA=0.16#cladding refractive index\n", + "lamda=0.9*10.**(-6.) #cut-off wavelength\n", + "d=60./100. #core radius in m\n", + "V=(math.pi*d*NA)/lamda #normalised frequency\n", + "print '%s %.2f %s' %(\"Normalised frequency =\",V*1e-5,\"*1e5\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Normalised frequency = 3.35 *1e5\n", + "\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E10 - Pg 698" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_10 Pg-698\n", + "#radis of core, numerical apperture, acceptance angle\n", + "import math \n", + "n1=1.48 #core refracrive index\n", + "n2=1.47 #cladding refractive index\n", + "lamda=850e-6 #cut-off wavelength\n", + "V=2.405 #normalised frequency\n", + "asin=1.\n", + "n=n1+n2\n", + "#In the book cut off wavelength in the question is 850 um but in\n", + "# the calcution part it is taken as 850nm. Here Ive taken 850um \n", + "d=V*lamda/(math.pi*math.sqrt(n1**2.-n2**2.)) #diamter of core\n", + "a=d/2. #radius of core\n", + "print '%s %.2f %s' %(\"Radius of core =\",a*1e3,\"mm\\n\")#answer in the book is wrong\n", + "NA=math.sqrt(n1**2.-n2**2.) #numerical apperture\n", + "print '%s %.2f %s' %(\"Numerical apperture =\",NA,\"\\n\")\n", + "AA_rad=math.asin(NA/n) #maximum Acceptance angle in rad\n", + "AA=AA_rad*180./math.pi #maximum entrance angle in degree\n", + "print '%s %.2f %s' %(\"Acceptance angle i0 =\",AA,\"degree\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Radius of core = 1.89 mm\n", + "\n", + "Numerical apperture = 0.17 \n", + "\n", + "Acceptance angle i0 = 3.34 degree\n", + "\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E11 - Pg 699" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_11 Pg-699\n", + "#loss in fiber\n", + "import math\n", + "L=500./1000. #length of fiber in m\n", + "Pin=1.*10.**(-3.) #input power in watt\n", + "Pout=85./100.*10.**(-3.) #output power in watt\n", + "alpha=(10./L)*math.log10(Pin/Pout) #loss\n", + "print '%s %.2f %s' %(\"Loss in the fiber =\",alpha,\"dB/Km\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Loss in the fiber = 1.41 dB/Km\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E12 - Pg 699" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_12 Pg-699\n", + "import math\n", + "L=10. #length of fiber in km\n", + "alpha=2.5 #loss in the fiber per km\n", + "Pin=500.*10.**(-6.) #input power in watt\n", + "tot_alpha=-1.*alpha*L #total loss in the fiber\n", + "Pout=Pin*10.**(tot_alpha/10.) #output power in watt\n", + "print '%s %.2f %s' %(\"Output power =\",Pout*1e6,\"uW\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Output power = 1.58 uW\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E13 - Pg 700" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_13 Pg-700\n", + "#Maximum core diameter which permit single mode operation\n", + "import math \n", + "dela=1./100. #fractional difference of refractive indices\n", + "lamda=1.3*10.**(-6.) #cutoff wavelength in m\n", + "n1=1.5 #refractive index\n", + "d=6.6*10.**(-6.) #diameter of the core\n", + "alpha=2. #loss in fiber\n", + "print'%s' %(\"We have for a GRIN , maximum value of normalized frequency for single mode operation is given by\")\n", + "print'%s' %(\"V = 2.4*math.sqrt(1+2/alpha)\")\n", + "V=2.4*math.sqrt(1.+2./alpha) #normalzed frequency\n", + "print'%s' %(\"For maximum core radiation , we have\")\n", + "r=V*lamda/(2.*math.pi*n1*math.sqrt(2.*dela)) #radius of the core\n", + "print'%s %.2f %s' %(\"r =\",r*1e6,\"um\\n\")\n", + "rr=2.*r #diameter of the core\n", + "print'%s %.2f %s' %(\"\\nMaximum core diameter which permit single mode operation\\n=2*r =\",rr*1e6,\"um\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We have for a GRIN , maximum value of normalized frequency for single mode operation is given by\n", + "V = 2.4*math.sqrt(1+2/alpha)\n", + "For maximum core radiation , we have\n", + "r = 3.31 um\n", + "\n", + "\n", + "Maximum core diameter which permit single mode operation\n", + "=2*r = 6.62 um\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E14 - Pg 700" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_14 Pg-700\n", + "#Maximum core diameter which permit single mode operation\n", + "import math\n", + "dela=1.5/100. #fractional difference of refractive indices\n", + "lamda=0.85*10.**(-6.) #cutoff wavelength in m\n", + "n1=1.48 #refractive index\n", + "d=6.6*10.**(-6.) #diameter of the core\n", + "V=2.4 #normalzed frequency\n", + "print '%s' %(\"For maximum core radiation,we have\")\n", + "r=V*lamda/(2.*math.pi*n1*math.sqrt(2.*dela))\n", + "print '%s %.2f %s' %(\"r=\",r*1e6,\"um\\n\")\n", + "r=1.3*10.**(-6.) #actual radius=1.266 micrometer and assumed to 1.3 micometer\n", + "rr=2.*r #diameter of the core\n", + "print '%s %.2f %s' %(\"\\nMaximum core diameter which permit single mode operation\\n=2*r=\",rr*1e6,\"um\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "For maximum core radiation,we have\n", + "r= 1.27 um\n", + "\n", + "\n", + "Maximum core diameter which permit single mode operation\n", + "=2*r= 2.60 um\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E15 - Pg 701" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_15 Pg-701\n", + "#attenuation of an optial fiber, output power\n", + "import math\n", + "alpha=3.5 #loss in fiber\n", + "Pi=0.5#input power in milli watt\n", + "L=4. #length of fiber in km\n", + "print '%s' %(\"The attenuation of an optical fiber is given by\")\n", + "print '%s' %(\"alpha=(10/L)*math.log(Pi/Po)\")\n", + "Po=Pi/(10.**(alpha*L/10.))\n", + "print '%s %.2f %s' %(\"\\nOutput power =\",Po*1e3,\"mW\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The attenuation of an optical fiber is given by\n", + "alpha=(10/L)*math.log(Pi/Po)\n", + "\n", + "Output power = 19.91 mW\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E16 - Pg 701" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex14_16 Pg-701\n", + "#cut-off wavelength expression\n", + "import math\n", + "n1=1.46 #core refracrive index\n", + "r=4.5*10.**(-6.) #radius of the core\n", + "dela=0.25/100. #fractional difference of refractive indices\n", + "Vc=2.405 #normalzed frequency\n", + "print '%s' %(\"We have, cut-off wavelength expression\")\n", + "lamda=(2*math.pi*r*n1*math.sqrt(2.*dela))/Vc\n", + "print '%s %.2f %s' %(\"=\",lamda*1e6,\"um\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We have, cut-off wavelength expression\n", + "= 1.21 um\n" + ] + } + ], + "prompt_number": 18 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_15.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_15.ipynb new file mode 100755 index 00000000..6a69bc61 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_15.ipynb @@ -0,0 +1,354 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:a909a7db08a7758f81190506b42caa1478b1be849707f941d9b31e833e8c5e3b" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 15 - Communication System" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 773" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_1 Pg-773\n", + "#calculte Total power\n", + "Pc=10000. #carrier input power in watt\n", + "m=30./100. #modulation of 30%\n", + "print '%s' %(\"Total power = carrier power*(1+m**2/2)\")\n", + "Pt=Pc*(1.+m**2./2.) #total power\n", + "print '%s %.2f' %(\" = W\",Pt*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total power = carrier power*(1+m**2/2)\n", + " = W 10.45\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 774" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_2 Pg-774\n", + "#calculte Total current\n", + "import math\n", + "Ic=100. #carrier current in A\n", + "m=80./100. #modulation of 80%\n", + "print '%s' %(\"Total current = carrier current*(1+m**2/2)\")\n", + "It=Ic*math.sqrt(1.+m**2./2.) #total power\n", + "print '%s %.1f' %(\" = A\",It)\n", + "change_I=It-Ic #change in current\n", + "print '%s %.1f' %(\"Therefore, increase in current due to modulation = A\",change_I)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total current = carrier current*(1+m**2/2)\n", + " = A 114.9\n", + "Therefore, increase in current due to modulation = A 14.9\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 774" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_3 Pg-774\n", + "#calculte Modulation Factor,Amplitude of each sideband,Frequenc of sidebands,Bandwidth of the wave\n", + "Em=5. #modulated wave amplitude\n", + "Ec=100. #carrier wave amplitude\n", + "Fm=50. #frequency of modulated wave\n", + "Fc=10.*10.**(3.) #frequency of carrier wave \n", + "print '%s' %(\"(1)Modulation Factor\")\n", + "m=Em/Ec #modulation factor\n", + "per_m=m*100. #modulation factor in percentage\n", + "print '%s %.0f' %(\"m =\",per_m)\n", + "print '%s' %(\"(2)Amplitude of each sideband = m*Ec/2\")\n", + "Amp=m*Ec/2. #amplitude of each sideband\n", + "print '%s %.1f' %(\"=\",Amp)\n", + "USB=Fc+Fm #upper side band\n", + "LSB=Fc-Fm #lower side band\n", + "print '%s' %(\"(3)Frequenc of sidebands\")\n", + "print '%s %.0f' %(\"USB = Hz\",USB)\n", + "print '%s %.0f' %(\"LSB = Hz\",LSB)\n", + "print '%s' %(\"(4) Bandwidth of the wave\")\n", + "BW=2*Fm #Bandwidth\n", + "print '%s %.0f' %(\"BW =\",BW)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1)Modulation Factor\n", + "m = 5\n", + "(2)Amplitude of each sideband = m*Ec/2\n", + "= 2.5\n", + "(3)Frequenc of sidebands\n", + "USB = Hz 10050\n", + "LSB = Hz 9950\n", + "(4) Bandwidth of the wave\n", + "BW = 100\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 774" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_4 Pg-774\n", + "#calculte Modulation factor\n", + "Vmax=600. #peak to peak voltage\n", + "Vmin=100. #valley to valley voltage\n", + "print '%s' %(\"From figure 15.49, we have\")\n", + "m=(Vmax-Vmin)/(Vmax+Vmin) #modulation factor\n", + "per_m=m*100. #modulation factor in percentage\n", + "print '%s %.1f' %(\"Modulation factor = \",per_m )\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "From figure 15.49, we have\n", + "Modulation factor = 71.4\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 775" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_5 Pg-775\n", + "#calculte Modulation factor,Carrier Amplitude,omega,Signal frequency,Emax ,Emin,BW\n", + "import math\n", + "print '%s' %(\"The standard equation of AM wave is\")\n", + "print '%s' %(\" e = Ec*(1+m*sin(omega_m*t)*sin(omega_c*t)) -->eqn 1\")\n", + "print '%s' %(\"Given the equation\")\n", + "print '%s' %(\" e = 20*(1+0.7*sin(6280*t)*sin(628000*t)) --eqn 2\")\n", + "print '%s' %(\"Comparing eqn 1 and eqn 2 one obtains\")\n", + "print '%s' %(\"(1)Modulation factor, m = 0.7\")\n", + "m=0.7 #modulation factor\n", + "print '%s' %(\"(2)Carrier Amplitude, Ec = 20 V\")\n", + "Ec=20. #carrier wave amplitude in V\n", + "print '%s' %(\"(3)omega_m = 6280\")\n", + "omega_m=6280 #modulating frequency\n", + "Fm=omega_m/(2.*math.pi) #signal frequency\n", + "print '%s %.0f' %(\"Signal frequency = kHz\",Fm*1e-3)\n", + "omega_c=628000. #carrier frequency in Hz\n", + "Fc=omega_c/(2.*math.pi) \n", + "print '%s %.0f' %(\"(4)Signal frequency = kHz\",Fc*1e-3)\n", + "Emax=Ec+m*Ec #minimum amplitude of wave\n", + "print '%s %.0f' %(\"(5)Emax = V\",Emax)\n", + "Emin=Ec-m*Ec #minimum amplitude of wave\n", + "print '%s %.0f' %(\"(5)Emin = V\",Emin)\n", + "BW=2.*Fm #Bandwidth\n", + "print '%s %.0f' %(\"(6)BW = kHZ\",BW*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The standard equation of AM wave is\n", + " e = Ec*(1+m*sin(omega_m*t)*sin(omega_c*t)) -->eqn 1\n", + "Given the equation\n", + " e = 20*(1+0.7*sin(6280*t)*sin(628000*t)) --eqn 2\n", + "Comparing eqn 1 and eqn 2 one obtains\n", + "(1)Modulation factor, m = 0.7\n", + "(2)Carrier Amplitude, Ec = 20 V\n", + "(3)omega_m = 6280\n", + "Signal frequency = kHz 1\n", + "(4)Signal frequency = kHz 100\n", + "(5)Emax = V 34\n", + "(5)Emin = V 6\n", + "(6)BW = kHZ 2\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 776" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_6 Pg-776\n", + "#calculte Total power\n", + "Pc=10000. #carrier power in watt\n", + "m=0.9 #modulation factor\n", + "print '%s' %(\"We have\")\n", + "print '%s' %(\"Total power = carrier power*(1+m**2/2)\")\n", + "Pt=Pc*(1.+m**2./2.) #total power\n", + "print '%s %.0f' %(\" = kW\",Pt*1e-3)\n", + "print '%s' %(\"This will be the maximum power handeled by the transmitter.\\nNow,increased unmodulated carrier power can be obtained by\")\n", + "m=40./100. #modulation in terms of percentage\n", + "Pt=14000. #total power\n", + "Pc=Pt/(1.+m**2./2.) #neew carrier power\n", + "print '%s %.2f' %(\"Pc = kW\",Pc*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We have\n", + "Total power = carrier power*(1+m**2/2)\n", + " = kW 14\n", + "This will be the maximum power handeled by the transmitter.\n", + "Now,increased unmodulated carrier power can be obtained by\n", + "Pc = kW 12.96\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 776" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex15_7 Pg-776\n", + "#calculte standard equations for modulated voltage wave\n", + "import math\n", + "print '%s' %(\"Given the equation\")\n", + "print '%s' %(\"\\nE = 100*sin(628000*t)+25*sin(621720*t)\\n-25*cos(634280*t))\\n\")\n", + "m=50./100. #modulation factor in percentage\n", + "Ec=100. #carrier wave amplitude in V\n", + "Em=10. #modulated wave amplitude in V\n", + "Fc=100000. #carier frequency in Hz\n", + "Fm=1000. #modulating frequency in Hz\n", + "pi=3.14 \n", + "omega_c=2.*pi*Fc #carier frequency\n", + "omega_m=2.*pi*Em #modulating frequency \n", + "print '%s' %(\"Now,putting these equation in the standard equations for modulated voltage wave,\")\n", + "print '%s' %(\" e = Ec*sin(omega_c*t)+m*Ec/2*cos(omega_c-omega_m)*t-m*Ec/2*cos(omega_c-omega_m)*t\")\n", + "USB=omega_c+omega_m #upper sideband\n", + "LSB=omega_c-omega_m #lower sideband\n", + "mEc=m*Ec/2.\n", + "print '%s %.0f' %(\"\\n=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t))\",mEc)\n", + "print '%s %.0f' %(\"\\n=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t))\",USB)\n", + "print '%s %.0f' %(\"\\n=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t))\",mEc)\n", + "print '%s %.0f' %(\"\\n=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t))\",LSB)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Given the equation\n", + "\n", + "E = 100*sin(628000*t)+25*sin(621720*t)\n", + "-25*cos(634280*t))\n", + "\n", + "Now,putting these equation in the standard equations for modulated voltage wave,\n", + " e = Ec*sin(omega_c*t)+m*Ec/2*cos(omega_c-omega_m)*t-m*Ec/2*cos(omega_c-omega_m)*t\n", + "\n", + "=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t)) 25\n", + "\n", + "=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t)) 628063\n", + "\n", + "=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t)) 25\n", + "\n", + "=100*sin(628000*t)+%.0f*sin(%.0f*t)-%.0f*cos(%.0f*t)) 627937\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_18.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_18.ipynb new file mode 100755 index 00000000..3cfc1964 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_18.ipynb @@ -0,0 +1,346 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:c96c12c91d19e317b71f22330124bbbc087ab88786dc882f203c4649ecee2c94" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 18 - Optoelectronic Devices" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 901" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_1 Pg-901\n", + "#calculate Source resistance,Wattage rating\n", + "Vs=12. #supply voltage in V\n", + "Vd=2. #forward bias voltage in V\n", + "Id=20.*10.**(-3.) #forward bias current\n", + "Rs=(Vs-Vd)/Id #source resistor\n", + "print '%s %.0f' %(\"Source resistance = ohm\",Rs)\n", + "P=Id**2.*Rs #power\n", + "print '%s %.1f' %(\"Wattage rating = mW\",P*1e3)\n", + "print '%s' %(\"Therefore a standard size 0.25 watt = 250mW resistor is required\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Source resistance = ohm 500\n", + "Wattage rating = mW 200.0\n", + "Therefore a standard size 0.25 watt = 250mW resistor is required\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 945" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_2 Pg-945\n", + "#calculate R\n", + "import math\n", + "T=2000. #temperature in Kelvin\n", + "f=5.*10.**(14.) # frequency in Hz\n", + "h=6.6*10.**(-34.) #planck constant\n", + "k=1.38*10.**(-23.) #Boltzmann constant\n", + "R=math.exp((h*f)/(k*T)) #ratio of spontaneous and stimulated emisson\n", + "print '%s %.2f' %(\"R =\",R*1e-5)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "R = 1.56\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 946" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_3 Pg-946\n", + "#calculate Average wavelength of visible radiation\n", + "import math\n", + "print '%s' %(\"Average wavelength of visible radiation = 550 nm\")\n", + "print '%s' %(\" E1 - E2 = hc/lamda\")\n", + "h=6.6*10.**(-34.) #planck constant\n", + "c=3.*10.**(8.) #speed of light in sec\n", + "lamda= 550.*10.**(-9.) #wavelength in m\n", + "E=h*c/lamda #difference in energy levels in Joules\n", + "e=1.6*10.**(-19.) #electron charge in eV\n", + "E_eV=E/e #difference in energy levels in electronVolt\n", + "print '%s %.1f' %(\" = J\",E*1e19)\n", + "print '%s %.2f' %(\" = eV\",E_eV)\n", + "T=300. #temperature in Kelvn\n", + "k=1.38*10.**(-23.) #Boltzmann constant\n", + "print '%s' %(\"Average room temperature=300K and g1=g2,we have\")\n", + "N=math.exp((-E)/(k*T))\n", + "print '%s %.2f' %(\"N2/N1 =\",N*1e37)\n", + "#answer in the book is wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average wavelength of visible radiation = 550 nm\n", + " E1 - E2 = hc/lamda\n", + " = J 3.6\n", + " = eV 2.25\n", + "Average room temperature=300K and g1=g2,we have\n", + "N2/N1 = 0.17\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 946" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_4 Pg-946\n", + "#calculate Energy absorbed,recombination radiation\n", + "import math\n", + "w=0.3*10.**(-6.)*100. #width of silicon in cm\n", + "alpha=4.*10.**(4.) \n", + "phi=10.**(-2.)\n", + "e=1.6*10.**(-19.) #electron charge in eV\n", + "print '%s' %(\"(1)Energy absorbed/sec is given by \")\n", + "E=phi*(1.-math.exp(alpha*w)) #energy absorbed(textbook answer is wrong)\n", + "print '%s %.1f' %(\" = mW\",abs(E)*1e3)\n", + "print '%s' %(\"(2)The portion of each photo energy that is converted into heat is obtained as hv-Eg/hv\")\n", + "Heat=(3-1.12)/3.*100. #photon energy coverted to heat\n", + "print '%s %.0f' %(\" = \",Heat)\n", + "E1=(62./100.)*0.0232 #energy dissipated/sec (textbook answer is wrong)\n", + "print '%s %.1f' %(\"\\nObviously, the amount of energy dissipated/sec to lattice is = mW\",E1*1e3)\n", + "print '%s' %(\"(3)Number of photons/sec from recombination is\")\n", + "num_photons=2.4/(e*1.12)\n", + "print '%s %.1f' %(\" = photon/sec\",num_photons*1e-19)\n", + "#textbook answer is wrong\n", + "print '%s' %(\"Therefore recombination radiation\")\n", + "RR=abs(E)-E1 #recombination radiation (textbok answer is wrong)\n", + "print '%s %.1f' %(\" = mW\",RR*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1)Energy absorbed/sec is given by \n", + " = mW 23.2\n", + "(2)The portion of each photo energy that is converted into heat is obtained as hv-Eg/hv\n", + " = 63\n", + "\n", + "Obviously, the amount of energy dissipated/sec to lattice is = mW 14.4\n", + "(3)Number of photons/sec from recombination is\n", + " = photon/sec 1.3\n", + "Therefore recombination radiation\n", + " = mW 8.8\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 947" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_5 Pg-947\n", + "#calculate Time taken to diffuse\n", + "d=5.*10.**(-6.) #thickness of silicon in m\n", + "Dc=3.4*10.**(-3.) #diffusion coefficient in m**2sec**(-1)\n", + "t=d**2./(2.*Dc) #time taken to diffuse\n", + "print '%s %.1f' %(\"Time taken to diffuse = sec\",t*1e9)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Time taken to diffuse = sec 3.7\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 947" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_6 Pg-947\n", + "#calculate Diode capacitance\n", + "import math\n", + "A=10.**(-6.) #diode area in m\n", + "epsilon_r=11.7 #relative permitivity \n", + "Nd=10.**(21.) #number of doping carriers\n", + "V=10. #bias potential in V\n", + "e=1.6*10.**(-19.) #electron charge in eV\n", + "epsilon_0=8.85*10.**(-12.) #permitivity of free space\n", + "Cj=A/2.*math.sqrt(2.*e*epsilon_r*epsilon_0*Nd)/math.sqrt(V)\n", + "print '%s %.f' %(\"Diode capacitance = pF\",Cj*1e12)\n", + "#textbook answer is wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Diode capacitance = pF 29\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 947" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_7 Pg-947\n", + "#calculate Gain\n", + "import math\n", + "L=10.**(-6.) #length of cavity in m\n", + "r2=0.5 #relative coefficient of semiconductor\n", + "r1=1.5 #relative coefficient of semiconductor\n", + "print '%s' %(\"No internal loss means di=0; we have\")\n", + "g=math.log10(1./(r1*r2))/(2.*L) #gain of the laser (textbook answer is wrong)\n", + "print '%s %.2f' %(\"Gain g = cm**(-1)\",g*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "No internal loss means di=0; we have\n", + "Gain g = cm**(-1) 62.47\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 947" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex18_8 Pg-947\n", + "#calculate gain\n", + "L=100.*10.**(-6.) #length of semiconductor in m\n", + "A=10.**(-7.) #area of semiconductor in cm**2\n", + "V=10. #applied voltage in V\n", + "mew_n=1350. #mobility of electrons \n", + "mew_p=480. #mobiltiy of protons\n", + "tp=10.**(-6.) #lifetime of protons in sec\n", + "tn=L/(mew_n*V) #lifetime of electrons in sec\n", + "Gain=tp/tn*(1+(mew_p/mew_n)) #gain of photoconductor\n", + "print '%s %.2f' %(\"Gain =\",Gain*1e-2)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Gain = 1.83\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_19.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_19.ipynb new file mode 100755 index 00000000..30dff9c1 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_19.ipynb @@ -0,0 +1,1129 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:6ebc3f292ace645106ed2da65b1d2986f934b4426d48b029320345efeadbaceb" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 19 - Digital Electronics" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 957" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_1 Pg-957 \n", + "#calculate decimal equivqlent of 101\n", + "a=\"101\"\n", + "b=int(a,base=2)\n", + "print'%s %.f'%(\"The decimal equivqlent of 101 is\",b)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 101 is 5\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 958" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_2 Pg-958\n", + "#decimal equivqlent of 11101\n", + "bina='11101'; #binary input\n", + "dec=int(bina,base=2) #decimal output\n", + "print(\"The decimal equivqlent of 11101 is\")\n", + "print(dec)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 11101 is\n", + "29\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 958" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_3 Pg-958\n", + "#decimal equivqlent of 0.101\n", + "a=1\n", + "b=0\n", + "c=1\n", + "dec=a*2**(-1)+b*2**(-2)+c*2**(-3) #decimal output\n", + "print(\"The decimal equivqlent of 0.101 is\")\n", + "print(dec)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 0.101 is\n", + "0.625\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 958" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_4 Pg-958\n", + "#The decimal equivqlent of 0.1101\n", + "a=1\n", + "b=1\n", + "c=0\n", + "d=1\n", + "dec=a*2**(-1)+b*2**(-2)+c*2**(-3)+d*2**(-4) #decimal output\n", + "print(\"The decimal equivqlent of 0.1101 is\")\n", + "print(dec)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 0.1101 is\n", + "0.8125\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 958" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_5 Pg-958 \n", + "# decimal equivqlent of 10101.101\n", + "#Integer part\n", + "bina='10101'; #binary input\n", + "dec_I=int(bina,base=2) #decimal output\n", + "\n", + "#Decimal part\n", + "a=1\n", + "b=0\n", + "c=1\n", + "dec_D=a*2**(-1)+b*2**(-2)+c*2**(-3)\n", + "dec=dec_I+dec_D #decimal output\n", + "print(\"The decimal equivqlent of 10101.101 is\")\n", + "print(dec)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 10101.101 is\n", + "21.625\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 959" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_6 Pg-959\n", + "#binary equivalent of 9\n", + "dec=9 #decimal input\n", + "bina=bin(dec) #binary output\n", + "print(\"The binary equivalent of 9 is\")\n", + "print(bina)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The binary equivalent of 9 is\n", + "0b1001\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 959" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_7 Pg-959 \n", + "#binary equivalent of 31\n", + "dec=31 #decimal input\n", + "bina=bin(dec) #binary output\n", + "print(\"The binary equivalent of 31 is\")\n", + "print(bina)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The binary equivalent of 31 is\n", + "0b11111\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 959" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_8 Pg-959 \n", + "#binary equivalent of 13\n", + "dec=13 #decimal input\n", + "bina=bin(dec) #binary output\n", + "print(\"The binary equivalent of 13 is\")\n", + "print(bina)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The binary equivalent of 13 is\n", + "0b1101\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 960" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_9 Pg-960\n", + "#Conversion of decimal number 31.65 base to its binary equivalent\n", + "import math\n", + "print(\"Conversion of decimal number 31.65 base to its binary equivalent \")\n", + "a=31.65;\n", + "z=a%1\n", + "x=math.floor(a);#separating the decimal from the integer part\n", + "b=0;\n", + "c=0;\n", + "d=0;\n", + "while(x>0): #taking integer part into a matrix and convert to equivalent binary\n", + "\ty=x%2;\n", + "\tb=b+(10**c)*y;\n", + "\tx=x/2.;\n", + "\tx=math.floor(x);\n", + "\tc=c+1;\n", + "\n", + "for i in range(1,10):#converting the values after the decimal point into binary\n", + " z=z*2;\n", + " q=math.floor(z);\n", + " d=d+q/(10**i);\n", + " if z>=1:\n", + " \tz=z-1;\n", + "\n", + "s=b+d;\n", + "print s\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Conversion of decimal number 31.65 base to its binary equivalent \n", + "11111.1010011\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E10 - Pg 961" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_10 Pg-961\n", + "#Calculate the decimal equivqlent of 1111 and 1111111\n", + "a1=\"1111\"\n", + "b1=int(a1,base=2)\n", + "print'%s %.f'%(\"(a)The decimal equivqlent of 1111 is\",b1)\n", + "a2=\"1111111\"\n", + "b2=int(a2,base=2)\n", + "print'%s %.f'%(\"(b)The decimal equivqlent of 1111111 is\",b2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)The decimal equivqlent of 1111 is 15\n", + "(b)The decimal equivqlent of 1111111 is 127\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E11 - Pg 962" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_11 Pg-962 \n", + "#calculate The decimal equivqlent of 23\n", + "a=\"23\"\n", + "b=int(a,base=8)\n", + "print'%s %.f'%(\"The decimal equivqlent of 23 is =\",b)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 23 is = 19\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E12 - Pg 962" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_12 Pg-962 \n", + "#calculate The decimal equivqlent of 23\n", + "a=\"257\"\n", + "b=int(a,base=8)\n", + "print'%s %.f'%(\"The decimal equivqlent of 257 is =\",b)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivqlent of 257 is = 175\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E13 - Pg 962" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_13 Pg-962 \n", + "#calculate The octal equivqlent of 257\n", + "a=\"175\"\n", + "b=oct(175)\n", + "print b\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0257\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E14 - Pg 963" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_14 Pg-963\n", + "#calculate the octal equivalent of 0.85\n", + "a=.85\n", + "b=.5\n", + "octal=int(a*8.) \n", + "octal2=int(b*64.)\n", + "print 'In octal representation it is .',octal,octal2\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In octal representation it is . 6 32\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E15 - Pg 963" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_15 Pg-963\n", + "a='34' #octal input\n", + "b=int(a,base=8) #decimal output\n", + "print b" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "28\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E16 - Pg 963" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_16 Pg-963\n", + "x='357'\n", + "decimal=int(x,base=8) #to convert octal to decimal\n", + "binary=bin(decimal) #to convert binary to decimal\n", + "print 'In decimal=',decimal\n", + "print'In binary = ',binary" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In decimal= 239\n", + "In binary = 0b11101111\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E17 - Pg 963" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_17 Pg-963\n", + "#Integer part\n", + "bina='1011'; #binary input\n", + "dec_I=int(bina,base=2) #decimal output\n", + "oct_I=oct(dec_I) #octal output\n", + "\n", + "#Decimal part\n", + "bina2='11010'; #binary input\n", + "dec_D=int(bina2,base=2) #decimal output\n", + "oct_D=oct(dec_D) #octal output\n", + "octa=oct_I + oct_D #final octal output\n", + "b = ([oct_I, oct_D ]) # combining intger and decimal part\n", + "print(\"The octal equivqlent of 1011.01101 is\")\n", + "print(b)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The octal equivqlent of 1011.01101 is\n", + "['013', '032']\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E18 - Pg 965" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_18 Pg-965\n", + "hexa='9AF' #hexadecimal input\n", + "dec=int(hexa,base=16) #decimal output\n", + "bina=bin(dec) #binary output\n", + "print(\"The binary equivalent of 9AF is\")\n", + "print(bina)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The binary equivalent of 9AF is\n", + "0b100110101111\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E19 - Pg 965" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_19 Pg-965\n", + "hexa='C5E2' #hexadecimal input\n", + "dec=int(hexa,base=16) #decimal output\n", + "bina=bin(dec) #binary output\n", + "print(\"The binary equivalent of C5E2 is\")\n", + "print(bina)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The binary equivalent of C5E2 is\n", + "0b1100010111100010\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E20 - Pg 957" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_20 Pg-957 \n", + "bina='10001100'; #binary input\n", + "dec=int(bina,base=2) #decimal output\n", + "hexa=hex(dec) #hexadecimal output\n", + "print(\"The hexadecimal equivqlent of 10001100 is\")\n", + "print(hexa)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The hexadecimal equivqlent of 10001100 is\n", + "0x8c\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E21 - Pg 965" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_21 Pg-965\n", + "#Integer part\n", + "hexa='F8E6'; #binary input\n", + "dec_I=int(hexa,base=16) #decimal output\n", + "\n", + "#Decimal part\n", + "a=3 \n", + "b=9\n", + "dec=dec_I+a*16**(-1)+b*16**(-2) #decimal output \n", + "print(\"The decimal equivalent of F8E6.39 is\")\n", + "print(dec)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The decimal equivalent of F8E6.39 is\n", + "63718.2226562\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E22 - Pg 996" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_22 Pg-966\n", + "dec=2479 #decimal input\n", + "hexa=hex(dec) #hexadecimal output\n", + "print(\"The Hexadecimal equivalent of 2479 is\")\n", + "print(hex)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The Hexadecimal equivalent of 2479 is\n", + "\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E23 - Pg 966" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_23 Pg-966\n", + "dec=65535 #decimal input\n", + "hexa=hex(dec) #hexadecimal output\n", + "print(\"The Hexadecimal equivalent of 65535 is\")\n", + "print(hexa)\n", + "\n", + "bina=bin(dec) #binary output\n", + "print(\"The Binary equivalent of 65535 is \")\n", + "print(bina)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The Hexadecimal equivalent of 65535 is\n", + "0xffff\n", + "The Binary equivalent of 65535 is \n", + "0b1111111111111111\n" + ] + } + ], + "prompt_number": 25 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E24 - Pg 969" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_24 Pg-969\n", + "x=int('11100',2) #1st input\n", + "y=int('11010',2) #2nd input\n", + "z=x+y #binary addition\n", + "add=bin(z)\n", + "print(\" 11100 + 11010 = \")\n", + "print(add)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 11100 + 11010 = \n", + "0b110110\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E25 - Pg 970" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_25 Pg-970\n", + "x=int('1101',2) #1st input\n", + "y=int('1010',2) #2nd input\n", + "z=x-y #subtraction\n", + "sub=bin(z)\n", + "print(\"1101-1010 =\")\n", + "print(sub)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1101-1010 =\n", + "0b11\n" + ] + } + ], + "prompt_number": 29 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E26 - Pg 970" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_26 Pg-970\n", + "x=200 #1st input\n", + "y=125 #2nd input\n", + "z=x-y #subtraction\n", + "print(\"For decimal system 200 - 125 = \")\n", + "print(z)\n", + "\n", + "a=hex(z) #hexadeciaml output of 200-125\n", + "print(\"For hexadecimal system C8 - 7D is\")\n", + "print(a)\n", + "\n", + "b=bin(z) #binary output of 200-125\n", + "print(\"For binary system 11001000 - 01111101 is\")\n", + "print(b)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "For decimal system 200 - 125 = \n", + "75\n", + "For hexadecimal system C8 - 7D is\n", + "0x4b\n", + "For binary system 11001000 - 01111101 is\n", + "0b1001011\n" + ] + } + ], + "prompt_number": 30 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E27 - Pg 997" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_27 Pg-997\n", + "print(\"(A+B)(A+C) = AA + AC + AB + BC \")\n", + "#by distributive law\n", + "print(\" = A + AC + AB +BC\")\n", + "#by theorem(6)\n", + "print(\" = A(1 + C) + AB + BC\")\n", + "#by distributive law\n", + "print(\" = A.1 + AB + BC \")\n", + "#by theorem(3)\n", + "print(\" = A(B + 1) + BC\")\n", + "#by distributive law\n", + "print(\" = A + BC\")\n", + "print(\"Therefore (A+B)(A+C) = A + BC\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(A+B)(A+C) = AA + AC + AB + BC \n", + " = A + AC + AB +BC\n", + " = A(1 + C) + AB + BC\n", + " = A.1 + AB + BC \n", + " = A(B + 1) + BC\n", + " = A + BC\n", + "Therefore (A+B)(A+C) = A + BC\n" + ] + } + ], + "prompt_number": 31 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E28 - Pg 998" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_28 Pg-998\n", + "print(\"AB + A(B + C) + B(B + C) = AB + AB + AC + BB + BC\")\n", + "#using distributive law\n", + "print(\" = AB + AC + B +BC \")\n", + "#using law 6\n", + "print(\" = AB + AC + B(1 + C) \")\n", + "#taking common B from B + BC \n", + "print(\" = AB + AC + B\")\n", + "#using law 7 \n", + "print(\" = B(A + 1) + AC\")\n", + "#taking common B from AB + B\n", + "print(\" = B + AC\")\n", + "#using law 7\n", + "print(\"Therefore AB + A(B + C) + B(B + C) = B + AC\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "AB + A(B + C) + B(B + C) = AB + AB + AC + BB + BC\n", + " = AB + AC + B +BC \n", + " = AB + AC + B(1 + C) \n", + " = AB + AC + B\n", + " = B(A + 1) + AC\n", + " = B + AC\n", + "Therefore AB + A(B + C) + B(B + C) = B + AC\n" + ] + } + ], + "prompt_number": 32 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E30 - Pg 998" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_30 Pg-998\n", + "# question in the textbook is wrong7 \n", + "print(\"LHS : (A + B + C)(A + B + C) \")\n", + "print(\" = AA + AB + AC + BA + BB +BC + CA + CB + CC\")\n", + "#using distributive law\n", + "print(\" = A + AB + AC + BA + B +BC + CA + CB + C\")\n", + "#using law 6\n", + "print(\" = A + AB + AC +BC + CB + C\")\n", + "#using law 5\n", + "print(\" = A(B + 1) + AC + B + C(B + 1)\")\n", + "#taking A common from A+AB and C from CB+C\n", + "print(\" = A + AC + B + C\")\n", + "#using law 3\n", + "print(\" = A + B + C(A + 1)\")\n", + "#taking common C from AC+C\n", + "print(\" = A + B + C\")\n", + "#using law 3\n", + "print(\"Therefore (A'' + B + C)(A'' + B'' + C) = A'' + C\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "LHS : (A + B + C)(A + B + C) \n", + " = AA + AB + AC + BA + BB +BC + CA + CB + CC\n", + " = A + AB + AC + BA + B +BC + CA + CB + C\n", + " = A + AB + AC +BC + CB + C\n", + " = A(B + 1) + AC + B + C(B + 1)\n", + " = A + AC + B + C\n", + " = A + B + C(A + 1)\n", + " = A + B + C\n", + "Therefore (A'' + B + C)(A'' + B'' + C) = A'' + C\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E31 - Pg 999" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex19_31 Pg-999\n", + "print(\"LHS : (A+ C)(A'' + B) \")\n", + "print(\" = AA'' + AB + CA'' + BC\") #using distributive law\n", + "print(\" = 0 + AB + CA'' + BC\") #using law 8\n", + "print(\" = AB + (A + A'')BC + CA''\") #using law 7\n", + "print(\" = AB + ABC + A''BC + CA''\") \n", + "#using distributive law\n", + "print(\" = AB + ABC + A''C(B + 1)\") \n", + "#taking common A'C from A'BC + CA'\n", + "print(\" = AB + ABC + A''C\") #using law 3\n", + "print(\" = AB(C + 1)+ A''C\") \n", + "#taking common AB from AB + ABC\n", + "print(\" = AB + A''C\") #using law 3\n", + "print(\"Therefore (A+ C)(A'' + B) = AB + A''C\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "LHS : (A+ C)(A'' + B) \n", + " = AA'' + AB + CA'' + BC\n", + " = 0 + AB + CA'' + BC\n", + " = AB + (A + A'')BC + CA''\n", + " = AB + ABC + A''BC + CA''\n", + " = AB + ABC + A''C(B + 1)\n", + " = AB + ABC + A''C\n", + " = AB(C + 1)+ A''C\n", + " = AB + A''C\n", + "Therefore (A+ C)(A'' + B) = AB + A''C\n" + ] + } + ], + "prompt_number": 34 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_2.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_2.ipynb new file mode 100755 index 00000000..1250b8e1 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_2.ipynb @@ -0,0 +1,515 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2998b80611e837f1cd7db034c5dd373d5c43fb4268c911031e23c03a219462da" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 2 - Semiconductor Physics" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 87" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#calculate Conductivity of pure silicon crystal\n", + "print '%s' %(\"Conductivity of pure silicon crystal is given by\")\n", + "print '%s' %(\" sigma = ni*e*(ue + uh)\")\n", + "uh=480. #mobility in cm**2/Volt-sec\n", + "ue=1350. #mobility of electrons in cm**2/Volt-sec\n", + "e=1.6*10.**(-19.) #electron charge\n", + "ni=1.072*10.**10. #density of electron hole\n", + "sigma_i=ni*e*(uh+ue) #conductivity of silicon\n", + "print '%s %.2f' %(\"\\n Conductivity of pure silicon crystal = %.8f ohm**(-1)/cm \\n\",sigma_i)\n", + "print '%s' %(\"Resistivity of silicon is given by\")\n", + "rho=1./sigma_i #resistivity of silicon\n", + "print '%s %.2f' %(\"\\n Resistivity of pure silicon crystal = %.0f ohm-cm \\n\",rho)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Conductivity of pure silicon crystal is given by\n", + " sigma = ni*e*(ue + uh)\n", + "\n", + " Conductivity of pure silicon crystal = %.8f ohm**(-1)/cm \n", + " 0.00\n", + "Resistivity of silicon is given by\n", + "\n", + " Resistivity of pure silicon crystal = %.0f ohm-cm \n", + " 318591.47\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 87" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_2 Pg-87\n", + "#calculate Conductivity of pure silicon crystal, Resistivity of pure phosphorous\n", + "print '%s' %(\"sigma = u*e*n\")\n", + "u=1200. #mobility\n", + "e=1.6*10.**(-19.) #electron charge\n", + "n=10.**13. #phosphorous concentration\n", + "sigma=u*e*n #conductivity \n", + "print '%s %.2f' %(\"\\n Conductivity of pure silicon crystal = %.5f ohm**(-1)/cm \\n\",sigma)\n", + "rho=1./sigma #resistivity\n", + "print '%s %.2f' %(\"\\n Resistivity of pure phosphorous = %.0f ohm-cm \\n\",rho)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "sigma = u*e*n\n", + "\n", + " Conductivity of pure silicon crystal = %.5f ohm**(-1)/cm \n", + " 0.00\n", + "\n", + " Resistivity of pure phosphorous = %.0f ohm-cm \n", + " 520.83\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 88" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_4 Pg-88\n", + "#calculate the ratio of n_p/n_i\n", + "print '%s' %(\"(n_i)**2 = n*p = n_p*N_a\")\n", + "ni=2.5*10.**19. #density of electron hole\n", + "Na=1.1*10.**20. #acceptor density\n", + "np=(ni**2.)/Na\n", + "N=np/ni \n", + "print '%s %.2f' %(\"\\n The ratio of n_p/n_i = %.4f\",N)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(n_i)**2 = n*p = n_p*N_a\n", + "\n", + " The ratio of n_p/n_i = %.4f 0.23\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 88" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_5 Pg-88\n", + "#calculate number density of donor atoms\n", + "print '%s' %(\"sigma_n = u_n*e*N_d\")\n", + "e=1.6*1e-19 #electron charge\n", + "sigma=5. #conductivity in mho/cm\n", + "un=3850. #mobility of electrons\n", + "Nd=sigma/(e*un) #concentration\n", + "print '%s %.2f' %(\"Number density of donor atoms = %.1f*1e16 per cm**3\",Nd*1e-16)\n", + "#the answer in the book is wrong the correct answer is 0.8*1e16 per cm**3\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "sigma_n = u_n*e*N_d\n", + "Number density of donor atoms = %.1f*1e16 per cm**3 0.81\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 88" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_6 Pg-88\n", + "#calculate Eg\n", + "print '%s' %(\"We know forbidden energy gap between conduction and valence bands for a semiconductor is nearly 1 eV.\\nFor Ge and Si,energy gap is 0.785 eV and 1.21 eV respectively at 0K.\\nEnergy gap decreases with increase in temperature which is represented by the expression.\\nObviously, Si and Ge will remain semiconductors at 1000K ambient temperature.\\n\")\n", + "print '%s' %(\"Eg(T) = 1.21 - 3.6*10**(-4)*T (For Si)\")\n", + "T=1000. #temperature\n", + "Eg=1.21 - 3.6*10**(-4)*T\n", + "print '%s %.2f %s' %(\"\\nEg(1000)=\",1.21 - 3.6*10**(-4)*T,\"eV\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We know forbidden energy gap between conduction and valence bands for a semiconductor is nearly 1 eV.\n", + "For Ge and Si,energy gap is 0.785 eV and 1.21 eV respectively at 0K.\n", + "Energy gap decreases with increase in temperature which is represented by the expression.\n", + "Obviously, Si and Ge will remain semiconductors at 1000K ambient temperature.\n", + "\n", + "Eg(T) = 1.21 - 3.6*10**(-4)*T (For Si)\n", + "\n", + "Eg(1000)= 0.85 eV\n", + "\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 88" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_7 Pg-88\n", + "#calculate Avg relaxation time of electrons\n", + "print '%s' %(\"Relaxation time in terms of mobility is given by\")\n", + "print '%s' %(\"t=m*u/e\")\n", + "print '%s' %(\"\\n\\nTaking effective mass of electron an holes in consideration,\\nrelaxation time is given by\\n\")\n", + "print '%s' %(\"t=m_star*u/e\")\n", + "print '%s' %(\"(a)For electrons,m_star = 0.259*m_0\")\n", + "m0=9.1*10.**(-31.) \n", + "ue=0.135 #mobility of electrons\n", + "e=1.6*10.**(-19.) #electron charge\n", + "t_e=(0.259*m0*ue)/e\n", + "print '%s %.2f %s' %(\"\\nAverage relaxation time of eletrons =\",t_e*1e13,\"*1e-13 secs\\n\")\n", + "uh=0.048 #mobility of holes\n", + "print '%s' %(\"(b)For holes in the valance band,m=0.537*m_0\")\n", + "t_h=(0.537*m0*uh)/e\n", + "print '%s %.2f %s' %(\"\\nAverage relaxation time of eletrons =\",t_h*1e13,\"*1e-13 secs\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Relaxation time in terms of mobility is given by\n", + "t=m*u/e\n", + "\n", + "\n", + "Taking effective mass of electron an holes in consideration,\n", + "relaxation time is given by\n", + "\n", + "t=m_star*u/e\n", + "(a)For electrons,m_star = 0.259*m_0\n", + "\n", + "Average relaxation time of eletrons = 1.99 *1e-13 secs\n", + "\n", + "(b)For holes in the valance band,m=0.537*m_0\n", + "\n", + "Average relaxation time of eletrons = 1.47 *1e-13 secs\n", + "\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 89" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_8 Pg-89\n", + "#calculation of Total conduction current density\n", + "import math\n", + "print '%s' %(\"Conductivity of an intrinsic material is given by \")\n", + "print '%s' %(\"sigma = e*ni*un*(1+up/un)\")\n", + "sigma_i=100./60. \n", + "ni=2.5*10.**19. #concentration of intrinsic carrier in m**3\n", + "up_un=0.5\n", + "e=1.6*10.**(-19.) #electron charge\n", + "un=(sigma_i/(e*ni*(1+(up_un)))) #concentration of electrons\n", + "up=un/2. #holes concentratin\n", + "print '%s' %(\"Let n be eletron concentration and p be hole con-centration for doped sample. Sincethe sample is electrically neutral,we have\")\n", + "print '%s' %(\"Nd + p = Na + n\")\n", + "print '%s' %(\"Where Nd is donor concentration and Na is acceptor concentration,assumed to be fully ionized. From mass action law,we have np =ni**2*S0\")\n", + "print '%s' %(\"Nd + (ni**2)/n = Na + n\")\n", + "print '%s' %(\"or n**2 + (Na-Nd)*n-ni**2 = 0\")\n", + "print '%s' %(\"or n=0.5*([Nd-N])(+/-) sqrt(Nd-Na)**2 + 4*ni**2)\")\n", + "print '%s' %(\"n is positive and hence we can drop negative sign before the radical\")\n", + "Nd=10.**20. #number density of donor atoms /m**3\n", + "Na=5.*10.**19. #number of acceptor atoms in /m**3\n", + "n=0.5*((Nd-Na)+ math.sqrt((Nd-Na)**2 + 4*ni**2)) #electron concentration for doped sample\n", + "p=ni**2./n #hole concentration for doped sample\n", + "conduct_doped=e*(n*un+p*up) #conductivity of doped sample(value in textbook is wrong)\n", + "print '%s %.2f' %(\"\\n Conductivity of doped sample = %.2f S/m \\n\",conduct_doped)\n", + "\n", + "print '%s' %(\"We have assumed that carrier mobilities in the doped signal sample are the same as those in the intrinsic material.This assumption is justified by the low doping level, and Coulomb scaterring Applied by the ionized impurities is weak at 300K.\")\n", + "print '%s' %(\"Applied electric field\")\n", + "\n", + "F_cm=2. #applied electric field in V/cm\n", + "F_m=2.*100. #applied electric field in V/m\n", + "J=conduct_doped*F_m #total conduction current density\n", + "J_cm=J/1000. #cm**2 to m**2s\n", + "\n", + "print '%s %.2f' %(\"Total conduction current density = %.0f A/m**2\",J) \n", + "print '%s %.2f' %(\"\\n = %.2f A/cm**2\",J_cm)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Conductivity of an intrinsic material is given by \n", + "sigma = e*ni*un*(1+up/un)\n", + "Let n be eletron concentration and p be hole con-centration for doped sample. Sincethe sample is electrically neutral,we have\n", + "Nd + p = Na + n\n", + "Where Nd is donor concentration and Na is acceptor concentration,assumed to be fully ionized. From mass action law,we have np =ni**2*S0\n", + "Nd + (ni**2)/n = Na + n\n", + "or n**2 + (Na-Nd)*n-ni**2 = 0\n", + "or n=0.5*([Nd-N])(+/-) sqrt(Nd-Na)**2 + 4*ni**2)\n", + "n is positive and hence we can drop negative sign before the radical\n", + "\n", + " Conductivity of doped sample = %.2f S/m \n", + " 2.91\n", + "We have assumed that carrier mobilities in the doped signal sample are the same as those in the intrinsic material.This assumption is justified by the low doping level, and Coulomb scaterring Applied by the ionized impurities is weak at 300K.\n", + "Applied electric field\n", + "Total conduction current density = %.0f A/m**2 582.52\n", + "\n", + " = %.2f A/cm**2 0.58\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 91" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_9 Pg-91\n", + "print '%s' %(\"For P-type,Nd=0. By charge neutrality and mass action law,\")\n", + "print '%s' %(\" p + Nd = p = +na = (ni)**2/n\")\n", + "print '%s' %(\"or n**2 + Na*n - (ni)**2 = 0\")\n", + "print '%s' %(\"Solving the quadratic equation for n and discharging the extraneous negative root,one obtains\")\n", + "print '%s' %(\" n = 0.5*(-Na + sqrt(Na**2 + 4*ni**2))\")\n", + "print '%s' %(\"Knowing n,one obtains from mass action law p = ni**2/n\")\n", + "print '%s' %(\"For N-type doping,Na=0. By analogous procedure,\")\n", + "print '%s' %(\" p = 0.5*(-Nd +sqrt(Nd**2 + 4*Ni**2)); n=ni**2/p\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "For P-type,Nd=0. By charge neutrality and mass action law,\n", + " p + Nd = p = +na = (ni)**2/n\n", + "or n**2 + Na*n - (ni)**2 = 0\n", + "Solving the quadratic equation for n and discharging the extraneous negative root,one obtains\n", + " n = 0.5*(-Na + sqrt(Na**2 + 4*ni**2))\n", + "Knowing n,one obtains from mass action law p = ni**2/n\n", + "For N-type doping,Na=0. By analogous procedure,\n", + " p = 0.5*(-Nd +sqrt(Nd**2 + 4*Ni**2)); n=ni**2/p\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E10 - Pg 91" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_10 Pg-91\n", + "e=1.6*10.**(-19.) #electron charge\n", + "un=700. #mobility of silicon\n", + "n=10**17. #concentration of phosphorous atoms\n", + "sigma=e*un*n #conductivity\n", + "print '%s %.2f' %(\"Conductivity = %.1f (ohm-cm)**-1\",sigma)\n", + "res=sigma**(-1) #resistivity\n", + "print '%s %.2f' %(\"\\n Resistivity = %.4f ohm-cm\",res)\n", + "Rh=-(e*n)**(-1) #hall coefficient\n", + "print '%s %.2f' %(\"\\n Hall coefficient = %.1f cm**3/C\",Rh)\n", + "Ix=10**-3. \n", + "Bz=10**(-5.) \n", + "x=10**(-2.)\n", + "Vh=(Ix*Bz*Rh)/x\n", + "print '%s %.2f' %(\"\\n Hall Volage = %.1f uV\",Vh*10.**6.)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Conductivity = %.1f (ohm-cm)**-1 11.20\n", + "\n", + " Resistivity = %.4f ohm-cm 0.09\n", + "\n", + " Hall coefficient = %.1f cm**3/C -62.50\n", + "\n", + " Hall Volage = %.1f uV -62.50\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E11 - Pg 91" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex2_11 Pg-91\n", + "print '%s' %(\"(a) Hall coefficient is\")\n", + "print '%s' %(\"Rh = Eh/(Jx*B)\")\n", + "Vh=21.4*10.**(-3.) #hall voltage\n", + "b=1.7*10.**(-2.) #breadth\n", + "Eh=Vh/b #electric field\n", + "t=0.052*10.**(-3.) #thickness\n", + "I=200*10.**(-6.) #current\n", + "Jx=I/(b*t) #current density\n", + "B=0.5 #magnetic field\n", + "Rh=Eh/(Jx*B)\n", + "print '%s %.2f' %(\"\\n Hall coefficient = %.6f m**3/C \\n\\n\",Rh)\n", + "\n", + "print '%s' %(\"(b) Electrons per unit volume,\")\n", + "e=1.6*10.**(-19.) #electron charge\n", + "n=1/(Rh*e) #electrons per unit volume\n", + "print '%s %.2f' %(\"\\n\\n Electrons per unit volume = %.0f electrons/m**3 \\n\\n\",n)\n", + "V=195.*10.**(-3.) #voltage\n", + "I=200.*10.**(-6.) #current \n", + "R=V/I #resistance\n", + "print '%s' %(\"Since R=(l/(A*sigma) = (l/(A*e*n*R))\")\n", + "l=2.65*10.**(-2.) #length\n", + "w=1.7*10.**(-2.) #width\n", + "t=0.052*10.**(-3.) #thicknes\n", + "A=t*w #area\n", + "sigma=l/(A*e*n*R) #conductivity\n", + "print '%s %.2f' %(\"\\n\\n Conductivity = %.3f m**3/Vs\",sigma)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a) Hall coefficient is\n", + "Rh = Eh/(Jx*B)\n", + "\n", + " Hall coefficient = %.6f m**3/C \n", + "\n", + " 0.01\n", + "(b) Electrons per unit volume,\n", + "\n", + "\n", + " Electrons per unit volume = %.0f electrons/m**3 \n", + "\n", + " 561646297627606056960.00\n", + "Since R=(l/(A*sigma) = (l/(A*e*n*R))\n", + "\n", + "\n", + " Conductivity = %.3f m**3/Vs 0.34\n" + ] + } + ], + "prompt_number": 12 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_21.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_21.ipynb new file mode 100755 index 00000000..6a0cb850 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_21.ipynb @@ -0,0 +1,296 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:448fe7630f3affc67a26ee31d0d2cd681158ac6be6a5f6e0cd51550e7fad58b6" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 21 - Integrated Circits" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 1067" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_1 Pg-1067\n", + "#calculate Pulse width\n", + "print'%s'%(\"Refer to figure 21.10\")\n", + "R=5000. #resistor R in ohm\n", + "C=0.1*10.**(-6.) #capacitance in farad\n", + "tau=1.1 #time constant\n", + "tON=tau*R*C #pulse width in sec\n", + "print'%s %.2f'%(\"Pulse width = msec\",tON*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to figure 21.10\n", + "Pulse width = msec 0.55\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 1068" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_2 Pg-1068\n", + "#calculate time output\n", + "print '%s' %(\"Refer to figure 21.12\")\n", + "R1=20000. #timing resistor R1 in ohm\n", + "R2=R1 #timing resistor R2 in ohm\n", + "C=0.1*10.**(-6.) #capacitance in farad\n", + "tau=0.69 #time constant\n", + "tHIGH=tau*(R1+R2)*C #time output that will remain high\n", + "print '%s %.2f' %(\"Time output = msec\",tHIGH*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to figure 21.12\n", + "Time output = msec 2.76\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 1069" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_3 Pg-1069\n", + "#calculate time output\n", + "print '%s' %(\"Refer to figure 21.12\")\n", + "R2=20000. #timing resistor R2 in ohm\n", + "C=0.1*10.**(-6.) #capacitance in farad\n", + "tau=0.69 #time constant\n", + "tLOW=tau*(R2)*C #time output that will remain high\n", + "print '%s %.2f' %(\"Time output = msec\",tLOW*1e3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to figure 21.12\n", + "Time output = msec 1.38\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 1069" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_4 Pg-1069\n", + "#calculate output frequency\n", + "R1=20000. #timing resistor R1 in ohm\n", + "R2=R1 #timing resistor R2 in ohm\n", + "C=0.1*10.**(-6.) #capacitance in farad\n", + "f0=1.45/((R1+2.*R2)*C) #output frequency\n", + "print '%s %.2f' %(\"Output frequency = Hz\",f0)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Output frequency = Hz 241.67\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 1069" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_5 Pg-1069\n", + "#calculate duty cycle\n", + "print '%s' %(\"Refer to figure 21.12\")\n", + "R1=20000. #timing resistor R1 in ohm\n", + "R2=R1 #timing resistor R2 in ohm\n", + "D=(R1+R2)/(R1+2.*R2)*100. #duty cylce\n", + "print '%s %.1f' %(\"Duty cycle =\",D)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to figure 21.12\n", + "Duty cycle = 66.7\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 1070" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_6 Pg-1070\n", + "#calculate R1 and R2\n", + "C=0.01*10.**(-6.) #capacitance in farad\n", + "f0=2000. #frequency in Hz\n", + "Req=1.45/(f0*C) #equivalent resistance or R1+R2\n", + "print '%s' %(\"Because a square wave has duty cycle of 50% each resistor must be the same\")\n", + "R1=Req/2. \n", + "R2=R1\n", + "print'%s %.2f' %(\"R1 = R2 = kohm\",R2*1e-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Because a square wave has duty cycle of 50% each resistor must be the same\n", + "R1 = R2 = kohm 36.25\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 1073" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_7 Pg-1073\n", + "#calculate pulse width\n", + "R=260000. #resistor R in ohm\n", + "C=25*10.**(-6.) #capacitance in farad\n", + "tau=1.1 #time constant\n", + "t_delay=tau*R*C #pulse width in sec\n", + "print '%s %.2f' %(\"Pulse width = sec\",t_delay)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Pulse width = sec 7.15\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 1076" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex21_8 Pg-1076\n", + "#calculate Binary value of 253\n", + "dec=253 #decimal number\n", + "bina=bin(dec) #binary value of 253\n", + "print bina" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0b11111101\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_3.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_3.ipynb new file mode 100755 index 00000000..be82e4b1 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_3.ipynb @@ -0,0 +1,978 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:eadee9a2b39309b25e607f3431ed8fcdf9fc4762e77d8aebc55b1ddd8ea037ae" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 3 - Semiconductor Diodes" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 127" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_1 Pg-127\n", + "#calculate current\n", + "print '%s' %(\"Refer to the diagram 3.11(b)\")\n", + "print '%s' %(\"Using ohm''s law\")\n", + "print '%s' %(\"Vt = Vd1 + Vr1\")\n", + "Vd1=0.7 #voltage drop in V\n", + "Vt=12. #supply voltage in V\n", + "R1=1.2*10.**3. #resistor R1 in ohm\n", + "Vr1=Vt-Vd1 #voltage across R1 in V\n", + "It=Vr1/R1 #current in A\n", + "print '%s' %(\"Ohm''s law\")\n", + "print '%s %.2f' %(\"\\n Current I_t = mA\",It*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the diagram 3.11(b)\n", + "Using ohm''s law\n", + "Vt = Vd1 + Vr1\n", + "Ohm''s law\n", + "\n", + " Current I_t = mA 9.42\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 182" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_2 Pg-182\n", + "#calculate the voltage applied across the junction\n", + "import math\n", + "J=10.**5. #forward current density\n", + "Js=250.*10.**(-3.) #saturation current density\n", + "e=1.6*10.**(-19.) #electron charge\n", + "T=300. #temperature\n", + "k=1.38*10.**(-23.) #Boltzmann constant\n", + "V=(math.log(J/Js)*k*T)/e #voltage applied across junction\n", + "print '%s %.2f' %(\"The voltage applied across the junction =V\",V)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The voltage applied across the junction =V 0.33\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 182" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_3 Pg-182\n", + "import math\n", + "I=2.*10.**6. #forward current density\n", + "Is=30. #saturation current density\n", + "ekt=40.\n", + "V=(1./40.)*math.log(I/Is) #Applied forward voltage\n", + "print '%s %.3f' %(\"Applied forward voltage =V\",V)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 182" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_4 Pg-182\n", + "import math\n", + "print '%s' %(\"I = Is*exp(eV/kT) = Is*exp(40V)\")\n", + "print '%s' %(\"Re = del_V/del_I = 1/40I\")\n", + "print '%s' %(\"Dividing throughtout by volume, one obtains the equation in the form of current density as\")\n", + "print '%s' %(\"J = Js*(exp(eV/kT)-1)\")\n", + "J=10.**5. #forward current density\n", + "Js=250.*10.**(-3.) #saturation current density\n", + "e=1.6*10.**(-19.) #electron charge\n", + "T=300. #temperature\n", + "k=1.38*10.**(-23.) #Boltzmann constant\n", + "V=(math.log(J/Js)*k*T)/e #voltage applied across junction\n", + "print '%s %.2f' %(\"\\n The voltage applied across the junction =V\",V)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I = Is*exp(eV/kT) = Is*exp(40V)\n", + "Re = del_V/del_I = 1/40I\n", + "Dividing throughtout by volume, one obtains the equation in the form of current density as\n", + "J = Js*(exp(eV/kT)-1)\n", + "\n", + " The voltage applied across the junction =V 0.33\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 183" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_5 Pg-183\n", + "print '%s' %(\"(a) Forward-bias\")\n", + "Av=50. #applied voltage\n", + "Jr=5000. #junction resistance\n", + "Er=50. #external resistance\n", + "cur=Av/(Er+Jr) #current\n", + "print '%s %.1f %s' %(\"Current =mA \\n\",cur*10.**3.,\"\\n\")\n", + "\n", + "print '%s' %(\"(b) Reverse-bias\")\n", + "cur_rev=Av/(Jr+10.**6.) #book expression is wrong\n", + "print '%s %.3f' %(\"Current =1e-2 mA \\n\",cur_rev*10**5)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a) Forward-bias\n", + "Current =mA \n", + " 9.9 \n", + "\n", + "(b) Reverse-bias\n", + "Current =1e-2 mA \n", + " 4.975\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 183" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_6 Pg-183\n", + "import math\n", + "print '%s' %(\"We know that\")\n", + "print '%s' %(\" r_ac = dV/dI - 1/(dI/dV) = 1/((I0/KT)exp(V/KT))\")\n", + "k=8.62*10.**(-5.)\n", + "T=300. #temperaturein K\n", + "kT=k*T\n", + "I0=10.**(-6.) #saturation current\n", + "V=150.*10.**(-3.) #voltage forward biased\n", + "r_ac = 1./((I0/kT)*math.exp(V/kT)) #value of exp(0.15/0.02586)=330.45 and not the textbook value of 332.66\n", + "print '%s %.2f' %(\"\\n The AC resistance =ohm\",r_ac) #text book value wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We know that\n", + " r_ac = dV/dI - 1/(dI/dV) = 1/((I0/KT)exp(V/KT))\n", + "\n", + " The AC resistance =ohm 78.26\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 184" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_7 Pg-184\n", + "import math\n", + "print '%s' %(\"We know that (I0)*T2 = (I0)*T1*(2)**((T2-T1/10))\")\n", + "\n", + "print '%s' %(\"Substituting the given values,we have \")\n", + "\n", + "print '%s' %(\"(40*10**(-6)) = (25*10**(-6)*(2)**x) where x=(T2-T1)/10\")\n", + "\n", + "print '%s' %(\"(2)**x = 1.6\")\n", + "\n", + "print '%s' %(\"Taking log on both sides,one obtains\")\n", + "\n", + "print '%s' %(\"x*log(2) = log(1.6)\")\n", + "\n", + "print '%s' %(\"or x = log(1.6)/log(2)\")\n", + "\n", + "x=math.log(1.6)/math.log(2.)\n", + "\n", + "print '%s' %(\" Now x = (T2-T1)/10 or 0.678 = (T2-25)/10\")\n", + "T1=25. #temperature T1\n", + "T2=x*10.+T1 #temperature T2\n", + "diff_temp=T2-T1 #change in temperature\n", + "print '%s %.2f' %(\"\\n So the change in temperature =degree celsius\",diff_temp)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We know that (I0)*T2 = (I0)*T1*(2)**((T2-T1/10))\n", + "Substituting the given values,we have \n", + "(40*10**(-6)) = (25*10**(-6)*(2)**x) where x=(T2-T1)/10\n", + "(2)**x = 1.6\n", + "Taking log on both sides,one obtains\n", + "x*log(2) = log(1.6)\n", + "or x = log(1.6)/log(2)\n", + " Now x = (T2-T1)/10 or 0.678 = (T2-25)/10\n", + "\n", + " So the change in temperature =degree celsius 6.78\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 185" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_8 Pg-185\n", + "import math\n", + "print '%s' %(\"Forward current I is given by \")\n", + "print '%s' %(\"I=I0*exp(V/(n*Vt))-1\")\n", + "V=0.3 #voltage\n", + "n=1. #constant\n", + "T1=22.+273. #temperature T1 in Kelvin\n", + "Vt1=T1/11600.\n", + "I=(math.exp(V/0.025)-1)\n", + "print '%s' %(\"When temperature rises to 72 degree celcius, then\")\n", + "\n", + "T2=72.+273. #temperature T2 in Kelvin\n", + "Vt2=T2/11600.\n", + "TR=T2-T1 #temperature rise\n", + "I_72=(2.)**(TR/10.)\n", + "\n", + "I_hash=I_72*(math.exp(V/(Vt2))-1)\n", + "for_cur_rises=I_hash/I\n", + "print '%s' %(\"Thus, at 72 degree celcius Forward current rises by \")\n", + "print '%s' %(for_cur_rises)\n", + "cur_I=768849.72\n", + "cur_I_hash=162753.79\n", + "FCR=cur_I/cur_I_hash\n", + "print '%s %.2f' %(\"\\n=\",FCR)\n", + " #answer in the book is wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 185" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_9 Pg-185\n", + "import math\n", + "n=1. #constant\n", + "T=27.+273. #temperature in K\n", + "Vt=T/11600.\n", + "V=0.2 #voltage\n", + "I0=10.**(-6.) #saturation current\n", + "I=I0*(math.exp(V/Vt)-1)\n", + "stat_res=V/I #static resistance\n", + "print '%s %.2f' %(\"Static resistance =ohm\",stat_res)\n", + "\n", + "dyn_res=Vt/(I+I0) #dynamic resistance\n", + "print '%s %.2f' %(\"Dynamic resistance =ohm\",dyn_res)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Static resistance =ohm 87.63\n", + "Dynamic resistance =ohm 11.33\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E10 - Pg 186" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_10 Pg-186\n", + "import math\n", + "print '%s' %(\"We know that I = I0*(math.exp(V/n*Vt)-1)\")\n", + "print '%s' %(\"Dividing on both sides by area A, one obtains\")\n", + "print '%s' %(\"I/A = I0/A*(mah.exp(V/n*Vt)-1)\")\n", + "print '%s' %(\"or J = J0*(math.exp(V/n*Vt)-1)\")\n", + "n=1. #constant\n", + "T=300. #temperature in K\n", + "Vt=T/11600.\n", + "J=10.**5. #forward current density\n", + "J0=250.*10.**(-3.) #saturation current density \n", + "V=Vt*math.log(J/J0)\n", + "print '%s %.4f' %(\"\\n The voltage applied across the junction =V\",V)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We know that I = I0*(math.exp(V/n*Vt)-1)\n", + "Dividing on both sides by area A, one obtains\n", + "I/A = I0/A*(mah.exp(V/n*Vt)-1)\n", + "or J = J0*(math.exp(V/n*Vt)-1)\n", + "\n", + " The voltage applied across the junction =V 0.3336\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E11 - Pg 186" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_11 Pg-186\n", + "Vmin=0.7 #minimum voltage across diode in V\n", + "V=5. #supply voltage in V\n", + "V_R1=V-Vmin #voltage across resistor R in V\n", + "Imin=10.**(-3.) #minimum current\n", + "R1=V_R1/Imin \n", + "print '%s %.1f' %(\"Maximum value of R =kohm \\n \",R1*1e-3)\n", + "I=5.*10.**(-3.) #current through resistance in A\n", + "V_R2=V-Vmin #voltage across resistor R in V\n", + "R2=V_R2/I\n", + "print '%s %.0f' %(\"\\n\\n Minimum value of R =ohm \",R2)\n", + "Vb=6. #supply voltage\n", + "Vb_res=Vb-Vmin #voltage across resistor\n", + "P=I*Vb_res #power dissipated across resistor\n", + "print '%s %.1f' %(\"\\n\\n Power dissipated across R =W\",P*10**3)\n", + "P_diode=I*Vmin #power dissipated across diode\n", + "print '%s %.1f' %(\"\\n power dissipated across diode =mW\",P_diode*1e3)\n", + "R=10.**3. #resistor in ohm\n", + "V_R=R*Imin #voltage drop across resistor R in V\n", + "Vb=V_R+Vmin \n", + "print '%s %.1f' %(\"\\n\\n The minimum voltage across diode =V\",Vb)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Maximum value of R =kohm \n", + " 4.3\n", + "\n", + "\n", + " Minimum value of R =ohm 860\n", + "\n", + "\n", + " Power dissipated across R =W 26.5\n", + "\n", + " power dissipated across diode =mW 3.5\n", + "\n", + "\n", + " The minimum voltage across diode =V 1.7\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E12 - Pg 188" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_12 Pg-188\n", + "print '%s' %(\"Refer to the figure 3.51\")\n", + "Id1=2.*10.**(-3.) #diode current in I\n", + "Vd1=0.5 #diode voltage in V\n", + "Rf1=Vd1/Id1 #Dc resistance\n", + "print '%s' %(\"At Id=2mA and Vd=0.5V\")\n", + "print '%s %.0f' %(\"\\n Rf =ohm\",Rf1)\n", + "\n", + "Id2=20.*10.**(-3.) #diode current in I\n", + "Vd2=0.75 #diode voltage in V\n", + "Rf2=Vd2/Id2 #Dc resistance\n", + "print '%s' %(\"At Id=20mA and Vd=0.75V\")\n", + "print '%s %.1f' %(\"\\n Rf =ohm \",Rf2)\n", + "\n", + "Id3=2.*10.**(-6.) #diode current in I\n", + "Vd3=10. #diode voltage in V\n", + "Rf3=Vd3/Id3 #Dc resistance\n", + "print '%s' %(\"At Id=2*10**(-6)A and Vd=10V\")\n", + "print '%s %.0f' %(\"\\n Rf =Mohm\",Rf3*10**-6)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 3.51\n", + "At Id=2mA and Vd=0.5V\n", + "\n", + " Rf =ohm 250\n", + "At Id=20mA and Vd=0.75V\n", + "\n", + " Rf =ohm 37.5\n", + "At Id=2*10**(-6)A and Vd=10V\n", + "\n", + " Rf =Mohm 5\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E13 - Pg 188" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_13 Pg-188\n", + "print '%s' %(\"Refer to the figure 3.52\")\n", + "print '%s' %(\"(a) Assuming the diode D to be ideal \")\n", + "print '%s' %(\" Ignoring diode D,voltage across R2 is given as (By applying potential divider concept)\")\n", + "R1=45. #resistor R1\n", + "R2=5. #resistor R2\n", + "Vaa=10. #supply voltage\n", + "Vab=Vaa*(R2/(R1+R2))\n", + "print '%s %.0f' %(\"\\n Vab=V\",Vab)\n", + "\n", + "print '%s' %(\" Thus,diode D is forward biased.It conducts,offering zero resistance Hence no current would flow through the parallel bransh R2.The circuit equivalent to that shown in figure 3.53(a)\")\n", + "ID=Vaa/R1 #diode current\n", + "print '%s %.0f' %(\"\\n Current through diode =mA \",ID*10**3)\n", + "\n", + "print '%s' %(\"(b)Assuming the diode to be real\")\n", + "print '%s' %(\" Voltage Vab is much larger than Vt hencethe diode conducts.It is replaced by its equivalent as shown in figure 3.53(b).To determine current Id through the diode we first find the Thevenin''s equivalent of the circuit on the left of AB.Vth=open circuit voltage across AB\")\n", + "Vth=Vaa*(R2/(R1+R2))\n", + "print '%s %.0f' %(\"\\n Vth=V\",Vth)\n", + "Rth=R1*R2/(R1+R2)\n", + "print '%s %.0f' %(\"\\n Rth=ohm \",Rth) #textbook value is wrong\n", + "print '%s' %(\"Thus,the equivalent circuit becomes as shown in figure 3.53(c)\")\n", + "Vt=0.3 #load voltage\n", + "tf=25. #load resistance\n", + "Id=(Vth-Vt)/(Rth+tf)\n", + "print '%s %.1f' %(\"\\n Current through diode = mA\",Id*10**3)\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 3.52\n", + "(a) Assuming the diode D to be ideal \n", + " Ignoring diode D,voltage across R2 is given as (By applying potential divider concept)\n", + "\n", + " Vab=V 1\n", + " Thus,diode D is forward biased.It conducts,offering zero resistance Hence no current would flow through the parallel bransh R2.The circuit equivalent to that shown in figure 3.53(a)\n", + "\n", + " Current through diode =mA 222\n", + "(b)Assuming the diode to be real\n", + " Voltage Vab is much larger than Vt hencethe diode conducts.It is replaced by its equivalent as shown in figure 3.53(b).To determine current Id through the diode we first find the Thevenin''s equivalent of the circuit on the left of AB.Vth=open circuit voltage across AB\n", + "\n", + " Vth=V 1\n", + "\n", + " Rth=ohm 4\n", + "Thus,the equivalent circuit becomes as shown in figure 3.53(c)\n", + "\n", + " Current through diode = mA 23.7\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E14 - Pg 190" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_14 Pg-190\n", + "print '%s' %(\"Diodes D2 and D3 are reverse-biased.\\nTherefore,these are like open-switches.\\nDiodes D1 and D2 are forward biased.\\nThese are replaced by their equivalent circuits,as shown in figure 3.54.\\nSince the diodes are silicon V=0.7V. \")\n", + "Vt=0.7 #voltage drop\n", + "Vaa=20. #supply voltage in V\n", + "net_emf=Vaa-Vt-Vt #net emf\n", + "R1=5. \n", + "R2=90.\n", + "R3=5. #R1,R2,R3 are resistances\n", + "tot_res=R1+R2+R3 #total resistance\n", + "print'%s' %(\"Therefore, current through 90 ohm resistor is\")\n", + "I=net_emf/tot_res\n", + "print'%s %.0f' %(\"\\nCurrent I =mA\",I*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Diodes D2 and D3 are reverse-biased.\n", + "Therefore,these are like open-switches.\n", + "Diodes D1 and D2 are forward biased.\n", + "These are replaced by their equivalent circuits,as shown in figure 3.54.\n", + "Since the diodes are silicon V=0.7V. \n", + "Therefore, current through 90 ohm resistor is\n", + "\n", + "Current I =mA 186\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E15 - Pg 190" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_15 Pg-190\n", + "print '%s' %(\"(a) When the diode is forward biased figure 3.55(b),it offers zero resistance.\\nIt is like shorted switch.This shorted switch across AB also short-circuits the resistance R2.Obviously,a parallel combination of the diode and R2 is equivalent to a resistance of zero ohms.\")\n", + "R1=100. #reisitor R1 in ohm \n", + "R=R1\n", + "Vaa=10. #supply voltage in V\n", + "I=Vaa/R\n", + "print '%s %.1f' %(\"\\n Current drawn from battery =A\",I)\n", + "print '%s' %(\"(a) When the diode is reverse biased figure 3.55(b).\\nIt is like open switch.Obviously,it then does not make any difference whether the diode is connected or not.\")\n", + "R2=100 #resistor R2 in ohm\n", + "tot_R=R1+R2\n", + "I1=Vaa/tot_R\n", + "print '%s %.2f' %(\"\\n Current drawn from battery =A\",I1)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a) When the diode is forward biased figure 3.55(b),it offers zero resistance.\n", + "It is like shorted switch.This shorted switch across AB also short-circuits the resistance R2.Obviously,a parallel combination of the diode and R2 is equivalent to a resistance of zero ohms.\n", + "\n", + " Current drawn from battery =A 0.1\n", + "(a) When the diode is reverse biased figure 3.55(b).\n", + "It is like open switch.Obviously,it then does not make any difference whether the diode is connected or not.\n", + "\n", + " Current drawn from battery =A 0.05\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E16 - Pg 191" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_16 Pg-191\n", + "Vz=9. #breakdown voltage in V\n", + "per=0.1 #10% tolerance \n", + "Tol=Vz*per\n", + "print '%s %.1f'%(\"Tolerance =V\",Tol)\n", + "tol_high=Vz+Tol\n", + "tol_low=Vz-Tol #ranges in tolerance\n", + "print'%s %.1f %.1f'%(\"\\n Range of breakdown voltage=to V\",tol_low,tol_high)\n", + "# in the textbook the value 8.2 is wrong the correct value is 8.1\n", + "T1=25. #temperature T1 in degree celcius\n", + "T2=75. #temperature T2 in degree celcius\n", + "diff_temp=T2-T1 #chnage in temperature\n", + "Vzener=2.*10.**(-3.) #zener voltage\n", + "fall_break_vol=Vzener*diff_temp #fall in breakdown voltage\n", + "new_break_vol=Vz-fall_break_vol #new break don voltage\n", + "print '%s %.1f' %(\"\\n New break don voltage =V\",new_break_vol)\n", + "range_high=tol_low-fall_break_vol\n", + "range_low=tol_high-fall_break_vol\n", + "print '%s %.1f %.1f' %(\"\\n Range of breakdown voltage=to V\",range_high,range_low)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Tolerance =V 0.9\n", + "\n", + " Range of breakdown voltage=to V 8.1 9.9\n", + "\n", + " New break don voltage =V 8.9\n", + "\n", + " Range of breakdown voltage=to V 8.0 9.8\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E17 - Pg 192" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_17 Pg-192\n", + "import math\n", + "C=20. #capacitance in pF\n", + "V=5. #supply voltage in V\n", + "K=C*math.sqrt(V)\n", + "C_V1=K/math.sqrt(V+1)\n", + "print '%s %.1f' %(\"Capacitance for 1V increase =pF\",C_V1)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Capacitance for 1V increase =pF 18.3\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E18 - Pg 192" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_18 Pg-192\n", + "import math\n", + "print '%s' %(\"(a) The two diodes are connected in series and hence the current I flows in D1 and D2.\\nObviously,it is in forward direction through D2 and in reverse direction through D1.\\nSince D2 diode is forward biased,V2 will be very small and hence V1=(5-V2) will be very much larger than Vt=0.026V.\\nThis means the current will be equal to reverse saturation current I0.\\nNow,we consider diode D2.\\nWe have \\n\\n\")\n", + "print '%s' %(\"I = I0*(exp(V/Vt)-1)\")\n", + "print '%s' %(\"Putting I=I0 and V=V2, we have\")\n", + "print '%s' %(\"I0 = I0*(exp(V2/Vt)-1)\")\n", + "print '%s' %(\"exp(V2/Vt)-1 = 1\")\n", + "Vt=0.026 #threshold voltage\n", + "V2=Vt*math.log(2.)\n", + "V=5. #supply voltage in V\n", + "V1=V-V2 #value in textbook incorrect\n", + "print '%s %.3f' %(\"\\n V2 =V\",V2)\n", + "print '%s %.3f' %(\"\\n V2 =V\\n \",V1)\n", + "print '%s' %(\"Effect of temperature : V2=Vt*ln(2) = kT*ln(2)\")\n", + "print '%s' %(\"So V2 will increase with temperature\\n\")\n", + "print '%s' %(\"(b) If Vz is 4.9V then D1 will breakdown. This means V1=4.9V\")\n", + "Vz=4.9 #breakdown voltage\n", + "V2=V-Vz\n", + "print '%s' %(\"Now using I0=5*10**(-6)A and V2=0.1V,one obtains\")\n", + "I0=5*10**(-6) #current in ampere\n", + "I=I0*(math.exp(V2/Vt)-1)\n", + "print '%s %.0f' %(\"\\n Current I=microA\",I*10**6)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a) The two diodes are connected in series and hence the current I flows in D1 and D2.\n", + "Obviously,it is in forward direction through D2 and in reverse direction through D1.\n", + "Since D2 diode is forward biased,V2 will be very small and hence V1=(5-V2) will be very much larger than Vt=0.026V.\n", + "This means the current will be equal to reverse saturation current I0.\n", + "Now,we consider diode D2.\n", + "We have \n", + "\n", + "\n", + "I = I0*(exp(V/Vt)-1)\n", + "Putting I=I0 and V=V2, we have\n", + "I0 = I0*(exp(V2/Vt)-1)\n", + "exp(V2/Vt)-1 = 1\n", + "\n", + " V2 =V 0.018\n", + "\n", + " V2 =V\n", + " 4.982\n", + "Effect of temperature : V2=Vt*ln(2) = kT*ln(2)\n", + "So V2 will increase with temperature\n", + "\n", + "(b) If Vz is 4.9V then D1 will breakdown. This means V1=4.9V\n", + "Now using I0=5*10**(-6)A and V2=0.1V,one obtains\n", + "\n", + " Current I=microA 229\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E19 - Pg 193" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_19 Pg-193\n", + "print '%s' %(\"We have Iv=40*iD\")\n", + "Iv=1. #luminous intensity\n", + "iD=Iv/(40.*10.**(-3.)) #LED current\n", + "print '%s %.0f' %(\"LED current =mA\",iD)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We have Iv=40*iD\n", + "LED current =mA 25\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E20 - Pg 193" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_20 Pg-193\n", + "print '%s %s' %(\"(a) At Id=10mA,\",\"\\n\")\n", + "V=25. #voltage in mV\n", + "Id=10. #current in mA\n", + "Rac=V/Id \n", + "#AC resistance (value in textbook is wrong)\n", + "print '%s %.1f %s' %(\"AC resistance Rac=ohm\",Rac,\"\\n\")\n", + "Id=20. #current in mA\n", + "Rac=V/Id \n", + "#AC resistance (value in textbook is wrong)\n", + "print '%s %.2f %s' %(\"AC resistance Rac=ohm\",Rac,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a) At Id=10mA, \n", + "\n", + "AC resistance Rac=ohm 2.5 \n", + "\n", + "AC resistance Rac=ohm 1.25 \n", + "\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E21 - Pg 194" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex3_21 Pg-194\n", + "import math\n", + "print '%s' %(\"We know that\")\n", + "print '%s' %(\" r_ac = dV/dI - 1/(dI/dV) = 1/((I0/KT)exp(V/KT))\")\n", + "k=8.62*10.**(-5.)\n", + "T=300. #temperaturein K\n", + "kT=k*T\n", + "I0=10.**(-6.) #saturation current\n", + "V=150.*10.**(-3.) #voltage forward biased\n", + "r_ac = 1./((I0/kT)*math.exp(V/kT))\n", + "#value of exp(0.15/0.02586)=330.45 and not the textbook value of 332.66\n", + "print '%s %.2f' %(\"\\n The AC resistance =ohm\",r_ac) #text book value wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "We know that\n", + " r_ac = dV/dI - 1/(dI/dV) = 1/((I0/KT)exp(V/KT))\n", + "\n", + " The AC resistance =ohm 78.26\n" + ] + } + ], + "prompt_number": 21 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_4.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_4.ipynb new file mode 100755 index 00000000..90e30550 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_4.ipynb @@ -0,0 +1,825 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2a1eb39510f3631fbcde9a4826e6d686285d8646443cf4d3538c3c9c67fda877" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 4 - Diode Circuits" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 213" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_1 Pg-213\n", + "#calculate Peak source voltage,DC load voltage With an ideal diode and With second approximation\n", + "import math\n", + "Vrms=110. #rms volatage in V\n", + "Vm=Vrms/0.707 #peak source voltage\n", + "print '%s %.1f' %(\"Peak source voltage=V\",Vm) #textbook answer wrong\n", + "\n", + "print '%s' %(\"(a) With an ideal diode \")\n", + "Vpout=Vm #peak output voltage\n", + "print '%s %.1f' %(\"\\n Peak output voltage=V\",Vpout)\n", + "Vdc=Vm/math.pi #Dc load voltage\n", + "print '%s %.2f' %(\"\\n DC load voltage=V \\n\",Vdc) #textbook answer wrong\n", + "\n", + "print '%s' %(\"(b) With second approximation\")\n", + "Vpin=Vm #peak input voltage\n", + "Vpout=Vpin-0.7\n", + "print '%s %.1f' %(\"\\n Peak output voltage=V\",Vpout)\n", + "Vdc=Vpout/math.pi #Dc load voltage\n", + "print '%s %.1f' %(\"\\n DC load voltage=V \\n\",Vdc) #textbook answer wrong\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Peak source voltage=V 155.6\n", + "(a) With an ideal diode \n", + "\n", + " Peak output voltage=V 155.6\n", + "\n", + " DC load voltage=V \n", + " 49.52\n", + "(b) With second approximation\n", + "\n", + " Peak output voltage=V 154.9\n", + "\n", + " DC load voltage=V \n", + " 49.3\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 214" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_2 Pg-214\n", + "#calculate VR\n", + "print '%s' %(\"VR = (V_NoLoad - V_FullLoad)/V_FullLoad*100%\")\n", + "print '%s' %(\"(a) VR = 0%\")\n", + "V_FullLoad=20. #full load voltage\n", + "V_NoLoad=V_FullLoad#no load voltage\n", + "print '%s %.0f' %(\"\\n V_FullLoad = V_NoLoad=V\",V_NoLoad)\n", + "print '%s' %(\"(b) VR = 100%\")\n", + "VR=100. #voltage regulation in %\n", + "V_NoLoad=(VR*V_FullLoad)/(100.)+V_FullLoad\n", + "print '%s %.0f' %(\"\\n V_NoLoad=V\",V_NoLoad)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "VR = (V_NoLoad - V_FullLoad)/V_FullLoad*100%\n", + "(a) VR = 0%\n", + "\n", + " V_FullLoad = V_NoLoad=V 20\n", + "(b) VR = 100%\n", + "\n", + " V_NoLoad=V 40\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 214" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_3 Pg-214\n", + "#calculate Ratio of rectification or efficiency of halfwave rectifier,Ac input powerfrom transformer secondary\n", + "print '%s' %(\"Ratio of rectification or efficiency of halfwave rectifier\")\n", + "print '%s' %(\"n = 0.406 = DC power deliverd to the load/AC input powerfrom transformer secondary \")\n", + "DC_power=500. #ddc power deliverd to the load\n", + "n=0.406 #efficiency\n", + "AC_in_power=DC_power/n #AC input powerfrom transformer secondary\n", + "print '%s %.0f' %(\"\\n AC input powerfrom transformer secondary =Watt\",AC_in_power)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ratio of rectification or efficiency of halfwave rectifier\n", + "n = 0.406 = DC power deliverd to the load/AC input powerfrom transformer secondary \n", + "\n", + " AC input powerfrom transformer secondary =Watt 1232\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 220" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_4 Pg-220\n", + "#calculate Peak value of current flowing,Average or DC current flowing,R.M.S value of current flowing, DC output power,AC input power,Efficiency of rectifier\n", + "import math\n", + "Rl=3.5*10.**(3.) #resistance in k-ohm\n", + "rF=800. #secondary resistance in k-ohm\n", + "Vm=240.# input voltage\n", + "print '%s' %(\"(1)(a) Peak value of current flowing\")\n", + "Im=Vm/(rF+Rl) #peak current\n", + "print '%s %.2f' %(\"Im=mA\",Im*10**3)\n", + "print '%s' %(\"(b) Average or DC current flowing\")\n", + "Idc=Im/math.pi #DC current\n", + "print '%s %.2f' %(\"Idc=mA\",Idc*10**3)\n", + "print '%s' %(\"(c) R.M.S value of current flowing\")\n", + "Irms=Im/2. #rms current\n", + "print '%s %.2f' %(\"Irms=mA\",Irms*10**3)\n", + "print '%s' %(\"(2) DC output power\")\n", + "Pdc=(Idc)**2.*Rl #dc output power\n", + "print '%s %.1f' %(\"Pdc=Watt\",Pdc)\n", + "print '%s' %(\"(3) AC input power\")\n", + "Pac=(Irms)**2.*(rF+Rl)\n", + "print '%s %.2f' %(\"Pac=Watt\",Pac)\n", + "print '%s' %(\"(4)Efficiency of rectifier\")\n", + "n=(Pdc/Pac)*100. #efficiency\n", + "print '%s %.2f' %(\"n=\",n)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1)(a) Peak value of current flowing\n", + "Im=mA 55.81\n", + "(b) Average or DC current flowing\n", + "Idc=mA 17.77\n", + "(c) R.M.S value of current flowing\n", + "Irms=mA 27.91\n", + "(2) DC output power\n", + "Pdc=Watt 1.1\n", + "(3) AC input power\n", + "Pac=Watt 3.35\n", + "(4)Efficiency of rectifier\n", + "n= 32.99\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 221" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_5 Pg-221\n", + "#calculate Peak output volatge,Average output current,Diode dissipation\n", + "import math\n", + "Vr=0.7 #diodes voltage drop\n", + "Rl=820. #load resistor in ohm\n", + "Vin=40. #input voltage in V\n", + "print '%s' %(\"(1) Peak output volatge: Current flows through load only when two diodes conduct. While conducting, there is voltage drop across the diode.\")\n", + "V_drop_2=2.*Vr #voltage drop across 2 diodes\n", + "Vm=Vin-V_drop_2 #peak voltage\n", + "print '%s %.2f' %(\"\\nVm=V\",Vm)\n", + "print '%s' %(\"\\n(2) Average output current\")\n", + "Idc=(2*Vm/math.pi)/Rl #average output current\n", + "print '%s %.0f' %(\"Idc=mA\",Idc*10**3)\n", + "print '%s' %(\"\\n(3) Diode dissipation\")\n", + "DD=Idc*Vr #Diode dissipation\n", + "print '%s %.0f' %(\"=mW\",DD*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) Peak output volatge: Current flows through load only when two diodes conduct. While conducting, there is voltage drop across the diode.\n", + "\n", + "Vm=V 38.60\n", + "\n", + "(2) Average output current\n", + "Idc=mA 30\n", + "\n", + "(3) Diode dissipation\n", + "=mW 21\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 222" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_6 Pg-222\n", + "#calculate RMS value of secondary voltage,,Peak secondary voltage,Peak inverse voltage of diode,Peak load voltage,DC load voltage\n", + "import math\n", + "Vr=0.7 #voltage drop\n", + "Vi=120. #input voltage\n", + "print '%s' %(\"RMS value of secondary voltage\")\n", + "V_sec=Vi/5. #RMS value of secondary voltage\n", + "print '%s %.0f' %(\"=V\",V_sec)\n", + "print '%s' %(\"Peak secondary voltage\")\n", + "Vm=V_sec*math.sqrt(2.) #Peak secondary voltage\n", + "print '%s %.0f' %(\"=V\",Vm)\n", + "print '%s' %(\"Peak inverse voltage of diode\")\n", + "Vinv=-(Vm) #Peak inverse voltage of diode\n", + "print '%s %.0f' %(\"=V\",Vinv)\n", + "print '%s %.0f' %(\"\\nPeak load voltage=V\",Vm)\n", + "print '%s' %(\"DC load voltage\")\n", + "Vdc=Vm/math.pi #DC load voltage\n", + "print '%s %.1f' %(\"=V\",Vdc)\n", + "print '%s' %(\"Assuming second approximation\")\n", + "print '%s' %(\"Vm'' = Vm - Vr \")\n", + "print '%s' %(\"Peak load voltage\")\n", + "Vm_dash=Vm-Vr #Peak load voltage\n", + "print '%s %.1f' %(\"=V\",Vm_dash)\n", + "print '%s' %(\"DC load voltage\")\n", + "Vdc=Vm_dash/math.pi #DC load voltage\n", + "print '%s %.1f' %(\"=V\",Vdc)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "RMS value of secondary voltage\n", + "=V 24\n", + "Peak secondary voltage\n", + "=V 34\n", + "Peak inverse voltage of diode\n", + "=V -34\n", + "\n", + "Peak load voltage=V 34\n", + "DC load voltage\n", + "=V 10.8\n", + "Assuming second approximation\n", + "Vm'' = Vm - Vr \n", + "Peak load voltage\n", + "=V 33.2\n", + "DC load voltage\n", + "=V 10.6\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 222" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_7 Pg-222\n", + "#calculate Secondary RMS voltage,Secondary pek voltage,Half of the secondary voltage is input to the half section,Peak voltage across load,DC load current\n", + "import math\n", + "Vi=120. #supply voltage n V\n", + "Rl=5.*10.**3. #load resistance\n", + "print '%s' %(\"Secondary RMS voltage\")\n", + "Vrms=Vi/5. #Secondary RMS voltage\n", + "print '%s %.0f' %(\"=V\",Vrms)\n", + "print '%s' %(\"Secondary pek voltage\")\n", + "Vm=Vrms*math.sqrt(2.) #Secondary pek voltage\n", + "print '%s %.0f' %(\"=V\",Vm)\n", + "print '%s' %(\" Half of the secondary voltage is input to the half section.\")\n", + "print '%s' %(\"So input to the half section\")\n", + "i=Vm/2. #input to the half section\n", + "print '%s %.0f' %(\"=V\",i)\n", + "print '%s' %(\"Peak voltage across load\")\n", + "print '%s %.0f' %(\"=V\",i)\n", + "print '%s' %(\"DC voltage across load = 17V. Since the capacitor gets changed up to peak value,\")\n", + "print '%s' %(\"DC load current\")\n", + "Vdc=i\n", + "Idc=Vdc/Rl #DC load current\n", + "print '%s %.1f' %(\"=mA\",Idc*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Secondary RMS voltage\n", + "=V 24\n", + "Secondary pek voltage\n", + "=V 34\n", + " Half of the secondary voltage is input to the half section.\n", + "So input to the half section\n", + "=V 17\n", + "Peak voltage across load\n", + "=V 17\n", + "DC voltage across load = 17V. Since the capacitor gets changed up to peak value,\n", + "DC load current\n", + "=mA 3.4\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 227" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_8 Pg-227\n", + "#calculate Ripple factor for a full wave rectifier,DC output voltage,Percentage voltage regulation\n", + "import math\n", + "f=50. #frequency in Hz\n", + "C=100.*10.**(-6.) #capacitance in F\n", + "Rl=2.*10.**3. #load resistance\n", + "Vrms=40. #rms secondary voltage\n", + "print '%s' %(\"(a) Ripple factor for a full wave rectifier\")\n", + "r=1./(4.*math.sqrt(3.)*f*C*Rl) #Ripple factor for a full wave rectifier\n", + "print '%s %.3f' %(\"=\",r)\n", + "print '%s' %(\"(b) DC output voltage\")\n", + "Vm=Vrms*math.sqrt(2.)\n", + "Vdc=Vm/(1.+(1./(4.*f*C*Rl))) #DC output voltage\n", + "print '%s %.1f' %(\"=V\",Vdc)\n", + "print '%s' %(\"(c) Percentage voltage regulation\")\n", + "per=100./(4.*f*C*Rl) #Percentage voltage regulation\n", + "print '%s %.1f' %(\"=\",per)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a) Ripple factor for a full wave rectifier\n", + "= 0.014\n", + "(b) DC output voltage\n", + "=V 55.2\n", + "(c) Percentage voltage regulation\n", + "= 2.5\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 237" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_9 Pg-237\n", + "#calculate Connected load,Ripple factor in case of shunt capacitor filter\n", + "import math\n", + "Vrms=300. #rms voltage in V\n", + "f=60. #frequency\n", + "Idc=0.2 #load current\n", + "C=10. #shunt capacitor in microFarad\n", + "Vm=Vrms*math.sqrt(2.) #peak voltage\n", + "Vdc=(2*Vm)/math.pi #Dc voltage\n", + "print '%s' %(\"Connected load\")\n", + "Rl=Vdc/Idc #Connected load\n", + "print '%s %.0f' %(\"Rl=ohm = (955.6)*sqrt(2) ohm\\n\",Rl)\n", + "print '%s' %(\"Ripple factor in case of shunt capacitor filter \")\n", + "print '%s' %(\"=2410/C*Rl\")\n", + "r=2410./(C*Rl) #ripple factor\n", + "print '%s %.2f' %(\"=\",r)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Connected load\n", + "Rl=ohm = (955.6)*sqrt(2) ohm\n", + " 1350\n", + "Ripple factor in case of shunt capacitor filter \n", + "=2410/C*Rl\n", + "= 0.18\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E10 - Pg 238" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_10 Pg-238\n", + "#calculate Peak voltage,DC output voltage,Ripple factor in case of capacitor filter\n", + "import math\n", + "f=60. #frequency in Hz\n", + "C=100.*10.**(-6.) #capacitance in F\n", + "Rl=1.*10.**3. #load resistance\n", + "\n", + "print '%s' %(\"Since the transformer is center tapped ,the rms value of voltage across half the secondary coil\")\n", + "Vct=12.6 #voltage of center tapped transformer\n", + "Vrms=Vct/2. #rms voltage\n", + "\n", + "print '%s' %(\"Peak voltage\")\n", + "Vm=Vrms*math.sqrt(2.) #peak voltage\n", + "print '%s %.2f' %(\"= V\\n \",Vm)\n", + "\n", + "print '%s' %(\"(b) DC output voltage\")\n", + "Vdc=Vm/(1.+(1./(4.*f*C*Rl))) #DC output voltage\n", + "print '%s %.2f' %(\"=V\\n \",Vdc)\n", + "\n", + "print '%s' %(\"Ripple factor in case of capacitor filter \")\n", + "print '%s' %(\"=2410/C*Rl\")\n", + "r=2410./(100.*Rl)*100. #ripple factor\n", + "print '%s %.1f' %(\"\\n=\\n \",r)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Since the transformer is center tapped ,the rms value of voltage across half the secondary coil\n", + "Peak voltage\n", + "= V\n", + " 8.91\n", + "(b) DC output voltage\n", + "=V\n", + " 8.55\n", + "Ripple factor in case of capacitor filter \n", + "=2410/C*Rl\n", + "\n", + "=\n", + " 2.4\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E11 - Pg 238" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_11 Pg-238\n", + "#calculate the LOad connected to the filter,Critical value of inductor,Capacitance\n", + "import math\n", + "Vdc=9. #dc voltage\n", + "Idc=100.*10.**(-3.) #dc load current\n", + "print '%s' %(\"Ripple factor with an L-C filter,r=(0.83/LC)\")\n", + "print '%s' %(\"where L-> Henry,C->microFarad\")\n", + "gamm=0.02 #maximum ripple\n", + "LC=0.83/gamm\n", + "print '%s %.1f' %(\"LC =\",LC) #let LC=42\n", + "\n", + "print '%s' %(\"LOad connected to the filter,\")\n", + "RL=Vdc/Idc #load resistance in ohm\n", + "print '%s %.0f' %(\"RL=ohm\",RL)\n", + "\n", + "print '%s' %(\"Critical value of inductor,\")\n", + "Lk=RL/900. #Critical value of inductor\n", + "print '%s %.1f' %(\"Lk=\",Lk)\n", + "\n", + "print '%s' %(\"Capacitance\")\n", + "LC=42. #rounding of 41.5 to 42\n", + "C=LC/Lk #capacitance in microFarad\n", + "print '%s %.0f' %(\"C =uF\",C)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ripple factor with an L-C filter,r=(0.83/LC)\n", + "where L-> Henry,C->microFarad\n", + "LC = 41.5\n", + "LOad connected to the filter,\n", + "RL=ohm 90\n", + "Critical value of inductor,\n", + "Lk= 0.1\n", + "Capacitance\n", + "C =uF 420\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E12 - Pg 245" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_12 Pg-245\n", + "#calculate Voltage across resistor,Current through series resistor\n", + "V=20. #source voltage\n", + "Vz=12. #zener voltage\n", + "Vr=V-Vz #voltage across resistor \n", + "Rs=330. #series resistance\n", + "print '%s' %(\"Voltage across resistor \")\n", + "print '%s %.0f' %(\"=V\",Vr)\n", + "print '%s' %(\"Current through series resistor\")\n", + "Iser=Vr/Rs #Current through series resistor\n", + "print '%s %.1f' %(\"=mA\",Iser*10**3)\n", + "print '%s' %(\"Since Zener diode is in series with resistor, current through it is equal to current flowing through resistor,i.e 24.2mA \")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Voltage across resistor \n", + "=V 8\n", + "Current through series resistor\n", + "=mA 24.2\n", + "Since Zener diode is in series with resistor, current through it is equal to current flowing through resistor,i.e 24.2mA \n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E13 - Pg 245" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_13 Pg-245\n", + "#calclate Voltage across resistor,Current through series resistor,Current through series load Il,Current through zener diode,Respective wattage of elements used\n", + "V=20. #source voltage in V\n", + "Vz=12. #zener voltage in V\n", + "Vs=V-Vz #voltage across resistor in V \n", + "Rs=330. #series resistance in ohm\n", + "RL=1.5*10**3 #load resistance in ohm\n", + "print '%s' %(\"Voltage across resistor \")\n", + "print '%s %.0f' %(\"=V\",Vs)\n", + "\n", + "print '%s' %(\"(1) Current through series resistor Is\")\n", + "Is=Vs/Rs #Current through series resistor\n", + "print '%s %.1f' %(\"Is=mA\",Is*10**3)\n", + "\n", + "print '%s' %(\"(2) Current through series load Il\")\n", + "VL=Vz #voltage across load\n", + "IL=VL/RL #Current through series load\n", + "print '%s %.0f' %(\"IL=mA\",IL*10**3)\n", + "\n", + "print '%s' %(\"(3)Current through zener diode\")\n", + "Iz=Is-IL #Current through zener diode\n", + "print '%s %.1f' %(\"IL=mA\",Iz*10**3)\n", + "\n", + "print '%s' %(\"(4)Respective wattage of elements used\")\n", + "print '%s' %(\"(a) Series resistor -> W=Is*Vs\")\n", + "W=Vs*Is #wattage of series resistor\n", + "print '%s %.1f' %(\"=mW\",W*10**3)\n", + "\n", + "print '%s' %(\"(b) Zener diode -> W=Iz*Vz\")\n", + "W=Vz*Iz #wattage of zener diode\n", + "print '%s %.1f' %(\"=mW\",W*10**3)\n", + "\n", + "\n", + "print '%s' %(\"(b) Load resistor -> W=IL*VL\")\n", + "W=VL*IL #wattage of zener diode\n", + "print '%s %.0f' %(\"=mW\",W*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Voltage across resistor \n", + "=V 8\n", + "(1) Current through series resistor Is\n", + "Is=mA 24.2\n", + "(2) Current through series load Il\n", + "IL=mA 8\n", + "(3)Current through zener diode\n", + "IL=mA 16.2\n", + "(4)Respective wattage of elements used\n", + "(a) Series resistor -> W=Is*Vs\n", + "=mW 193.9\n", + "(b) Zener diode -> W=Iz*Vz\n", + "=mW 194.9\n", + "(b) Load resistor -> W=IL*VL\n", + "=mW 96\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E14 - Pg 246" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_14 Pg-246\n", + "#calculate, Applying Thevenin's theorem, Thevenin voltage across the zener diode\n", + "RL=1.*10.**3. #load resistance in ohm\n", + "Rs=270. #series resistor in ohm\n", + "Vs=18. #supply voltage in V\n", + "vz=10. #xener voltage\n", + "print '%s' %(\"Applying Thevenin''s theorem, Thevenin voltage across the zener diode\")\n", + "Vth=(RL/(RL+Rs))*Vs #Thevenin voltage\n", + "print '%s %.1f' %(\"Vth=V\",Vth)\n", + "print '%sf' %(\"Thus Vth is greater than Vz(zener voltage),i.e 14.2 >10. So Zener diode is operating in the breakdown voltage.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Applying Thevenin''s theorem, Thevenin voltage across the zener diode\n", + "Vth=V 14.2\n", + "Thus Vth is greater than Vz(zener voltage),i.e 14.2 >10. So Zener diode is operating in the breakdown voltage.f\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E15 - Pg 246" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex4_15 Pg-246\n", + "#calculate Average load current,Total current entering the circuit,Series resistor,Power rating of resistor\n", + "IL1=10.*10.**(-3.) \n", + "IL2=20.*10.**(-3.) #IL1,IL2 range of load current in A\n", + "Vin=20. #supply voltage in V\n", + "Izt=6.*10.**(-3.) #zener current in A\n", + "Vz=15. #zener voltage in V\n", + "\n", + "print '%s' %(\"Average load current\")\n", + "IL=(IL1+IL2)/2. # Average load current\n", + "print '%s %.0f' %(\"\\nIL=mA\",IL*10**3)\n", + "\n", + "print '%s' %(\"Total current entering the circuit\")\n", + "Is=IL+Izt #current entering the circuit\n", + "print '%s %.0f' %(\"\\nIs=mA\",Is*10**3)\n", + "\n", + "print '%s' %(\"Series resistor\")\n", + "Rs=(Vin-Vz)/Is #Series resistor in ohm\n", + "print '%s %.0f' %(\"Rs=ohm\",Rs)\n", + "\n", + "print '%s' %(\"Power rating of resistor\")\n", + "Vs=Vin-Vz \n", + "P=(Vs**2.)/Rs #Power rating of resistor\n", + "print '%s %.1f' %(\"\\nP=W\",P)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average load current\n", + "\n", + "IL=mA 15\n", + "Total current entering the circuit\n", + "\n", + "Is=mA 21\n", + "Series resistor\n", + "Rs=ohm 238\n", + "Power rating of resistor\n", + "\n", + "P=W 0.1\n" + ] + } + ], + "prompt_number": 15 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_5.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_5.ipynb new file mode 100755 index 00000000..010ef3d2 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_5.ipynb @@ -0,0 +1,147 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:0fc065a608f382e46ef4cfe7a37f8897fcb5ae3ef927491454131279917b9b2c" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5 - Transistors" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 278" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex5_1 Pg-278\n", + "#calculate Collector current,Emitter current\n", + "alpha_dc=0.97 #transistor current gain\n", + "ICBO=10.*10.**(-6.) #collector to base leakage current in A\n", + "Ib=50.*10.**(-6.) #base current in A\n", + "Ic=((alpha_dc*Ib)/(1.-alpha_dc))+(ICBO/(1.-alpha_dc)) #collector current\n", + "print '%s %.2f' %(\"Collector current =mA\",Ic*10**3)\n", + "Ie=Ic+Ib #emitter current\n", + "print '%s %.0f' %(\"Emitter curren=mA\",Ie*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Collector current =mA 1.95\n", + "Emitter curren=mA 2\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 279" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex5_2 Pg-279\n", + "#calculate Common current gain factor alpha_dc,Dc emitter current gain factor beta,Emitter current\n", + "Ic=5.255*10.**(-3.) #collector current in A\n", + "Ib=100.*10.**(-6.) #base current in A\n", + "ICBO=5.*10.**(-6.) #collector to base leakage current in A\n", + "alpha_dc=(Ic-ICBO)/(Ib+Ic) #common current gain factor\n", + "print '%s %.2f' %(\"Common current gain factor alpha_dc=\",alpha_dc) \n", + "Beta=alpha_dc/(1-alpha_dc) #Dc emitter current gain factor value in text book is wrong\n", + "print '%s %.2f' %(\"\\nDc emitter current gain factor beta =\",Beta)\n", + "Ie=Ic+Ib #emitter current value in text book wrong\n", + "print '%s %.3f' %(\"\\nEmitter current=mA\",Ie*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Common current gain factor alpha_dc= 0.98\n", + "\n", + "Dc emitter current gain factor beta = 50.00\n", + "\n", + "Emitter current=mA 5.355\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 279" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex5_3 Pg-279\n", + "#calculate Dc emitter current gain factor beta,Emitter current,Common current gain factor alpha_dc,Collector current\n", + "Ic=12.427*10.**(-3.) #collector current in A\n", + "Ib=200.*10.**(-6.) #base current in A\n", + "ICBO=7.*10.**(-6.) #collector to base leakage current in A\n", + "Beta=(Ic-ICBO)/(Ib+ICBO) #Dc emitter current gain factor (value in texbook is wrong)\n", + "print '%s %.0f' %(\"\\nDc emitter current gain factor beta=\",Beta)\n", + "Ie=Ic+Ib #emitter current \n", + "print '%s %.1f' %(\"\\nEmitter current=mA\",Ie*10**3)\n", + "alpha_dc=(Ic-ICBO)/(Ib+Ic) #common current gain factor\n", + "print '%s %.2f' %(\"\\nCommon current gain factor alpha_dc=\",alpha_dc) \n", + "Ib=150.*10.**(-6.) #new base current\n", + "Ic=Beta*Ib+(Beta+1.)*ICBO #collector current (value in textbook is wrong)\n", + "print '%s %.3f' %(\"\\nCollector current=mA\",Ic*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Dc emitter current gain factor beta= 60\n", + "\n", + "Emitter current=mA 12.6\n", + "\n", + "Common current gain factor alpha_dc= 0.98\n", + "\n", + "Collector current=mA 9.427\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_6.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_6.ipynb new file mode 100755 index 00000000..f251fb09 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_6.ipynb @@ -0,0 +1,202 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:30ef5343042903d8510275136ddf0764ce01b270d174089f40bb683199c9a8e1" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 6 - Thermal Stability" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 333" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex6_1 Pg-333\n", + "#calculate The relation for thermal stability\n", + "Ta=25. #ambient temperature in degree celsius\n", + "tetha=10. #thermal resistance \n", + "Pd=2. #power dessipated in transistor\n", + "Tj=Ta+tetha*Pd #collector base junction transistor temperature\n", + "print '%s %.0f' %(\"\\nCollector base junction transistor temperature=degree celcius\\n\",Tj)\n", + "print '%s' %(\"tetha=10 degree celcius/watt means for every watt consumed its temperature will rise by 10 degree celcius\")\n", + "print '%s' %(\"\\nWhile using a transistor,we must keep in mind that it must not reach a condition called thermal runaway.\\nThe heat released at collector base junction must not exceed the rate at which heat can dissipated under steady state. For this,\\n \")\n", + "print '%s' %(\"(del_Pd/del_Tj) < (1/tetha)\")\n", + "print '%s' %(\"This is the relation for thermal stability.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Collector base junction transistor temperature=degree celcius\n", + " 45\n", + "tetha=10 degree celcius/watt means for every watt consumed its temperature will rise by 10 degree celcius\n", + "\n", + "While using a transistor,we must keep in mind that it must not reach a condition called thermal runaway.\n", + "The heat released at collector base junction must not exceed the rate at which heat can dissipated under steady state. For this,\n", + " \n", + "(del_Pd/del_Tj) < (1/tetha)\n", + "This is the relation for thermal stability.\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 335" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex6_2 Pg-335\n", + "#calculate the dissipation capability at 50 degree celcius\n", + "print '%s' %(\"Draw a vertical line from temperature axis at 50 degree celcius to cut the 71 degree celcius line.\\nJoin the point of intersection P through a horizontal line at Y-axis.\\nThe point where it intersects Y-axis gives the value of permissible dissipation equal to 45 of maximum rating.\\n\")\n", + "per=.45 #permissible dissipation in percentage\n", + "max_diss=165. #maximum dissipation\n", + "diss_cap=per*max_diss #dissipation capability\n", + "print '%s' %(\"The dissipation capability at 50 degree celcius\")\n", + "print '%s %.0f' %(\"= %.0f mW \\n \",diss_cap)\n", + "print '%s' %(\"Its value ranges from (0.2) degree celcius/watt to (1000) degree celcius/watt for a transistor that has an efficient heat sink\")\n", + "print '%s' %(\"Tj = Ta + tetha*Pd\")\n", + "print '%s' %(\"The above equation reflects that collector-junction temperature Tj of the transistor will be higher than ambient temperature Ta by an amount equal to the product of tetha and Pd.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Draw a vertical line from temperature axis at 50 degree celcius to cut the 71 degree celcius line.\n", + "Join the point of intersection P through a horizontal line at Y-axis.\n", + "The point where it intersects Y-axis gives the value of permissible dissipation equal to 45 of maximum rating.\n", + "\n", + "The dissipation capability at 50 degree celcius\n", + "= %.0f mW \n", + " 74\n", + "Its value ranges from (0.2) degree celcius/watt to (1000) degree celcius/watt for a transistor that has an efficient heat sink\n", + "Tj = Ta + tetha*Pd\n", + "The above equation reflects that collector-junction temperature Tj of the transistor will be higher than ambient temperature Ta by an amount equal to the product of tetha and Pd.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 335" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex6_3 Pg-335\n", + "#calculate The operating point coordinates\n", + "Rb=200.*10.**(3.) #base resistance in ohm\n", + "Vcc=10. #supply voltage in V\n", + "Vbe=0.7 #voltage drop in V\n", + "Rl=2.*10.**(3.) #load resistor in ohm\n", + "Beta=50. #transistor gain\n", + "print '%s' %(\"If Beta=50\")\n", + "Ib=(Vcc-Vbe)/Rb #base current in A\n", + "Ic=Beta*Ib #collector current\n", + "Vce=Vcc-Ic*Rl #collector emitter voltage\n", + "print '%s %.2f %.2f' %(\"The operating point coordinates are [V,mA]\\n\",Vce, Ic*10**3)\n", + "print '%s' %(\"\\nIf Beta=60\")\n", + "Beta2=60 #second transistor gain \n", + "Ic2=Beta2*Ib #collector current\n", + "Vce2=Vcc-Ic2*Rl #collector emitter voltage\n", + "print '%s %.2f %.2f' %(\"The operating point coordinates are [V,mA]\\n\",Vce2, Ic2*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "If Beta=50\n", + "The operating point coordinates are [V,mA]\n", + " 5.35 2.33\n", + "\n", + "If Beta=60\n", + "The operating point coordinates are [V,mA]\n", + " 4.42 2.79\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 335" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex6_4 Pg-335\n", + "#calculate The collector emitter voltage\n", + "Rb=330.*10.**(3.) #base resistance in ohm\n", + "Vcc=15. #supply voltage in V\n", + "Vbe=0.7 #voltage drop in V\n", + "Rl=3.3*10.**(3.) #load resistor in ohm\n", + "Beta=60. #transistor gain\n", + "Ib=(Vcc-Vbe)/Rb #base current in A\n", + "Ic=Beta*Ib #collector current (value in textbook is wrong)\n", + "Vce=Vcc-(Ic+Ib)*Rl \n", + "print '%s %.2f' %(\"The collector emitter voltage=V\",Vce)\n", + "#collector emitter voltage (value in textbook is wrong) \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The collector emitter voltage=V 6.28\n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_7.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_7.ipynb new file mode 100755 index 00000000..15242e34 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_7.ipynb @@ -0,0 +1,451 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:66025946991647ff9e251a330d5b2003c23b73f54893a4b198da6580fdd0210c" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 7 - Amplifiers" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 369" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_1 Pg-369\n", + "#calculate Lowest frequency\n", + "import math\n", + "print '%s' %(\"Refer to the figure 7.19\")\n", + "print '%s' %(\"For good coupling\")\n", + "print '%s' %(\"Xc <= 0.1*R\")\n", + "R=10.*10.**(3.) #resistor R in ohm\n", + "C=68.*10.**(-6.) #capacitance in Farad\n", + "f=1./(2.*math.pi*C*0.1*R)\n", + "print '%s' %(\"Lowest frequency,f\")\n", + "print '%s %.2f' %(\"=Hz\",f)\n", + "print '%s' %(\"or lowest frequency is approximately 3 Hz\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 7.19\n", + "For good coupling\n", + "Xc <= 0.1*R\n", + "Lowest frequency,f\n", + "=Hz 2.34\n", + "or lowest frequency is approximately 3 Hz\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 369" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_2 Pg-369\n", + "#calculate\n", + "import math\n", + "print '%s' %(\"Refer to the figure 7.20\")\n", + "print '%s' %(\"For good coupling\")\n", + "print '%s' %(\"Xc <= 0.1*R\")\n", + "R=10.*10.**(3.) #resistor R in ohm\n", + "C=220.*10.**(-6.) #capacitance in Farad\n", + "f=1./(2.*math.pi*C*0.1*R)\n", + "print '%s' %(\"Lowest frequency,f\")\n", + "print '%s %.2f' %(\"=Hz\",f)\n", + "print '%s' %(\"or lowest frequency is approximately 1 Hz\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Refer to the figure 7.20\n", + "For good coupling\n", + "Xc <= 0.1*R\n", + "Lowest frequency,f\n", + "=Hz 0.72\n", + "or lowest frequency is approximately 1 Hz\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 369" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_3 Pg-369\n", + "#calculate Base voltage,Emitter voltage,Emitter current,AC emitter diode resistance\n", + "Beta=250. #transistor gain\n", + "Vcc=15. #supply voltage\n", + "R1=2000. #resistor R1 in ohm\n", + "R2=470. #resistor R2 in ohm\n", + "Vce=0.7 #voltage drop in V\n", + "Re=220. #emitter resistor in ohm\n", + "Vb=(Vcc*R2)/(R1+R2) #base voltage in V\n", + "print '%s' %(\"(1) Base voltage Vb\")\n", + "print '%s %.2f' %(\"=V\",Vb)\n", + "Ve=Vb-Vce #emitter voltage in V\n", + "print '%s' %(\"Emitter voltage Vb\")\n", + "print '%s %.2f' %(\"=V\",Ve)\n", + "Ie=Ve/Re #emitter current\n", + "print '%s' %(\"Emitter current \")\n", + "print '%s %.3f' %(\"Ie=*10**-2 A\",Ie*10**2)\n", + "print '%s' %(\"For small signal operation, ie <= 0.1*Ie\")\n", + "ie=0.1*Ie \n", + "print '%s %.3f' %(\"=mA\",ie*10**3)\n", + "print '%s' %(\"(2) AC emitter diode resistance =25mV/ie\")\n", + "Re_ac=25.*10.**(-3.)/ie #AC emitter diode resistance\n", + "print '%s %.0f' %(\"=ohm\",Re_ac)\n", + "print '%s' %(\"(3) Z''vm = Beta*r''e\")\n", + "Re_ac=26. #AC emitter diode resistance assumed 26 ohm not 25.53 ohm\n", + "Zvm=Beta*Re_ac\n", + "print '%s %.0f' %(\"=ohm\",Zvm)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) Base voltage Vb\n", + "=V 2.85\n", + "Emitter voltage Vb\n", + "=V 2.15\n", + "Emitter current \n", + "Ie=*10**-2 A 0.979\n", + "For small signal operation, ie <= 0.1*Ie\n", + "=mA 0.979\n", + "(2) AC emitter diode resistance =25mV/ie\n", + "=ohm 26\n", + "(3) Z''vm = Beta*r''e\n", + "=ohm 6500\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 370" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_4 Pg-370\n", + "#calculate Base voltage,Emitter voltage,Emitter current,AC emitter diode resistance,Voltage gai,Zin stage,Input voltage,Output voltage\n", + "import math \n", + "Beta=100. #transistor gain\n", + "Vcc=10.#supply voltage\n", + "R1=10.*10.**(3.) #resistor R1 in ohm\n", + "R2=2200. #resistor R2 in ohm\n", + "Vce=0.7 #voltage drop in V\n", + "Re=2000. #emitter resistor in ohm\n", + "Rs=600. #source resistor in ohm\n", + "Vb=(Vcc*R2)/(R1+R2) #base voltage in V\n", + "print '%s' %(\"Base voltage Vb\")\n", + "print '%s %.1f' %(\"=V\",Vb)\n", + "Ve=Vb-Vce #emitter voltage in V\n", + "print '%s' %(\"Emitter voltage Vb\")\n", + "print '%s %.1f' %(\"=V\",Ve)\n", + "Ie=Ve/Re #emitter current\n", + "print '%s' %(\"Emitter current\")\n", + "print '%s %.2f' %(\"=mA\",Ie*10**3)\n", + "print '%s' %(\"AC emitter diode resistance =25mV/ie\")\n", + "re=25.*10.**(-3.)/Ie #AC emitter diode resistance\n", + "print '%s %.0f' %(\"=ohm\",re)\n", + "rc=((3.6*10.)/(3.6+10.))*10.**(3.) #Collector dioed resistance\n", + "A=rc/re #voltage gain(value in text book is wrong)\n", + "print '%s' %(\"Voltage gain A\")\n", + "print '%s %.0f' %(\"=\",A)\n", + "zin_1=((10.*2.2)/(10.+2.2))\n", + "zin=((zin_1*Beta*A)/(zin_1+(Beta*A)))*1000\n", + "print '%s' %(\"Zin stage\")\n", + "print '%s %.3f' %(\"=kohm\",zin*10**-3)\n", + "Vin=(zin/(Rs+zin))*10.**(-3.) #input voltage (value in text book is wrong)\n", + "print '%s' %(\"Input voltage\")\n", + "print '%s %.2f' %(\"=mV\",Vin*10**3)\n", + "Vout=A*Vin #output voltage (value in textbook is wrong)\n", + "print '%s' %(\"Output voltage\")\n", + "print '%s %.2f' %(\"=mV\",Vout*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Base voltage Vb\n", + "=V 1.8\n", + "Emitter voltage Vb\n", + "=V 1.1\n", + "Emitter current\n", + "=mA 0.55\n", + "AC emitter diode resistance =25mV/ie\n", + "=ohm 45\n", + "Voltage gain A\n", + "= 58\n", + "Zin stage\n", + "=kohm 1.803\n", + "Input voltage\n", + "=mV 0.75\n", + "Output voltage\n", + "=mV 43.82\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 371" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_5 Pg-371\n", + "#calculate\n", + "hfe=50. #current gain\n", + "Rl=10.*10.**(3.) #load resistor in ohm\n", + "Rs=500. #source resistor in ohm\n", + "hie=10.**(3.) #input resitance in ohm\n", + "A=hfe*Rl/(Rs+hie) #volatge gain\n", + "print '%s %.1f' %(\"Voltage gain=\",A)\n", + "Vs=0.02 #source voltage in V\n", + "Vout=A*Vs #output voltage\n", + "print '%s %.2f' %(\"Output voltage=V\",Vout)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Voltage gain= 333.3\n", + "Output voltage=V 6.67\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 372" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_6 Pg-372\n", + "#calculate Voltage gain,Power gain\n", + "import math\n", + "Vout=5. #output voltage\n", + "Vin=0.5 #input voltage\n", + "Ri=10.*10.**(3.) #input resistance in ohm\n", + "Ro=10. #output resistance\n", + "A=Vout/Vin #voltage gain\n", + "print '%s %.0f' %(\"Voltage gain =%.0f \\n\",A)\n", + "Pi=Vin**2./Ri #input power\n", + "Po=Vout**2./Ro #output power\n", + "Pow_gain=10.*(math.log10(Po)-math.log10(Pi)) #power gain\n", + "print '%s %.0f' %(\" Power gain(in decibel) = %.0f dB \\n\\n\",Pow_gain)\n", + "print '%s' %(\"When Ri=Ro\")\n", + "Ri=Ro\n", + "A=Vout/Vin #voltage gain\n", + "Pi=Vin**2./Ri #input power\n", + "Po=Vout**2./Ro #output power\n", + "Pow_gain=10.*(math.log10(Po)-math.log10(Pi)) #power gain \n", + "print '%s %.0f' %(\" Power gain(in decibel) = %.0f dB\",Pow_gain)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Voltage gain =%.0f \n", + " 10\n", + " Power gain(in decibel) = %.0f dB \n", + "\n", + " 50\n", + "When Ri=Ro\n", + " Power gain(in decibel) = %.0f dB 20\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 372" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_7 Pg-372\n", + "#calculate\n", + "import math\n", + "Rl=2.*10.**(3.) #load resistance in ohm\n", + "Ri=500. #input resistance in ohm\n", + "C=2.*10.**(-6.) #capacitor in microFarad\n", + "f=(1./(2.*math.pi*C*(Rl+Ri))) #textbook answer is wrong\n", + "print '%s %.0f' %(\"Lowest cut-off frequency=Hz\",f)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Lowest cut-off frequency=Hz 32\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 372" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_8 Pg-372\n", + "#calculate Coupling Capacitor\n", + "import math\n", + "Rl=20.*10.**(3.) #loaH resistance in ohm\n", + "Ri=5000. #input resistance in ohm\n", + "f=33. #lower cut-off frequency in Hz\n", + "f2=33.*10.**(3.) #higher cut-off frequency\n", + "C=(1./(2.*math.pi*f*(Rl+Ri))) #coupling capacitance (value in textbook is wrong)\n", + "print '%s %.1f' %(\"Coupling Capacitor=uF\",C*10**6)\n", + "Req=(Rl*Ri)/(Rl+Ri) #equivalent resistance\n", + "Cs=1/(2*math.pi*f2*Req) #shunting capacitance (value in textbook is wrong)\n", + "print '%s %.0f' %(\"Coupling Capacitor=uF\",Cs*10**12)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Coupling Capacitor=uF 0.2\n", + "Coupling Capacitor=uF 1206\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 373" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex7_9 Pg-373\n", + "#calculate Voltage Amplification,Output voltage\n", + "Rd=3000. #source resistance in ohm\n", + "Rl=5000. #load resistance in ohm\n", + "Req=Rd*Rl/(Rd+Rl) #equivqlent resistance\n", + "gm=4500.*10.**(-6.) #voltage gain in microMhos\n", + "Av=(-1.)*gm*Req #voltage amplification\n", + "print '%s %.2f' %(\"Voltage Amplification=\",Av)\n", + "Vi=100.*10.**(-3.) #input voltage\n", + "Vout=abs(Av)*Vi #output voltage (value in textbook is wrong)\n", + "print '%s %.1f' %(\"Output voltage=V\",Vout)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Voltage Amplification= -8.44\n", + "Output voltage=V 0.8\n" + ] + } + ], + "prompt_number": 9 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_8.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_8.ipynb new file mode 100755 index 00000000..8d024566 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_8.ipynb @@ -0,0 +1,271 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:60cd4e612c661e75774f4e02987168334e7c814ac1287153a9eb4e69ab4db901" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 8 - Feedback Amplifiers" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 434" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex8_1 pg-434\n", + "#calculate Input signal,Gain after feedback,Feedback\n", + "import math\n", + "A=120. #amplification gain\n", + "Vi=50.*10.**(-3.) #input voltage\n", + "Beta=0.1 #feedback factor\n", + "Vo= A*Vi #output voltage without feedback\n", + "print '%s %.2f' %(\"Input signal = V\",Vo)\n", + "Vs=Vi-Beta*Vo \n", + "#input signal +ve output because of -ve feedback (calue in texxtbook is wrong)\n", + "print '%s %.2f' %(\"Input signal = V\",abs(Vs))\n", + "vg=A/(1.+Beta*A) #voltage gain \n", + "print '%s %.1f' %(\"Gain after feedback =\",vg)\n", + "fb=(-1.)*20.*math.log10(1+(Beta*A))\n", + "print '%s %.3f' %(\"Feedback (db)=\",fb)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Input signal = V 6.00\n", + "Input signal = V 0.55\n", + "Gain after feedback = 9.2\n", + "Feedback (db)= -22.279\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 435" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex8_2 pg-435\n", + "#calculate\n", + "ff=4. #feedback factor\n", + "BW=6.*10.**(6.) #bandwidth in Hz\n", + "BW_fb=BW*(1.+ff) #Bandwidth with feedback factor(since Beta is +ve)\n", + "print '%s %.0f' %(\"Bandwidth with feedback factor = MHz\",BW_fb*10**-6)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Bandwidth with feedback factor = MHz 30\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 435" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex8_3 pg-435\n", + "#calculate Negative Feedback factor,Beta\n", + "openA=60000. #open loop gain \n", + "closeA=10000. #closed loop gain\n", + "Beta=((openA/closeA)-1.)/closeA\n", + "print '%s %.4f' %(\"Negative Feedback factor=\",Beta)\n", + "BA=Beta*openA #value of Beta*A\n", + "print '%s %.0f' %(\"Beta*A=\",BA)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Negative Feedback factor= 0.0005\n", + "Beta*A= 30\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 435" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex8_4 pg-435\n", + "#calculate Feedback factor,Gain after negative feedback\n", + "Df=0.5/100. #distortion after negative feedback\n", + "D=8./100. #harmonic distortion \n", + "BA=D/Df-1 #value of Beta*A\n", + "A=200.\n", + "Beta=BA/A #feedback factor\n", + "print'%s %.3f'%(\"Feedback factor=\",Beta)\n", + "Af=A/(1.+BA) #Gain after -ve feedback\n", + "print'%s %.1f'%(\"Gain after negative feedback=\",Af)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Feedback factor= 0.075\n", + "Gain after negative feedback= 12.5\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 436" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex8_5 pg-436\n", + "#calculate Decrement in distortion,Percentage change in distortion\n", + "A=100. #voltage gain\n", + "per=10./100. #percentage of negative feedback applied\n", + "BA=A*per #value of Beta*A\n", + "Af=A/(1.+BA) #gain after negative feedback\n", + "print '%s' %(\"Decrement in distortion,D-Df = D-(D/(1+Beta*A))\")\n", + "print '%s %.1f' %(\"=\",Af)\n", + "per_dis=(BA/(1.+BA))*100. #percentage change in distortion \n", + "print '%s %.0f' %(\"Percentage change in distortion=\",per_dis)\n", + "red=100-per_dis #reduction\n", + "print '%s %.0f' %(\"Therefore reduction is=\",red)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Decrement in distortion,D-Df = D-(D/(1+Beta*A))\n", + "= 9.1\n", + "Percentage change in distortion= 91\n", + "Therefore reduction is= 9\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 436" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex8_6 pg-436\n", + "#calculate Voltage gain after negative feedback,Voltage gain after negative feedback,Beta\n", + "A=50. #voltage gain\n", + "per=10./100. #percentage of negative feedback applied\n", + "BA=per*A #value of Beta*A\n", + "Af=A/(1.+BA) #gain after negative feedback\n", + "print '%s' %(\"(1) Voltage gain after negative feedback\")\n", + "print '%s %.2f' %(\"=\",Af)\n", + "A=50. #voltage gain\n", + "per=5./100. #percentage of negative feedback applied\n", + "BA=per*A #value of Beta*A\n", + "Af1=A/(1.+BA) #gain after negative feedback\n", + "print '%s' %(\"(2) Voltage gain after negative feedback\")\n", + "print '%s %.1f' %(\"=\",Af1)\n", + "print '%s' %(\"\\nSo the new gain is not double the previous case\")\n", + "print '%s' %(\"The difference between expected value and actual value of gain obtained is\")\n", + "diff_value=2.*Af-Af1 \n", + "print '%s %.2f' %(\"=\",diff_value)\n", + "print '%s' %(\"\\n(3) To have the gain double of case(1) i.e 16.66,let the feedback introduced be Beta(assuming negative feedback)\")\n", + "Af=16.66 #voltage gain with negative feedback\n", + "A=50. #voltage gain\n", + "Beta=((A/Af)-1.)/A #feedback in percentage\n", + "print '%s %.2f' %(\"Beta=\",Beta)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) Voltage gain after negative feedback\n", + "= 8.33\n", + "(2) Voltage gain after negative feedback\n", + "= 14.3\n", + "\n", + "So the new gain is not double the previous case\n", + "The difference between expected value and actual value of gain obtained is\n", + "= 2.38\n", + "\n", + "(3) To have the gain double of case(1) i.e 16.66,let the feedback introduced be Beta(assuming negative feedback)\n", + "Beta= 0.04\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_9.ipynb b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_9.ipynb new file mode 100755 index 00000000..8c67de26 --- /dev/null +++ b/Electronic_Devices_and_Circuits_by_S._L._Kakani_and_K._C._Bhandari/Chapter_9.ipynb @@ -0,0 +1,312 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:18f46455ac6bb4531327a629132bc2c4fc08dd747165df43064aceca96736d0b" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 9 - Negative Feedback Amplifier using Op-Amp" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 475" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_1 Pg-475\n", + "#calculate Close loop Bandwidth\n", + "Aol= 250000. #open loop gain\n", + "fol=160. #open loop frequency in HZ\n", + "Acl=50. #close loop gain\n", + "fcl=Aol/Acl*fol #close loop frequency in Hz\n", + "print '%s %.0f' %(\"Close loop Bandwidth = %.0f kHz\",fcl*10**-3) \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Close loop Bandwidth = %.0f kHz 800\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - 475" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_2 Pg-475\n", + "#calculate Close loop Bandwidth\n", + "Aol= 50000. #open loop gain\n", + "fol=14. #open loop frequency in HZ\n", + "fcl=(Aol+1)*fol #close loop frequency in Hz\n", + "print '%s %.0f' %(\"Close loop Bandwidth = kHz\",fcl*10**-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Close loop Bandwidth = kHz 700\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - 475" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_3 Pg-475\n", + "#calculate Close loop Bandwidth\n", + "Aol_Beta_1= 2500. #open loop gain\n", + "fol=20. #open loop frequency in HZ\n", + "fcl=Aol_Beta_1*fol #close loop frequency in Hz\n", + "print '%s %.0f' %(\"Close loop Bandwidth = kHz\",fcl*10**-3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Close loop Bandwidth = kHz 50\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - 475" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_4 Pg-475\n", + "#calculate Close loop Bandwidth,Peak value of output\n", + "import math\n", + "funi=1.*10.**(6.) #unity frequency in Hz\n", + "Sr=0.5/10.**(-6.) #slew rate in V/sec\n", + "Acl=10. #close loop gain\n", + "fcl=funi/Acl #close loop frequency in Hz\n", + "print '%s %.0f' %(\"(1)Close loop Bandwidth = kHz\",fcl*10**-3)\n", + "Vp_max=Sr/(2.*math.pi*fcl) #output peak value\n", + "print '%s %.3f' %(\"(2)Peak value of output = V\",Vp_max)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1)Close loop Bandwidth = kHz 100\n", + "(2)Peak value of output = V 0.796\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - 475" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_5 Pg-475\n", + "#calculate Feedback fraction,Ideal closed loop gain,Exact closed loop voltage gain\n", + "Aol= 88. #open loop gain in db\n", + "R1=2.7*10.**(3.) #resistor R1 in ohm\n", + "R2=68.*10.**(3.) #resistor R2 in ohm\n", + "Beta=R1/(R1+R2) #Feedback fraction\n", + "print '%s %.3f' %(\"Feedback fraction = \",Beta)\n", + "Acl=1./Beta #ideal closed loop gain\n", + "print '%s %.2f' %(\"Ideal closed loop gain = \",Acl)\n", + "Aol=10.**(88./20.) #open loop gain\n", + "Acl=Aol/(1.+Beta*Aol) #exact closed loop voltage gain\n", + "print '%s %.2f' %(\"Exact closed loop voltage gain = \",Acl)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Feedback fraction = 0.038\n", + "Ideal closed loop gain = 26.19\n", + "Exact closed loop voltage gain = 26.16\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - 476" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_6 Pg-476\n", + "#calculate Feedback fraction,Closed loop input impedance\n", + "Aol=20000.#open loop gain\n", + "R1=100. #resistor R1 in ohm\n", + "R2=7.5*10.**(3.) #resistor R2 in ohm\n", + "Rin=3.*10.**(6.) #input resistor in ohm\n", + "Rcm=500.*10.**(6.) \n", + "Beta=R1/(R1+R2) #Feedback fraction\n", + "print '%s %.5f' %(\"Feedback fraction = 1\\\\76 =\",Beta)\n", + "Req=(Rin*Rcm)/(Rin+Rcm) #equivalent resistance of Rin and Rcm\n", + "Zcl=(1.+Beta*Aol)*Req #closed loop input impedance (textbook answer is wrong)\n", + "print '%s %.0f %s' %(\"Closed loop input impedance =\",Zcl*10**-6,\"Mohm\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Feedback fraction = 1\\76 = 0.01316\n", + "Closed loop input impedance = 788 Mohm\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - 477" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_7 Pg-477\n", + "#calculate Current gain,Output current\n", + "R1=1.8 #resistor R1 in ohm\n", + "R2=1.5*10.**(3.) #resistor R2 in ohm\n", + "Iin=1.*10.**(-3.) #input current in A\n", + "Ai=1.+(R2/R1) #Current gain\n", + "print '%s %.0f' %(\"Current gain =\",Ai)\n", + "Il=Ai*Iin #Output current\n", + "print '%s %.0f' %(\"Output current = mA pp\",Il*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Current gain = 834\n", + "Output current = mA pp 834\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - 477" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Ex9_8 Pg-477\n", + "#calculate Output current,Load power,Load power\n", + "R1=2.7 #resistor R1 in ohm\n", + "R2=1.#resistor R2 in ohm\n", + "Vin=0.5 #input voltage in V\n", + "Io=Vin/R1 #output current\n", + "print '%s %.0f' %(\"(1) Output current = mA\",Io*10**3)\n", + "P=Io**2.*R2 #load power\n", + "print '%s %.1f' %(\"(2a) Load power = mW\",P*10**3)\n", + "R2=2 # new load resistor R2 in ohm\n", + "P=Io**2*R2 #load power\n", + "print '%s %.1f' %(\"(2b) Load power = mW\",P*10**3)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(1) Output current = mA 185\n", + "(2a) Load power = mW 34.3\n", + "(2b) Load power = mW 68.6\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Engineering_Physics_By_G_Vijayakumari/Chapter1.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter1.ipynb new file mode 100755 index 00000000..aea79a8c --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter1.ipynb @@ -0,0 +1,684 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#1: Acoustics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.1, Page number 2" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sound intensity level is imcreased by 13.01 dB when the intensity is doubled\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "i=20; #the intensity of a source is increased 20 times\n", + "\n", + "#Calculation\n", + "I=(10*(math.log10(i))); #intensity of sound(dB)\n", + "\n", + "#Result\n", + "print \"The sound intensity level is imcreased by\",round(I,2),\"dB when the intensity is doubled\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.2, Page number 2" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sound intensity level is increased by 6 dB\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "i=4; #the intensity of a source is increased 4 times\n", + "\n", + "#Calculation\n", + "I=(10*(math.log10(i))); #intensity of sound(dB)\n", + "\n", + "#Result\n", + "print \"The sound intensity level is increased by\",int(I),\"dB\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.3, Page number 2" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intensity level of a plane just leaving the runway is 150.0 dB\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "I=1000; #sound intensity of plane leaving the runway(Wm**-2)\n", + "Io=10**-12; #threshold intensity of sound(Wm**-2)\n", + "\n", + "#Calculation\n", + "IL=(10*math.log10(I/Io)); #The intensity level of a plane just leaving the runway(dB)\n", + "\n", + "#Result\n", + "print \"The intensity level of a plane just leaving the runway is\",IL,\"dB\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.4, Page number 2" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intensity level is 60.0 dB\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "I=10**-6; #intensity of sound during heavy traffic(Wm**-2)\n", + "Io=10**-12; #threshold intensity of sound(Wm**-2)\n", + "\n", + "#Calculation\n", + "IL=(10*math.log10(I/Io)); #The intensity level(dB)\n", + "\n", + "#Result\n", + "print \"The intensity level is\",IL,\"dB\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.5, Page number 3" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intensity level is -48.9994 dB\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", + "Q=3.56; #rate of energy radiates(W)\n", + "r=15; #distance of intensity level(m)\n", + "Io=100; #reference intensity(Wm^-2)\n", + "\n", + "#Calculation\n", + "A=4*math.pi*r**2; #Area(m^2)\n", + "I=(Q/A); #sound intensity(Wm^-2)\n", + "IL=(10*math.log10(I/Io)); #The intensity level(dB)\n", + "\n", + "#Result\n", + "print \"The intensity level is\",round(IL,4),\"dB\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.6, Page number 3" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The resultant sound level is 80.41 dB\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Il1=70; #sound(dB)\n", + "Il2=80; #sound(dB)\n", + "\n", + "#Calculation\n", + "I1=10**(Il1/10); #ratio of intensity\n", + "I2=10**(Il2/10); #ratio of intensity\n", + "I=I1+I2; #intensity of sound(dB)\n", + "Il=10*math.log10(I); #resultant intensity(dB)\n", + "\n", + "#Result\n", + "print \"The resultant sound level is\",round(Il,2),\"dB\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.7, Page number 4" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The noise level at the point when 4 such drills are working at the same distance away is 101.02 dB\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "i=4; #the intensity of a source\n", + "I1=95; #The noise level of sound from a drill(dB)\n", + "\n", + "#Calculation\n", + "I2=(10*(math.log10(i))); #intensity of source(dB)\n", + "IL=I1+I2; #The noise level at this point(dB)\n", + "\n", + "#Result\n", + "print \"The noise level at the point when 4 such drills are working at the same distance away is\",round(IL,2),\"dB\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.8, Page number 4" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The flow of energy across 1m^2 per second is 6.638 *10**4 Wm**-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", + "f=426; #frequency of sound(Hz)\n", + "a=0.65*10**-2; #amplitude of sound wave(m)\n", + "A=1; #area(m^2)\n", + "v=340; #velocity of sound in air(ms^-1)\n", + "d=1.29; #density of air(Kgm^-3)\n", + "\n", + "#Calculation\n", + "I=(2*math.pi**2*f**2*a**2*d*v); #The flow of energy across 1m^2 per second(Wm^-2*10^4)\n", + "\n", + "#Result\n", + "print \"The flow of energy across 1m^2 per second is\",round(I/10**4,3),\"*10**4 Wm**-2\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.9, Page number 12" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The reverberation time of the hall is 2.087 sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=1000; #volume of hall(m^3)\n", + "S=400; #sound absorbing surface of area(m^2)\n", + "a=0.2; #average absorption coefficient(sabine)\n", + "\n", + "#Calculation\n", + "T=(0.167*V)/(a*S); #The reverberation time of the hall(sec)\n", + "\n", + "#Result\n", + "print \"The reverberation time of the hall is\",round(T,3),\"sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.10, Page number 12" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average absorbtion coefficient is 0.2374 O.W.U\n", + "Total sound absorbtion of the room is 128.2 O.W.U m^2\n", + "answer varies due to rounding off errors\n", + "The reverberation time is 1.954 sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=1500; #volume of room(m^3)\n", + "a1=0.03; #average sound coefficient for wall(sabine)\n", + "a2=0.06; #average sound coefficient for the ceiling(sabine)\n", + "a3=0.8; #average sound coefficient for the floor(sabine)\n", + "S1=260; #The wall area of the room(m^2)\n", + "S2=140; #The floor area of the room(m^2)\n", + "S3=140; #The ceiling area of the room(m^2)\n", + "\n", + "#Calculation\n", + "a=((a1*S1)+(a2*S2)+(a3*S3))/(S1+S2+S3); #The average absorbtion coefficient(O.W.U)\n", + "TS=S1+S2+S3; #total area of the room(m^2)\n", + "x=(a*TS); #Total sound absorbtion of the room(O.W.U m^2)\n", + "T=((0.167*V)/x); #The reverberation time(sec)\n", + "\n", + "#Result\n", + "print \"The average absorbtion coefficient is\",round(a,4),\"O.W.U\"\n", + "print \"Total sound absorbtion of the room is\",x,\"O.W.U m^2\"\n", + "print \"answer varies due to rounding off errors\"\n", + "print \"The reverberation time is\",round(T,3),\"sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.11, Page number 13" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The area of interior surfaces is 3340.0 m**2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=12000; #volume of auditorium(m^3)\n", + "T=1.5; #The reverberation time of the auditorium(sec)\n", + "a=0.4; #average absorption coefficient(sabine)\n", + "\n", + "#Calculation\n", + "S=(0.167*V)/(a*T); #area of interior surfaces(m^2)\n", + "\n", + "#Result\n", + "print \"The area of interior surfaces is\",S,\"m**2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.12, Page number 13" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total absorbtion in the hall is 835.0 sabine m^2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=7500; #volume of cinema hall(m^3)\n", + "T=1.5; #The reverberation time of the cinema hall(sec)\n", + "\n", + "#Calculation\n", + "TaS=(0.167*V)/(T); #The total absorbtion in the hall(sabine m^2)\n", + "\n", + "#Result\n", + "print \"The total absorbtion in the hall is\",TaS,\"sabine m^2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.13, Page number 13" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The new reverberation time after placing the cushioned chairs is 1.3115 sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=12500; #volume of hall(m^3)\n", + "T1=1.5; #The reverberation time of the hall(sec)\n", + "a2S2=200; #The number of cushioned chairs are additionally placed in the hall(sabine-m^2)\n", + "\n", + "#Calculation\n", + "Ta1S1=(0.167*V)/T1; #The reverberation time before placed cushioned chairs(sabine m^2)\n", + "T2=(0.167*V)/(Ta1S1+a2S2); #The new reverberation time after placing the cushioned chairs(sec)\n", + "\n", + "#Result\n", + "print \"The new reverberation time after placing the cushioned chairs is\",round(T2,4),\"sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.14, Page number 14" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The reverberation time for the hall is 1.2794 sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=475; #volume of hall(m^3)\n", + "a1=0.025; #absorbtion coefficient for wall(O.W.U)\n", + "a2=0.02; #absorbtion coefficient for the ceiling(O.W.U)\n", + "a3=0.55; #absorbtion coefficient for the floor(O.W.U)\n", + "S1=200; #The wall area of the room(m^2)\n", + "S2=100; #The floor area of the room(m^2)\n", + "S3=100; #The ceiling area of the room(m^2)\n", + "\n", + "#Calculation\n", + "TaS=((a1*S1)+(a2*S2)+(a3*S3)); #The average absorbtion coefficient(O.W.U-m^2)\n", + "T=((0.167*V)/TaS); #The reverberation time(sec)\n", + "\n", + "#Result\n", + "print \"The reverberation time for the hall is\",round(T,4),\"sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.15, Page number 14" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The reverberation time in the hall without audience is 3.9879 sec\n", + "The reverberation time in the hall with audience is 1.99396 sec\n", + "Thus,the reverberation reduces to half of its initial value when the audience fill the hall\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=2265; #volume of hall(m^3)\n", + "Ta1S1=94.85; #The total absorbtion coefficient(m^2)\n", + "\n", + "#Calculation\n", + "T1=((0.167*V)/Ta1S1); #The reverberation time in the hall without audience(sec)\n", + "Ta2S2=2*Ta1S1; #The new absorbtion coefficient(m^2)\n", + "T2=((0.167*V)/Ta2S2); #The reverberation time in the hall with audience(sec)\n", + "\n", + "#Result\n", + "print \"The reverberation time in the hall without audience is\",round(T1,4),\"sec\"\n", + "print \"The reverberation time in the hall with audience is\",round(T2,5),\"sec\"\n", + "print \"Thus,the reverberation reduces to half of its initial value when the audience fill the hall\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 1.16, Page number 14" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The average absorbing power of the surface is 0.48789 sabine\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=120000; #Volume of the hall(m^3)\n", + "T=1.55; #The reverberation time(sec)\n", + "S=26500; #The total absorbing surface(m^2)\n", + "\n", + "#Calculation\n", + "TaS=(0.167*V)/T; #The average absorbtion coefficient(sabine-m^2)\n", + "a=(TaS/S); #The average absorbing power of the surface(sabine)\n", + "\n", + "#Result\n", + "print \"The average absorbing power of the surface is\",round(a,5),\"sabine\"" + ] + } + ], + "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_G_Vijayakumari/Chapter10.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter10.ipynb new file mode 100755 index 00000000..d6847b23 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter10.ipynb @@ -0,0 +1,627 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#10: Intrinsic Semiconductors" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.1, Page number 277" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intrinsic carrier concentration at room temperature is 1.3889 *10**16 m^-3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "ec=4*10**-4; #electrical conductivity of intrinsic silicon at room temperature(ohm^-1 m^-1)\n", + "me=0.14; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.04; #The hole mobility(m^2 V^-1 s^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "ni=ec/(e*(me+mh)); #The intrinsic carrier concentration at room temperature(m^-3)\n", + "\n", + "#Result\n", + "print \"The intrinsic carrier concentration at room temperature is\",round(ni/10**16,4),\"*10**16 m^-3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.2, Page number 277" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The resistivity of intrinsic carrier is 0.4709 ohm m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=2.37*10**19; #The intrinsic carrier density at room temperature(m^-3)\n", + "me=0.38; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.18; #The hole mobility(m^2 V^-1 s^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "r=1/(d*e*(me+mh)); #The resistivity of intrinsic carrier(ohm m)\n", + "\n", + "#Result\n", + "print \"The resistivity of intrinsic carrier is\",round(r,4),\"ohm m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.3, Page number 277" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intrinsic carrier density at room tepmerature is 5.04 *10**21 m^-3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "r=2*10**-4; #the resistivity of In-Sb(ohm m)\n", + "me=6; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.2; #The hole mobility(m^2 V^-1 s^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "d=1/(r*e*(me+mh)); #The intrinsic carrier density at room tepmerature(m^-3)\n", + "\n", + "#Result\n", + "print \"The intrinsic carrier density at room tepmerature is\",round(d/10**21,2),\"*10**21 m^-3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.4, Page number 278" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electrical conductivity at room temperature is 1.4374 *10**-3 ohm^-1 m^-1\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", + "Eg=1.1*1.6*10**-19; #The energy gap of silicon(J)\n", + "me=0.48; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.13; #The hole mobility(m^2 V^-1 s^-1)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of an electron\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "t=300; #temperature(K)\n", + "\n", + "#Calculation\n", + "ni=2*(2*math.pi*m*kb*t/h**2)**(3/2)*math.exp(-Eg/(2*kb*t)); #intrinsic carrier concentration(m^-3)\n", + "ec=ni*e*(me+mh); #The electrical conductivity at room temperature(ohm^-1 m^-1 *10^-3)\n", + "\n", + "#Result\n", + "print \"The electrical conductivity at room temperature is\",round(ec*10**3,4),\"*10**-3 ohm^-1 m^-1\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.5, Page number 279" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intrinsic carrier concentration is 1.983 *10**12 m^-3\n", + "The electrical conductivity at room temperature is 2.8239 *10**-7 ohm^-1 m^-1\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", + "Eg=1.43*1.6*10**-19; #The energy gap of intrinsic GaAs(J)\n", + "xe=0.85; #The electron mobility(m^2 V^-1 s^-1)\n", + "xh=0.04; #The hole mobility(m^2 V^-1 s^-1)\n", + "me=0.068*9.11*10**-31; #effective mass of electron(m)\n", + "mh=0.5*9.11*10**-31; #effective mass of hole(m)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of an electron(kg)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "t=300; #temperature(K)\n", + "\n", + "#Calculation\n", + "ni=2*(2*math.pi*kb*t/h**2)**(3/2)*(me*mh)**(3/4)*math.exp(-Eg/(2*kb*t)); #intrinsic carrier concentration(m^-3)\n", + "ec=ni*e*(xe+xh); #The electrical conductivity at room temperature(ohm^-1 m^-1)\n", + "\n", + "#Result\n", + "print \"The intrinsic carrier concentration is\",round(ni/10**12,3),\"*10**12 m^-3\"\n", + "print \"The electrical conductivity at room temperature is\",round(ec*10**7,4),\"*10**-7 ohm^-1 m^-1\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.6, Page number 279" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The position of the fermi level is 9.223086 *10**-20 J or 0.5764 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Eg=1.12*1.6*10**-19; #Energy gap of Si semi conductor(J)\n", + "me=0.12*9.11*10**-31; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.28*9.11*10**-31; #The hole mobility(m^2 V^-1 s^-1)\n", + "t=300; #temperature of fermi level(K)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "m=9.11*10**-31; #mass of an electron(Kg)\n", + "\n", + "#Calculation\n", + "Ef=(Eg/2)+((3*kb*t/4)*math.log(mh/me)); #position of the fermi level(J)\n", + "\n", + "#Result\n", + "print \"The position of the fermi level is\",round(Ef*10**20,6),\"*10**-20 J or\",round(Ef/(1.6*10**-19),4),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.7, Page number 280" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Temperature of the fermi level shifted by 10% is 1115.127 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Eg=1*1.6*10**-19; #Energy gap(J)\n", + "E=0.1*1.6*10**-19; #Fermi level is shifted by 10%(J)\n", + "me=1*9.11*10**-31; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=4*9.11*10**-31; #Effective mass of holes is 4 times that of electrons(m^2 V^-1 s^-1)\n", + "m=9.11*10**-31; #mass of an electron(kg)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "T=4*E/(3*kb*math.log(4)); #The Temperature of the fermi level shifted by 10%(K)\n", + "\n", + "#Result\n", + "print \"The Temperature of the fermi level shifted by 10% is\",round(T,3),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.8, Page number 281" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The resistance of an intrinsic Ge rod is 4310 ohm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "l=1*10**-2; #length of the intrinsic Ge rod(m)\n", + "b=1*10**-3; #breadth of the intrinsic Ge rod(m)\n", + "t=1*10**-3; #thickness of the intrinsic Ge rod(m)\n", + "T=300; #temperature of the intrinsic Ge rod(K)\n", + "me=0.39; #The electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.19; #The hole mobility(m^2 V^-1 s^-1)\n", + "ni=2.5*10**19; #intrinsic carrier conduction(m^3)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "ec=ni*e*(me+mh); #The electrical conductivity at room temperature(ohm^-1 m^-1)\n", + "A=b*t; #area(m^2)\n", + "R=l/(ec*A); #The resistance of an intrinsic Ge rod(ohm)\n", + "\n", + "#Result\n", + "print \"The resistance of an intrinsic Ge rod is\",int(R),\"ohm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.9, Page number 281" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The ratio of conductiveness is 1.08 *10**5\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Eg=1.2*1.6*10**-19; #The energy gap of intrinsic semiconductor(J)\n", + "T1=600; #Temperature(K)\n", + "T2=300; #Temperature(K)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "x=math.exp((-Eg/(2*kb))*((1/T1)-(1/T2))); #The ratio of conductiveness\n", + "\n", + "#Result\n", + "print \"The ratio of conductiveness is\",round(x/10**5,2),\"*10**5\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.10, Page number 282" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The conductivity of Ge at T2 is 4.969895 ohm^-1 m^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Eg=0.72*1.6*10**-19; #The band gap of Ge(J)\n", + "T1=293; #Temperature(K)\n", + "T2=313; #Temperature(K)\n", + "x1=2; #The conductivity of Ge at T1(ohm^-1 m^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "x2=x1*math.exp((Eg/(2*kb))*((1/T1)-(1/T2))); #The ratio of conductiveness\n", + "\n", + "#Result\n", + "print \"The conductivity of Ge at T2 is\",round(x2,6),\"ohm^-1 m^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.11, Page number 282" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The intrinsic carrier density of A to B is 1015\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Eg1=0.36; #The energy gap of intrinsic semiconductor A(eV)\n", + "Eg2=0.72; #The energy gap of intrinsic semiconductor B(eV)\n", + "T1=300; #Temperature of semiconductor A(K)\n", + "T2=300; #Temperature of semiconductor B(K)\n", + "m=9.11*10**-31; #mass of an electron(kg)\n", + "KT=0.026; #kt(eV)\n", + "\n", + "#Calculation\n", + "x=math.exp((Eg2-Eg1)/(2*KT)); #The intrinsic carrier density of A to B\n", + "\n", + "#Result\n", + "print \"The intrinsic carrier density of A to B is\",int(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.12, Page number 283" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The band gap of semiconductor is 5.5863 *10**-20 J or 0.349 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "T1=293; #Temperature(K)\n", + "T2=373; #Temperature(K)\n", + "x1=250; #The conductivity of semiconductor at T1(ohm^-1 m^-1)\n", + "x2=1100; #The conductivity of semiconductor at T2(ohm^-1 m^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "Eg=2*kb*math.log(x2/x1)*(T1*T2/(T2-T1)); #The band gap of semiconductor(J)\n", + "\n", + "#Result\n", + "print \"The band gap of semiconductor is\",round(Eg*10**20,4),\"*10**-20 J or\",round(Eg/(1.6*10**-19),3),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.13, Page number 284" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mobility of pure semi conductor is 0.08283 m^2 V^-1 s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "me=50; #The electron mobility of pure semi conductor(m^2 V^-1 s^-1)\n", + "t1=4.2; #temperature of pure semi conductor(K)\n", + "t2=300; #temperature(K)\n", + "\n", + "#Calculation\n", + "m=me*((t2**(-3/2))/(t1**(-3/2))); #mobility of pure semi conductor(m^2 V^-1 s^-1)\n", + "\n", + "#Result\n", + "print \"mobility of pure semi conductor is\",round(m,5),\"m^2 V^-1 s^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 10.14, Page number 284" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The band gap of an intrinsic semi conductor is 1.183808 *10**-19 J or 0.7399 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "ec1=19.96; #The electrical conductivity of an intrinsic semi conductor(ohm^-1 m^-1)\n", + "ec2=79.44; #The increasing electrical conductivity of an intrinsic semi conductor(ohm^-1 m^-1)\n", + "t1=333; #temperature of an intrinsic semi conductor(K)\n", + "t2=373; #increasing temperature of an intrinsic semi conductor(K)\n", + "kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "Eg=2*kb*math.log(ec2/ec1)*((t1*t2)/(t2-t1)); #The band gap of an intrinsic semi conductor(J)\n", + "\n", + "#Result\n", + "print \"The band gap of an intrinsic semi conductor is\",round(Eg*10**19,6),\"*10**-19 J or\",round(Eg/(1.6*10**-19),4),\"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_G_Vijayakumari/Chapter11.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter11.ipynb new file mode 100755 index 00000000..a7245a22 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter11.ipynb @@ -0,0 +1,613 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#11: Extrinsic Semiconductors" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.1, Page number 307" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Before adding boron atoms,the semiconductor is an intrinsic semiconductor\n", + "conductivity before adding boron atoms is 2.016 ohm^-1 m^-1\n", + "After adding boron atoms,the semiconductor becomes a P-type semiconductor\n", + "conductivity after adding boron atoms is 1.44 *10**4 ohm^-1 m^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "ni=2.1*10**19; #intrinsic charge carriers(m^-3)\n", + "me=0.4; #electron mobility(m^2 V^-1 s^-1)\n", + "mh=0.2; #hole mobility(m^2 V^-1 s^-1)\n", + "d=4.5*10**23; #density of boron(m^-3)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "C=ni*e*(me+mh); #conductivity before adding boron atoms(ohm^-1 m^-1)\n", + "c=d*e*mh; #conductivity after adding boron atoms(ohm^-1 m^-1)\n", + "\n", + "#Result\n", + "print \"Before adding boron atoms,the semiconductor is an intrinsic semiconductor\"\n", + "print \"conductivity before adding boron atoms is\",C,\"ohm^-1 m^-1\"\n", + "print \"After adding boron atoms,the semiconductor becomes a P-type semiconductor\"\n", + "print \"conductivity after adding boron atoms is\",c/10**4,\"*10**4 ohm^-1 m^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.2, Page number 307" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DensiTy of electrons in n-type silicon is 1.4423 *10**24 electrons/m^3\n", + "DensiTy of holes in n-type silicon is 1.56 *10**8 holes/m^3\n", + "DensiTy of holes in p-type silicon is 3.75e+24 holes/m^3\n", + "DensiTy of electrons in p-type silicon is 6.0 *10**7 electrons/m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "ni=1.5*10**16; #intrinsic charge carriers(m^-3)\n", + "me=1300*10**-4; #electron mobility(m^2 V^-1 s^-1)\n", + "mh=500*10**-4; #hole mobility(m^2 V^-1 s^-1)\n", + "c=3*10**4; #conductivity of n-tpye silicon(ohm^-1 m^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "ne=c/(e*me); #DensiTy of electrons in n-type silicon(electrons/m^3)\n", + "nh=ni**2/ne; #Density of holes in n-type silicon(holes/m^3)\n", + "Ne=c/(e*mh); #Density of holes in p-type silicon(holes/m^3)\n", + "Nh=ni**2/Ne; #Density of electrons in p-type silicon(holes/m^3)\n", + "\n", + "#Result\n", + "print \"DensiTy of electrons in n-type silicon is\",round(ne/10**24,4),\"*10**24 electrons/m^3\"\n", + "print \"DensiTy of holes in n-type silicon is\",nh/10**8,\"*10**8 holes/m^3\"\n", + "print \"DensiTy of holes in p-type silicon is\",Ne,\"holes/m^3\"\n", + "print \"DensiTy of electrons in p-type silicon is\",Nh/10**7,\"*10**7 electrons/m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.3, Page number 308" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electron concentration is 2.0 *10**9 electrons/m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "ni=2*10**16; #intrinsic charge carriers(m^-3)\n", + "Na=5*10**23; #density of acceptor concentration of silicon with arsenic(atoms)\n", + "Nd=3*10**23; #density of donor concentration of silicon with arsenic(atoms)\n", + "\n", + "#Calculation\n", + "nh=Na-Nd; #density of hole(m^-3)\n", + "ne=ni**2/nh; #The electron concentration(electrons/m^3)\n", + "\n", + "#Result\n", + "print \"The electron concentration is\",ne/10**9,\"*10**9 electrons/m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.4, Page number 309" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The position of fermi level is 4.893 *10**-20 J or 0.3058 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=5*10**28; #density of silicon atom(atoms/m^3)\n", + "nd=2.5*10**7; #donor concentration in 1 atom per si atom\n", + "T=300; #Temperature(K)\n", + "Eg=1.1*1.6*10**-19; #Eg for silicon(eV)\n", + "kb=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "m=9.11*10**-31; #mass of electon(kg)\n", + "h=6.625*10**-34; #plank's constant(m^2 Kg/sec)\n", + "\n", + "#Calculation\n", + "Nd=d/nd; #The donor concentration(atoms/m^3)\n", + "Ef=(Eg/2)+(kb*T*(math.log(Nd/(2*((2*math.pi*m*kb*T)/h**2)**(3/2))))); #The position of fermi level at 300K(J)\n", + "\n", + "#Result\n", + "print \"The position of fermi level is\",round(Ef*10**20,3),\"*10**-20 J or\",round(Ef/(1.6*10**-19),4),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.5, Page number 310" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The density of the intrinsic crystal for p-type is 1.302 *10**21 m^-3\n", + "The minor carrier concentration for p-type is 1.728e+11 electrons/m^3\n", + "The density of the intrinsic crystal for n-type is 4.6296 *10**20 m^-3\n", + "The minor carrier concentration for n-type is 4.86e+11 holes/m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "ni=1.5*10**16; #intrinsic charge carriers(m^-3)\n", + "r1=10*10**-2; #resistivity of p-type silicon(ohm m)\n", + "r2=10*10**-2; #resistivity of n-type silicon(ohm m)\n", + "me=1350*10**-4; #The mobility of the charge carrier(m^2 V^-1 s^-1)\n", + "mh=480*10**-4; #The hole charge carrier(m^2 V^-1 s^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "Na=1/(r1*e*mh); #The density of the intrinsic crystal for p-type(m^-3)\n", + "ne=ni**2/Na; #The minor carrier concentration for p-type(electrons/m^3)\n", + "Nd=1/(r2*e*me); #The density of the intrinsic crystal for n-type(m^-3)\n", + "nh=ni**2/Nd; #The minor carrier concentration for n-type(electrons/m^3)\n", + "\n", + "#Result\n", + "print \"The density of the intrinsic crystal for p-type is\",round(Na/10**21,3),\"*10**21 m^-3\"\n", + "print \"The minor carrier concentration for p-type is\",ne,\"electrons/m^3\"\n", + "print \"The density of the intrinsic crystal for n-type is\",round(Nd/10**20,4),\"*10**20 m^-3\"\n", + "print \"The minor carrier concentration for n-type is\",nh,\"holes/m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.6, Page number 315" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electron mobility is 0.14 m^2 V^-1 s^-1\n", + "The charge carrier density is 5e+21 electrons/m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "c=112; #conductivity of a n-type silicon specimen(ohm^-1 m^-1)\n", + "RH=1.25*10**-3; #Hall coefficient of a n-type silicon specimen(m^3 C^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "me=c*RH; #electron mobility(m^2 V^-1 s^-1)\n", + "ne=c/(me*e); #The charge carrier density(electrons/m^3)\n", + "\n", + "#Result\n", + "print \"The electron mobility is\",me,\"m^2 V^-1 s^-1\"\n", + "print \"The charge carrier density is\",ne,\"electrons/m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.7, Page number 315" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hall coefficient of semiconductor is 3.7e-06 C^-1 m^3\n", + "The density of the charge carrier is 1.689 *10**24 electrons/m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "l=12*10**-3; #length of semi conductor crystal(m)\n", + "b=1*10**-3; #breadth of semi conductor crystal(m)\n", + "t=1*10**-3; #thickness of semi conductor crystal(m)\n", + "I=20*10**-3; #current(A)\n", + "Vh=37*10**-6; #voltage measured across the width(V)\n", + "B=0.5; #magnetic flux density(Wb/m^2)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "RH=Vh*t/(I*B); #Hall coefficient of semiconductor(C^-1 m^3)\n", + "ne=1/(RH*e); #The density of the charge carrier(electrons/m^3)\n", + "\n", + "#Result\n", + "print \"Hall coefficient of semiconductor is\",RH,\"C^-1 m^3\"\n", + "print \"The density of the charge carrier is\",round(ne/10**24,3),\"*10**24 electrons/m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.8, Page number 315" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hall coefficient of silicon plate is 3.66 *10**-4 m^3 C^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "l=100*10**-3; #length of silicon plate(m)\n", + "b=10*10**-3; #breadth of silicon plate(m)\n", + "t=1*10**-3; #thickness of silicon plate(m)\n", + "I=10**-2; #current(A)\n", + "Vh=1.83*10**-3; #voltage measured across the width(V)\n", + "B=0.5; #magnetic flux density(Wb/m^2)\n", + "\n", + "#Calculation\n", + "RH=Vh*t/(I*B); #Hall coefficient of silicon plate(m^3 C^-1)\n", + "\n", + "#Result\n", + "print \"Hall coefficient of silicon plate is\",RH*10**4,\"*10**-4 m^3 C^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.9, Page number 316" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The negative sign of the Hall coefficient indicates that the nature of the semiconductor is n-type\n", + "The density of the charge carrier is 8.503 *10**22 electrons/m^3\n", + "The mobility of the charge carrier is 14.7 *10**-3 m^2 V^-1 s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "RH=7.35*10**-5; #Hall coefficient of silicon specimen(m^3 C^-1)\n", + "rh=-7.35*10**-5; #Hall coefficient of silicon specimen(m^3 C^-1)\n", + "c=200; #conductivity(ohm^-1 m^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "ne=1/(RH*e); #The density of the charge carrier(electrons/m^3)\n", + "me=c*RH; #The mobility of the charge carrier(m^2 V^-1 s^-1)\n", + "\n", + "#Result\n", + "print \"The negative sign of the Hall coefficient indicates that the nature of the semiconductor is n-type\"\n", + "print \"The density of the charge carrier is\",round(ne/10**22,3),\"*10**22 electrons/m^3\"\n", + "print \"The mobility of the charge carrier is\",me*10**3,\"*10**-3 m^2 V^-1 s^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.10, Page number 316" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The density of the charge carrier is 1.7728 *10**22 electrons/m^3\n", + "The mobility of the charge carrier is 0.06346 m^2 V^-1 s^-1\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", + "RH=4.16*10**-4; #Hall coefficient of n-type semiconductor(m^3 C^-1)\n", + "c=180; #conductivity(ohm^-1 m^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "x=1.18; #correction factor for RH\n", + "\n", + "#Calculation\n", + "ne=x/(RH*e); #The density of the charge carrier(electrons/m^3)\n", + "me=c/(ne*e); #The mobility of the charge carrier(m^2 V^-1 s^-1)\n", + "\n", + "#Result\n", + "print \"The density of the charge carrier is\",round(ne/10**22,4),\"*10**22 electrons/m^3\"\n", + "print \"The mobility of the charge carrier is\",round(me,5),\"m^2 V^-1 s^-1\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.11, Page number 317" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The hall coefficient measured by the probes is 1.75 mV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "l=1*10**-3; #length of rectangular plane sheet of doped silicon(m)\n", + "b=1*10**-3; #breadth of semi rectangular plane sheet of doped silicon(m)\n", + "t=0.5*10**-3; #thickness of rectangular plane sheet of doped silicon(m)\n", + "RH=1.25*10**-3; #Hall coefficient of the material(m^3 C^-1)\n", + "I=1*10**-3; #current(A)\n", + "B=0.7; #magnetic flux density(Wb/m^2)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "Vh=RH*I*B/t; #The hall coefficient measured by the probes(mV)\n", + "\n", + "#Result\n", + "print \"The hall coefficient measured by the probes is\",Vh*10**3,\"mV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.12, Page number 317" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The density of the charge carrier is 1.70765 *10**22 m^-3\n", + "The mobility is 0.04099 m^2 V^-1 s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "RH=3.66*10**-4; #Hall coefficient of a doped silicon(m^3 C^-1)\n", + "r=8.93*10**-3; #The resistivity(ohm m)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "n=1/(RH*e); #The density of the charge carrier(m^-3)\n", + "me=RH/r; #The mobility(m^2 V^-1 s^-1)\n", + "\n", + "#Result\n", + "print \"The density of the charge carrier is\",round(n/10**22,5),\"*10**22 m^-3\"\n", + "print \"The mobility is\",round(me,5),\"m^2 V^-1 s^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 11.13, Page number 317" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The current density is 2880.0 A/m^2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "RH=0.0125; #Hall coefficient of a sample n-type semiconductor(m^3 C^-1)\n", + "rh=-0.0125; #Hall coefficient of a sample n-type semiconductor(m^3 C^-1)\n", + "me=0.36; #electron mobility(m^2 V^-1 s^-1)\n", + "EH=100; #electric field(V/m)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "n=1/(RH*e); #The density of the charge carrier(m^-3)\n", + "c=n*e*me; #conductivity of n-type semiconductor(ohm^-1 m^-1)\n", + "J=c*EH; #The current density(A/m^2)\n", + "\n", + "#Result\n", + "print \"The current density is\",J,\"A/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_G_Vijayakumari/Chapter12.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter12.ipynb new file mode 100755 index 00000000..54bbbf07 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter12.ipynb @@ -0,0 +1,351 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#12: Superconducting Materials" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.1, Page number 328" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The transition temperature for the isotope of mercury of mass number 200 is 4.2209 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "M1=202; #mass number of mercury\n", + "a=0.50; #coefficient of mass number\n", + "T1=4.2; #temperaturefor mass number 200(K)\n", + "M2=200; #mass number of mercury\n", + "\n", + "#Calculation\n", + "T2=((M1/M2)**a)*T1; #The transition temperature for the isotope of mercury of mass number 200(K)\n", + "\n", + "#Result\n", + "print \"The transition temperature for the isotope of mercury of mass number 200 is\",round(T2,4),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.2, Page number 328" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical field is 0.1117 T\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Tc=9.15; #critical temperature of Nb(K)\n", + "t=6; #temperature of critical field(K)\n", + "Ho=0.196; #The critical field AT 0K(T)\n", + "\n", + "#Calculation\n", + "Hc=(Ho*(1-(t/Tc)**2)); #The critical field at 6K(T)\n", + "\n", + "#Result\n", + "print \"The critical field is\",round(Hc,4),\"T\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.3, Page number 329" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Isotopic mass if the critical temperature falls is 204.55\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "M1=199.5; #Isotopic mass of metal\n", + "T1=4.185; #Critical temperature for a metal with isotopic mass(K)\n", + "T2=4.133; #fall of critical temperature for a metal with isotopic mass(K)\n", + "a=0.50; #coefficient of mass\n", + "\n", + "#Calculation\n", + "M2=(((M1)**a)*(T1/T2))**2; #The Isotopic mass if the critical temperature falls to 4.133\n", + "\n", + "#Result\n", + "print \"The Isotopic mass if the critical temperature falls is\",round(M2,2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.4, Page number 329" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical current through a long thin superconductor is 22.619 A\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", + "Hc=7.2*10**3; #The critical magnetic field(A/m)\n", + "r=0.5*10**-3; #radius of long thin superconducting wire(m)\n", + "\n", + "#Calculation\n", + "Ic=(2*math.pi*Hc*r); #The critical current through a long thin superconductor(A)\n", + "\n", + "#Result\n", + "print \"The critical current through a long thin superconductor is\",round(Ic,3),\"A\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.5, Page number 329" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical field is 0.021659 tesla\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Tc=3.7; #critical temperature of superconducting Sn(K)\n", + "t=2; #temperature of critical field(K)\n", + "Ho=0.0306; #The critical field at 0K(T)\n", + "\n", + "#Calculation\n", + "Hc=(Ho*(1-(t/Tc)**2)); #The critical field at 6K(T)\n", + "\n", + "#Result\n", + "print \"The critical field is\",round(Hc,6),\"tesla\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.6, Page number 329" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical density for a superconducting wire of lead is 134.33 A\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", + "Ho=6.5*10**4; #The critical field at 0K(A/m)\n", + "Tc=7.18; #The temperature for lead(K)\n", + "r=0.5*10**-3; #radius of superconducting wire of lead(m)\n", + "T=4.2; #temperature of superconducting wire(K)\n", + "\n", + "#Calculation\n", + "Hc=(Ho*(1-(T/Tc)**2)); #The critical field(KA/m)\n", + "Ic=2*math.pi*Hc*r; #The critical density for a superconducting wire of lead(A)\n", + "\n", + "#Result\n", + "print \"The critical density for a superconducting wire of lead is\",round(Ic,2),\"A\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.7, Page number 330" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical temperature is 12.13395 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Hc=10**5; #The critical field for vanadium(A/m)\n", + "Ho=2*10**5; #The critical field for vanadium at 0K(A/m)\n", + "T=8.58; #temperature for vanadium(K)\n", + "\n", + "#Calculation\n", + "Tc=T/math.sqrt(1-(Hc/Ho)); #The critical temperature(K)\n", + "\n", + "#Result\n", + "print \"The critical temperature is\",round(Tc,5),\"K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 12.8, Page number 338" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The frequency of the radiation emitted by the junction is 2.85196 *10**9 Hz\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "V=5.9*10**-6; #voltage applied across a Josephson junction(V)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "h=6.62*10**-34; #Planck's constant(J-sec)\n", + "\n", + "#Calculation\n", + "v=(2*e*V)/h; #The frequency of the radiation emitted by the junction(Hz)\n", + "\n", + "#Result\n", + "print \"The frequency of the radiation emitted by the junction is\",round(v/10**9,5),\"*10**9 Hz\"" + ] + } + ], + "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_G_Vijayakumari/Chapter13.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter13.ipynb new file mode 100755 index 00000000..afb202a5 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter13.ipynb @@ -0,0 +1,243 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#13: Dielectrics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 13.1, Page number 356" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electron polarisation is 3.945 *10**-7 C/m^2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=3.61*10**-10; #lattice constant of copper which is Fcc crystal(m)\n", + "x=1*10**-18; #average displacement of the electrons relative to the nucleus(m)\n", + "z=29; #atomic number of copper\n", + "n=4; #number of atoms per unit cell in FCC crystal\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "ne=((n*z)/(a*a*a)); #number of electrons(electrons/m^3) \n", + "P=ne*e*x; #The electron polarisation(C/m^2)\n", + "\n", + "#Result\n", + "print \"The electron polarisation is\",round(P*10**7,3),\"*10**-7 C/m^2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 13.2, Page number 356" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The dipole moment of each atom in a field is 1.9646 *10**-35 C m**-3\n", + "The effective distance at this field strength between the centre and the nucleus is 8.77 *10**-18 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "rp=11.7; #relative permittivity of silicon\n", + "N=4.82*10**28; #number of atoms per unit volume(atoms/m^3)\n", + "ro=8.85*10**-12; #permittivity of free space\n", + "E=10**4; #E(Vm^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "Z=14; #atomic number of silicon \n", + "\n", + "#Calculation\n", + "z=(ro*(rp-1))/N #electronic polarisability(Fm^2)\n", + "mew=z*E; #The dipole moment of each atom(Cm^-3)\n", + "x=y/(Z*e); #The effective distance at this field strength between the centre and the nucleus(m)\n", + "\n", + "#Result\n", + "print \"The dipole moment of each atom in a field is\",round(y*10**35,4),\"*10**-35 C m**-3\"\n", + "print \"The effective distance at this field strength between the centre and the nucleus is\",round(x*10**18,2),\"*10**-18 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 13.3, Page number 357" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electronic polarisability is 1.39 *10**-41 Fm**2\n", + "The relative permittivity in hydrogen gas is 1.0015\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=9.8*10**26; #density of hydrogen gas(atoms/m^3)\n", + "r=0.50*10**-10; #radius of the hydrogen atom(m)\n", + "ro=8.85*10**-12; #permittivity of free space\n", + "\n", + "#Calculation\n", + "z=(4*math.pi*ro*r**3)/10**-41; #electronic polarisability(Fm^2)\n", + "rp=(((d*z*10**-41)/ro)+1); #The relative permittivity in hydrogen gas\n", + "\n", + "#Result\n", + "print \"The electronic polarisability is\",round(z,2),\"*10**-41 Fm**2\"\n", + "print \"The relative permittivity in hydrogen gas is\",round(rp,4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 13.4, Page number 357" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The static dielectric constant of solid argon is 1.53679\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "z=1.75*10**-40; #electronic polarisability(Fm^2)\n", + "d=1.8*10**3; #density of argon atom(Kg/m^3)\n", + "Z=39.95; #atomic weight of argon\n", + "NA=6.025*10**26; #Avagadro number(mole^-1)\n", + "ro=8.85*10**-12; #permittivity of free space\n", + "\n", + "#Calculation\n", + "N=((NA*d)/Z); #The number of atoms/unit volume(atoms/m^3) \n", + "rp=(((N*z)/ro)+1); #The static dielectric constant of solid argon\n", + "\n", + "#Result\n", + "print \"The static dielectric constant of solid argon is\",round(rp,5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 13.5, Page number 366" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ratio between electronic and ionic polarisability of this material is 1.7376\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "er=4.94; #static dielecric constant of a material\n", + "n=2.69; #index of friction\n", + "\n", + "#Calculation\n", + "x=((er-1)*(n+2))/((er+2)*(n-1))-1; #Ratio between ionic and electronic polarisability of this material\n", + "y=1/x; #Ratio between electronic and ionic polarisability of this material\n", + "\n", + "#Result\n", + "print \"Ratio between electronic and ionic polarisability of this material is\",round(y,4)" + ] + } + ], + "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_G_Vijayakumari/Chapter15.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter15.ipynb new file mode 100755 index 00000000..1d22e338 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter15.ipynb @@ -0,0 +1,71 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#15: Non Destructive Testing" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 15.1, Page number 412" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The frequency to which a piezo electric oscillator circuit should be turned is 2.7451 *10**6 Hz\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "t=0.1*10**-2; #thickness of piezo electric crystal(m)\n", + "E=80*10**9; #Young's modulus of crystal(pa)\n", + "d=2654; #density of material of crystal(Kgm^-3)\n", + "\n", + "#Calculation\n", + "f=1/(2*t)*math.sqrt(E/d); #The frequency to which a piezo electric oscillator circuit should be turned(Hz)\n", + "\n", + "#Result\n", + "print \"The frequency to which a piezo electric oscillator circuit should be turned is\",round(f/10**6,4),\"*10**6 Hz\"" + ] + } + ], + "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_G_Vijayakumari/Chapter2.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter2.ipynb new file mode 100755 index 00000000..79e12829 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter2.ipynb @@ -0,0 +1,156 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#2: Ultrasonics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 2.1, Page number 30" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The frequency of vibration is 2.7451 *10**6 Hz\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=80*10**9; #Young's modulus of material of piezo electric crystal(Pa)\n", + "d=2654; #Density of material of piezo electric crystal(Kg/m^3)\n", + "t=0.1*10**-2; #Thickness of piezo electric crystal(m)\n", + "p=1; #for fundamental first overtone\n", + "\n", + "#Calculation\n", + "f=((p/(2*t))*(math.sqrt(E/d))); #Frequency of vibration of first overtone(Hz)\n", + "\n", + "#Result\n", + "print \"The frequency of vibration is\",round(f/10**6,4),\"*10**6 Hz\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 2.2, Page number 30" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Frequency in the first mode of vibration is 5.5 *10**4 Hz\n", + "Frequency in the second mode of vibration is 110.0 *10**3 Hz\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "v=5.5*10**3; #Velocity of longitudanal waves in Quartz Crystal(m/s)\n", + "t=0.05; #Thickness of Quartz Crystal(m)\n", + "\n", + "#Calculation\n", + "w=2*t; #wavelength(m)\n", + "v1=(v/w); #Frequency in the first mode of vibration(Hz)\n", + "v2=(2*v1); #Frequency in the second mode of vibration(Hz)\n", + "\n", + "#Result\n", + "print \"Frequency in the first mode of vibration is\",v1/10**4,\"*10**4 Hz\"\n", + "print \"Frequency in the second mode of vibration is\",v2/10**3,\"*10**3 Hz\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 2.3, Page number 31" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The depth of sea is 495.0 m\n", + "The wavelength of ultrasonic pulse is 0.02 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "f=0.09*10**6; #Frequency of Ultrasonic source(Hz)\n", + "t=0.55; #time(sec)\n", + "v=1800; #velocity of sound in water(m/s)\n", + "\n", + "#Calculation\n", + "D=(v*t)/2; #Depth of sea(m)\n", + "W=(v/f); #Wavelength of ultrasonic pulse(m)\n", + "\n", + "#Result\n", + "print \"The depth of sea is\",D,\"m\"\n", + "print \"The wavelength of ultrasonic pulse is\",W,\"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_G_Vijayakumari/Chapter3.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter3.ipynb new file mode 100755 index 00000000..b55e472d --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter3.ipynb @@ -0,0 +1,1072 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#3: Crystal Physics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.3, Page number 60" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The interplanar distance is 6.3589 *10**-11 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "h=3; #miller indices with respect to x axis\n", + "k=1; #miller indices with respect to y axis\n", + "l=1; #miller indices with respect to z axis\n", + "a=2.109*10**-10; #lattice constant of plane in a simple cubic lattice(m)\n", + "\n", + "#Calculation\n", + "d=(a/(math.sqrt(h**2+k**2+l**2))); #The interplanar distance(m)\n", + "\n", + "#Result\n", + "print \"The interplanar distance is\",round(d*10**11,4),\"*10**-11 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.4, Page number 60" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lattice constant is 4.0447 *10**-10 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "h=1; #miller indices with respect to x axis\n", + "k=1; #miller indices with respect to y axis\n", + "l=0; #miller indices with respect to z axis\n", + "d=2.86*10**-10; #the distance between miller indices(m)\n", + "\n", + "#Calculation\n", + "a=(d*(math.sqrt(h**2+k**2+l**2))); #The lattice constant(m)\n", + "\n", + "#Result\n", + "print \"The lattice constant is\",round(a*10**10,4),\"*10**-10 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.6, Page number 61" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The ratio of intercepts on the three axis by ( 1 1 1 ) plane is 1.0 : 1.0 : 1.0\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "h=1; #miller indices of x-axis\n", + "k=1; #miller indices of y-axis\n", + "l=1; #miller indices of z-axis\n", + "\n", + "#Calculation\n", + "p=1/h; #intercept on x-axis\n", + "q=1/k; #intercept on y-axis\n", + "r=1/l; #intercept on z-axis\n", + "\n", + "#Result\n", + "print \"The ratio of intercepts on the three axis by (\",h,k,l,\") plane is\",p,\":\",q,\":\",r" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.7, Page number 61" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The inter planar spacing distance in 1st plane is 2.0347 *10**-10 m\n", + "The inter planar spacing distance in 2nd plane is 1.7621 *10**-10 m\n", + "The inter planar spacing distance in 3rd plane is 1.246e-10 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "r=1.246*10**-10; #atomic radius of Fcc crystal(m)\n", + "h1=1; #miller indices with respect to x axis in 1st plane\n", + "k1=1; #miller indices with respect to y axis in 1st plane\n", + "l1=1; #miller indices with respect to z axis in 1st plane\n", + "h2=2; #miller indices with respect to x axis in 2nd plane\n", + "k2=0; #miller indices with respect to y axis in 2nd plane\n", + "l2=0; #miller indices with respect to z axis in 2nd plane\n", + "h3=2; #miller indices with respect to x axis in 3rd plane\n", + "k3=2; #miller indices with respect to y axis in 3rd plane\n", + "l3=0; #miller indices with respect to z axis in 3rd plane\n", + "\n", + "#Calculation\n", + "a=(4*r)/math.sqrt(2); #The lattice constant in a FCC crystal(m)\n", + "d1=(a/(math.sqrt(h1**2+k1**2+l1**2))); #inter planar spacing distance in 1st plane(m)\n", + "d2=(a/(math.sqrt(h2**2+k2**2+l2**2))); #inter planar spacing distance in 2nd plane(m)\n", + "d3=(a/(math.sqrt(h3**2+k3**2+l3**2))); #inter planar spacing distance in 3rd plane(m)\n", + "\n", + "#Result\n", + "print \"The inter planar spacing distance in 1st plane is\",round(d1*10**10,4),\"*10**-10 m\"\n", + "print \"The inter planar spacing distance in 2nd plane is\",round(d2*10**10,4),\"*10**-10 m\"\n", + "print \"The inter planar spacing distance in 3rd plane is\",d3,\"m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.8, Page number 62" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The inter planar spacing distance in 1st plane is a* 1.0 m\n", + "The inter planar spacing distance in 2nd plane is a* 0.707 m\n", + "The inter planar spacing distance in 3rd plane is a* 0.577 fm\n", + "Ratio of interplanar distance of three planes d100:d110:d111= 1.0 : 0.707 : 0.577\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=1; #assume\n", + "h1=1; #miller indices with respect to x axis in 1st plane\n", + "k1=0; #miller indices with respect to y axis in 1st plane\n", + "l1=0; #miller indices with respect to z axis in 1st plane\n", + "h2=1; #miller indices with respect to x axis in 2nd plane\n", + "k2=1; #miller indices with respect to y axis in 2nd plane\n", + "l2=0; #miller indices with respect to z axis in 2nd plane\n", + "h3=1; #miller indices with respect to x axis in 3rd plane\n", + "k3=1; #miller indices with respect to y axis in 3rd plane\n", + "l3=1; #miller indices with respect to z axis in 3rd plane\n", + "\n", + "#Calculation\n", + "x1=math.sqrt(h1**2+k1**2+l1**2);\n", + "d100=a/x1; #inter planar spacing distance in 1st plane(m)\n", + "x2=math.sqrt(h2**2+k2**2+l2**2);\n", + "d110=a/x2; #inter planar spacing distance in 2nd plane(m)\n", + "x3=math.sqrt(h3**2+k3**2+l3**2);\n", + "d111=a/x3; #inter planar spacing distance in 3rd plane(m)\n", + "\n", + "#Result\n", + "print \"The inter planar spacing distance in 1st plane is a*\",d100,\"m\"\n", + "print \"The inter planar spacing distance in 2nd plane is a*\",round(d110,3),\"m\"\n", + "print \"The inter planar spacing distance in 3rd plane is a*\",round(d111,3),\"fm\"\n", + "print \"Ratio of interplanar distance of three planes d100:d110:d111=\",(1/x1),\":\",round((1/x2),3),\":\",round((1/x3),3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.9, Page number 62" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The miller indices of the plane is (h k l)=( 3.0 6.0 1.0 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "p=1; #x-intercept of the plane\n", + "q=1/2; #y-intercept of the plane\n", + "r=3; #z-intercept of the plane\n", + "\n", + "#Calculation\n", + "h=(1/p)*3; #miller indices with respect to x axis\n", + "k=(1/q)*3; #miller indices with respect to y axis\n", + "l=(1/r)*3; #miller indices with respect to z axis\n", + "\n", + "#Result\n", + "print \"The miller indices of the plane is (h k l)=(\",h,k,l,\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.10, Page number 63" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The inter planar d-spacing distance is 2.814 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=2.814; #the lattice constant of a simple cubic system(angstrom)\n", + "h1=1; #miller indices with respect to x axis\n", + "k1=0; #miller indices with respect to y axis\n", + "l1=0; #miller indices with respect to z axis\n", + "\n", + "#Calculation\n", + "d=a/math.sqrt(h1**2+k1**2+l1**2); #inter planar d spacing distance(angstrom)\n", + "\n", + "#Result\n", + "print \"The inter planar d-spacing distance is\",d,\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.11, Page number 63" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The miller indices of the set of parallel lines is ( 2.0 2.0 3.0 )\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "OA=0.025; #The unit cell makes intercepts on a(nm)\n", + "OB=0.02; #The unit cell makes intercepts on b(nm)\n", + "OC=0.01; #The unit cell makes intercepts on c(nm)\n", + "a=0.05; #The unit cell edge of an orthorhombic crystal(nm)\n", + "b=0.04; #The unit cell edge of an orthorhombic crystal(nm)\n", + "c=0.03; #The unit cell edge of an orthorhombic crystal(nm)\n", + "\n", + "#Calculation\n", + "p=a/OA; #miller indices with respect to x axis\n", + "q=b/OB; #miller indices with respect to y axis\n", + "r=c/OC; #miller indices with respect to z axis\n", + "\n", + "#Result\n", + "print \"The miller indices of the set of parallel lines is (\",p,q,r,\")\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.12, Page number 63" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The miller indices are 2 1 2\n", + "The miller indices are 1 2 1\n", + "The miller indices are 1 0 3.0\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=0.424; #value of one axial unit\n", + "b=1; #value of second axial unit\n", + "c=0.367; #value of third axial unit\n", + "i1=0.212; #value at x-intercept\n", + "j1=1; #value at y-intercept\n", + "k1=0.183; #value at z-intercept\n", + "i2=0.848; #value at x-intercept\n", + "j2=1; #value at y-intercept\n", + "k2=0.732; #value at z-intercept\n", + "i3=0.424; #value at x-intercept\n", + "k3=0.123; #value at z-intercept\n", + "\n", + "#Calculation\n", + "p1=1/(i1/a); #miller indices at x-intercept\n", + "q1=1/(j1/b); #miller indices at y-intercept\n", + "r1=1/(k1/c); #miller indices at z-intercept\n", + "p2=1/(i2/a)*2; #miller indices at x-intercept\n", + "q2=1/(j2/b)*2; #miller indices at y-intercept\n", + "r2=1/(k2/c)*2; #miller indices at z-intercept\n", + "p3=1/(i3/a); #miller indices at x-intercept\n", + "q3=0; #miller indices at y-intercept\n", + "r3=1/(k3/c); #miller indices at z-intercept\n", + "\n", + "#Result\n", + "print \"The miller indices are\",int(p1),int(q1),int(r1)\n", + "print \"The miller indices are\",int(p2),int(q2),int(r2)\n", + "print \"The miller indices are\",int(p3),int(q3),round(r3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.13, Page number 65" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Miller indices are (1/infinite 1/ 2 1/ 7 )= 0 7 2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "OB=2; #The intercept made by the parrell line ,OB=2b\n", + "OC=7; #The intercept made by the parrell line ,OC=2c\n", + "#OA=infinite The intercept made by the parrell line ,OB=2b\n", + "\n", + "#Calculation\n", + "A=0; #miller indice along x-axis\n", + "B=1/OB; #miller indice along y-axis\n", + "C=1/OC; #miller indice along z-axis\n", + "X=(B*(OC*OB)); #taking L.C.M\n", + "Y=(C*(OC*OB)); #taking L.C.M\n", + "\n", + "#Result\n", + "print \"Miller indices are (1/infinite 1/\",OB,\"1/\",OC,\")=\",A,int(X),int(Y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.14, Page number 75" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The atomic radius of copper is 1.273 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=3.6; #lattice parameter of copper(angstrom)\n", + "\n", + "#Calculation\n", + "r=(a*math.sqrt(2))/4; #The atomic radius of copper(angstrom)\n", + "\n", + "#Result\n", + "print \"The atomic radius of copper is\",round(r,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.15, Page number 76" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The inter planar d-spacing distance is 1.1011 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=4.12; #the lattice constant of a simple cubic system(angstrom)\n", + "h1=3; #miller indices with respect to x axis\n", + "k1=2; #miller indices with respect to y axis\n", + "l1=1; #miller indices with respect to z axis\n", + "\n", + "#Calculation\n", + "d=a/math.sqrt(h1**2+k1**2+l1**2); #inter planar d spacing distance(angstrom)\n", + "\n", + "#Result\n", + "print \"The inter planar d-spacing distance is\",round(d,4),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.16, Page number 76" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The density of copper is 8934 Kg/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", + "n=4; #no.of atoms in FCC structure\n", + "A=63.54; #Atomic weight of copper\n", + "r=1.278*10**-10; #atomic radius(m)\n", + "N=6.023*10**26; #Avogadro's Number(per Kg mol)\n", + "\n", + "#Calculation\n", + "a=(4*r/math.sqrt(2)); #The lattice constant(m)\n", + "d=A*n/(N*a**3); #The density of copper(Kg/m^3)\n", + "\n", + "#Result\n", + "print \"The density of copper is\",int(d),\"Kg/m^3\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.17, Page number 76" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The ratio of interplanar distance between successive lattice planes in a simple cubic lattice is d100:d110:d111= 1 : 0.707 : 0.577\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "h1=1; #miller indices with respect to x axis in 1st plane\n", + "k1=0; #miller indices with respect to y axis in 1st plane\n", + "l1=0; #miller indices with respect to z axis in 1st plane\n", + "h2=1; #miller indices with respect to x axis in 2nd plane\n", + "k2=1; #miller indices with respect to y axis in 2nd plane\n", + "l2=0; #miller indices with respect to z axis in 2nd plane\n", + "h3=1; #miller indices with respect to x axis in 3rd plane\n", + "k3=1; #miller indices with respect to y axis in 3rd plane\n", + "l3=1; #miller indices with respect to z axis in 3rd plane\n", + "a=1; #The lattice constant in a in a simple cubic lattice(m)\n", + "\n", + "#Calculation\n", + "d100=a/math.sqrt(h1**2+k1**2+l1**2); #inter planar spacing distance in 1st plane(m)\n", + "d110=a/math.sqrt(h2**2+k2**2+l2**2); #inter planar spacing distance in 2nd plane(m)\n", + "d111=a/math.sqrt(h3**2+k3**2+l3**2); #inter planar spacing distance in 3rd plane(m)\n", + "\n", + "#Result\n", + "print \"The ratio of interplanar distance between successive lattice planes in a simple cubic lattice is d100:d110:d111=\",int(d100),\":\",round(d110,3),\":\",round(d111,3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.18, Page number 76" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The distance between two adjacent atoms is 2.81 *10**-10 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=23; #atomic weight of sodium\n", + "y=35.45; #atomic weight of chloride\n", + "AW=58.45; #atomic weight of sodium chloride(NaCl)\n", + "n=4; #no.of atoms in FCC structure\n", + "d=2.18*10**6; #density of NaCl crystal of FCC structure(kg/m^3)\n", + "N=6.023*10**23; #Avogadro's Number(per Kg mol)\n", + "\n", + "#Calculation\n", + "a=(n*AW/(d*N))**(1/3); #The lattice constant(m)\n", + "r=a/2; #The distance between two adjacent atoms(m)\n", + "\n", + "#Result\n", + "print \"The distance between two adjacent atoms is\",round(r*10**10,2),\"*10**-10 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.19, Page number 77" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The atomic radius of Fe which has BCC structure is 1.242 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=2; #no.of atoms in BCC structure\n", + "d=7.86*10**6; #density of iron of FCC structure(kg/m^3)\n", + "AW=55.85; #atomic weight of Fe\n", + "N=6.023*10**23; #Avogadro's Number(per Kg mol)\n", + "\n", + "#Calculation\n", + "a=(n*AW/(d*N))**(1/3); #The lattice constant(m)\n", + "r=a*math.sqrt(3)*10**10/4; #The atomic radius of Fe which has BCC structure(angstrom)\n", + "\n", + "#Result\n", + "print \"The atomic radius of Fe which has BCC structure is\",round(r,3),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.20, Page number 77" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lattice constant is 6.6 angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=4; #no.of atoms in FCC structure\n", + "d=2.7*10**3; #density of potassium bromide(Kg/m^3)\n", + "AW=119; #molecular weight of KBr\n", + "N=6.023*10**26; #Avagadro's number(Kg mol)\n", + "\n", + "#Calculation\n", + "a=((n*AW/(d*N))**(1/3))*10**10; #The lattice constant(angstrom)\n", + "\n", + "#Result\n", + "print \"The lattice constant is\",round(a,1),\"angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.21, Page number 78" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of atoms per unit cell of a crystal is 2.0\n", + "If n=2,the crystal system is body centered cubic\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=9.6*10**2; #density of crystal(Kg/m^3)\n", + "AW=23; #molecular weight of the crystal\n", + "N=6.023*10**26; #Avagadro's number(per Kg mol)\n", + "a=4.3*10**-10; #lattice constant(m)\n", + "\n", + "#Calculation\n", + "n=d*N*a**3/AW; #Number of atoms per unit cell of a crystal\n", + "\n", + "#Result\n", + "print \"Number of atoms per unit cell of a crystal is\",round(n)\n", + "print \"If n=2,the crystal system is body centered cubic\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.22, Page number 78" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The volume of cell is 2.128 *10**-29 m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "r=1.2*10**-10; #atomic radius of crystal of BCC structure(m)\n", + "\n", + "#Calculation\n", + "a=4*r/math.sqrt(3); #lattice constant of BCC structure(m)\n", + "V=a**3; #The volume of cell(m^3)\n", + "\n", + "#Result\n", + "print \"The volume of cell is\",round(V*10**29,3),\"*10**-29 m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.23, Page number 78" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The planar atomic density is 6.25e+12 atoms/mm^2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=4*10**-7; #lattice constant of the crystal(mm)\n", + "h1=1; #miller indices with respect to x axis in 1st plane\n", + "k1=0; #miller indices with respect to y axis in 1st plane\n", + "l1=0; #miller indices with respect to z axis in 1st plane\n", + "\n", + "#Calculation\n", + "n=4*(1/4); #Number of atoms contained in a plane per unit cell\n", + "A=a**2; #Area of the plane(mm^2)\n", + "d=n/A; #The planar atomic density(atoms/mm^2)\n", + "\n", + "#Result\n", + "print \"The planar atomic density is\",d,\"atoms/mm^2\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.24, Page number 79" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lattice constant is 4.0 *10**-10 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=4; #no.of atoms in Face centered cubic lattice\n", + "d=6250; #density of potassium bromide(Kg/m^3)\n", + "AW=60.2; #molecular weight of crysal with face centered cubic lattice\n", + "N=6.023*10**26; #Avagadro's number(per Kg mol)\n", + "\n", + "#Calculation\n", + "a=((n*AW/(d*N))**(1/3)); #The lattice constant(m)\n", + "\n", + "#Result\n", + "print \"The lattice constant is\",round(a*10**10),\"*10**-10 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.25, Page number 79" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The change in volume percentage is 0.49326\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", + "r1=0.1258*10**-9; #atomic radii of the iron atom in BCC structure(m)\n", + "r2=0.1292*10**-9; #atomic radii of the iron atom in FCC structure(m)\n", + "T=910; #metallic iron changes from BCC to FCC(C)\n", + "\n", + "#Calculation\n", + "a1=(4*r1/math.sqrt(3)); #lattice constant of BCC structure(m)\n", + "v1=a1**3/2; #The volume occupied by one BCC atom(m^3)\n", + "a2=4*r2/math.sqrt(2); #lattice constant of FCC structure(m)\n", + "v2=a2**3/4; #The volume occupied by one FCC atom(m^3)\n", + "V=((v1-v2)/v1)*100; #The change in volume percentage\n", + "\n", + "#Result\n", + "print \"The change in volume percentage is\",round(V,5)\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.26, Page number 80" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Number of unit cells is 4.70419 *10**22\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=0.405*10**-9; #lattice constant of unit cell of aluminium which is face centered cubic(m)\n", + "s=25*10**-2; #Side of aluminium foil(m)\n", + "t=0.005*10**-2; #Thickness of aluminium foil(m)\n", + "\n", + "#Calculation\n", + "ar=s**2; #area of aluminium foil(m^2)\n", + "V=ar*t; #volume of the aluminium foil(m^3)\n", + "v=a**3; #volume of the unit cell(m^3)\n", + "n=(V/v); #Number of unit cells\n", + "\n", + "#Result\n", + "print \"The Number of unit cells is\",round(n/10**22,5),\"*10**22\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 3.27, Page number 81" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Volume of the unit cell of Magnesium which has HCP structure is 1.0 *10**-28 m^3\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.1605*10**-9; #radius of magnesium atom which has HCP structure(m)\n", + "\n", + "#Calculation\n", + "a=2*r; #lattice constant of magnesium which has HCP structure(m)\n", + "c=a*math.sqrt(8/3); #height of the HCP structure(m)\n", + "V=3*math.sqrt(3)*(a**2)*c/3; #Volume of the unit cell of Magnesium which has HCP structure(m^3)\n", + "\n", + "#Result\n", + "print \"The Volume of the unit cell of Magnesium which has HCP structure is\",round(V*10**28),\"*10**-28 m^3\"\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_G_Vijayakumari/Chapter4.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter4.ipynb new file mode 100755 index 00000000..49292516 --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter4.ipynb @@ -0,0 +1,499 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#4: Wave Optics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.1, Page number 92" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The wavelength of light used is 640 nm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=125; #number of fingers cross the field of view\n", + "d=0.04*10**-3; #distance of one of mirror moved(m)\n", + "\n", + "#Calculation\n", + "w=2*d/n; #wavelength of light used(m)\n", + "\n", + "#Result\n", + "print \"The wavelength of light used is\",int(w*10**9),\"nm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.2, Page number 92" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The wavelength of light used is 600.0 nm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Ri=1.5; #refractive index of thin film of glass\n", + "n=30; #number of fringes of sodium light is observed across the field of view\n", + "t=0.018*10**-3; #thickness of glass film(m)\n", + "\n", + "#Calculation\n", + "w=2*(Ri-1)*t/n; #wavelength of the light used(m)\n", + "\n", + "#Result\n", + "print \"The wavelength of light used is\",w*10**9,\"nm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.3, Page number 92" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The wavelength of the monochromatic source used is 589.0 nm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=200; #number of fringes cross the field of view\n", + "d=0.0589*10**-3; #distance of mirror displaced(m)\n", + "\n", + "#Calculation\n", + "w=2*d/n; #wavelength of the monochromatic source used(m)\n", + "\n", + "#Result\n", + "print \"The wavelength of the monochromatic source used is\",w*10**9,\"nm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.4, Page number 92" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thickness of the film is 1.9636 *10**-4 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=1.55; #refractive index of transparent film of glass \n", + "w=480*10**-9; #wavelength of light(m)\n", + "n=450; #number of fringes to sweep across the field\n", + "\n", + "#Calculation\n", + "t=n*w/(2*(x-1)); #thickness of the film(m)\n", + "\n", + "#Result\n", + "print \"The thickness of the film is\",round(t*10**4,4),\"*10**-4 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.5, Page number 93" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The refractive index of material is 1.675\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "t=0.004*10**-2; #thickness of transparent sheet(m)\n", + "d=0.0027*10**-2; #distance of mirror displaced(m)\n", + "\n", + "#Calculation\n", + "X=(d/t)+1; #refractive index of the material\n", + "\n", + "#Result\n", + "print \"The refractive index of material is\",X" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.6, Page number 93" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number of fringes shifted across the cross wire of eye piece of the telescope is 110\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=0.03205*10**-3; #distance of movable mirror displaced(m)\n", + "w=580.9*10**-9; #wavelength of light(m)\n", + "\n", + "#Calculation\n", + "n=2*d/w; #number of fringes shifted across the cross wire of eye piece of the telescope\n", + "\n", + "#Result\n", + "print \"The number of fringes shifted across the cross wire of eye piece of the telescope is\",int(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.7, Page number 101" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thickness of a quarter wave plate of quartz for sodium light is 7.36625 micro m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "w=5893*10**-10; #wavelength of sodium light(m)\n", + "Re=1.5532; #Refractive index of quartz for e ray\n", + "Ro=1.5332; #Refractive index of quartz for o ray\n", + "\n", + "#Calculation\n", + "t=w/(4*(Re-Ro)); #thickness of a quarter wave plate of quartz for sodium light(m)\n", + "\n", + "#Result\n", + "print \"The thickness of a quarter wave plate of quartz for sodium light is\",t*10**6,\"micro m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.8, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thickness of a double refracting crystal required at w/2 is 2.727 micro m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "w=6000*10**-10; #wavelength(m)\n", + "Re=1.54; #Refractive index of double refracting crystal for e ray\n", + "Ro=1.65; #Refractive index of double refracting crystal for o ray\n", + "\n", + "#Calculation\n", + "t=w/(2*(Ro-Re)); #thickness of a double refracting crystal required at w/2(m)\n", + "\n", + "#Result\n", + "print \"The thickness of a double refracting crystal required at w/2 is\",round(t*10**6,3),\"micro m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.9, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The least thickness of a plate when the emergent beam will be plane polarised is 9.54 micro m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "w=5*10**-7; #wavelength(m)\n", + "Re=1.5573; #Refractive index for e ray when the emergent beam will be plane polarised\n", + "Ro=1.5442; #Refractive index for o ray when the emergent beam will be plane polarised\n", + "\n", + "#Calculation\n", + "t=w/(4*(Re-Ro)); #least thickness of a plate(m)\n", + "\n", + "#Result\n", + "print \"The least thickness of a plate when the emergent beam will be plane polarised is\",round(t*10**6,2),\"micro m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.10, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thickness of the quarter wave plate for calcite is 1.713 *10**-6 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", + "w=5893*10**-10; #wavelength of sodium light(m)\n", + "Ro=1.658; #Refractive index of calcite for o ray\n", + "Re=1.486; #Refractive index of calcite for e ray\n", + "\n", + "#Calculation\n", + "t=w/(2*(Ro-Re)); #thickness of the quarter wave plate for calcite(m)\n", + "\n", + "#Result\n", + "print \"The thickness of the quarter wave plate for calcite is\",round(t*10**6,3),\"*10**-6 m\"\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.11, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The wavelength for which it can act as a half wave plate is 600.0 *10**-9 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "t=30*10**-6; #thickness of wave plate(m)\n", + "Ro=1.55; #Refractive index of wave plate for o ray\n", + "Re=1.54; #Refractive index of wave plate for e ray\n", + "\n", + "#Calculation\n", + "w=2*t*(Ro-Re); #wavelength for which it can act as a half wave plate(m)\n", + "\n", + "#Result\n", + "print \"The wavelength for which it can act as a half wave plate is\",w*10**9,\"*10**-9 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 4.12, Page number 102" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thickness of a mica sheet required for making a half wave plate for a light is 4.5508 *10**-5 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "w=546.1*10**-9; #wavelength of light(m)\n", + "Re=1.592; #Refractive index of mica for e ray\n", + "Ro=1.586; #Refractive index of mica for o ray\n", + "\n", + "#Calculation\n", + "t=w/(2*(Re-Ro)); #thickness of a mica sheet(m)\n", + "\n", + "#Result\n", + "print \"The thickness of a mica sheet required for making a half wave plate for a light is\",round(t*10**5,4),\"*10**-5 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_G_Vijayakumari/Chapter5.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter5.ipynb new file mode 100755 index 00000000..9c78727b --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter5.ipynb @@ -0,0 +1,193 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#5: Laser" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 5.1, Page number 124" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The ratio of propulsion of the two states in a laser is 1.3893 *10**-30\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "t=300; #temperature(K)\n", + "w=698.3*10**-9; #wavelength of photon(m)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "Kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg.s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "Ratio=math.exp((-h*c)/(w*Kb*t)); #ratio of propulsion of the two states in a laser\n", + "\n", + "#Result\n", + "print \"The ratio of propulsion of the two states in a laser is\",round(Ratio*10**30,4),\"*10**-30\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 5.2, Page number 133" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The band gap for lnp laser diode is 0.8014 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "w=1.55*10**-6; #wavelength of light emission(m)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "Eg=(h*c)/(w*e); #band gap(eV)\n", + "\n", + "#Result\n", + "print \"The band gap for lnp laser diode is\",round(Eg,4),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 5.3, Page number 133" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The long wavelength limit of an extrinsic semiconductor is 6.2109 *10**-5 m\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=0.02*1.6*10**-19; #Ionisation energy(J)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "\n", + "#Calculation\n", + "w=h*c/E; #long wavelength limit of an extrinsic semiconductor(m)\n", + "\n", + "#Result\n", + "print \"The long wavelength limit of an extrinsic semiconductor is\",round(w*10**5,4),\"*10**-5 m\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 5.4, Page number 133" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number of photons emitted per minute is 6.562 *10**17 photons/minute\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=3.5*10**-3*60; #power output(J/min)\n", + "w=0.621*10**-6; #wavelength of light(m)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "\n", + "#Calculation\n", + "e=h*c/w; #energy emitted by one photon(J)\n", + "n=E/e; #The number of photons emitted per minute(photons/minute)\n", + "\n", + "#Result\n", + "print \"The number of photons emitted per minute is\",round(n/10**17,3),\"*10**17 photons/minute\"" + ] + } + ], + "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_G_Vijayakumari/Chapter6.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter6.ipynb new file mode 100755 index 00000000..7c2ac18d --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter6.ipynb @@ -0,0 +1,267 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#6: Fiber Optics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 6.1, Page number 146" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical angle is 75 degrees 23 minutes\n", + "The acceptance angle is 22 degrees 56 minutes\n", + "The numerical aperture is 0.3899\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.545; #refractive index of optical fibre core\n", + "n2=1.495; #refractive index of cladding\n", + "\n", + "#Calculation\n", + "CA=math.asin(n2/n1); #critical angle(radian)\n", + "CA=CA*180/math.pi; #critical angle(degree)\n", + "CAm=int(CA);\n", + "CAs=int(60*(CA-CAm));\n", + "AA=math.asin(math.sqrt(n1**2-n2**2)); #acceptance angle(radian)\n", + "AAd=AA*180/math.pi; #acceptance angle(degree) \n", + "AAm=int(AAd);\n", + "AAs=int(60*(AAd-AAm));\n", + "NA=math.sin(AA); #numerical aperture\n", + "\n", + "#Result\n", + "print \"The critical angle is\",CAm,\"degrees\",CAs,\"minutes\"\n", + "print \"The acceptance angle is\",AAm,\"degrees\",AAs,\"minutes\"\n", + "print \"The numerical aperture is\",round(NA,4)\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 6.2, Page number 147" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The numerical aperture is 0.3487\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n1=1.54; #refractive index of optical fibre core\n", + "n2=1.5; #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,4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 6.3, Page number 147" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The critical angle is 71 degrees 30 minutes\n", + "The acceptance angle is 29 degrees 26 minutes\n", + "The numerical aperture is 0.4915\n", + "answer for acceptance angle and numerical aperture given in the book is wrong\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n1=1.55; #refractive index of optical fibre core\n", + "n2=1.47; #refractive index of cladding\n", + "\n", + "#Calculation\n", + "CA=math.asin(n2/n1); #critical angle(radian)\n", + "CA=CA*180/math.pi; #critical angle(degree) \n", + "CAm=int(CA);\n", + "CAs=int(60*(CA-CAm));\n", + "NA=math.sqrt(n1**2-n2**2); #numerical aperture \n", + "AA=math.asin(NA); #acceptance angle(radian)\n", + "AAd=AA*180/math.pi; #acceptance angle(degree) \n", + "AAm=int(AAd);\n", + "AAs=int(60*(AAd-AAm));\n", + "\n", + "#Result\n", + "print \"The critical angle is\",CAm,\"degrees\",CAs,\"minutes\"\n", + "print \"The acceptance angle is\",AAm,\"degrees\",AAs,\"minutes\"\n", + "print \"The numerical aperture is\",round(NA,4)\n", + "print \"answer for acceptance angle and numerical aperture given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 6.4, Page number 147" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The refractive index of optical fibre is 1.5628\n", + "The numerical aperture when fibre is in water is 0.15\n", + "The Acceptance angle for the fibre in water is 8 degrees 38 minutes\n", + "answer for minutes varies due to rounding off errors\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n2=1.55; #refractive index of cladding\n", + "no=1.33; #refractive index of water\n", + "NA=0.20; #numerical aperture of optical fibre\n", + "\n", + "#Calculation\n", + "n1=math.sqrt(n2**2+NA**2); #refractive index of optical fibre\n", + "NAW=math.sqrt(n1**2-n2**2)/no; #numerical aperture when fibre is in water\n", + "AA=math.asin(NAW); #Acceptance angle for the fibre in water(degrees)\n", + "AAd=AA*180/math.pi; #acceptance angle(degree) \n", + "AAm=int(AAd);\n", + "AAs=int(60*(AAd-AAm));\n", + "\n", + "#Result\n", + "print \"The refractive index of optical fibre is\",round(n1,4)\n", + "print \"The numerical aperture when fibre is in water is\",round(NAW,2)\n", + "print \"The Acceptance angle for the fibre in water is\",AAm,\"degrees\",AAs,\"minutes\"\n", + "print \"answer for minutes varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 6.5, Page number 148" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The refractive index of the core of a fibre is 1.42\n", + "The refractive index of the cladding is 1.403\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.22; #numerical aperture of optical fibre\n", + "no=0.012; #refractive index difference\n", + "\n", + "#Calculation\n", + "n1=NA/math.sqrt(2*no); #The refractive index of the core of a fibre\n", + "n2=n1*(1-no); #The refractive index of the cladding\n", + "\n", + "#Result\n", + "print \"The refractive index of the core of a fibre is\",round(n1,2)\n", + "print \"The refractive index of the cladding is\",round(n2,3)\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_G_Vijayakumari/Chapter7.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter7.ipynb new file mode 100755 index 00000000..13a2a17f --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter7.ipynb @@ -0,0 +1,781 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#7: Conducting Materials" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.1, Page number 178" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The current density in the conductor corresponds to a drift velocity is 5.9 *10**9 A m^-1\n", + "Mobility of the charge carrires is 6.58898 *10**-3 m^2 V^-1 s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=5.9*10**28; #electron concentration of conductor(m^-3)\n", + "v=0.625; #drift velocity of a conductor(ms^-1)\n", + "x=6.22*10**7; #electrical conductivity(ohm^-1 m^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "J=n*e*v; #current density in the conductor corresponds to drift velocity(Am^-1)\n", + "z=x/(n*e); #mobility of the charge(m^2V^-1s^-1)\n", + " \n", + "#Result\n", + "print \"The current density in the conductor corresponds to a drift velocity is\",J/10**9,\"*10**9 A m^-1\"\n", + "print \"Mobility of the charge carrires is\",round(z*10**3,5),\"*10**-3 m^2 V^-1 s^-1\"\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.2, Page number 179" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The drift velocity of free electron in a copper wire is 7.0028 *10**-5 ms^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=8.5*10**28; #density of free electrons in copper(m^-3)\n", + "A=1.05*10**-6; #sectional area of copper(m^2)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "I=1; #copper wire carries a current(A)\n", + "\n", + "#Calculation\n", + "V=1/(A*n*e); #drift velocity of free electrons in copper wire(ms^-1)\n", + "\n", + "#Result\n", + "print \"The drift velocity of free electron in a copper wire is\",round(V*10**5,4),\"*10**-5 ms^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.3, Page number 179" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The drift velocity of free electrons in copper is 1.75 *10**-3 ms^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "X=3.5*10**-3; #mobility of free electrons in copper(m^2 V^-1 s^-1)\n", + "E=0.5; #elactric field strength of copper(V m^-1)\n", + "\n", + "#Calculation\n", + "V=X*E; #drift velocity of free electrons in copper(m s^-1)\n", + "\n", + "#Result\n", + "print \"The drift velocity of free electrons in copper is\",V*10**3,\"*10**-3 ms^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.4, Page number 179" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The relaxation time of conduction electrons is 3.815 *10**-14 s\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=6.5*10**28; #conduction electron(m^-3)\n", + "r=1.435*10**-8; #metal resistivity(ohm-metre)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of a electron(kg)\n", + "\n", + "#Calculation\n", + "T=m/(r*n*e**2); #relaxation time of conduction electrons(s)\n", + "\n", + "#Result\n", + "print \"The relaxation time of conduction electrons is\",round(T*10**14,3),\"*10**-14 s\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.5, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The mean free path between collision of free electrons in copper is 2.8153 *10**-9 m\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", + "r=1.72*10**-8; #resistivity of copper(ohm metre)\n", + "T=293; #temperature of copper(K)\n", + "n=8.48*10**28; #density of free electron(m^-3)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of a electron(kg)\n", + "k=1.38*10**-23; #boltzmann constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "t=m/(r*n*(e**2)); #relaxation time(s)\n", + "v=math.sqrt(3*k*T/m); #thermal velocity(ms^-1)\n", + "Lamda=t*v; #mean free path between collision of free electrons in copper(m)\n", + "\n", + "#Result\n", + "print \"The mean free path between collision of free electrons in copper is\",round(Lamda*10**9,4),\"*10**-9 m\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.6, Page number 180" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thermal velocity is 116.76 *10**3 m s^-1\n", + "Drift velocity of electrons is 40.0 m s^-1\n", + "Thus the terminal velocity is high compared to the drift velocity\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "t=1*10**-3; #thickness of metal(m)\n", + "V=1; #potential difference applied in volts(V)\n", + "T=300; #temperature(K)\n", + "m=0.04; #mobility(m^2 V^-1 s^-1)\n", + "k=1.38*10**-23; #boltzmann constant(m^2 Kg s^-2 k^-1)\n", + "m1=9.11*10**-31; #mass of a electron(kg)\n", + "\n", + "#Calculation\n", + "v=math.sqrt(3*k*T/m1); #thermal velocity(ms^-1)\n", + "E=V/t; #unit potenyial voltage gradient(V m^-1)\n", + "vd=E*m; #drift velocity of electrons(m s^-1)\n", + "\n", + "#Result\n", + "print \"The thermal velocity is\",round(v/10**3,2),\"*10**3 m s^-1\"\n", + "print \"Drift velocity of electrons is\",vd,\"m s^-1\"\n", + "print \"Thus the terminal velocity is high compared to the drift velocity\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.7, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electrical conductivity of copper is 5.9 *10**7 S m^-1\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", + "AW=63.5; #atomic weight of copper\n", + "D=8.93*10**3; #density of copper(kg m^-3)\n", + "t=2.48*10**-14; #relaxation time of copper(s)\n", + "AV=6.023*10**26; #avagadro no(mole^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of a electron(kg)\n", + "\n", + "#Calculation\n", + "n=AV*D/AW; #density of electrons per unit volume(m^-3)\n", + "sigma=n*e**2*t/m; #electrical conductivity of copper(Sm^-1)\n", + "\n", + "#Result\n", + "print \"The electrical conductivity of copper is\",round(sigma/10**7,1),\"*10**7 S m^-1\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.8, Page number 181" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The drift velocity in copper is 3.6657 *10**-6 ms^-1\n", + "The current density in copper is 4.9736 *10**4 Am^-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", + "I=10; #current(A)\n", + "r=0.8*10**-2; #radius of wire(m)\n", + "n=8.48*10**28; #density of free electron(m^-3)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "J=I/(math.pi*r**2); #current density of copper(Am^-2)\n", + "v=J/(n*e); #drift velocity of copper(ms^-1)\n", + "\n", + "#Result\n", + "print \"The drift velocity in copper is\",round(v*10**6,4),\"*10**-6 ms^-1\"\n", + "print \"The current density in copper is\",round(J/10**4,4),\"*10**4 Am^-2\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.9, Page number 182" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The mobility of charge is 6.997 *10**-3 m^2 V^-1 s^-1\n", + "The drift velocity of electrons is 0.6997 m s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "r=1.54*10**-8; #resistivity of silver wire at room temperature(ohm metre)\n", + "E=100; #Electric field along the wire(V/m)\n", + "n=5.8*10**28; #n is assuming of conduction electrons(m^-3)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "mew=1/(r*n*e); #mobility of charge(m^2 V^-1 s^-1)\n", + "vd=mew*E; #drift velocity of electrons(m s^-1)\n", + "\n", + "#Result\n", + "print \"The mobility of charge is\",round(mew*10**3,3),\"*10**-3 m^2 V^-1 s^-1\"\n", + "print \"The drift velocity of electrons is\",round(vd,4),\"m s^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.10, Page number 182" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The relaxation time collision of electrons in copper obeying classical laws is 2.43 *10**-14 s\n", + "The mobility charge of copper obeying classical laws is 0.427 *10**-2 m^2 V^-1 s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "D=8.92*10**3; #density of copper(kg m^-3)\n", + "AW=63.5; #atomic weight of copper\n", + "r=1.73*10**-8; #resistivity of copper(ohm metre)\n", + "AV=6.023*10**26; #avagadro no(mole^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of a electron(kg)\n", + "\n", + "#Calculation\n", + "n=AV*D/AW; #density of electrons per unit volume(m^-3)\n", + "tow=m/(r*n*e**2); #average time collision of electrons in copper(s)\n", + "mew=1/(r*n*e); #mobility of charge(m^2 V^-1 s^-1)\n", + "\n", + "#Result\n", + "print \"The relaxation time collision of electrons in copper obeying classical laws is\",round(tow*10**14,2),\"*10**-14 s\"\n", + "print \"The mobility charge of copper obeying classical laws is\",round(mew*10**2,3),\"*10**-2 m^2 V^-1 s^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.11, Page number 183" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The electrical resistivity is 4.63 *10**-8 ohm metre\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", + "r=1.85*10**-10; #the radius of sodium atom(m)\n", + "t=3*10**-14; #the classic value of mean free time(sec)\n", + "temp=0; #temperature(centigrade)\n", + "na=2; #number of atoms in a unit cell\n", + "ne=1; #number of electrons per unit cell\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "m=9.11*10**-31; #mass of a electron(kg)\n", + "\n", + "#Calculation \n", + "a=4*r/math.sqrt(3); #a is one side in bcc structure unit cell(m)\n", + "v=a**3; #volume of bcc structure unit cell(m^3)\n", + "n=na*ne/v; #density of electrons per unit volume(m^-3)\n", + "rho=m/(n*e**2*t); #The electrical resistivity(ohm metre)\n", + "\n", + "#Result\n", + "print \"The electrical resistivity is\",round(rho*10**8,2),\"*10**-8 ohm metre\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.12, Page number 184" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Free electron concentration in aluminium is 0.18 V/m\n", + "Mobility of the charge is 1.28 *10**-3 m^2 V^-1 S^-1\n", + "The drift velocity of electrons is 2.304 *10**-4 m s^-1\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=2.7*10**-8; #electrical resistivity of aluminium(ohm metre)\n", + "AW=26.98; #atomic weight of aluminium\n", + "d=2.7*10**3; #density of volume(Kg/m^3)\n", + "R=60*10**-3; #resistance(W)\n", + "l=5; #length of aluminium wire(m)\n", + "i=15; #aluminuim wire carries a current(A)\n", + "fe=3; #number of free electrons \n", + "AV=6.023*10**26; #avagadro no(mole^-1)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "n=AV*d*fe/AW; #density of electrons per unit volume(electrons/m^-3)\n", + "mew=1/(n*e*rho); #mobility of the charge(m^2 V^-1 S^-1)\n", + "E=i*R/l; #free electron concentration(V/m)\n", + "vd=mew*E; #drift velocity(m s^-1)\n", + "\n", + "#Result\n", + "print \"Free electron concentration in aluminium is\",E,\"V/m\"\n", + "print \"Mobility of the charge is\",round(mew*10**3,2),\"*10**-3 m^2 V^-1 S^-1\"\n", + "print \"The drift velocity of electrons is\",round(vd*10**4,3),\"*10**-4 m s^-1\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.13, Page number 184" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The resistance of an intrinsic Ge rod is 4310 ohm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "l=1*10**-2; #length of intrinsic Ge rod(m)\n", + "b=1*10**-3; #breadth of intrinsic Ge rod(m)\n", + "t=1*10**-3; #thickness of intrinsic Ge rod(m)\n", + "temp=300; #temperature(K)\n", + "d=2.5*10**19; #intrinsic carrier density(Kg/m^3)\n", + "z=0.39; #mobility of electron(m^2 V^-1 S^-1)\n", + "zh=0.19; #mobility of hole(m^2 V^-1 S^-1) \n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "x=d*e*(z+zh); #electrical conductivity(ohm^-1 m^-1)\n", + "r=1/x; #electrical resistivity(ohm metre)\n", + "A=b*t; #area(m^2)\n", + "R=r*l/A; #resistance of an intrinsic Ge rod(ohm)\n", + "\n", + "#Result\n", + "print \"The resistance of an intrinsic Ge rod is\",int(R),\"ohm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.14, Page number 188" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thermal conductivity of copper is 189.9299 W m^-1 K^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "d=8.48*10**28; #free electron density of copper(m^-3)\n", + "y=2.8138*10**-9; #mean free path(m)\n", + "v=1.1536*10**5; #velocity of copper(m s^-1)\n", + "t=20; #temperature of copper(C)\n", + "Kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "K=1/2*(d*v*y*Kb); #thermal conductivity of copper(W m^-1 K^-1)\n", + "\n", + "#Result\n", + "print \"The thermal conductivity of copper is\",round(K,4),\"W m^-1 K^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.15, Page number 189" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thermal conductivity of brass is 14.64 W m^-1 K^-1\n", + "The thermal resistance of brass is 4.503 K W^-1\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", + "er=50*10**-8; #electrical resistivity(ohm metre)\n", + "t=300; #temperature(K)\n", + "r=13*10**-3; #radius of brass(m)\n", + "th=35*10**-3; #thickness of brass(m)\n", + "L=2.44*10**-8; #Lorentz number(W ohm K^-2)\n", + "\n", + "#Calculation\n", + "K=L*t/er; #thermal conductivity of brass(W m^-1 K^-1)\n", + "A=math.pi*r**2; #area of brass disk(m^2)\n", + "Rt=th/(K*A); #thermal resistance of brass(K W^-1)\n", + "\n", + "#Result\n", + "print \"The thermal conductivity of brass is\",K,\"W m^-1 K^-1\"\n", + "print \"The thermal resistance of brass is\",round(Rt,3),\"K W^-1\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.16, Page number 189" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lorentz number is 2.2094 *10**-8 W ohm K^-2\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=5.87*10**7; #electrical conductivity(ohm^-1 m^-1)\n", + "k=380; #thermal conductivity of copper(W m-1 K^-1)\n", + "t=293; #temperature of copper(K)\n", + "\n", + "#Calculation\n", + "L=k/(x*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\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 7.17, Page number 189" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The thermal conductivity of copper is 468.48 W m^-1 K^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=6.40*10**7; #electrical conductivity(mho m^-1)\n", + "t=300; #temperature of copper(K)\n", + "L=2.44*10**-8; #Lorentz number(W ohm K^-2)\n", + "\n", + "#Calculation\n", + "K=x*t*L; #thermal conductivity of copper(W m^-1 K^-1)\n", + "\n", + "#Result\n", + "print \"The thermal conductivity of copper is\",K,\"W m^-1 K^-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/Engineering_Physics_By_G_Vijayakumari/Chapter8.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter8.ipynb new file mode 100755 index 00000000..e403d61e --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter8.ipynb @@ -0,0 +1,669 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#8: Quantum Physics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.1, Page number 204" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The energy of photon is 12412.5 eV\n", + "The momentum of the photon is 6.62e-24 Kg m s^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "W=0.1*10**-9; #wavelength of photon(m)\n", + "h=6.62*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "E=h*c/(W*e); #energy of photon(eV)\n", + "P=h/W; #momentum of the photon(Kgms^-1)\n", + "\n", + "#Result\n", + "print \"The energy of photon is\",E,\"eV\"\n", + "print \"The momentum of the photon is\",P,\"Kg m s^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.2, Page number 205" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total number of photons emitted per second is 2.965 *10**20 per sec\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", + "w=5893*10**-10; #wavelength of emitted light(m)\n", + "e=100; #total energy emitted per sec\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "\n", + "#Calculation\n", + "E=h*c/w; #energy of one photon(J)\n", + "N=e/E; #The total numberof photons emitted(sec)\n", + "\n", + "#Result\n", + "print \"The total number of photons emitted per second is\",round(N/10**20,3),\"*10**20 per sec\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.3, Page number 205" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The energy density per unit wavelength in a black body cavity is 0.018349 J/m^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", + "w=4000*10**-10; #wavelength in black body(m)\n", + "t=1500; #temperature of black body(K)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "Kb=1.38*10**-23; #Boltzmann's constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "Edw=(8*math.pi*h*c/w**5)*(1/(math.exp(h*c/(w*Kb*t))-1)); #The energy density per unit wavelength in a black body cavity(J/m^4)\n", + "\n", + "#Result\n", + "print \"The energy density per unit wavelength in a black body cavity is\",round(Edw,6),\"J/m^4\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.4, Page number 211" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The compton wavelength for an electron is 0.0242 Angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "\n", + "#Calculation\n", + "w=h/(c*m)*10**10; #The compton wavelength for an electron(Armstrong)\n", + "\n", + "#Result\n", + "print \"The compton wavelength for an electron is\",round(w,4),\"Angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.5, Page number 212" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The change in wavelength for X ray photon is 0.0242 Angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "theta=90; #x ray photon scattered at a angle(degrees)\n", + "h=6.625*10**-34; #Planck's constant(J-sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "\n", + "#Calculation\n", + "theta=theta*math.pi/180; #angle(radian)\n", + "deltalamda=((h/(c*m))*(1-math.cos(x)))/10**-10; #The change in wavelength for Xray photon(Angstrom)\n", + "\n", + "#Result\n", + "print \"The change in wavelength for X ray photon is\",round(deltalamda,4),\"Angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.6, Page number 212" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The wavelength of X-rays carbon is 1.72 Angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "theta=180; #x ray carbon scattered at a angle(degrees)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/s)\n", + "m=9.11*10**-31; #mass of electron(kg)\n", + "v=1.8*10**18; #frequency of incident rays(s^-1)\n", + "\n", + "#Calculation\n", + "theta=theta*math.pi/180; #angle(radian)\n", + "w=c/v; #wavelength(m)\n", + "tw=(h/(c*m))*(1-math.cos(theta)); #The change wavelength for Xray carbon(m)\n", + "lamda_dash=(w+tw)/10**-10; #The wavelength of X-rays carbon(Angstrom)\n", + "\n", + "#Result\n", + "print \"The wavelength of X-rays carbon is\",round(lamda_dash,2),\"Angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.7, Page number 212" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The wavelength of scattered photons is 3.012 Angstrom\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "w=3*10**-10; #wavelength of incident photons(m)\n", + "theta=60; #angle of view(degrees)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "\n", + "#Calculation\n", + "theta=theta*math.pi/180; #angle(radian)\n", + "lamda_dash=(w+((h/(c*m))*(1-math.cos(theta))))/10**-10; #The wavelength of scattered photons(Angstrom)\n", + "\n", + "#Result\n", + "print \"The wavelength of scattered photons is\",round(lamda_dash,3),\"Angstrom\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.8, Page number 213" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Velocity of moving electron is 2.9047 *10**8 m/sec\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "x=4; #Total energy increase to 4 times of its initial rest energy\n", + "c=3*10**8; #velocity of light(m/sec)\n", + "\n", + "#Calculation\n", + "v=math.sqrt(c**2*(1-(1/x**2))); #The Velocity of moving electron(m/sec)\n", + "\n", + "#Result\n", + "print \"The Velocity of moving electron is\",round(v/10**8,4),\"*10**8 m/sec\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.9, Page number 224" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The least energy of the particle can be obtained is 37.639 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", + "a=0.1*10**-9; #width of high potential box(m)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "n=1; #take n equal to one\n", + "\n", + "#Calculation\n", + "E=(n**2*h**2)/(8*m*a**2*e); #The least energy of the particle can be obtained(eV)\n", + "\n", + "#Result\n", + "print \"The least energy of the particle can be obtained is\",round(E,3),\"eV\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.10, Page number 224" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The least energy of the neutron can be obtained is 2.053 MeV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=10**-14; #length of impenerable box(m)\n", + "m=1.67*10**-27; #mass of neutron(Kg)\n", + "n=1; #for lowest energy\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "\n", + "#Calculation\n", + "E=(n**2*h**2)/(8*m*a**2); #The least energy of the neutron can be obtained(J)\n", + "\n", + "#Result\n", + "print \"The least energy of the neutron can be obtained is\",round(E/(1.6*10**-19*10**6),3),\"MeV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.11, Page number 225" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The first permitted energy level by taking n=1 is 2.352 eV\n", + "The second permitted energy level by taking n=2 is 9.41 eV\n", + "The third permitted energy level by taking n=3 is 21.172 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", + "a=4*10**-10; #width of electron box(m)\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "m=9.11*10**-31; #mass of electron(kg)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "n=1; #first permitted level\n", + "\n", + "#Calculation\n", + "E1=((n**2*h**2)/(8*m*a**2*e)); #The first permitted energy level by taking n=1(eV)\n", + "E2=4*E1; #The second permitted energy level by taking n=2(eV)\n", + "E3=9*E1; #The third permitted energy level by taking n=3(eV)\n", + "\n", + "#Result\n", + "print \"The first permitted energy level by taking n=1 is\",round(E1,3),\"eV\"\n", + "print \"The second permitted energy level by taking n=2 is\",round(E2,2),\"eV\"\n", + "print \"The third permitted energy level by taking n=3 is\",round(E3,3),\"eV\"\n", + "print \"answer varies due to rounding off errors\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.12, Page number 226" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lowest energy of electron in a cubical box is 50.186 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=1.5*10**-10; #each side of cubical box(m)\n", + "n1=1; #for lowest energy\n", + "n2=1; #for lowest energy\n", + "n3=1; #for lowest energy\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "n=(n1**2+n2**2+n3**2); #total value of n\n", + "E=((n*h**2)/(8*m*a**2*e)); #The lowest energy of electron ina cubical box(eV)\n", + "\n", + "#Result\n", + "print \"The lowest energy of electron in a cubical box is\",round(E,3),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.13, Page number 226" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lowest energy of electron in deep potential well is 0.02352 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=4*10**-9; #width of potential well(m)\n", + "n=1; #For minimum energy n value\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "E=((n**2*h**2)/(8*m*a**2*e)); #The lowest energy of electron in deep potential well(eV)\n", + "\n", + "#Result\n", + "print \"The lowest energy of electron in deep potential well is\",round(E,5),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.14, Page number 227" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The energy required the electron from its ground state to the fifth exited state is 1317 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "a=0.1*10**-9; #length of one dimensional box(m)\n", + "n=1; #first permitted level\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "m=9.11*10**-31; #mass of electron(kg)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "\n", + "#Calculation\n", + "E1=((n**2*h**2)/(8*m*a**2*e)); #The ground state of electron in an one dimensional box(eV)\n", + "E6=36*E1; #The fifth exited state of electron(eV)\n", + "E=E6-E1; #The energy required the electron from its ground state to the fifth exited state(eV)\n", + "\n", + "#Result\n", + "print \"The energy required the electron from its ground state to the fifth exited state is\",int(E),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 8.15, Page number 227" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lowest energy of the system consisting of three electron ia a one dimensional box is 112.9184 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", + "a=0.1*10**-9; #length of one dimensional box(m)\n", + "n=1; #first permitted level\n", + "h=6.625*10**-34; #Planck's constant(m^2 Kg/sec)\n", + "m=9.11*10**-31; #mass of electron(Kg)\n", + "e=1.6*10**-19; #charge of electron(c)\n", + "ne=3; #the number of electrons\n", + "\n", + "#Calculation\n", + "E=((n**2*h**2)/(8*m*a**2*e))*ne; #The lowest energy of the system consisting of three electron ia a one dimensional box(eV)\n", + "\n", + "#Result\n", + "print \"The lowest energy of the system consisting of three electron ia a one dimensional box is\",round(E,4),\"eV\"\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_G_Vijayakumari/Chapter9.ipynb b/Engineering_Physics_By_G_Vijayakumari/Chapter9.ipynb new file mode 100755 index 00000000..90c89eeb --- /dev/null +++ b/Engineering_Physics_By_G_Vijayakumari/Chapter9.ipynb @@ -0,0 +1,585 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#9: Energy bands in solids" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.1, Page number 240" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi function for an energy kt above fermi energy is 0.269\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "#E-EF=KT\n", + "#K=KB is the boltzmann constant in m^2 Kg s^-2 k^-1\n", + "\n", + "#Calculation\n", + "f=1/(1+math.exp(1)); #The fermi function for an energy kt above fermi energy\n", + "\n", + "#Result\n", + "print \"The fermi function for an energy kt above fermi energy is\",round(f,3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.2, Page number 240" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi function is 0.358999\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", + "X=0.01*1.6*10**-19; #difference between energy and fermi energy(J)\n", + "T=200; #temperature(K)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(J/K)\n", + "\n", + "#Calculation\n", + "f=1/(1+math.exp(X/(KB*T))); #The fermi function\n", + "\n", + "#Result\n", + "print \"The fermi function is\",round(f,6)\n", + "print \"answer given in the book is wrong\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.3, Page number 241" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi velocity fo conducting electron in aluminium is 2.02118 *10**6 ms^-1\n", + "The mean free path for conducting electron of aluminium is 14.7546 nm\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "EF=11.63*1.6*10**-19; #fermi energy of conducting electron in aluminium(J)\n", + "t=7.3*10**-15; #relaxation time for electron(sec)\n", + "m=9.11*10**-31; #mass of electon(Kg)\n", + "\n", + "#Calculation\n", + "Vf=math.sqrt(2*EF/m); #The fermi velocity fo conducting electron in aluminium(ms^-1)\n", + "x=t*Vf*10**9; #mean free path for conducting electron of aluminium(nm)\n", + "\n", + "#Result\n", + "print \"The fermi velocity fo conducting electron in aluminium is\",round(Vf/10**6,5),\"*10**6 ms^-1\"\n", + "print \"The mean free path for conducting electron of aluminium is\",round(x,4),\"nm\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.4, Page number 241" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi energy in a metal is 3.36888 *10**-19 J or 2.1055 eV\n", + "The fermi temperature in a metal is 24.41 *10**3 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Vf=0.86*10**6; #The femi energy of electons in the metal(m/sec)\n", + "m=9.11*10**-31; #mass of electon(Kg)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "Ef=(1/2)*m*Vf**2; #The fermi energy in a metal(J)\n", + "Tf=Ef/KB; #The fermi temperature in a metal(K)\n", + "\n", + "#Result\n", + "print \"The fermi energy in a metal is\",round(Ef/10**-19,5),\"*10**-19 J or\",round(Ef/(1.6*10**-19),4),\"eV\"\n", + "print \"The fermi temperature in a metal is\",round(Tf/10**3,2),\"*10**3 K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.5, Page number 242" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi temparature for sodium is 37.1 *10**3 K\n", + "The fermi velocity fo conducting electron in aluminium is 1.0602 *10**6 ms^-1\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Ef=3.2*1.6*10**-19; #The fermi energy in a metal(J)\n", + "m=9.11*10**-31; #mass of electon(Kg)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "Tf=Ef/KB; #The fermi temparature for sodium(K)\n", + "Vf=math.sqrt(2*Ef/m); #The fermi velocity fo conducting electron in aluminium(ms^-1)\n", + "\n", + "#Result\n", + "print \"The fermi temparature for sodium is\",round(Tf/10**3,2),\"*10**3 K\"\n", + "print \"The fermi velocity fo conducting electron in aluminium is\",round(Vf/10**6,4),\"*10**6 ms^-1\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.6, Page number 242" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The temperature at which there is 1% probability that an electron in a solid is 1.26158 *10**3 K\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "E=5.5*1.6*10**-19; #energy level(J)\n", + "Ef=5*1.6*10**-19; #fermi energy level(J)\n", + "x=0.5*1.6*10**-19; #Difference between energy and fermi energy(J)\n", + "f=0.01; #fermi function at which there is 1% probability that an electron in a solid\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "T=x/(KB*(math.log(1-f)-math.log(f))); #The temperature at which there is 1% probability that an electron in a solid(K)\n", + "\n", + "#Result\n", + "print \"The temperature at which there is 1% probability that an electron in a solid is\",round(T/10**3,5),\"*10**3 K\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.7, Page number 244" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The energy for probability of occupancy at 1st is 1.98 eV\n", + "The energy for probability of occupancy at 2nd is 2.219 eV\n", + "The energy for probability of occupancy at 3rd is 2.1 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Ef=2.1*1.6*10**-19; #fermi energy level in potassium(J)\n", + "f1=0.99; #fermi factor for 1st\n", + "f2=0.01; #fermi factor for 2nd\n", + "f3=0.5; #fermi factor for 3rd\n", + "T=300; #temperature(K)\n", + "e=1.6*10**-19; #charge of electron(C)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "E1=(Ef+((KB*T)*(math.log(1-f1)-math.log(f1))))/e; #The energy for probability of occupancy at 1st(eV)\n", + "E2=(Ef+((KB*T)*(math.log(1-f2)-math.log(f2))))/e; #The energy for 1st at which the probability of occupancy(eV)\n", + "E3=(Ef+((KB*T)*(math.log(1-f3)-math.log(f3))))/e; #The energy for 1st at which the probability of occupancy(eV)\n", + "\n", + "#Result\n", + "print \"The energy for probability of occupancy at 1st is\",round(E1,2),\"eV\"\n", + "print \"The energy for probability of occupancy at 2nd is\",round(E2,3),\"eV\"\n", + "print \"The energy for probability of occupancy at 3rd is\",E3,\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.8, Page number 245" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The probability of unoccupancy by an electron at room temperature is 0.97946\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "X=0.1*1.6*10**-19; #difference between energy and fermi energy(J)\n", + "T=300; #temperature(K)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "f=1-1/(1+math.exp(X/(KB*T))); #The probability of unoccupancy by an electron at room temperature \n", + "\n", + "#Result\n", + "print \"The probability of unoccupancy by an electron at room temperature is\",round(f,5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.9, Page number 252" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi energy for the metal is 11.66 eV\n", + "The fermi factor is 0.0205\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=4; #number of atoms/unit cell in Al\n", + "a=4.05*10**-10; #lattice constant of Aluminium which is FCC crystal(m)\n", + "nf=3; #number of free electrons per atom in Al\n", + "T=300; #ambient temperature(K)\n", + "x=0.1*1.6*10**-19; #The same difference energy and fermi energy(J)\n", + "m=9.11*10**-31; #mass of electon(kg)\n", + "h=6.625*10**-34; #plank's constant(m^2 Kg/sec)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "\n", + "#Calculation\n", + "nc=n*nf/(a**3); #number of electrons per unit volume\n", + "Ef=h**2/(8*m)*((3*nc)/math.pi)**(2/3); #The fermi energy for the metal(eV)\n", + "f=1/(1+math.exp(x/(KB*T))); #he fermi factor\n", + "\n", + "#Result\n", + "print \"The fermi energy for the metal is\",round(Ef/(1.6*10**-19),2),\"eV\"\n", + "print \"The fermi factor is\",round(f,4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.10, Page number 253" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi energy for cesium is 1.537 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "n=2; #number of atoms/unit cell in cesium which is Bcc\n", + "a=6.14*10**-10; #lattice constant of cesium which is BCC crystal(m)\n", + "nf=1; #number of free electrons per atom in cesium\n", + "m=9.11*10**-31; #mass of electon(kg)\n", + "h=6.625*10**-34; #plank's constant(m^2 Kg/sec)\n", + "KB=1.38*10**-23; #Boltzmann's Constant(m^2 Kg s^-2 k^-1)\n", + "e=1.6*10**-19; #charge of electron(C)\n", + "\n", + "#Calculation\n", + "nc=n*nf/(a**3); #number of electrons per unit volume\n", + "Ef=(h**2/(8*m)*((3*nc)/math.pi)**(2/3))/e; #The fermi energy for the metal(eV)\n", + "\n", + "#Result\n", + "print \"The fermi energy for cesium is\",round(Ef,3),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.11, Page number 254" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number of free electrons per unit volume in potassium is 1.38 *10**28 electrons/m^3\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "Ef=2.1*1.6*10**-19; #The fermi energy level in potassium at a particular temperature(J)\n", + "m=9.11*10**-31; #mass of electron(kg)\n", + "h=6.625*10**-34; #plank's constant(m^2 Kg/sec)\n", + "\n", + "#Calculation\n", + "nc=(8*m/(h**2)*Ef)**(3/2)*(math.pi/3); #ThE Number of free electrons per unit volume in potassium(electrons/m^3)\n", + "\n", + "#Result\n", + "print \"The number of free electrons per unit volume in potassium is\",round(nc/10**28,2),\"*10**28 electrons/m^3\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.12, Page number 254" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi energy for the sodium is 3.155 eV\n" + ] + } + ], + "source": [ + "#importing modules\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable declaration\n", + "AW=23; #atomic weight of sodium(gm/mole)\n", + "d=0.971*10**6; #density of sodium(gm/m^3)\n", + "m=9.11*10**-31; #mass of electon(kg)\n", + "h=6.625*10**-34; #plank's constant(m^2 Kg/sec)\n", + "AV=6.02*10**23; #Avagadro number(mole^-1)\n", + "e=1.6*10**-19; #charge of electron(C)\n", + "\n", + "#Calculation\n", + "nc=AV*d/AW; #number of electrons per unit volume\n", + "Ef=(h**2/(8*m)*((3*nc)/math.pi)**(2/3))/e; #The fermi energy for the sodium(eV)\n", + "\n", + "#Result\n", + "print \"The fermi energy for the sodium is\",round(Ef,3),\"eV\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Example number 9.13, Page number 255" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fermi energy for the sodium is 7.046 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", + "AW=63.5; #atomic weight of copper(u)\n", + "M=63.5*1.66*10**-27; #mass of one copper atom(kg)\n", + "d=8.94*10**3; #density of sodium(Kg/m^3)\n", + "m=9.11*10**-31; #mass of electon(Kg)\n", + "h=6.625*10**-34; #plank's constant(m^2 Kg/sec)\n", + "e=1.6*10**-19; #charge of electron(C)\n", + "\n", + "#Calculation\n", + "nc=d/M; #number of electrons per unit volume(electrons/m^3)\n", + "Ef=h**2/(8*m)*((3*nc)/math.pi)**(2/3)/e; #The fermi energy for the sodium(eV)\n", + "\n", + "#Result\n", + "print \"The fermi energy for the sodium is\",round(Ef,3),\"eV\"\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/Fundamental_Electrical_and_Electronic_Principles/README.txt b/Fundamental_Electrical_and_Electronic_Principles/README.txt new file mode 100755 index 00000000..f8a55062 --- /dev/null +++ b/Fundamental_Electrical_and_Electronic_Principles/README.txt @@ -0,0 +1,10 @@ +Contributed By: Muktesh Chaudhary +Course: be +College/Institute/Organization: Anglo Eastern ship management india Pvt. Ltd +Department/Designation: Electrical & Electronics Officer +Book Title: Fundamental Electrical and Electronic Principles +Author: C. R. Robertson +Publisher: Newens (Elsevier) +Year of publication: 2008 +Isbn: 978-0-7506-8737-9 +Edition: 3rd \ No newline at end of file diff --git a/Meachanics-DEMO/README.txt b/Meachanics-DEMO/README.txt new file mode 100755 index 00000000..db3a2289 --- /dev/null +++ b/Meachanics-DEMO/README.txt @@ -0,0 +1,10 @@ +Contributed By: Khushbu Pattani +Course: bca +College/Institute/Organization: Saraswati College, Dhoraji +Department/Designation: BCA +Book Title: Meachanics-DEMO +Author: Unknown +Publisher: Unknown +Year of publication: 2000 +Isbn: 1 +Edition: 1 \ No newline at end of file diff --git a/Meachanics-DEMO/screenshots/screen2.png b/Meachanics-DEMO/screenshots/screen2.png new file mode 100755 index 00000000..eb6ad8e1 Binary files /dev/null and b/Meachanics-DEMO/screenshots/screen2.png differ diff --git a/Meachanics-DEMO/screenshots/screen2_1.png b/Meachanics-DEMO/screenshots/screen2_1.png new file mode 100755 index 00000000..eb6ad8e1 Binary files /dev/null and b/Meachanics-DEMO/screenshots/screen2_1.png differ diff --git a/Meachanics-DEMO/screenshots/screen2_2.png b/Meachanics-DEMO/screenshots/screen2_2.png new file mode 100755 index 00000000..eb6ad8e1 Binary files /dev/null and b/Meachanics-DEMO/screenshots/screen2_2.png differ diff --git a/Meachanics-DEMO_by_Unknown/chapter1.ipynb b/Meachanics-DEMO_by_Unknown/chapter1.ipynb new file mode 100755 index 00000000..cf45a409 --- /dev/null +++ b/Meachanics-DEMO_by_Unknown/chapter1.ipynb @@ -0,0 +1,423 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1: Tension Comprssion and Shear" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.1, page no. 9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "Find compressive stress and strain in the post\n", + "\"\"\"\n", + "\n", + "import math\n", + "\n", + "#initialisation\n", + "\n", + "d_1 = 4 # inner diameter (inch)\n", + "d_2 = 4.5 #outer diameter (inch)\n", + "P = 26000 # pressure in pound\n", + "L = 16 # Length of cylinder (inch)\n", + "my_del = 0.012 # shortening of post (inch)\n", + "\n", + "#calculation\n", + "A = (math.pi/4)*((d_2**2)-(d_1**2)) #Area (inch^2)\n", + "s = P/A # stress\n", + "\n", + "print \"compressive stress in the post is \", round(s), \"psi\"\n", + "\n", + "e = my_del/L # strain\n", + "\n", + "print \"compressive strain in the post is %e\" %e" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "compressive stress in the post is 7789.0 psi\n", + "compressive strain in the post is 7.500000e-04\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.2, page no. 10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "formula for maximum stress & calculating maximum stress\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "W = 1500 # weight (Newton)\n", + "d = 0.008 #diameter(meter) \n", + "g = 77000 # Weight density of steel\n", + "L = 40 # Length of bar (m)\n", + "\n", + "#calculation\n", + "\n", + "A = (math.pi/4)*(d**2) # Area\n", + "s_max = (1500/A) + (g*L) # maximum stress\n", + "\n", + "#result\n", + "print \"Therefore the maximum stress in the rod is \", round(s_max,1), \"Pa\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Therefore the maximum stress in the rod is 32921551.8 Pa\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.3. page no. 26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculating change in lenght of pipe, strain in pipe, increase in diameter & increase in wall thickness\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "d1 = 4.5 # diameter in inch\n", + "d2 = 6 # diameter in inch\n", + "A = (math.pi/4)*((d2**2)-(d1**2)) # Area\n", + "P = 140 # pressure in K\n", + "s = -P/A # stress (compression)\n", + "E = 30000 # young's modulus in Ksi\n", + "e = s/E # strain\n", + "\n", + "#calculation\n", + "\n", + "# Part (a)\n", + "my_del = e*4*12 # del = e*L \n", + "print \"Change in length of the pipe is\", round(my_del,3), \"inch\"\n", + "\n", + "# Part (b)\n", + "v = 0.30 # Poissio's ratio\n", + "e_ = -(v*e)\n", + "print \"Lateral strain in the pipe is %e\" %e_\n", + "\n", + "# Part (c)\n", + "del_d2 = e_*d2 \n", + "del_d1 = e_*d1\n", + "print \"Increase in the inner diameter is \", round(del_d1,6), \"inch\"\n", + "\n", + "# Part (d)\n", + "t = 0.75\n", + "del_t = e_*t\n", + "print \"Increase in the wall thicness is %f\" %del_t, \"inch\"\n", + "del_t1 = (del_d2-del_d1)/2 \n", + "print \"del_t1 = del_t\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Change in length of the pipe is -0.018 inch\n", + "Lateral strain in the pipe is 1.131768e-04\n", + "Increase in the inner diameter is 0.000509 inch\n", + "Increase in the wall thicness is 0.000085 inch\n", + "del_t1 = del_t\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.4, page no. 35" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculate average shear stress and compressive stress\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "d = 0.02 # diameter in m\n", + "t = 0.008 # thickness in m\n", + "A = math.pi*d*t # shear area\n", + "P = 110000 # prassure in Newton\n", + "\n", + "#calculation\n", + "A1 = (math.pi/4)*(d**2) # Punch area\n", + "t_aver = P/A # Average shear stress \n", + "\n", + "\n", + "print \"Average shear stress in the plate is \", t_aver, \"Pa\"\n", + "s_c = P/A1 # compressive stress\n", + "print \"Average compressive stress in the plate is \", s_c, \"Pa\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average shear stress in the plate is 218838046.751 Pa\n", + "Average compressive stress in the plate is 350140874.802 Pa\n" + ] + } + ], + "prompt_number": 37 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Eample 1.5, page no. 36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculate bearing stress, shear stress in pin,\n", + "bearing stress between pin and gussets,\n", + "shear stress in anchor bolts\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "\n", + "P = 12.0 # Pressure in K\n", + "t = 0.375 # thickness of wall in inch\n", + "theta = 40.0 # angle in degree\n", + "d_pin = 0.75 # diameter of pin in inch\n", + "t_G = 0.625 # thickness of gusset in inch\n", + "t_B = 0.375 #thickness of base plate in inch\n", + "d_b = 0.50 # diameter of bolt in inch\n", + "\n", + "#calculation\n", + "\n", + "#Part (a)\n", + "s_b1 = P/(2*t*d_pin) # bearing stress\n", + "print \"Bearing stress between strut and pin\", round(s_b1,1), \"ksi\"\n", + "\n", + "#Part (b)\n", + "t_pin = (4*P)/(2*math.pi*(d_pin**2)) # average shear stress in the \n", + "print \"Shear stress in pin is \", round(t_pin,1), \"ksi\"\n", + "\n", + "# Part (c)\n", + "s_b2 = P/(2*t_G*d_pin) # bearing stress between pin and gusset\n", + "print \"Bearing stress between pin and gussets is\", s_b2, \"ksi\"\n", + "\n", + "# Part (d)\n", + "s_b3 = (P*math.cos(math.radians(40))/(4*t_B*d_b)) # bearing stress between anchor bolt and base plate\n", + "print \"Bearing stress between anchor bolts & base plate\", round(s_b3,1), \"ksi\"\n", + "\n", + "# Part (e)\n", + "t_bolt = (4*math.cos(math.radians(40))*P)/(4*math.pi*(d_b**2)) # shear stress in anchor bolt\n", + "print \"Shear stress in anchor bolts is\", round(t_bolt,1), \"ksi\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Bearing stress between strut and pin 21.3 ksi\n", + "Shear stress in pin is 13.6 ksi\n", + "Bearing stress between pin and gussets is 12.8 ksi\n", + "Bearing stress between anchor bolts & base plate 12.3 ksi\n", + "Shear stress in anchor bolts is 11.7 ksi\n" + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.7, page no. 42" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "determine stress at various parts\n", + "\"\"\"\n", + "\n", + "import math\n", + "\n", + "#initialisation\n", + "b1 = 1.5 # width of recmath.tangular crosssection in inch\n", + "t = 0.5 # thickness of recmath.tangular crosssection in inch\n", + "b2 = 3.0 # width of enlarged recmath.tangular crosssection in inch\n", + "d = 1.0 # diameter in inch\n", + "\n", + "#calculation\n", + "\n", + "# Part (a)\n", + "s_1 = 16000 # maximum allowable tensile stress in Psi\n", + "P_1 = s_1*t*b1 \n", + "print \"The allowable load P1 is\", P_1, \"lb\"\n", + "\n", + "# Part (b)\n", + "s_2 = 11000 # maximum allowable tensile stress in Psi\n", + "P_2 = s_2*t*(b2-d) \n", + "print \"allowable load P2 at this section is\", P_2, \"lb\"\n", + "\n", + "#Part (c)\n", + "s_3 = 26000 # maximum allowable tensile stress in Psi\n", + "P_3 = s_3*t*d \n", + "print \"The allowable load based upon bearing between the hanger and the bolt is\", P_3, \"lb\"\n", + "\n", + "# Part (d)\n", + "s_4 = 6500 # maximum allowable tensile stress in Psi\n", + "P_4 = (math.pi/4)*(d**2)*2*s_4 \n", + "print \"the allowable load P4 based upon shear in the bolt is\", round(P_4), \"lb\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The allowable load P1 is 12000.0 lb\n", + "allowable load P2 at this section is 11000.0 lb\n", + "The allowable load based upon bearing between the hanger and the bolt is 13000.0 lb\n", + "the allowable load P4 based upon shear in the bolt is 10210.0 lb\n" + ] + } + ], + "prompt_number": 42 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.8, page no. 46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculating the cross sectional area \n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "R_ah = (2700*0.8 + 2700*2.6)/2 # Horizontal component at A in N\n", + "R_ch = R_ah # Horizontal component at C in N\n", + "R_cv = (2700*2.2 + 2700*0.4)/3 # vertical component at C in N\n", + "R_av = 2700 + 2700 - R_cv # vertical component at A in N\n", + "R_a = math.sqrt((R_ah**2)+(R_av**2))\n", + "R_c = math.sqrt((R_ch**2)+(R_cv**2))\n", + "Fab = R_a # Tensile force in bar AB\n", + "Vc = R_c # Shear force acting on the pin at C\n", + "s_allow = 125000000 # allowable stress in tension \n", + "t_allow = 45000000 # allowable stress in shear\n", + "\n", + "#calculation\n", + "Aab = Fab / s_allow # required area of bar \n", + "Apin = Vc / (2*t_allow) # required area of pin\n", + "\n", + "\n", + "print \"Required area of bar is %f\" %Apin, \"m^2\"\n", + "d = math.sqrt((4*Apin)/math.pi) # diameter in meter\n", + "print \"Required diameter of pin is %f\" %d, \"m\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Required area of bar is 0.000057 m^2\n", + "Required diameter of pin is 0.008537 m\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Meachanics-DEMO_by_Unknown/chapter2.ipynb b/Meachanics-DEMO_by_Unknown/chapter2.ipynb new file mode 100755 index 00000000..c4e1ad0f --- /dev/null +++ b/Meachanics-DEMO_by_Unknown/chapter2.ipynb @@ -0,0 +1,501 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 2: Axially Loaded Members" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.1, page no. 72" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculating the number of revolutions for the nut\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "\n", + "W = 2.0 #lb\n", + "b = 10.5 #inch\n", + "c = 6.4 #inch\n", + "k = 4.2 #inch\n", + "p = 1.0/16.0 #inch\n", + "\n", + "#calculation\n", + "\n", + "n = (W*b)/(c*k*p) #inch\n", + "\n", + "#result\n", + "\n", + "print \" No. of revolution required = \", n, \"revolutions\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " No. of revolution required = 12.5 revolutions\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.2, page no. 74" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "finding maximum allowable load\n", + "\"\"\"\n", + "\n", + "import math \n", + "import numpy\n", + "\n", + "#initialisation\n", + "\n", + "Fce_ = 2.0 #dummy variable\n", + "Fbd_ = 3.0 #dummy variable \n", + "Lbd = 480.0 #mm\n", + "Lce = 600.0 #mm\n", + "E = 205e6 #205Gpa\n", + "Abd = 1020.0 #mm\n", + "Ace = 520.0 #mm\n", + "\n", + "#calculation\n", + "Dbd_ = (Fbd_*Lbd)/(E*Abd) #dummy variable\n", + "Dce_ = (Fce_*Lce)/(E*Ace) #dummy variable\n", + "Da = 1 #limiting value\n", + "P = ((((450+225)/225)*(Dbd_ + Dce_) - Dce_ )**(-1)) * Da \n", + "Fce = 2*P # Real value in newton\n", + "Fbd = 3*P #real value in newton\n", + "Dbd = (Fbd*Lbd)/(E*Abd) #print lacement in mm\n", + "Dce = (Fce*Lce)/(E*Ace) # print lacement in mm\n", + "a = numpy.degrees(numpy.arctan(((Da+Dce)/675))) #alpha in degree\n", + "\n", + "#result\n", + "print \"alpha = \", round(a,2), \"degree\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "alpha = 0.11 degree\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.3, page no. 80" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculation if vertical displacement\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "P1 = 2100.0 #lb\n", + "P2 = 5600.0 #lb\n", + "b = 25.0 #inch\n", + "a = 28.0 #inch\n", + "A1 = 0.25 #inch^2\n", + "A2 = 0.15 #inch^2\n", + "L1 = 20.0 #inch\n", + "L2 = 34.8 #inch\n", + "E = 29e6 #29Gpa\n", + "\n", + "#Calculations\n", + "P3 = (P2*b)/a \n", + "Ra = P3-P1\n", + "N1 = -Ra \n", + "N2 = P1 \n", + "D = ((N1*L1)/(E*A1)) + ((N2*L2)/(E*A2)) #print lacement\n", + "\n", + "#Result\n", + "print \"Downward print lacement is = \", D, \"inch\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Downward print lacement is = 0.0088 inch\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.6, page no. 90" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "obtaing formula and calculating allowable load\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#Numerical calculation of allowable load\n", + "\n", + "d1 = 4.0 #mm\n", + "d2 = 3.0 #mm\n", + "A1 = (math.pi*(d1**2))/4 #area\n", + "A2 = (math.pi*(d2**2))/4 #area\n", + "L1 = 0.4 #meter\n", + "L2 = 0.3 #meter\n", + "E1 = 72e9 #Gpa\n", + "E2 = 45e9 #Gpa\n", + "f1 = L1/(E1*A1) * 1e6 # To cpmpensate for the mm**2\n", + "f2 = L2/(E2*A2) * 1e6 \n", + "s1 = 200e6 #stress\n", + "s2 = 175e6 #stress\n", + "\n", + "#Calculations\n", + "P1 = ( (s1*A1*(4*f1 + f2))/(3*f2) ) * 1e-6 # To cpmpensate for the mm**2\n", + "P2 = ( (s2*A2*(4*f1 + f2))/(6*f1) ) * 1e-6 \n", + "\n", + "#Result\n", + "print \"Newton Minimum allowable stress aomong the two P1 and P2 is smaller one, therefore MAS = \", P2" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Newton Minimum allowable stress aomong the two P1 and P2 is smaller one, therefore MAS = 1264.49104307\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.10, page no. 113" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "calculate stress acting on inclined section &\n", + "the complete state of stress\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "P = 90000.0 #newton\n", + "A = 1200e-6 # meter^2\n", + "s_x = -P/A #stress\n", + "t_1 = 25.0 #for the stresses on ab and cd plane\n", + "\n", + "#Calculations\n", + "s_1 = s_x*(math.cos(math.radians(t_1))**2)\n", + "T_1 = -s_x*math.cos(math.radians(t_1))*math.sin(math.radians(t_1))\n", + "t_2 = -65.0 #for the stresses on ad and bc plane\n", + "s_2 = s_x*(math.cos(math.radians(t_2))**2)\n", + "T_2 = -s_x*math.cos(math.radians(t_2))*math.sin(math.radians(t_2))\n", + "\n", + "#Result\n", + "print \"The normal and shear stresses on the plane ab and cd are\", round((T_1/1E+6),2), round((s_1/1E+6),2), \"MPa respecively\" \n", + "print \"respecively The normal and shear stresses on the plane ad and bc are\", round((T_2/1E+6),2), round((s_2/1E+6),2), \"MPa respecively\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The normal and shear stresses on the plane ab and cd are 28.73 -61.6 MPa respecively\n", + "respecively The normal and shear stresses on the plane ad and bc are -28.73 -13.4 MPa respecively\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.11, page no. 114" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "Calculate the vertical displacement of the joint\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "# Value of s_x based on allowable stresses on glued joint\n", + "\n", + "#initialisation\n", + "s_t = -750.0 #psi\n", + "t = -50.0 #degree\n", + "T_t = -500.0 #psi\n", + "\n", + "sg_x_1 = s_t/(math.cos(math.radians(t))**2)\n", + "sg_x_2 = -T_t/(math.cos(math.radians(t))*math.sin(math.radians(t)))\n", + "\n", + "# Value of s_x based on allowable stresses on plastic\n", + "\n", + "sp_x_1 = -1100.0 #psi\n", + "T_t_p = 600.0 #psi\n", + "t_p = 45.0 #degree\n", + "sp_x_2 = -T_t_p/(math.cos(math.radians(t_p))*math.sin(math.radians(t_p)))\n", + "\n", + "# Minimum width of bar\n", + "\n", + "P = 8000.0 #lb\n", + "A = P/sg_x_2\n", + "b_min = math.sqrt(abs(A)) #inch\n", + "print \"The minimum width of the bar is\", round(b_min,2), \"inch\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The minimum width of the bar is 2.81 inch\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.15, page no. 126" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "Comparison of energy-absorbing capacity with different type of bolts\n", + "\"\"\"\n", + "\n", + "import math \n", + "#Bolt with reduced shank diameter\n", + "\n", + "#initialisation\n", + "g = 1.50 # inch\n", + "d = 0.5 #inch\n", + "t = 0.25 #inch\n", + "d_r = 0.406 #inch\n", + "L = 13.5 #inch\n", + "\n", + "#calculation\n", + "ratio = ((g*(d**2))/(((g-t)*(d_r**2))+(t*(d**2)))) #U2/U1\n", + "\n", + "print \"The energy absorbing capacity of the bolts with reduced shank diameter\", round(ratio,2)\n", + "ratio_1 = ( (((L-t)*(d_r**2))+(t*(d**2))) / ((2*(g-t)*(d_r**2))+2*(t*(d**2))) ) #U3/2U1\n", + "print \"The energy absorbing capacity of the long bolts\", round(ratio_1,2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The energy absorbing capacity of the bolts with reduced shank diameter 1.4\n", + "The energy absorbing capacity of the long bolts 4.18\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + " Example 2.16, page no. 133" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "Determine the maximum elongation and tensile stress\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "#initialisation\n", + "# Maximum elongation\n", + "M = 20 #kg\n", + "g = 9.81 #m/s^2\n", + "L = 2 #meter\n", + "E = 210e9 #210Gpa\n", + "h = 0.15 #meter\n", + "diameter = 0.015 #milimeter\n", + "\n", + "#Calculations & Result\n", + "A = (math.pi/4)*(diameter**2) #area\n", + "D_st = ((M*g*L)/(E*A)) \n", + "D_max = D_st*(1+(1+(2*h/D_st))**0.5) \n", + "D_max_1 = math.sqrt(2*h*D_st) # another approach to find D_max\n", + "i = D_max / D_st # Impact factor\n", + "print \"Maximum elongation is\",round((D_max/1E-3),2), \"mm\" # Maximum tensile stress\n", + "s_max = (E*D_max)/L #Maximum tensile stress\n", + "s_st = (M*g)/A #static stress\n", + "i_1 = s_max / s_st #Impact factor \n", + "print \"Maximum tensile stress is \", round((s_max/1E+6),2), \"MPa\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Maximum elongation is 1.79 mm\n", + "Maximum tensile stress is 188.13 MPa\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.18, page no. 148" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "determine displacement at the lower end of bar in various conditions\n", + "\"\"\"\n", + "\n", + "import math \n", + "\n", + "\n", + "#initialisation\n", + "P1 = 108000.0 #Newton\n", + "P2 = 27000.0 #Newton\n", + "L = 2.2 #meter\n", + "A = 480.0 #mm^2\n", + "\n", + "\n", + "#calculations\n", + "\n", + "# Displacement due to load P1 acting alone\n", + "s = (P1/A) #stress in MPa\n", + "e = (s/70000) + (1/628.2)*((s/260)**10) #strain\n", + "D_b = e*L*1e3 #elongation in mm\n", + "print \"elongation when only P1 load acting is = \", round(D_b,2), \" mm\"\n", + "\n", + "# Displacement due to load P2 acting alone\n", + "s_1 = (P2/A) #stress in MPa\n", + "e_1 = (s_1/70000) + (1/628.2)*((s_1/260)**10) #strain\n", + "D_b_1 = e_1*(L/2)*1e3 #elongation in mm (no elongation in lower half)\n", + "print \"elongation when only P2 load acting is = \", round(D_b_1,2), \" mm\"\n", + "\n", + "# Displacement due to both load acting simonmath.taneously\n", + "#upper half\n", + "s_2 = (P1/A) #stress in MPa\n", + "e_2 = (s_2/70000) + (1/628.2)*((s_2/260)**10) #strain\n", + "\n", + "#lower half\n", + "s_3 = (P1+P2)/A #stress in MPa\n", + "e_3 = (s_3/70000) + (1/628.2)*((s_3/260)**10) #strain\n", + "D_b_2 = ((e_2*L)/2 + (e_3*L)/2) * 1e3 # elongation in mm\n", + "print \"elongation when P1 and P2 both loads are acting is = \", round(D_b_2,2), \" mm\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "elongation when only P1 load acting is = 7.9 mm\n", + "elongation when only P2 load acting is = 0.88 mm\n", + "elongation when P1 and P2 both loads are acting is = 12.21 mm\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Non_Conventional_Energy_Resources/README.txt b/Non_Conventional_Energy_Resources/README.txt new file mode 100755 index 00000000..95f3b0d4 --- /dev/null +++ b/Non_Conventional_Energy_Resources/README.txt @@ -0,0 +1,10 @@ +Contributed By: Ashish Vimal +Course: btech +College/Institute/Organization: Abes Engineering college, Ghaziabad +Department/Designation: Mechanical +Book Title: Non Conventional Energy Resources +Author: B.H.Khan +Publisher: TMH. +Year of publication: 2009 +Isbn: 9780070142763 +Edition: 2nd Edition \ No newline at end of file diff --git a/Propagation_Engineering_in_Wireless_Communications/screenshots/Channels_separation.png b/Propagation_Engineering_in_Wireless_Communications/screenshots/Channels_separation.png new file mode 100755 index 00000000..c1dd1b04 Binary files /dev/null and b/Propagation_Engineering_in_Wireless_Communications/screenshots/Channels_separation.png differ diff --git a/Propagation_Engineering_in_Wireless_Communications/screenshots/Difraction_loss.png b/Propagation_Engineering_in_Wireless_Communications/screenshots/Difraction_loss.png new file mode 100755 index 00000000..a373010b Binary files /dev/null and b/Propagation_Engineering_in_Wireless_Communications/screenshots/Difraction_loss.png differ diff --git a/Propagation_Engineering_in_Wireless_Communications/screenshots/Path_gain.png b/Propagation_Engineering_in_Wireless_Communications/screenshots/Path_gain.png new file mode 100755 index 00000000..eed3802a Binary files /dev/null and b/Propagation_Engineering_in_Wireless_Communications/screenshots/Path_gain.png differ diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1.ipynb new file mode 100755 index 00000000..d6586880 --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1.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.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2.ipynb new file mode 100755 index 00000000..78101446 --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2.ipynb @@ -0,0 +1,436 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:f6b25265ec5908e2fd1cca31e32c84564874aefa67eae115ae60252b952f2e2d" + }, + "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": [] + }, + { + "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.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3.ipynb new file mode 100755 index 00000000..ce1dfb31 --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3.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": "iVBORw0KGgoAAAANSUhEUgAAAaIAAAEfCAYAAAADX8LEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X2UXFWZ7/HvL9CQaCKNoIAQpkURCQE6ASPBhDQqISAC\nKgo66nTgCiLgMMIoL96bMA6QGUSigAx6B1p5UyGXLAIkECAVo5Ko0IGEhgwIuRIFHEwIyRCGkDzz\nR53uFJV+qUqf7lMvv89atVL7nF1VTz3rpJ4+e+86pYjAzMwsK0OyDsDMzOqbC5GZmWXKhcjMzDLl\nQmRmZplyITIzs0y5EJmZWaZciMy2gaTNkvYZhNf5W0n3DfTrmGXJhcjqhqSVkl6TtE7Si5JulPT2\nEh6Xk3TaYMRYLCJuiYijt+WxkqZL2pi8387b+WnHaNZfLkRWTwI4LiJGAGOBQ4Fvl/i4ahTAbREx\nouD23ayDMivmQmR1KSL+DMwDRktqlHS3pL9IWi1pjqQ9ASRdCkwErknOKH5Q8DRHSfoPSWskXdPT\na0kaJuknyXN3SPqmpOcL9l8g6RlJr0p6QtKJBftaJS0qaG+WdEYprwsouZlVNBciqzcCkDQSOAZ4\nlPz/g38H9k5uG4BrACLiYmARcFZyRvH1guf6BPmzqoOAz0nqaQhtWvK87wWOAr7IW8+yngEmRMQ7\ngEuAmyXt1st7KPV1zaqCC5HVEwGzJa0hX1xywGURsToi7oyI1yNiPXAZMKmbxxabERGvRsTzwAKg\nuYfX/WzyOmsj4k/A9wufLyLuiIgXk/u/AJ4GPtzL+yj1dSFfqNYkt9WSdu+lr1kmts86ALNBFMAJ\nEfFQ4UZJbwOuAo4Gdk42D5ek2HJV4O7miV4suP8aMLyH130P8HxBe1XR638Z+AegqfO1gV16eR+l\nvi7AzyPiy73sN8ucz4jM4DzgA8C4iNiJ/NlQ4fxKfxcrvACMLGh33Zf0N8CPgLOAd0bEzsBy0pnb\niZSex2xAuRCZ5c8oNgBrJb2T/JxOoZeA9/XxHL194P8CuDBZFLEncDZbitvbk/svA0MkTQVGlxF7\nb6/rImRVwYXIDGYCw8gXg98Ac3nrWdD3gZOSOZaZPTxH0POZ0z+RH457DrgfuB14AyAiOoArgYfJ\nD7mNBn7Vy/MWv0Zvr9vbPrOKoWr7YTxJK4FXgU3AxogYl21EZuWRdCbwuYg4MutYzCpBNS5WCKAl\nIlZnHYhZKZKVau8jf9azL/AN4OpMgzKrINVYiMBj31ZddgD+jfz3iF4BbgN+mGlEZhWkGofmngXW\nkh+auz4ifpxxSGZm1g/VeEb0kYh4QdK7gPmSnoqIRX0+yszMKlLVFaKIeCH59z8l3QmMI/8teSRV\n1+mdmVmFiIjMpjyqavm2pLdJGpHcfzswGVhW2CcifEvpNm3atMxjqKWb8+l8Vuota9V2RrQbcKck\nyMd+S0Tcn21ItWvlypVZh1BTnM90OZ+1o6oKUUQ8R+8XeDQzsypTVUNzNrhaW1uzDqGmOJ/pcj5r\nR9Ut3+7NWy+WbGZmpZBEeLGCVaJcLpd1CDXF+UyX81k7aroQTZ8+nSuvvBKAxYsXc/rpp2/Vp6Wl\nhUcffRSAyy67bFDjMzOzGi9EkkhW2DF37lyOOeaYbvt0uvzyywcttmrQ0tKSdQg1xflMl/NZO2qu\nEF166aXst99+TJw4kRUrVnRtf+ihh/j4xz/Ohg0bOOWUUxg1ahSf/vSn2bBhAxHBBRdcwIYNGxgz\nZgxf+tKXMnwHZmb1peYK0c9//nMee+wx7r33Xn73u98B8PLLL9PQ0MCIESO47rrrGD58OB0dHVxy\nySU88sgjSGLGjBkMGzaM9vZ2brrppozfRWXwGHy6nM90OZ+1o+YK0ac//WmGDh3KiBEjOP7444kI\n5s+fz9FHHw3AokWL+OIXvwjAgQceyEEHHZRluGZmda/mClF3y7fnzp3LlClTeu1jW/MYfLqcz3Q5\nn7Wj5grR7Nmzef3111m3bh1z5swhInj88cc5+OCDATjiiCO49dZbAVi+fDmPP/5412MbGhp48803\nM4nbzKxe1VwhOvnkkzn44IM59thjGTduHJIYO3Zs1/4zzzyT9evXM2rUKKZNm8ahhx7ate/000/n\noIMO6vdihVNPPZXddtuNAw88sNv9Tz31FOPHj2fo0KFdy8u7U7j8HAZ/CbrH4NPlfKbL+awdNVeI\nLrroIlasWMGiRYu4+eabef31198yLDd06FBuu+02Ojo6mDVrFg8//HBXoZoxYwYdHR39XqwwdepU\n5s2b1+P+XXbZhauvvprzzz+/1+cpXFoOXoJuZrWp5gpRsYsvvpjPfe5zg/qaEydOZOedd+5x/7ve\n9S4OPfRQGhoattrX0/JzGPwl6B6DT5fzmS7ns3ZU1dW3a90jjzzStfx848aNjB07tmvosHAJ+ve+\n972uJejLli1j7NixXUvQr732Wtrb2zN+J2Zmpav5M6JqsmjRom6XnwPcf//9g74E3WPw6XI+0+V8\n1g4XogqSXAG3qx0RXfM/8+bN8xJ0M6tJVVWIJE2R9JSkpyV9q7s+o5sb+OTxU7rbVXGKi8kRRxzx\nluXnd999d1e/LJageww+Xe973/s48sgjOeCAAxg9ejQ/+MEPtuqzcuXKrVZbHnrooWzcuPEt29ra\n2jjnnHOA/FcWnnzyyYELvEL5+KwdVVOIJG0HXANMAUYBn5e0f3G/a2a+yX/99/2ZFqPPf/7zHH74\n4axYsYKRI0dyww03cP3113P99dcD8OKLLzJy5Eiuuuoq/vmf/5m9996b9evXM2bMmK2Wn0N+7mjM\nmDFdzz8YS9AtfQ0NDVx11VU88cQTLF68mGuvvbbPAvLcc8+x5557druwpdPs2bPp6OhIO1yzQVM1\nP4wnaTwwLSKmJO0LACJiRkGfWLAgf//scxtYvvSNDCJN36WXXsq+++476Kv/crmc/+pMUXE+Tzzx\nRM455xwaGxs59dRTkcTkyZOZO3cuy5YtA+C6665DEl/96le58cYbmTFjBo2NjRx88MHsuOOOfOEL\nX+C4445jp512YqeddmLWrFnss88+Gb3DweXjMz3+YbzS7Qk8X9BelWzr1tBh1VFgS5HFEnQbWCtX\nrqS9vZ1x48YxdepUrr32WpYuXbpVv/vuu48pU6bwwgsvMH36dH7zm9/wq1/9io6ODiQxfvx4jj/+\neL773e/S3t5eN0XIaks1FaKSKsuMGdDWBn98bjMzZ858y8qaXC7ndhntzm2VEk+1tzu3rV+/npNO\nOomvfOUrLFy4kLVr1zJhwgRyuRwf/OAHu/rOnz+fJ598kqamJpYsWcL+++/PsmXLaGho4OSTT2bV\nqlVdzx8Rmb+/rPJZKfFUUzuXy9Ha2kprayvTp08ncxFRFTfgMGBeQftC4FtFfWLBAuLIo4jjPnl0\nmFWaN954IyZPnhxXXXVVRESsWbMm9t577679jz32WIwePToiIh544IE499xzIyJi9uzZ8eUvf7mr\n3/e///04++yzIyKitbU1Zs2aNVhvwWpQvhRk9/leTWdEvwf2ldQkaQfgZOCu4k5nn9vA24cezZy7\ner7EjpWm+K9P658FCxZw2mmnMWrUKM4991wAGhsbaWxs5Ne//jUAt9xyS1f/efPmdV3Sady4cSxc\nuJDVq1ezceNGbr/99q6l/SNGjODVV18d5HeTPR+ftaNqClFEvAmcDdwHdAA/j4itlhwtX/qGi5BV\npOXLl3PzzTezYMECxowZw5gxY5g7dy433ngjZ511VtfKyM4Cs3DhQiZNmgTAHnvswfTp0xk/fjwT\nJkzggAMO6HreU045hSuuuIJDDjmEZ599dvDfmFk/Vc2quVJIilp6P1a/Vq1axRlnnME999yTdShW\nB7JeNedCZGZW57IuRFUzNGeDz2Pw6XI+0+V81g4XosRxR01ilwax6/ZilwZx3FGTsg7JzKwueGiO\nfBFa+MAvWV+wbTgw6eNHcPf8hanFZ2ZWibIemnMhAnZpEKu7uU7oLtvDyxtrJz9mZt3JuhB5aA5Q\nT7WmzmuQx+DT5Xymy/msHS5EQI9/B2T294GZWf3w0ByeIzKz+pb10JwLUeK4oyaxOPfL/HCc4LAW\nFyEzqw9ZFyIPzSXunr+QlzcGL78ZvLwxXITwGHzanM90OZ+1w4XIzMwy5aE5M7M656E5MzOray5E\n1iOPwafL+UyX81k7XIjMzCxTniMyM6tzniMqkaTpklZJak9uU7KOyawUH5v8GYaMOJIhIz7JkBFH\n8rHJn8k6JLOKUjWFiPxXTb8XEWOSm38PfIB5DL7/Pjb5Mzy0aASxfgGx/jxi/QIeWjTCxSgFPj5r\nRzUVIvDV36zKLHh4Nbze9taNr7eRe3h1JvGYVaJqK0TnSHpM0r9Lasw6mFrX0tKSdQg1YHjB/Zau\ne/GW7bYtfHzWju2zDqCQpPnA7t3suhi4DvinpP0d4ErgtOKOra2tNDU1AdDY2Ehzc3PXAdt5Ku+2\n24PVjjefZ4tc8m8LYn1FxOd2fbZzuRxtbW0AXZ+XWarKVXOSmoA5EXFg0XavmktRLpfrOoht23TO\nEeWH53JACwz9Oz46cT0P3j8r09iqnY/P9HjVXIkk7VHQ/BSwLKtYzEr14P2z+OjEdQwZfiQMvZAh\nw490ETIrUjVnRJJ+CjSTXz33HHBGRLxU1MdnRGZmZcr6jKhqClEpXIjMzMqXdSGqmqE5G3ydk5uW\nDuczXc5n7XAhMjOzTHlozsysznlozszM6poLkfXIY/Dpcj7T5XzWDhciMzPLlOeIzMzqnOeIzMys\nrrkQWY88Bp8u5zNdzmftcCEyM7NMeY7IzKzOeY7IzMzqmguR9chj8OlyPtPlfNYOFyIzM8uU54jM\nzOqc54jMzKyuVVQhkvRZSU9I2iRpbNG+CyU9LekpSZOzirGeeAw+Xc5nupzP2rF91gEUWQZ8Cri+\ncKOkUcDJwChgT+ABSR+IiM2DH6KZmaWpIueIJC0AzouIR5P2hcDmiPiXpD0PmB4Ri4se5zkiM7My\neY6oNO8BVhW0V5E/MzIzsyo36ENzkuYDu3ez66KImFPGU3V76tPa2kpTUxMAjY2NNDc309LSAmwZ\nU3a7tPbMmTOdvxTbzme6bedz29u5XI62tjaArs/LLFXL0NwFABExI2nPA6ZFxJKix3loLkW5XK7r\nILb+cz7T5XymJ+uhuUouROdHxCNJexRwKzCOZLEC8P7iquNCZGZWvqwLUUXNEUn6lKTngcOAeyTN\nBYiIDuAXQAcwF/iaK46ZWW2oqEIUEXdGxMiIGBYRu0fEMQX7LouI90fEByPivizjrBedY8qWDucz\nXc5n7aioQmRmZvWnIueItpXniMzMyuc5IjMzq2vbVIgkDZW0Y9rBWGXxGHy6nM90OZ+1o6QvtEoa\nApwIfB44nHwBk6RNwMPALcBsj4uZmVm5SpojkvRLYBFwF7A0Iv472b4jMAY4HpgQEUcMYKx98hyR\nmVn5sp4jKrUQ7dhZfPrTZ6C5EJmZlS/rQlTSHFF3BUbSrpLUWx+rbh6DT5fzmS7ns3aUVIgkjZeU\nk/T/JI2VtBxYDvxF0jF9Pd7MzKwnpQ7NPQJcCOwE/BiYEhGLJX0Q+FlENA9smKXx0JyZWfmqYmgO\n2C4i7o+I24EXOn+QLiKeooefYzAzMytFqYWosNi8PhCBWOXxGHy6nM90OZ+1o9QfxjtI0rrk/rCC\n+wDDUo7JzMzqiK81Z2ZW56pljsjMzGxAlLp8+7yC2zeK7n8jrWAkfVbSE5I2SRpbsL1J0gZJ7cnt\nh2m9pvXMY/Dpcj7T5XzWjlLniEaQX7CwH/Ah8pf6EXAc8NsU41kGfAq4vpt9z0TEmBRfy8zMKkBZ\nc0SSFgHHRsS6pD0CuDciJqYalLQAOC8iHk3aTcCciDiwj8d5jsjMrEzVNkf0bmBjQXtjsm0wvDcZ\nlstJmjBIr2lmZgOs3EL0U+C3kqZLugRYAvyknCeQNF/Ssm5un+zlYX8GRiZDc98Abk3OxmwAeQw+\nXc5nupzP2lHqHBEAEXGppHnARPJzRq0R0V7mcxxVTv/kMW8AbyT3H5X0B2Bf4NHivq2trTQ1NQHQ\n2NhIc3MzLS0twJYD1+3S2kuXLq2oeKq97Xym23Y+t72dy+Voa2sD6Pq8zFKp15rrc/KllD4lB5Wf\nIzo/Ih5J2rsCayJik6R9gF8CoyPilaLHeY7IzKxM1TJHlJP0j5I+ULxD0n6SvgUs7G8wkj4l6Xng\nMOAeSXOTXZOAxyS1A7cDZxQXITMzq06lFqLJwF+BayW9IOk/JD0t6QXgGuAl4OP9DSYi7oyIkREx\nLCJ2j4hjku2zImJ0RIyJiEMi4p7+vpb1rfNU3tLhfKbL+awdJc0RJT96dwNwg6TtgF2TXS9HxKaB\nCs7MzGqfrzVnZlbnqmWOyMzMbEC4EFmPPAafLuczXc5n7XAhMjOzTJU8RyTp7cDfAqOB7YChwGZg\nPbAYuD0iNg9QnCXxHJGZWfmyniMq9Qut3wT+G9gcEVcX7RNwMPnl2w9ExNKBCLQULkRmZuXLuhD1\nOTQnaRhwEPCD4iIEEHlLI+K7gJdy1xCPwafL+UyX81k7+vweUURskJSLiJDUCBwNvAL8LiJWF/Vd\nNkBxmplZjSp1aO4rEfHj5L6AH5E/Q6qowuOhOTOz8mU9NFdqIfoL8GtgKfA4sE9EXJns+3BELBnQ\nKEvkQmRmVr6sC1Gpy7cvBf4FWAucBJwp6Y+SbgK+NVDBWbY8Bp8u5zNdzmftKPVac99P7i7u3Jb8\nNMM44OwBiMvMzOpEv681J+mwiFjcd8+B56E5M7PyVfzQnKQdk7OfbhUWIUl7pxWYmZnVhz4LUfIT\nEIdJ+kLynaKtSNpZ0unA36QdoGXHY/Dpcj7T5XzWjlLniO6WtAfwD5LeTf7yPg3kv8D6GrAK+HFE\nrO1PMJKuAI4D3gD+AEztfE5JFwKnJq/59Yi4vz+vZWZmlaGifo9I0lHAgxGxWdIMgIi4QNIo4Fbg\nQ8CewAPAB4qvbec5IjOz8lX8HFExSddL+p6kkyS9J81gImJ+QXFZAuyV3D8BuC0iNkbESuAZ8iv2\nzMysym3Lz0D8Bui8rtw3JT0s6UdpFyXyw3D3JvffQ374r9Mq8mdGNoA8Bp8u5zNdzmftKGmOqMhI\n4NWIuBO4U9JnyA+VnQ5c0deDJc0Hdu9m10URMSfpczHwRkTc2stTeQzOzKwGbEshugG4Jbnm3Apg\nU0TMkvR0KQ+OiKN62y+pFTgW+FjB5j+RL4Cd9kq2baW1tZWmpiYAGhsbaW5upqWlBdjyF5TbpbU7\nt1VKPNXe7txWKfFUe7tzW6XEU03tXC5HW1sbQNfnZZa2ebGCpL8BdgaWAbsCMyJiar+CkaYAVwKT\nIuLlgu2dixXGsWWxwvuLVyZ4sYKZWfmqcbHC/pKuBk4D/isiNkXES/0tQomrgeHAfEntkn4IEBEd\nwC+ADmAu8DVXnIHX+ReUpcP5TJfzWTu2ZWjuE8B15L+8eoGkOyJibhrBRMS+vey7DLgsjdcxM7PK\nUfbQnKS/i4if9NTOkofmzMzKl/XQ3LacEf1V0s+AW4A/Au9ONyQzM6snJc0RSfqOpE9I2jUi7gb+\nD3AYcCP5H8yzGuQx+HQ5n+lyPmtHqWdEw4C9gZOSa82tAX5L/reIJpD/kquZmVnZtmn5tqR3kL/u\n26HAHyLijrQD2xaeIzIzK1/VzBFJmgh8lPxVETYB/wksjoj7Big2MzOrA6XOEV1Evgi1A3cAdwFP\nAB/tvEq21R6PwafL+UyX81k7Sj0jWh4Rd3Wz/Q5JJ6UZkJmZ1ZeS5ogk/W9AwKPkfwhvE/B24CDg\nXRFx3kAGWSrPEZmZlS/rOaKSFytI+jhwOPnvDQ0BXgJ+BTxUKZ/+LkRmZuXLuhCVc625deTnhWZE\nxNci4pJk+6j0w7JK4DH4dDmf6XI+a0dJc0SSvgN8EHgW+IqkhyLiX4GF5M+Mdhm4EM3MrJaVOkd0\nXkRcWdBuAT4CXA68FBHvGrAIy+ChOTOz8lXL0Nzrkt4p6UxJb4uIHPBvwFlAw4BFZ2ZmNa/UQvQj\n4GhgN2AzQET8FbgGuHBgQrOseQw+Xc5nupzP2lHSHFFEbARu62Z7kP9tIjMzs22yzT8VPhAkXQEc\nB7wB/AGYGhFrJTUBTwJPJV0fjoivdfN4zxGZmZUp6zmiSitERwEPRsTmzksHRcQFSSGaExEH9vF4\nFyIzszJlXYjK+R7RgIuI+RGxOWkuAfbKMp565zH4dDmf6XI+a0dFFaIipwL3FrTfK6ldUk7ShKyC\nMjOzdG3LT4X3i6T55H9KothFETEn6XMx8EZE3Jrs+zMwMiLWSBoLzJZ0QESsK36S1tZWmpqaAGhs\nbKS5uZmWlhZgy19QbpfW7txWKfFUe7tzW6XEU+3tzm2VEk81tXO5HG1tbQBdn5dZqqg5IgBJrcBX\ngI9FxOs99FkAnBcRjxZt9xyRmVmZPEdUQNIU4B+BEwqLkKRdJW2X3N8H2Jf85YZsAHX+BWXpcD7T\n5XzWjkEfmuvD1cAOwHxJsGWZ9iTgEkkbyX+h9oyIeCW7MM3MLC0VNzTXHx6aMzMrn4fmzMysrrkQ\nWY88Bp8u5zNdzmftcCEyM7NMeY7IzKzOeY7IzMzqmguR9chj8OlyPtPlfNYOFyIzM8uU54jMzOqc\n54jMzKyuuRBZjzwGny7nM13OZ+1wITIzs0x5jsjMrM55jsjMzOqaC5H1yGPw6XI+0+V81g4XIjMz\ny5TniMzM6pzniApI+o6kxyQtlfSgpJEF+y6U9LSkpyRNzjJOMzNLT0UVIuBfI+LgiGgGZgPTACSN\nAk4GRgFTgB9KqrTYa47H4NPlfKbL+awdFfVhHhHrCprDgZeT+ycAt0XExohYCTwDjBvk8MzMbABU\n3ByRpEuBLwEbgHERsVbS1cDiiLgl6fN/gbkRMavosZ4jMjMrU9ZzRNsP9gtKmg/s3s2uiyJiTkRc\nDFws6QJgJjC1h6fqtuK0trbS1NQEQGNjI83NzbS0tABbTuXddtttt+u5ncvlaGtrA+j6vMxSxZ0R\ndZK0N3BvRIxOihIRMSPZNw+YFhFLih7jM6IU5XK5roPY+s/5TJfzmZ6sz4gqao5I0r4FzROA9uT+\nXcApknaQ9F5gX+C3gx2fmZmlr6LOiCTdAewHbAL+AJwZEX9J9l0EnAq8Cfx9RNzXzeN9RmRmVqas\nz4gqqhD1lwuRmVn5si5EFTU0Z5Wlc3LT0uF8psv5rB0uRGZmlikPzZmZ1TkPzZmZWV1zIbIeeQw+\nXc5nupzP2uFCZGZmmfIckZlZnfMckZmZ1TUXIuuRx+DT5Xymy/msHS5EZmaWKc8RmZnVOc8RmZlZ\nXXMhsh55DD5dzme6nM/a4UJkZmZIWiJpqaQOSZd3s79J0rKibb+X1FC0rVXS1cn9EyXt39druxBZ\nj/zrl+lyPtPlfKbuyIhoBg4CjpQ0obfOyY+U/ikiNvbS7URgVF8v7EJkZmZExGvJ3R2A7YDVkg6R\n9JikpcDXih4yBZgLIGmqpBWSlgCHJ9vGA58ErpDULmmfnl67ogqRpO90vmlJD0oamWxvkrQheTPt\nkn6Ydaz1wGPw6XI+0+V8pkvSkKTgvAQsiIgO4EbgrORMqdjRwDxJewDTyRegCeTPgCIiHgbuAs6P\niDER8WxPr11RhQj414g4OHnTs4FpBfueSd7MmIgorsxmZtYPEbE5+ezdCzhC0onAThHxq6TLTZ19\nJe0A7BURK4EPky9cf02G6X4OFC4F73NZeEUVoohYV9AcDrycVSzmMfi0OZ/pcj4HRkSsBe4B3l+0\nq7CgTAQWdT6E3gtPn1/urKhCBCDpUkl/BP4OmFGw673JsFyur0k0MzMrj6TG5N9hwFHAUuAVSR9J\nuvxtQfeu+SHgt8AkSe9MVtB9li3FZx3wjr5ee/v+h18eSfOB3bvZdVFEzImIi4GLJV0AXAVMBf4M\njIyINZLGArMlHVB0BgVAa2srTU1NADQ2NtLc3Nz1l1PnmLLbpbVnzpzp/KXYdj7TbTuf297O5XK0\ntbUBdH1eAg9JGkL+BOWmiHhA0lTgBkkB3M+WAjMJ+DZARLwgaTrwMPAK0M4WPwN+LOkc4LM9zRNV\n7CV+JO0N3BsRo7vZtwA4LyIeLdruS/ykKJfLdR3E1n/OZ7qcz/SUc4kfSXsB10fEJ1J7/Ur64Ja0\nb0Q8ndw/BxgXEV+StCuwJiI2JUsAfwmMjohXih7vQmRmVqasrzU36ENzfbhc0n7AJuAPwJnJ9iOA\nf5K0EdgMnFFchMzMrDpV1BlRf/mMKF0e+kiX85ku5zM9WZ8RVdyqOTMzqy8+IzIzq3M+IzIzs7rm\nQmQ96vzegaXD+UyX81k7XIjMzCxTniMyM6tzniMyM7O65kJkPfIYfLqcz3Q5n/03ecoJjBi5c9Zh\nuBCZmdWjyVNOYNGqB1j/v7K/SI3niMzM6tCIkTtvKULT8RyRmZkNsgq60qgLkfXIY/Dpcj7T5Xz2\n05tZB7CFC5GZWR0af8ARDL39bVmHAXiOyMysbk2ecgIPP7GI9avWZDpH5EJkZlbn/IXWbkg6T9Jm\nSe8s2HahpKclPSVpcpbx1QuPwafL+UyX81k7Kq4QSRoJHAX8/4Jto4CTgVHAFOCHkiou9lqzdOnS\nrEOoKc5nupzP2lGJH+bfA75ZtO0E4LaI2BgRK4FngHGDHVi9eeWV7L/oVkucz3Q5n7WjogqRpBOA\nVRHxeNGu9wCrCtqrgD0HLTAzMxswg/6VJknzgd272XUxcCFQOP/T2+SZVyUMsJUrV2YdQk1xPtPl\nfNaOilk1J2k08CDwWrJpL+BPwIeBqQARMSPpOw+YFhFLip6jMt6MmVmV8fLtbkh6DjgkIlYnixVu\nJT8vtCfwAPB+r9U2M6t+FXS1oa10FZmI6JD0C6CD/IUpvuYiZGZWGyr2jMjMzOpDRa2aK4WkGyS9\nJGlZL31+kHz59TFJYwYzvmrTVz4ltUhaK6k9uX17sGOsJpJGSlog6QlJyyV9vYd+Pkb7UEoufXyW\nTtJQSUvMHFLxAAADqElEQVQkLZXUIenyHvoN/rEZEVV1AyYCY4BlPew/Frg3uf9hYHHWMVfyrYR8\ntgB3ZR1ntdzIrwhtTu4PB1YA+xf18TGaXi59fJaX07cl/24PLAYmFO3P5NisujOiiFgErOmly/HA\nT5K+S4BGSbsNRmzVqIR8Qu/L6K1ARLwYEUuT++uBJ8l/D66Qj9ESlJhL8PFZsojoXJW8A7AdsLqo\nSybHZtUVohLsCTxf0F5Ffim4bZsADk9O0+9NVjBaCSQ1kT/bXFK0y8domXrJpY/PMkgaImkp8BKw\nICI6irpkcmxW8qq5/ij+C8krMrbdo8DIiHhN0jHAbOADGcdU8SQNB+4A/j75a36rLkVtH6M96COX\nPj7LEBGbgWZJOwH3SWqJiFxRt0E/NmvxjOhPwMiCducXY20bRMS6ztP5iJgLNBReFd22JqkBmAXc\nHBGzu+niY7REfeXSx+e2iYi1wD3AoUW7Mjk2a7EQ3QV8GUDSYcArEfFStiFVL0m7SVJyfxz5Jf/F\n48qWSHL170BHRMzsoZuP0RKUkksfn6WTtKukxuT+MPK/ctBe1C2TY7PqhuYk3QZMAnaV9DwwDWgA\niIjrI+JeScdKegb4L5LLA1n3+soncBJwpqQ3yV9+6ZSsYq0SHwG+CDwuqfM/+UXA3uBjtEx95hIf\nn+XYA/hJ8hM6Q4CbIuJBSWdAtsemv9BqZmaZqsWhOTMzqyIuRGZmlikXIjMzy5QLkZmZZcqFyMzM\nMuVCZGZmmXIhMjOzTLkQmZlZplyIzAaBpO0l7Zd1HGaVyIXILGWS9pW0TNIuBZtbgM0l9DOrOy5E\nZimLiKeBZyLirwWb90u2d9tP0v6SLhrUQM0qhAuRWcokvQ14tWjz5j76HcnWV0I2qwtVd/Vts0ol\n6Qvkr1z+fuB3BdvHFbUL+/1e0hTgNODfJO0eES8OauBmGfMZkVkKkoUIkyPiJ8B63vqT1odExO97\n6Lc4IuYBf46IH7sIWT1yITJLxxfJ/6gYwEHA0oJ9Q3rrJ2l3wAXI6pYLkVk6GoEVknYAhgOHQdcZ\n0Io++n0I+K2kDyXzRmZ1xYXILB0/BSYDJwDPAu9OtrcAuV767Qb8GdgTGB4Rrw1OuGaVw7/QajaA\nJJ0TEVdnHYdZJfMZkdkAkfQe4E9Zx2FW6VyIzAbOROC+rIMwq3QemjMzs0z5jMjMzDLlQmRmZply\nITIzs0y5EJmZWaZciMzMLFMuRGZmlikXIjMzy5QLkZmZZep/AGvYqv3AZr2FAAAAAElFTkSuQmCC\n", + "text": [ + "" + ] + }, + { + "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.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4.ipynb new file mode 100755 index 00000000..9666b1af --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4.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.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5.ipynb new file mode 100755 index 00000000..9a18598b --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5.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.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6.ipynb new file mode 100755 index 00000000..aa1b8e58 --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6.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.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7.ipynb new file mode 100755 index 00000000..87872c97 --- /dev/null +++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7.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/sample_notebooks/Jaya Sravya/Chapter10.ipynb b/sample_notebooks/Jaya Sravya/Chapter10.ipynb new file mode 100755 index 00000000..c2b2749b --- /dev/null +++ b/sample_notebooks/Jaya Sravya/Chapter10.ipynb @@ -0,0 +1,694 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:7afbb46d48c2bdf700c3dc220becf18da8796860629c8c3b8505b530a4a07b18" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter10:Rotational Mechanics" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#example 10.1\n", + "#calculation of the number of revolutions made\n", + "#given data\n", + "import math \n", + "wzero=100.*2.*math.pi/60.#initial angular velocity(in rad/s) of the motor\n", + "w=0#final angular velocity(in rad/s) of the motor\n", + "t=15.#time interval(in s)\n", + "\n", + "#calculation\n", + "alpha=(w-wzero)/t#equation of angular motion\n", + "theta=(wzero*t)+(alpha*t*t/2.)#equation of angular motion\n", + "\n", + "print '%s %.2f' %(\"the number of revolutions the motor makes before coming to rest is\",theta/(2*math.pi))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the number of revolutions the motor makes before coming to rest is 12.50\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1w - Pg 26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.1w\n", + "#calculation of the number of revolutions made by the wheel \n", + "\n", + "#given data\n", + "wzero=0#initial angular velocity(in rad/s) of the wheel \n", + "alpha=2.#angular acceleration(in rad/s**2)\n", + "t=10#time(in s) interval\n", + "\n", + "#calculation\n", + "theta=(wzero*t)+(alpha*t*t/2.)#equation of angular motion\n", + "n=round(theta/(2.*math.pi))#number of revolutions\n", + "\n", + "print '%s %.2f' %(\"the number of revolutions made by the wheel is\",n)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the number of revolutions made by the wheel is 16.00\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.2\n", + "#calculation of the time taken by the fan to attain half of the maximum speed\n", + "\n", + "#given data\n", + "wzero=0#initial angular velocity(in rad/s) of the fan\n", + "w=400.*(2.*math.pi/60.)#final angular velocity(in rad/s) of the fan\n", + "t=5#tiem(in s) taken\n", + "\n", + "#calculation\n", + "alpha=(w-wzero)/t#equation of angular motion\n", + "wdash=w/2.#half of maximum speed\n", + "t1=(wdash-wzero)/alpha#equation of angular motion\n", + "\n", + "print '%s %.2f %s' %(\"the time taken by the fan to attain half of the maximum speed is\",t1,\"s\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the time taken by the fan to attain half of the maximum speed is 2.50 s\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2w - Pg 27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.2w\n", + "#calculation of the angle rotated during the next second\n", + "\n", + "#given data\n", + "theta=2.5#angular displacement(in rad) of the wheel\n", + "t=1.#time(in s) required\n", + "\n", + "#calculation\n", + "alpha=(theta*2.)/(t*t)#equation of angular motion\n", + "theta1=(alpha*(t+1.)*(t+1.)/2.)#angle rotated during first two seconds\n", + "thetar=theta1-theta#angle rotated during next second\n", + "\n", + "print '%s %.2f %s' %(\"the angle rotated during the next second is\",thetar,\"rad\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the angle rotated during the next second is 7.50 rad\n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#example 10.3\n", + "#calculation of the angular velocity and angular acceleration of the pulley \n", + "\n", + "#given data\n", + "v=20.#linear speed(in cm/s) of the bucket\n", + "r=10.#radius(in cm) of the pulley\n", + "a=4.*10.**2.#linear acceleration(in cm/s**2) of the pulley\n", + "\n", + "#calculation\n", + "w=v/r#formula of angular velocity\n", + "alpha=a/r#formula of angular acceleration\n", + "\n", + "print '%s %.2f %s %s %.2f %s' %(\"the angular velocity of the pulley is\",w,\"rad/s\",\"and angular acceleration of the pulley is\",alpha,\"rad/s**2\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the angular velocity of the pulley is 2.00 rad/s and angular acceleration of the pulley is 40.00 rad/s**2\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3w - Pg 28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.3w\n", + "#calculation of the torque required to stop the wheel in one minute\n", + "\n", + "#given data\n", + "wzero=50.*(2.*math.pi/60.)#initial angular velocity(in rad/s) of the wheel\n", + "w=0#final angular velocity(in rad/s) of the wheel\n", + "t=60.#time(in s) taken to stop the wheel\n", + "I=2.#moment of inertia(in kg-m**2) of the wheel\n", + "\n", + "#calculation\n", + "alpha=(w-wzero)/t#equation of angular motion\n", + "tau=I*abs(alpha)#torque\n", + "\n", + "print '%s %.2f %s' %(\"the torque required to stop the wheel in one minute is\",tau,\"N-m\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the torque required to stop the wheel in one minute is 0.17 N-m\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4w - Pg 30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.4w\n", + "#calculation of the angular velocity of the wheel\n", + "\n", + "#given data\n", + "F=20.#force(in N) of pull applied\n", + "I=.2#moment of inertia(in kg-m**2)\n", + "r=20.*10.**-2.#radius(in m) of the wheel\n", + "t=5.#time(in s) interval\n", + "wzero=0#initial angular velocity(in rad/s) of the wheel \n", + "\n", + "#calculation\n", + "tau=F*r#torque applied to the wheel\n", + "alpha=tau/I#angular acceleration\n", + "w=wzero+(alpha*t)#equation of angular motion\n", + "\n", + "print '%s %.2f %s' %(\"the angular velocity of the wheel after 5 s is\",w,\"rad/s\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the angular velocity of the wheel after 5 s is 100.00 rad/s\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.5\n", + "#calculation of the moment of inertia of the wheel\n", + "\n", + "#given data\n", + "r=10.*10.**-2.#radius(in m) of the wheel\n", + "F=5.#force(in N) of pulling\n", + "aplha=2.#angular acceleration(in rad/s**2) of the wheel\n", + "\n", + "#calculation\n", + "tau=F*r#net torque\n", + "I=tau/aplha#moment of inertia\n", + "\n", + "print '%s %.2f %s' %(\"the moment of inertia of the wheel is\",I,\"kg-m**2\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the moment of inertia of the wheel is 0.25 kg-m**2\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7w - Pg 31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.7w\n", + "#calculation of the position of second kid on a balanced seesaw\n", + "\n", + "#given data\n", + "ma=10.#mass(in kg) of kid A\n", + "mb=15.#mass(in kg) of kid B\n", + "l=5.#length(in m) of the seesaw\n", + "la=(l/2.)#distance of A kid from fulcrum as he is sitting at an end\n", + "\n", + "#calculation\n", + "#taking torque about fulcrum...........(mb*g*x) = (ma*g*)\n", + "x=(ma*la)/mb\n", + "\n", + "print '%s %.2f %s' %(\"the second kid should sit at a distance of\",x,\"m from the centre\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the second kid should sit at a distance of 1.67 m from the centre\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8w - Pg 31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#example 10.8w\n", + "#calculation of the normal force and the frictional force that the floor exerts on the ladder\n", + "\n", + "#given data\n", + "m=10.#mass(in kg) of the ladder\n", + "theta=53.#angle(in degree) made by the ladder against the vertical wall\n", + "g=9.8#gravitational acceleration(in m/s**2) of the earth\n", + "\n", + "#calculation\n", + "#taking horizontal and vertical components\n", + "#N1 = f........................(1)\n", + "#N2 = W........................(2)\n", + "#taking torque about B\n", + "W=m*g\n", + "N2=W#from equation (2)\n", + "f=(W*math.sin(theta)*57.3/2.)/(math.cos(theta)*57.3)#from equation (1)\n", + "\n", + "print '%s %.2f %s' %(\"the normal force that the floor exerts on the ladder is\",N2,\"N\\n\")\n", + "print '%s %.2f %s' %(\"the frictional force that the floor exerts on the ladder is\",f,\"N\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the normal force that the floor exerts on the ladder is 98.00 N\n", + "\n", + "the frictional force that the floor exerts on the ladder is -21.13 N\n", + "\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9w - Pg 35" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.9w\n", + "#calculation of the contact force exerted by the floor on each leg of ladder\n", + "\n", + "#given data\n", + "theta=60.#angle(in degree) between the two legs\n", + "m=80.#mass(in kg) of the person\n", + "g=9.8#gravitational acceleration(in m/s**2) of the earth\n", + "\n", + "#calculation\n", + "N=m*g/2.\n", + "T=(N*2.*math.tan(90-theta)*57.3)/1.\n", + "\n", + "print '%s %.2f %s' %(\"the contact force exerted by the floor on each leg of ladder\",N,\"N\\n\")\n", + "print '%s %.2f %s' %(\"the tension in the crossbar is\",T,\"N\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the contact force exerted by the floor on each leg of ladder 392.00 N\n", + "\n", + "the tension in the crossbar is -287747.97 N\n", + "\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E12 - Pg 36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.12\n", + "#calculation of the kinetic energy of the sphere\n", + "\n", + "#given data\n", + "M=200.*10.**-3.#mass(in kg) of the sphere\n", + "vcm=2.*10.**-2.#speed(in m/s) of the sphere\n", + "\n", + "#calculation\n", + "#kinetic energy is K = (Icm*w*w/2) + (M*vcm*vcm/2)\n", + "#taking Icm = (2*M*r*r*w*w/5) and w=vcm/r\n", + "K=(M*vcm*vcm/5.)+(M*vcm*vcm/2.)#kinetic energy\n", + "\n", + "print '%s %.5f %s' %(\"the kinetic energy of the sphere is\",K,\"J\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the kinetic energy of the sphere is 0.00006 J\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E13w - Pg 37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.13w\n", + "#calculation of the kinetic energy and angular momentum of the disc\n", + "\n", + "#given data\n", + "M=200.*10.**-3.#mass(in kg) of the disc\n", + "r=4.*10.**-2.#radius(in m) of the disc\n", + "w=10.#angular velocity(in rad/s) \n", + "\n", + "#calculation\n", + "I=(M*r*r)/4.#moment of inertia\n", + "K=(I*w*w/2.)#kinetic energy\n", + "L=I*w#angular momentum\n", + "\n", + "print '%s %.2f %s' %(\"the kinetic energy of the disc is\",K,\"J\")\n", + "print '%s %.2f %s' %(\"\\nthe angular momentum of the disc is\",L,\"J-s\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the kinetic energy of the disc is 0.00 J\n", + "\n", + "the angular momentum of the disc is 0.00 J-s\n", + "\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E14w - Pg 38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#example 10.14w\n", + "#calculation of the work done by the torque in first two seconds\n", + "#given data\n", + "wzero=20.#initial angular velocity(in rad/s) of the motor\n", + "w=0#final angular velocity(in rad/s) of the motor\n", + "t=4.#time(in s) taken to attain rest position\n", + "I=.20#moment of inertia(in kg-m**2) of the disc about axis of rotation\n", + "t1=2.#time(in s)\n", + "\n", + "#calculation\n", + "alpha=(wzero-w)/t#equation of angular motion in case of deceleration\n", + "tau=I*alpha#torque\n", + "theta=(wzero*t1)-(alpha*t1*t1/2)#equation of angular motion\n", + "W=tau*theta#work done by the torque\n", + "\n", + "print '%s %.2f %s' %(\"the work done by the torque in first two seconds is\",W,\"J\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the work done by the torque in first two seconds is 30.00 J\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E19w - Pg 39" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#example 10.19w\n", + "#calculation of the moment of inertia of the system about the axis perpendicular to the rod passing through its middle point\n", + "\n", + "#given data\n", + "m=1.2#mass(in kg) of the sphere\n", + "R=10.*10.**-2.#radius(in cm) of the sphere\n", + "sep=50.*10.**-2.#separation(in m) between the two spheres\n", + "\n", + "#calculation\n", + "d=sep/2.#distance of each sphere from centre\n", + "Icm=(2.*m*R*R)/5.#moment of inertia about diameter\n", + "I=Icm+(m*d*d)#by parallel axis theorem,moment of inertia about given axis \n", + "#since second sphere has same moment of inertia\n", + "Isys=2.*I#moment of inertia of the system\n", + "\n", + "print '%s %.2f %s' %(\"the moment of inertia of the system about the axis perpendicular to the rod passing through its middle point is\",Isys,\"kg-m**2\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the moment of inertia of the system about the axis perpendicular to the rod passing through its middle point is 0.16 kg-m**2\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E22w - Pg 42" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#example 10.22w\n", + "#calculation of the number of revolutions made by the wheel per second\n", + "\n", + "#given data\n", + "p=220.*10.**-2.#perimeter(in cm) of the wheel\n", + "v=9.*10.**3./(60.*60.)#linear speed(in m/s) of wheel on the road\n", + "\n", + "#calculation\n", + "r=p/(2.*math.pi)#radius of the wheel\n", + "w=v/r#angular speed\n", + "n=w/(2.*math.pi)#number of revolutions\n", + "\n", + "print '%s %.2f %s' %(\"the number of revolutions made by the wheel per second is\",n,\"rev/s\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "the number of revolutions made by the wheel per second is 1.14 rev/s\n", + "\n" + ] + } + ], + "prompt_number": 16 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/KumarRaju/Chapter12.ipynb b/sample_notebooks/KumarRaju/Chapter12.ipynb new file mode 100755 index 00000000..d309457b --- /dev/null +++ b/sample_notebooks/KumarRaju/Chapter12.ipynb @@ -0,0 +1,647 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2259086c8cee958c316a471676c823626713e37889548ae1aff2070252fca121" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter12:Power System Transients" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "rc=.5e-2;\n", + "rs=1.5e-2;\n", + "u=4\n", + "\n", + "L=2e-7 * math.log(rs/rc);\n", + "print '%s %.2f %s' %(\"\\nL=\",L*1e7,\"e-7H/m\")\n", + "C=u*1e-9/(18 * math.log(rs/rc))\n", + "print '%s %.2f %s' %(\"\\nC=\", C*1e9,\"e-9F/m\")\n", + "v=1/math.sqrt(L*C);\n", + "print '%s %.2f %s' %(\"\\nv=\", v*1e-8,\"e8m/s\")\n", + "Zc=math.sqrt(L/C)\n", + "print '%s %.2f %s' %(\"\\nZc=\",Zc,\"ohm\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "L= 2.20 e-7H/m\n", + "\n", + "C= 0.20 e-9F/m\n", + "\n", + "v= 1.50 e8m/s\n", + "\n", + "Zc= 32.96 ohm\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "ef=100.;\n", + "Zc=400.;\n", + "Z=50.;\n", + "et=2.*ef*Z/(Z+Zc)\n", + "print '%s %.2f %s' %(\"Surge transmitted=\",et,\"kV\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Surge transmitted= 22.22 kV\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "\n", + "ef=200.;\n", + "Zc=400.;\n", + "Z1=500.;\n", + "Z2=300.;\n", + "et=2.*ef*(Z1*Z2/(Z1+Z2))/((Z1*Z2/(Z1+Z2))+Zc)\n", + "print '%s %.2f %s' %(\"\\nSurge Voltage transmitted=\",et,\"kV\\n\")\n", + "it1=et/Z1;\n", + "print '%s %.2f %s' %(\"\\nSurge Current transmitted=\",it1,\"kA\\n\")\n", + "it2=et/Z2;\n", + "print '%s %.2f %s' %(\"\\nSurge Current transmitted=\",(it2*100.)/100.,\"kA\\n\")\n", + "er=et-ef;\n", + "print '%s %.2f %s' %(\"\\nSurge Voltage Reflected=\",er,\"kV\\n\")\n", + "ir=it1+it2-(ef/Zc)\n", + "print '%s %.2f %s' %(\"\\nSurge Current Reflected=\",ir,\"kA\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Surge Voltage transmitted= 127.66 kV\n", + "\n", + "\n", + "Surge Current transmitted= 0.26 kA\n", + "\n", + "\n", + "Surge Current transmitted= 0.43 kA\n", + "\n", + "\n", + "Surge Voltage Reflected= -72.34 kV\n", + "\n", + "\n", + "Surge Current Reflected= 0.18 kA\n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 35" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "\n", + "E=100.\n", + "Zc=400.\n", + "L=4000.\n", + "\n", + "print '%s %.2f %s %.2f' %(\"et=\",2*E,\"math.exp( - %.1f t) KV\\n\",Zc/L)\n", + "print '%s %.2f %s %.2f' %(\"er=\",E,\"(2*math.exp( - %.1f t) -1) KV\\n\",Zc/L)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "et= 200.00 math.exp( - %.1f t) KV\n", + " 0.10\n", + "er= 100.00 (2*math.exp( - %.1f t) -1) KV\n", + " 0.10\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E7 - Pg 36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "\n", + "V=300e3\n", + "R=400.\n", + "k=1.5e-27\n", + "\n", + "E=10.\n", + "x=1.\n", + "e=1e-5\n", + "while (E>e):\n", + " f=(k*R*x**6.) +x -(2.*V)\n", + " df=(6.* k*R*x**5.) +1.\n", + " x1=x-(f/df)\n", + " E=abs(x1-x)\n", + " x=x1\n", + "eA=round(x)\n", + "IA=k*eA**6.\n", + "\n", + "print '%s %.2f %s %.2f' %(\"eA=\",eA,\"Ia=\",IA)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "eA= 97101.00 Ia= 1257.28\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E8 - Pg 36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "V=300e3\n", + "R1=400.\n", + "R2=50.\n", + "R=1.+(400./50.)\n", + "k=1.5e-27\n", + "\n", + "E=10.\n", + "x=1.\n", + "e=1e-5\n", + "while (E>e) :\n", + " f=(k*R1*x**6.) +(R*x) -(2.*V)\n", + " df=(6.* k*R1*x**5.) +R\n", + " x1=x-(f/df)\n", + " E=abs(x1-x)\n", + " x=x1\n", + "eA=round(x)\n", + "IA=k*eA**6.\n", + "\n", + "print '%s %.2f %s %.2f' %(\"eA=\",eA,\"Ia=\",IA)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "eA= 62640.00 Ia= 90.62\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E9 - Pg 45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "\n", + "ef=3000.;\n", + "Zc=300.;\n", + "ea=1700.;\n", + "iF=ef/Zc\n", + "print '%s %.2f %s' %(\"\\nCurrent in line=\",iF,\"kA\\n\")\n", + "Ia=((2.*ef)-ea)/Zc\n", + "print '%s %.2f %s' %(\"\\nCurrent through Arrester=\",Ia,\"kA\\n\")\n", + "Ia=round(Ia *1000.)/1000.\n", + "R=ea/Ia\n", + "print '%s %.2f %s' %(\"\\nresistance of arrester=\",R,\"ohm\\n\")\n", + "er=ea-ef;\n", + "print '%s %.2f %s' %(\"\\nSurge Voltage Reflected=\",er,\"kV\\n\")\n", + "Cr=er/ef;\n", + "CR=ea/ef;\n", + "print '%s %.2f %s %.2f' %(\"\\nCoeff of Reflection =\",Cr,\"Coeff of Refraction=\",CR)\n", + "Cr=(R-Zc)/(R+Zc);\n", + "CR=(R*2)/(R+Zc);\n", + "print '%s %.2f %s %.2f' %(\"\\nVerification: Coeff of Reflection =\",Cr,\"Coeff of Refraction=\",CR)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Current in line= 10.00 kA\n", + "\n", + "\n", + "Current through Arrester= 14.33 kA\n", + "\n", + "\n", + "resistance of arrester= 118.61 ohm\n", + "\n", + "\n", + "Surge Voltage Reflected= -1300.00 kV\n", + "\n", + "\n", + "Coeff of Reflection = -0.43 Coeff of Refraction= 0.57\n", + "\n", + "Verification: Coeff of Reflection = -0.43 Coeff of Refraction= 0.57\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E10 - Pg 45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ef=10000.;\n", + "Zc=400.;\n", + "iF=ef/Zc\n", + "print '%s %.2f' %(\"\\n(a)\\nIncident Wave magnitude= A\",iF)\n", + "\n", + "R=1000\n", + "et=ef*(R*2)/(R+Zc);\n", + "it=et/R;\n", + "er=et-ef;\n", + "print '%s %.2f' %(\"\\n(b)\\nSurge Voltage Reflected= KV\",er/1000)\n", + "ir=-1*er/Zc\n", + "print '%s %.2f' %(\"\\nSurge Current Reflected= A\",ir)\n", + "edr=et*it;\n", + "print '%s %.2f' %(\"\\nRate of dissipation of energy= KW\",edr/1000)\n", + "err=er*-ir;\n", + "print '%s %.2f' %(\"\\nRate of reflection of energy= KW\",err/1000)\n", + "\n", + "print '%s %.2f' %(\"\\n(c)\\nfor complete dissipation, R=Zc= ohm\",Zc);\n", + "\n", + "R=50\n", + "et=ef*(R*2)/(R+Zc);\n", + "print '%s %.2f' %(\"\\n(d)\\nSurge Voltage Transmitted= KV\",et/1000)\n", + "it=et/R;\n", + "print '%s %.2f' %(\"\\nSurge Current Transmitted= A\",it)\n", + "er=et-ef;\n", + "print '%s %.2f' %(\"\\nSurge Voltage Reflected= kV\",er/1000)\n", + "ir=-1*er/Zc\n", + "print '%s %.2f' %(\"\\nSurge Current Reflected= A\",ir)\n", + "edr=et*it;\n", + "print '%s %.2f' %(\"\\nRate of dissipation of energy= KW\",edr/1000)\n", + "err=er*-ir;\n", + "print '%s %.2f' %(\"\\nRate of reflection of energy= KW\",err/1000)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "(a)\n", + "Incident Wave magnitude= A 25.00\n", + "\n", + "(b)\n", + "Surge Voltage Reflected= KV 4.29\n", + "\n", + "Surge Current Reflected= A -10.71\n", + "\n", + "Rate of dissipation of energy= KW 204.08\n", + "\n", + "Rate of reflection of energy= KW 45.92\n", + "\n", + "(c)\n", + "for complete dissipation, R=Zc= ohm 400.00\n", + "\n", + "(d)\n", + "Surge Voltage Transmitted= KV 2.22\n", + "\n", + "Surge Current Transmitted= A 44.44\n", + "\n", + "Surge Voltage Reflected= kV -7.78\n", + "\n", + "Surge Current Reflected= A 19.44\n", + "\n", + "Rate of dissipation of energy= KW 98.77\n", + "\n", + "Rate of reflection of energy= KW 151.23\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E11 - Pg 46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "Zc=400.\n", + "ef=20.\n", + "z1=150.;\n", + "z2=200.\n", + "z=round((z1*z2/(z1+z2))*100.)/100.\n", + "\n", + "et=2*ef*z/(Zc+z)\n", + "print '%s %.2f %s' %(\"\\nSurge Voltage Transmitted=\",et,\"kV\\n\")\n", + "\n", + "it1=et*1000./z1;\n", + "print '%s %.2f %s' %(\"\\nSurge Current Transmitted in line 1=\",it1,\"A\\n\")\n", + "\n", + "it2=et*1000./z2;\n", + "print '%s %.2f %s' %(\"\\nSurge Current Transmitted in line 2=\",it2,\"A\\n\")\n", + "\n", + "er=et-ef\n", + "print '%s %.2f %s' %(\"\\nSurge Voltage Reflected=\",er,\"kV\\n\")\n", + "ir=-1*er*1000./Zc\n", + "print '%s %.2f %s' %(\"\\nSurge Current Reflected=\",ir,\"A\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Surge Voltage Transmitted= 7.06 kV\n", + "\n", + "\n", + "Surge Current Transmitted in line 1= 47.06 A\n", + "\n", + "\n", + "Surge Current Transmitted in line 2= 35.29 A\n", + "\n", + "\n", + "Surge Voltage Reflected= -12.94 kV\n", + "\n", + "\n", + "Surge Current Reflected= 32.35 A\n", + "\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E12 - Pg 49" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "ef=100.\n", + "Zc=400.\n", + "z=50.\n", + "R=z+Zc;\n", + "E=(2.*ef/(Zc+z+R))**2. *R\n", + "E=round(E*100.)/100.\n", + "print '%s %.2f %s %s %.2f %s' %(\"\\n(a)Energy transfer max when R=\",R,\"ohm\\n\",\"energy=\",E,\"KW\\n\");\n", + "etB=2.*ef*z/(z+Zc+R);\n", + "etB=round(etB*100.)/100.\n", + "print '%s %.2f %s' %(\"\\n(b)Surge Voltage Transmitted=\",etB,\"kV\\n\")\n", + "it=etB*1000./z;\n", + "it=round(it*100.)/100.\n", + "print '%s %.2f %s' %(\"\\nSurge Current Transmitted =\",it,\"A\\n\")\n", + "etA=2.*ef*(z+R)/(z+Zc+R);\n", + "etA=round(etA*100.)/100.\n", + "erA=etA-ef\n", + "print '%s %.2f %s' %(\"\\n(c)Surge Voltage Reflected=\",erA,\"kV\\n\")\n", + "irA=-1.*erA*1000./Zc\n", + "print '%s %.2f %s' %(\"\\nSurge Current Reflected=\",irA,\"A\\n\")\n", + "iF=ef*1000./Zc\n", + "Pi=ef*iF\n", + "print '%s %.2f %s' %(\"\\n(d)Power Incident=\",Pi,\"kW\\n\")\n", + "Pr=erA*-irA\n", + "print '%s %.2f %s' %(\"\\nPower Reflected=\",Pr,\"kW\\n\")\n", + "Pt=erA*it\n", + "print '%s %.2f %s' %(\"\\nPower Transmitted=\",Pt,\"kW\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "(a)Energy transfer max when R= 450.00 ohm\n", + " energy= 22.22 KW\n", + "\n", + "\n", + "(b)Surge Voltage Transmitted= 11.11 kV\n", + "\n", + "\n", + "Surge Current Transmitted = 222.20 A\n", + "\n", + "\n", + "(c)Surge Voltage Reflected= 11.11 kV\n", + "\n", + "\n", + "Surge Current Reflected= -27.77 A\n", + "\n", + "\n", + "(d)Power Incident= 25000.00 kW\n", + "\n", + "\n", + "Power Reflected= 308.58 kW\n", + "\n", + "\n", + "Power Transmitted= 2468.64 kW\n", + "\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E14 - Pg 50" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "I=5.;\n", + "z1=400.\n", + "z2=50.\n", + "V=I * z1* z2/(z2+z1)\n", + "print '%s %.2f %s' %(\"\\nSurge Voltage Transmitted=\",V,\"kV\\n\")\n", + "ic=V/z2\n", + "print '%s %.2f %s' %(\"\\nSurge Current Transmitted in cable=\",ic,\"kA\\n\")\n", + "\n", + "io=-V/z1;\n", + "print '%s %.2f %s' %(\"\\nSurge Current Transmitted in OH line=\",io,\"kA\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Surge Voltage Transmitted= 222.22 kV\n", + "\n", + "\n", + "Surge Current Transmitted in cable= 4.44 kA\n", + "\n", + "\n", + "Surge Current Transmitted in OH line= -0.56 kA\n", + "\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E16 - Pg 51" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "i=100.\n", + "L=4e-3\n", + "C=300e-12\n", + "E=i* math.sqrt(L/C)\n", + "T=1./ math.sqrt(L*C)\n", + "print '%s %.2f %s %.2f' %(\"e=\",E/1e3,\"*1e3 sin( %.3f *1e6 t) kV\",T/1e6)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "e= 365.15 *1e3 sin( %.3f *1e6 t) kV 0.91\n" + ] + } + ], + "prompt_number": 12 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/MohdAkhlak/ch3.ipynb b/sample_notebooks/MohdAkhlak/ch3.ipynb new file mode 100755 index 00000000..82035c0d --- /dev/null +++ b/sample_notebooks/MohdAkhlak/ch3.ipynb @@ -0,0 +1,256 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:931ccf820f91dc3bd263fe2430c73233b66e02ab90eedbd3236bc42b5727ead5" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 3, Waveform generators" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex 1 - page : 145" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Given data \n", + "\n", + "R2 = 100.0 # ohm\n", + "R1 = 50.0*10**3 # ohm\n", + "Vref = 0 # V\n", + "vi = 1 # V\n", + "Vsat = 14.0 # V\n", + "# Solution \n", + "\n", + "VUT = (R2*Vsat)/(R1+R2) # V\n", + "VLT = (R2*-Vsat)/(R1+R2) # V\n", + "\n", + "# Displaying the values\n", + "\n", + "print \"The value of Upper threshold voltage = \",int(round(VUT*10**3,0)),\"mV\"\n", + "print \"The value of Lower threshold voltage = \",int(round(VLT*10**3,0)),\"mV\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of Upper threshold voltage = 28 mV\n", + "The value of Lower threshold voltage = -28 mV\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex 2 - page : 148" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy as np \n", + "# Given data\n", + "\n", + "VUT = 0\n", + "VH = 0.3\n", + "f = 10.0**3\n", + "# Solution \n", + "\n", + "VLT = VUT - VH\n", + "theta = round(np.arcsin(VH/2),1)\n", + "T = 1/f\n", + "Ttheta = theta/(2*np.pi*f) \n", + "T1 = (T/2) + Ttheta\n", + "T2 = (T/2) - Ttheta \n", + "\n", + "# Displayig the values \n", + "\n", + "print \"The value of Lower threshold voltage = \",VLT,\"V\"\n", + "print \"The value of angle theta = \",theta,\"Radian\"\n", + "print \"The value of T1 = \",round(T1*10**3,3),\"ms\"\n", + "print \"The value of T2 = \",round(T2*10**3,3),\"ms\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of Lower threshold voltage = -0.3 V\n", + "The value of angle theta = 0.2 Radian\n", + "The value of T1 = 0.532 ms\n", + "The value of T2 = 0.468 ms\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex 3 - page : 152" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "# Given data \n", + "\n", + "f = 100\n", + "C = 0.1*10**-6\n", + "\n", + "# Solution \n", + "\n", + "R = 1/(math.sqrt(6)*2*math.pi*(10**-7)*100)\n", + "R1 = 10*R\n", + "Rf = 29*R1\n", + "\n", + "# Displaying the solutions \n", + "\n", + "print \"The value of R1 =\",int(round(R1*10**-3,0)),\"Kilo Ohms\"\n", + "print \"The value of Rf =\",int(round(Rf*10**-3,0)),\"Kilo Ohms\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of R1 = 65 Kilo Ohms\n", + "The value of Rf = 1884 Kilo Ohms\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex 4 - page 158" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "# Given data \n", + "\n", + "f = 50\n", + "C = 0.2*10**-6\n", + "\n", + "# Solution \n", + "\n", + "R = 1/(math.sqrt(6)*2*math.pi*(10**-7)*100)\n", + "R1 = 10*R\n", + "Rf = 29*R1\n", + "\n", + "# Displaying the solutions \n", + "\n", + "print \"The value of R1 is %0.2f kohms\"%(R1*10**-3)\n", + "print \"The value of Rf is %0.2f kohms\"%(Rf*10**-3)\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of R1 is 64.97 kohms\n", + "The value of Rf is 1884.27 kohms\n" + ] + } + ], + "prompt_number": 27 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex 5 - page 162" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from numpy import pi, arcsin \n", + "# Given data\n", + "\n", + "VUT = 0\n", + "VH = 0.5\n", + "f = 1000\n", + "# Solution \n", + "\n", + "VLT = VUT - VH\n", + "theta = round(arcsin(VH/2),1)\n", + "T = 1/f\n", + "Ttheta = theta/(2*pi*f) \n", + "T1 = (T/2) + Ttheta\n", + "T2 = (T/2) - Ttheta \n", + "\n", + "# Displayig the values \n", + "\n", + "print \"The value of Lower threshold voltage = \",VLT,\"V\"\n", + "print \"The value of angle theta = \",theta,\"Radian\"\n", + "print \"The value of T1 = \",round(T1*10**3,3),\"ms\"\n", + "print \"The value of T2 = \",round(T2*10**3,3),\"ms\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of Lower threshold voltage = -0.5 V\n", + "The value of angle theta = 0.3 Radian\n", + "The value of T1 = 0.048 ms\n", + "The value of T2 = -0.048 ms\n" + ] + } + ], + "prompt_number": 29 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/PradeepChoudari/Chapter01.ipynb b/sample_notebooks/PradeepChoudari/Chapter01.ipynb new file mode 100755 index 00000000..00a54c26 --- /dev/null +++ b/sample_notebooks/PradeepChoudari/Chapter01.ipynb @@ -0,0 +1,326 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:18faacea8ac62a8f633d38b4dcf07dd31cdf79c796296b846bc3a06dfe56da57" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter01:Single phase transformer Principle and Constructions" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 23" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Caption:Find the (a) n ratio (b) load current referred to high voltage side (c) load impedance on low voltage side for full load (d) and impedance referred to high voltage side\n", + "#Exa:1.1\n", + "import math \n", + "P_s=25000.#Supplied power (in VA)\n", + "V_1=1910.#Voltage on primary side (in volt)\n", + "V_2=240.#Voltage on secondary side (in volt)\n", + "f=50.#frequency in hertz\n", + "n=V_1/V_2\n", + "print '%s %.2f' %('(a)n-ratio=',n)\n", + "I_1=P_s/V_1\n", + "print '%s %.2f' %('(b)load current referred to high voltage side (in A)=',I_1)\n", + "I_2=P_s/V_2\n", + "Z_2=V_2/I_2\n", + "print '%s %.2f' %('(c)load impedance on low voltage side for full load (in ohm)=',Z_2)\n", + "Z_1=Z_2*(n**2)\n", + "print '%s %.2f' %('(d)impedance referred to high voltage side(in ohm)=',Z_1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)n-ratio= 7.96\n", + "(b)load current referred to high voltage side (in A)= 13.09\n", + "(c)load impedance on low voltage side for full load (in ohm)= 2.30\n", + "(d)impedance referred to high voltage side(in ohm)= 145.92\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Caption:Find (a) Power factor on no load (b) active current (c) magnetising current (d) copper loss in the primary winding (e) core loss\n", + "#Exa:1.2\n", + "import math,cmath\n", + "from math import acos,sin\n", + "V_1=3300.#Primary voltage (in volt)\n", + "V_2=240.#Secondary voltage (in volt)\n", + "I_0=2.#No load current (in A)\n", + "P=60.#Power (in watt)\n", + "R=0.8#Resistance of the low voltage winding (in ohm)\n", + "Pf=P/(V_2*I_0)\n", + "print '%s %.2f' %('(a)Power factor on no load=',Pf)\n", + "I_c=I_0*Pf\n", + "print '%s %.2f' %('(b)Active current(in A)=',I_c)\n", + "theta=(acos(Pf)*57.3)\n", + "I_m=I_0*sin(theta)\n", + "print '%s %.2f' %('(c)magnetising current is(in A)=',I_m)\n", + "Culoss=(I_0**2)*R\n", + "print '%s %.2f' %('(d)copper loss in the primary winding is(in watt)=',Culoss)\n", + "Coreloss=P-Culoss\n", + "print '%s %.2f' %('(e)core loss(in watt)=',Coreloss)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)Power factor on no load= 0.12\n", + "(b)Active current(in A)= 0.25\n", + "(c)magnetising current is(in A)= 1.82\n", + "(d)copper loss in the primary winding is(in watt)= 3.20\n", + "(e)core loss(in watt)= 56.80\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Caption:Find number of turns per limb on the (a) high voltage and (b) low voltage sides\n", + "#Exa:1.3\n", + "import math \n", + "A=0.0386#cross sectional area of core(in m**2)\n", + "B=1.#maximum flux density (in weber/m**2)\n", + "f=50.#frequency (in hertz)\n", + "V_1=3300.#voltage on primary side (in volt)\n", + "V_2=240.#voltage on secondary side (in volt)\n", + "C=B*A\n", + "n_2=V_2/(4.44*C*f)\n", + "T_2=n_2/2.\n", + "print '%s %.2f' %('(a)number of turns on low voltage side is=',T_2)\n", + "T_1=T_2*V_1/V_2\n", + "print '%s %.2f' %('(b)number of turns on high voltage side is=',T_1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)number of turns on low voltage side is= 14.00\n", + "(b)number of turns on high voltage side is= 192.55\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E4 - Pg 29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Caption:Calculate (a) equivalent resistance and reactance of low voltage side in terms of high voltage side (b) equivalent resistance and reactance of high voltage side in terms of low voltage side (c) total resistance and reactance of transformer in terms of high voltage side (d) total resistance and reactance of transformer in terms of low voltage side \n", + "#Exa:1.4\n", + "import math \n", + "V_1=2200.#Primary side voltage(in volt)\n", + "V_2=220.#secondary side voltage(in volt)\n", + "f=50.#frequency(in hertz)\n", + "r_1=1.25#Primary side resistance(in ohm)\n", + "x_1=4.#Primary side reactance(in ohm)\n", + "r_2=0.04#Secondary side resistance(in ohm)\n", + "x_2=0.15#Secondary side reactance(in ohm)\n", + "n=V_1/V_2\n", + "R_2=(n**2.)*r_2\n", + "print '%s %.2f' %('(a)equivalent resistance of low voltage side in terms of high voltage side=',R_2)\n", + "X_2=(n**2)*x_2\n", + "print '%s %.2f' %('\\nequivalent reactance of low voltage side in terms of high voltage side=',X_2)\n", + "R_1=r_1/(n**2)\n", + "print '%s %.2f' %('\\n(b)equivalent resistance of high voltage side in terms of low voltage side =',R_1)\n", + "X_1=x_1/(n**2)\n", + "print '%s %.2f' %('\\nequivalent reactance of high voltage side in terms of low voltage side =',X_1)\n", + "R_t=r_1+R_2\n", + "print '%s %.2f' %('\\n(c)total resistance of transformer in terms of high voltage side=',R_t)\n", + "X_t=x_1+X_2\n", + "print '%s %.2f' %('\\ntotal reactance of transformer in terms of high voltage side=',X_t)\n", + "R_e=r_2+R_1\n", + "print '%s %.2f' %('\\n(d)total resistance of transformer in terms of low voltage side=',R_e)\n", + "X_e=x_2+X_1\n", + "print '%s %.2f' %('\\ntotal reactance of transformer in terms of low voltage side=',X_e)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)equivalent resistance of low voltage side in terms of high voltage side= 4.00\n", + "\n", + "equivalent reactance of low voltage side in terms of high voltage side= 15.00\n", + "\n", + "(b)equivalent resistance of high voltage side in terms of low voltage side = 0.01\n", + "\n", + "equivalent reactance of high voltage side in terms of low voltage side = 0.04\n", + "\n", + "(c)total resistance of transformer in terms of high voltage side= 5.25\n", + "\n", + "total reactance of transformer in terms of high voltage side= 19.00\n", + "\n", + "(d)total resistance of transformer in terms of low voltage side= 0.05\n", + "\n", + "total reactance of transformer in terms of low voltage side= 0.19\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Caption:Find (a) terminal voltage on load (b) voltage on load at high voltage terminals (c) efficiency of transformer\n", + "#Exa:1.5 \n", + "import math,cmath \n", + "n=10.#ratio of high voltage to low voltage\n", + "V_1=200.#Voltage on low voltage side(in volt)\n", + "x_m=231.#Magnetising resistance(in ohms)\n", + "r_c=400.#Core loss resistance(in ohms)\n", + "r_e=0.1#Equivalent resistance referred to low voltage side(in ohms)\n", + "x_e=0.5#Equivalent reactance referred to low voltage side(in ohms)\n", + "r_l=7.9#Load resistance(in ohms)\n", + "x_l=5.5#Load reactance(in ohms)\n", + "I_m=V_1/x_m\n", + "I_c=V_1/r_c\n", + "I_0=I_c+(1j*I_m)\n", + "R_l=r_l+r_e\n", + "X_l=x_l+x_e\n", + "I=V_1/(R_l+(1j*X_l))\n", + "I_1=I+I_0\n", + "V_2=V_1-I*(r_e+(1j*x_e))\n", + "v=193.;#math.sqrt(V_2*conj(V_2))\n", + "print '%s %.2f' %('(a)terminal voltage on load(in volt)=',v)\n", + "V=v*n\n", + "print '%s %.2f' %('(b)voltage on load at hgih voltage terminals(in volt)=',V)\n", + "P_o=v*I.real\n", + "P_i=V_1*I_1.real\n", + "eff=(P_o/P_i)*100\n", + "print '%s %.2f' %('(c)efficiency of transformer is(in %)=',eff)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)terminal voltage on load(in volt)= 193.00\n", + "(b)voltage on load at hgih voltage terminals(in volt)= 1930.00\n", + "(c)efficiency of transformer is(in %)= 93.58\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 30" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Caption:Find (a) impedance (b) % resistance and reactance\n", + "#Exa:1.6\n", + "import math\n", + "P_s=500000.#Power supplied(in VA)\n", + "V_1=2200.#Voltage on primary side(in volt)\n", + "V_2=500.#Voltage on secondary side(in volt)\n", + "f=50.#frequency(in hertz)\n", + "r=0.01#Resistance of transformer(in ohms)\n", + "z=0.1#impedance of transformer(in %)\n", + "I=P_s/V_2\n", + "Z=z*V_2/I\n", + "print '%s %.2f' %('(a)Impedance(in ohms)=',Z)\n", + "R=(I*r/V_2)*100\n", + "print '%s %.2f' %('(b) Resistance(in %)=',R)\n", + "x=math.sqrt(Z**2-r**2)\n", + "X=(x*I/V_2)*100\n", + "print '%s %.2f' %('Reactance(in %)=',X)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(a)Impedance(in ohms)= 0.05\n", + "(b) Resistance(in %)= 2.00\n", + "Reactance(in %)= 9.80\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/RajbeeVakkalagadda/Chapter04.ipynb b/sample_notebooks/RajbeeVakkalagadda/Chapter04.ipynb new file mode 100755 index 00000000..1b360b5e --- /dev/null +++ b/sample_notebooks/RajbeeVakkalagadda/Chapter04.ipynb @@ -0,0 +1,476 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:36d59fdfc24a2deb7849a2ba98aa4b099fd70d413ba4136a658e9181b78b3321" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter04:The Transistor At Low Frequency" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E1 - Pg 42" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Exa 4.1\n", + "import math\n", + "# Given data\n", + "R1 = 100.*10.**3.;# in ohm\n", + "R2 = 10.*10.**3.;# in ohm\n", + "h_fe = 50.;\n", + "h_oe = 1./40.;# in ohm\n", + "R_L = 5.*10.**3.;# in ohm\n", + "R_S= 5.*10.**3;# in ohm\n", + "h_ie = 1.1*10.**3.;# in ohm\n", + "h_re = 2.5*10.**-4.;\n", + "R_B = (R1*R2/(R1+R2));# in ohm\n", + "A_I = (-h_fe)/(1 + h_oe*R_L);\n", + "print '%s %.2f %s' %(\"The internal current gain is\",A_I,\"\\n\");\n", + "#Internal input impedance, Zi = Vbe/Ib or \n", + "Zi = (h_ie + h_re*A_I*R_L);# in ohm\n", + "Zi= Zi*10.**-3.;# in k ohm\n", + "print '%s %.2f %s' %(\"The internal input impedance in k ohm is\",Zi,\"\\n\");\n", + "Zi= Zi*10.**3.;# in ohm\n", + "#Internal voltage gain, Av = Vce/Vbe or \n", + "Av = (A_I*R_L)/Zi;\n", + "print '%s %.2f %s' %(\"The internal voltage gain is\",Av,\"\\n\");\n", + "Ri =round(R_B*Zi/(R_B+Zi));# in ohm\n", + "Ri= Ri*10**-3;# in k ohm\n", + "print '%s %.2f %s' %(\"The overall input impedance in k ohm is\",Ri,\"\\n\");\n", + "Ri= Ri*10**3;# in ohm\n", + "# V_S= I_i*R_S+v_be or\n", + "VS_by_vbe= Ri/(Ri+R_S);\n", + "Avs= Av*VS_by_vbe;\n", + "print '%s %.2f %s' %(\"The overall voltage gain is : \",Avs,\"\\n\")\n", + "# R_B*(I_i-I_b)= Zi*I_b or\n", + "I_bBYI_i= R_B/(R_B+Zi);\n", + "A_IS= A_I*I_bBYI_i;\n", + "print '%s %.2f %s' %(\"The overall current gain is : \",A_IS,\"\\n\")\n", + "Rdesh_S= R_B*R_S/(R_B+R_S);# in ohm\n", + "Rdesh_S= 3220\n", + "I_bByVce= -h_re/(h_ie+Rdesh_S);\n", + "Yo= h_oe-h_fe*h_re/(h_ie+Rdesh_S)*10**3;\n", + "Zo= 1/Yo;\n", + "print '%s %.2f %s' %(\"The Output impedance in ohm is : \",Zo,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The internal current gain is -0.40 \n", + "\n", + "The internal input impedance in k ohm is 1.10 \n", + "\n", + "The internal voltage gain is -1.80 \n", + "\n", + "The overall input impedance in k ohm is 0.98 \n", + "\n", + "The overall voltage gain is : -0.30 \n", + "\n", + "The overall current gain is : -0.35 \n", + "\n", + "The Output impedance in ohm is : 45.24 \n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E2 - Pg 43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Exa 4.2\n", + "import math\n", + "# Given data\n", + "V_CC = 15.;# in V\n", + "R_L = 10.;# in k ohm\n", + "Rf = 200.;# in k ohm\n", + "R_S = 5.;# in k ohm\n", + "Rf2 = Rf;# in k ohm\n", + "h_fe = 50.;\n", + "V_S= 10.*10.**-3.;# in V\n", + "h_oe = 1./40.;# in k ohm\n", + "R_L = (R_L*Rf2)/(R_L+Rf2);# in k ohm\n", + "Ai = -h_fe/(1.+h_oe*R_L);\n", + "print '%s %.2f %s' %(\"The internal current gain is\",Ai,\"\\n\");\n", + "#Zi = Vbe/Ib = h_ie +Ai*h_re*R_L;\n", + "h_ie = 1.1;# in k ohm\n", + "h_re = 2.5*10.**-4.;\n", + "Zi = h_ie +Ai*h_re*R_L;# in k ohm\n", + "print '%s %.2f %s' %(\"The internal input impedance in k ohm is\",Zi,\"\\n\");\n", + "#A_V = Vce/Vbe = (Ai*R_L)/Zi;\n", + "A_V = (Ai*R_L)/Zi;\n", + "print '%s %.2f %s' %(\"The internal voltage gain is\",A_V,\"\\n\");\n", + "Rf1= Rf/(1-A_V)\n", + "# Rf1 = Rf/(1-A_V);# in k ohm\n", + "#Ri = Vi/Ii = Vbe/Ii = (Rf1*Zi)/(Rf1+Zi);\n", + "Ri = (Rf1*Zi)/(Rf1+Zi);# in k ohm\n", + "print '%s %.2f %s' %(\"The overall input impedance in k ohm is\",Ri,\"\\n\");\n", + "#A_VS = Vo/V_S or \n", + "A_VS = A_V*(Ri/(R_S+Ri));\n", + "print '%s %.2f %s' %(\"The overall voltage gain is\",A_VS,\"\\n\");\n", + "#A_IS = I_L/Ii or\n", + "A_IS = (Rf2/(Rf2+R_L))*Ai*(Rf1/(Rf1+Zi));\n", + "print '%s %.2f %s' %(\"The overall current gain is\",A_IS,\"\\n\");\n", + "Rdesh_S= Rf1*R_S/(Rf1+R_S);# in k ohm\n", + "Yo= h_oe-h_re*h_fe/(h_ie+Rdesh_S);# in mho\n", + "Zo= 1/Yo;# in ohm\n", + "print '%s %.2f %s' %(\"The output impedance in ohm is : \",Zo,\"\\n\")\n", + "Zdesh_o= Rf2*Zo/(Rf2+Zo);# in ohm\n", + "print '%s %.2f %s' %(\"The overall output impedance in ohm is : \",Zdesh_o,\"\\n\");\n", + "Vo= V_S*abs(A_VS);# in V\n", + "Vo= Vo*10**3;# in mV\n", + "print '%s %.2f %s' %(\"The magnitude of output voltage in mV is : \",Vo,\"\\n\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The internal current gain is -40.38 \n", + "\n", + "The internal input impedance in k ohm is 1.00 \n", + "\n", + "The internal voltage gain is -383.14 \n", + "\n", + "The overall input impedance in k ohm is 0.34 \n", + "\n", + "The overall voltage gain is -24.58 \n", + "\n", + "The overall current gain is -13.17 \n", + "\n", + "The output impedance in ohm is : 58.66 \n", + "\n", + "The overall output impedance in ohm is : 45.36 \n", + "\n", + "The magnitude of output voltage in mV is : 245.85 \n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E3 - Pg 43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Exa 4.3\n", + "import math \n", + "# Given data\n", + "h_ic = 2.;# in k ohm\n", + "h_fc = -51.;\n", + "h_oc = 25.*10.**-6.;# in ohm\n", + "h_rc= 1.;\n", + "V_CC = 20.;# in V\n", + "R1 = 10.;# in k ohm\n", + "R2 = 10.;# in k ohm\n", + "R_S = 1.;# in k ohm\n", + "R_E = 5.;# in k ohm\n", + "R_B= 5.;# in k ohm\n", + "R_L= 5.;# in k ohm\n", + "# (i) Current Gain\n", + "Ai = (-h_fc)/(1.+h_oc*R_E*10.**3.);\n", + "print '%s %.2f %s' %(\"The current gain is\",Ai,\"\\n\");\n", + "# (ii) Input impedance\n", + "Zi = h_ic*10**3 + h_rc*Ai*R_E*10**3;# in ohm\n", + "Zi = Zi * 10**-3;# in k ohm\n", + "print '%s %.2f %s' %(\"The input impedance in k ohm is\",Zi,\"\\n\");\n", + "# (iii) Voltage Gain\n", + "A_V = (Ai*R_L*10**3)/(Zi*10**3);\n", + "A_V = 1;# (approx)\n", + "print '%s %.2f %s' %(\"The voltage gain is\",A_V,\"\\n\");\n", + "# (iv) Overall Input Impedance\n", + "Z_IS = (R_B*Zi)/(R_B+Zi);# in k ohm\n", + "print '%s %.2f %s' %(\"The overall input impedance in k ohm is\",Z_IS,\"\\n\");\n", + "# (v) Overall voltage gain\n", + "A_VS = (A_V*Zi)/(Zi+R_S); \n", + "print '%s %.2f %s' %(\"The overall voltage gain is\",A_VS,\"\\n\");\n", + "# (vi) Overall current gain\n", + "A_IS =Ai*(R_B/(R_B+Zi));\n", + "print '%s %.2f %s' %(\"The overall current gain is\",A_IS,\"\\n\");\n", + "# (vii) Output impedance\n", + "RdasS = (R_S*R_B)/(R_S+R_B);# in k ohm\n", + "Yo = h_oc - ( (h_fc*h_rc)/(h_ic*10.**3.+RdasS*10.**3.) );# in mho \n", + "Zo = 1./Yo;# in ohm\n", + "print '%s %.2f %s' %(\"The output impedance in ohm is\",Zo,\"\\n\");\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The current gain is 45.33 \n", + "\n", + "The input impedance in k ohm is 228.67 \n", + "\n", + "The voltage gain is 1.00 \n", + "\n", + "The overall input impedance in k ohm is 4.89 \n", + "\n", + "The overall voltage gain is 1.00 \n", + "\n", + "The overall current gain is 0.97 \n", + "\n", + "The output impedance in ohm is 55.48 \n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E44 - Pg 44" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Exa 4.4\n", + "# Given data\n", + "h_ie = 1.1;# in k ohm\n", + "h_re = 2.5*10.**-4.;\n", + "h_fe = 50.;\n", + "h_oe = 25.*10.**-6.;# in A\n", + "V_CC = 15.;# in V\n", + "R1 = 20.;# in k ohm\n", + "R_C = 2.;# in k ohm\n", + "R2 = 10.;# in k ohm\n", + "R_S = 1.;# in k ohm\n", + "R_E = 1.;# in k ohm\n", + "# (i) Current Gain\n", + "Ai = -h_fe/(1. + h_oe*R_C*10.**3.);\n", + "print '%s %.2f %s' %(\"The current gain is\",Ai,\"\\n\");\n", + "# (ii) Input impedance\n", + "Zi = (h_ie*10**3) + (h_re*Ai*R_C*10**3);#in ohm\n", + "Zi = Zi * 10**-3;# in k ohm\n", + "print '%s %.2f %s' %(\"The input impedance in k ohm is\",Zi,\"\\n\");\n", + "# (iii) Voltage gain\n", + "A_V = (Ai*R_C)/Zi;\n", + "print '%s %.2f %s' %(\"The voltage gain is\",A_V,\"\\n\");\n", + "# (iv) Overall input impedance\n", + "R_B = (R1*R2)/(R1+R2);# in k ohm\n", + "Z_IS = (Zi*R_B)/(Zi+R_B);# in k ohm\n", + "print '%s %.2f %s' %(\"The overall input impedance in k ohm is\",Z_IS,\"\\n\");\n", + "# (v) Overall voltage gain\n", + "A_VS = A_V * (Z_IS/(Z_IS+R_S));\n", + "print '%s %.2f %s' %(\"The overall voltage gain is\",A_VS,\"\\n\");\n", + "# (vi) Overall current gain\n", + "A_IS =Ai*(R_B/(R_B+Zi));\n", + "print '%s %.2f %s' %(\"The overall current gain is\",A_IS,\"\\n\");\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The current gain is -47.62 \n", + "\n", + "The input impedance in k ohm is 1.08 \n", + "\n", + "The voltage gain is -88.50 \n", + "\n", + "The overall input impedance in k ohm is 0.93 \n", + "\n", + "The overall voltage gain is -42.56 \n", + "\n", + "The overall current gain is -41.00 \n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E5 - Pg 46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Exa 4.5\n", + "# Given data\n", + "h_ie = 1.1;# in k ohm\n", + "h_oe = 25.;# in A/V\n", + "h_oe = h_oe * 10.**-6.;# in A/V\n", + "h_fe = 50.;\n", + "h_re = 2.5*10.**-4.;\n", + "R_L = 1.6;# in ohm\n", + "R_S = 1.;# in k ohm\n", + "V_CC = 15.;# in V\n", + "# (i) Current Gain\n", + "Ai = -h_fe/(1. + (h_oe*R_L));\n", + "print '%s %.2f %s' %(\"The current gain is\",Ai,\"\\n\");\n", + "# (ii) Input impedance\n", + "Zi = (h_ie*10**3) + (h_re*Ai*R_L);# in ohm\n", + "Zi= Zi*10**-3;# in k ohm\n", + "print '%s %.2f %s' %(\"The input impedance in k ohm is\",Zi,\"\\n\");\n", + "Zi= Zi*10**3;# in ohm\n", + "# (iii) Voltage gain\n", + "A_V = Ai*R_L/Zi;\n", + "print '%s %.2f %s' %(\"The voltage gain is\",A_V,\"\\n\");\n", + "# (iv) Power gain\n", + "A_P = Ai*A_V;\n", + "print '%s %.2f %s' %(\"The power gain is\",A_P,\"\\n\");\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The current gain is -50.00 \n", + "\n", + "The input impedance in k ohm is 1.10 \n", + "\n", + "The voltage gain is -0.07 \n", + "\n", + "The power gain is 3.64 \n", + "\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example E6 - Pg 50" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Exa 4.6\n", + "# Given data\n", + "h_fe = 150.;\n", + "Beta_dc = h_fe;\n", + "h_ie = 1.*10.**3.;# in ohm\n", + "h_re = 0;\n", + "h_oe = 0;\n", + "V_CC = 18.;# in V\n", + "V_BE= 0.7;# in V\n", + "R1 = 100.*10.**3.;# in ohm\n", + "R2 = 50.*10.**3.;# in ohm\n", + "R_C = 1.*10.**3.;# in ohm\n", + "R_E = 0.5*10.**3.;# in ohm\n", + "V_Th = (V_CC/(R1+R2))*R2;# in V\n", + "R_Th =(R1*R2)/(R1+R2);# in ohm\n", + "# V_Th - I_B*R_Th - V_BE - (1+Beta)*-I_B*R_E = 0;\n", + "I_B = (V_Th-V_BE)/( R_Th + (1+Beta_dc)*R_E);# in A\n", + "#I_C = I_CQ = Beta*I_B;\n", + "I_C = Beta_dc*I_B;# in A\n", + "I_CQ = I_C;# in A\n", + "I_CQ= I_CQ*10.**3.;# in mA\n", + "print '%s %.2f %s' %(\"The value of I_CQ in mA is\",I_CQ,\"\\n\");\n", + "I_E = (1+Beta_dc)*I_B;# in mA\n", + "# V_CC - I_C*R_C - V_CE - I_E*R_E = 0;\n", + "V_CE = V_CC - (I_C*R_C) - (I_E*R_E);# in V\n", + "print '%s %.2f %s' %(\"The value of V_CE in V is\",V_CE,\"\\n\");\n", + "R_L =R_C;# in ohm\n", + "Ai = -h_fe/(1+(h_oe*R_L));\n", + "print '%s %.2f %s' %(\"The current gain is \",Ai,\"\\n\");\n", + "Zi = h_ie + h_re*Ai*R_L;# in ohm\n", + "Zi= Zi*10**-3;# in k ohm\n", + "print '%s %.2f %s' %(\"The input impedance in k ohm is\",Zi,\"\\n\");\n", + "Zi= Zi*10**3;# in ohm\n", + "A_V = Ai*(R_L/Zi);\n", + "print '%s %.2f %s' %(\"The voltage gain is\",A_V,\"\\n\");\n", + "R_B= (R1*R2)/(R1+R2);# in ohm\n", + "Z_IS =(Zi*R_B)/(Zi+R_B);# in ohm\n", + "Z_IS= Z_IS*10**-3;# in kohm\n", + "print '%s %.2f %s' %(\"The overall input impedance in k ohm is\",Z_IS,\"\\n\");\n", + "Z_IS= Z_IS*10**3;# in ohm\n", + "A_VS =A_V*(Z_IS/Z_IS);\n", + "print '%s %.2f %s' %(\"The overall voltage gain is\",A_VS,\"\\n\");\n", + "A_IS =Ai * (R_B/(R_B+Zi));\n", + "print '%s %.2f %s' %(\"The overall current gain is\",A_IS,\"\\n\");\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of I_CQ in mA is 7.30 \n", + "\n", + "The value of V_CE in V is 7.02 \n", + "\n", + "The current gain is -150.00 \n", + "\n", + "The input impedance in k ohm is 1.00 \n", + "\n", + "The voltage gain is -150.00 \n", + "\n", + "The overall input impedance in k ohm is 0.97 \n", + "\n", + "The overall voltage gain is -150.00 \n", + "\n", + "The overall current gain is -145.63 \n", + "\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/ajinkyakhair/chapter2.ipynb b/sample_notebooks/ajinkyakhair/chapter2.ipynb new file mode 100755 index 00000000..8b221e49 --- /dev/null +++ b/sample_notebooks/ajinkyakhair/chapter2.ipynb @@ -0,0 +1,240 @@ +{ + "metadata": { + "celltoolbar": "Raw Cell Format", + "name": "", + "signature": "sha256:4fe36e3e0da1a77ee9793bbcdad9ed8d44455b05327e70b42ad389ca8fb3e239" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 2: Semiconductor Physics" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.21.1,Page number 2-47" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Given Data:\n", + "\n", + "ro=1.72*10**-8 #resistivity of Cu\n", + "s=1/ro #conductivity of Cu\n", + "n=10.41*10**28 #no of electron per unit volume\n", + "e=1.6*10**-19 #charge on electron\n", + "\n", + "u=s/(n*e)\n", + "print\"mobility of electron in Cu =\",round(u,4),\"m**2/volt-sec\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "mobility of electron in Cu = 0.0035 m**2/volt-sec\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.21.2,Page number 2-47" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Given Data:\n", + "\n", + "m=63.5 #atomic weight\n", + "u=43.3 #mobility of electron\n", + "e=1.6*10**-19 #charge on electron\n", + "N=6.02*10**23 #Avogadro's number\n", + "d=8.96 #density\n", + "\n", + "Ad=N*d/m #Atomic density\n", + "n=1*Ad\n", + "\n", + "ro=1/(n*e*u)\n", + "\n", + "print\"Resistivity of Cu =\",\"{0:.3e}\".format(ro),\"ohm-cm\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Resistivity of Cu = 1.699e-06 ohm-cm\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.21.3,Page number 2-47" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Given Data:\n", + "\n", + "e=1.6*10**-19 #charge on electron\n", + "ne=2.5*10**19 #density of carriers\n", + "nh=ne #for intrinsic semiconductor\n", + "ue=0.39 #mobility of electron\n", + "uh=0.19 #mobility of hole\n", + "\n", + "s=ne*e*ue+nh*e*uh #conductivity of Ge\n", + "ro=1/s #resistivity of Ge\n", + "\n", + "print\"Resistivity of Ge =\",round(ro,4),\"ohm-m\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Resistivity of Ge = 0.431 ohm-m\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.21.6,Page number 2-49" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Given Data:\n", + "\n", + "c=5*10**28 #concentration of Si atoms\n", + "e=1.6*10**-19 #charge on electron\n", + "u=0.048 #mobility of hole\n", + "s=4.4*10**-4 #conductivity of Si\n", + "\n", + "#since millionth Si atom is replaced by an indium atom\n", + "\n", + "n=c*10**-6\n", + "sp=u*e*n #conductivity of resultant\n", + "\n", + "print\"conductivity =\",sp,\"mho/m\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "conductivity = 384.0 mho/m\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.21.7,Page number 2-49" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "#Given Data:\n", + "\n", + "m=28.1 #atomic weight of Si\n", + "e=1.6*10**-19 #charge on electron\n", + "N=6.02*10**26 #Avogadro's number\n", + "d=2.4*10**3 #density of Si\n", + "p=0.25 #resistivity\n", + "\n", + "#no. of Si atom/m**3\n", + "Ad=N*d/m #Atomic density\n", + "\n", + "#impurity level is 0.01 ppm i.e. 1 atom in every 10**8 atoms of Si\n", + "n=Ad/10**8 #no of impurity atoms\n", + "\n", + "#since each impurity produce 1 hole\n", + "nh=n\n", + "print\"1) hole concentration =\",\"{0:.3e}\".format(n),\"holes/m**3\"\n", + "up=1/(e*p*nh)\n", + "print\"2) mobility =\",round(up,4),\"m**2/volt.sec\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1) hole concentration = 5.142e+20 holes/m**3\n", + "2) mobility = 0.0486 m**2/volt.sec\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/kartiksankhla/Chapter2.ipynb b/sample_notebooks/kartiksankhla/Chapter2.ipynb new file mode 100755 index 00000000..21f2d4c4 --- /dev/null +++ b/sample_notebooks/kartiksankhla/Chapter2.ipynb @@ -0,0 +1,159 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:e984fee9b841dd6e9b7eedf1533b0a0d297cd9f484c047f051ce48a09b156826" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter2-Nuclear Engineering" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg54" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "## Example 2.1\n", + "import math\n", + "#determine atoms in deuterium\n", + "## Given data\n", + "atom_h = 6.6*10**24; ## Number of atoms in Hydrogen\n", + "## Using the data given in Table II.2, Appendix II for isotropic abundance of deuterium\n", + "isoab_H2 = 0.015; ## Isotropic abundance of deuterium\n", + "## Calculation\n", + "totatom_d=(isoab_H2*atom_h)/100.;\n", + "## Result\n", + "print\"%s %.2e %s \"%('\\n Number of deuterium atoms = ',totatom_d,'');\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Number of deuterium atoms = 9.90e+20 \n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg54" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "## Example 2.2\n", + "import math\n", + "#determine atomic weight of oxygen\n", + "## Given data \n", + "## Using the data given in the example 2.2\n", + "atwt_O16 = 15.99492; ## Atomic weight of O-16 isotope\n", + "isoab_O16 = 99.759; ## Abundance of O-16 isotope\n", + "atwt_O17 = 16.99913; ## Atomic weight of O-17 isotope\n", + "isoab_O17 = 0.037; ## Abundance of O-17 isotope\n", + "atwt_O18 = 17.99916; ## Atomic weight of O-18 isotope\n", + "isoab_O18 = 0.204; ## Abundance of O-18 isotope\n", + "## Calculation\n", + "atwt_O=(isoab_O16*atwt_O16 + isoab_O17*atwt_O17 + isoab_O18*atwt_O18)/100.;\n", + "## Result\n", + "print\"%s %.2f %s \"%('\\n Atomic Weight of Oxygen = ',atwt_O,'');\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Atomic Weight of Oxygen = 16.00 \n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg55" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "## Example 2.3\n", + "import math\n", + "#determine rest mass energy of electron\n", + "## Given data\n", + "me = 9.1095*10**(-28); ## Mass of electron in grams\n", + "c = 2.9979*10**10; ## Speed of light in vacuum in cm/sec\n", + "## Calculation\n", + "rest_mass = me*c**2;\n", + "## Result\n", + "print\"%s %.2e %s \"%('\\n Rest mass energy of electron = ',rest_mass,' ergs\\n');\n", + "print('Expressing the result in joules')\n", + "## 1 Joule = 10^(-7)ergs\n", + "rest_mass_j = rest_mass*10**(-7);\n", + "print\"%s %.2e %s \"%('\\n Rest mass energy of electron = ',rest_mass_j,' joules\\n');\n", + "print('Expressing the result in MeV')\n", + "## 1 MeV = 1.6022*10^(-13)joules\n", + "rest_mass_mev = rest_mass_j/(1.6022*10**(-13));\n", + "print\"%s %.2f %s \"%('\\n Rest mass energy of electron = ',rest_mass_mev,' MeV\\n');\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " Rest mass energy of electron = 8.19e-07 ergs\n", + " \n", + "Expressing the result in joules\n", + "\n", + " Rest mass energy of electron = 8.19e-14 joules\n", + " \n", + "Expressing the result in MeV\n", + "\n", + " Rest mass energy of electron = 0.51 MeV\n", + " \n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer).ipynb b/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer).ipynb new file mode 100755 index 00000000..b114e915 --- /dev/null +++ b/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer).ipynb @@ -0,0 +1,278 @@ +{ + "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": [ + "#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": [ + "#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": [ + "\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": [ + "#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": 6, + "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 \n", + "125.4\n" + ] + } + ], + "source": [ + "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 \\n\",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/kumargugloth/Chapter1.ipynb b/sample_notebooks/kumargugloth/Chapter1.ipynb new file mode 100755 index 00000000..df9ba4d0 --- /dev/null +++ b/sample_notebooks/kumargugloth/Chapter1.ipynb @@ -0,0 +1,348 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:84e452258bd05b64c16351467c4970051f4494cb47d7a832df03bdce07abddb8" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter1-Introduction" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + " #determine\n", + "##This numerical is Ex 1_1E,page 9.\n", + "Pso=20.5\n", + "Psc=20.5*550##converting hp to fps system\n", + "Qo=385.\n", + "Qc=385./449.##converting gpm to ft^3/s\n", + "E=0.83\n", + "dp=E*Psc/(Qc*144.)\n", + "print\"%s %.2f %s \"%('The pressure rise is ',dp,' psi')\n", + "print(\"After rounding off,pressure rise is 75.8 psi\")\n", + "dpr=75.8\n", + "dHw=75.8*144/62.4##62.4 is accelaration due to gravity in fps system\n", + "print\"%s %.2f %s \"%(' The head of water is ',dHw,' ft of water')\n", + "print(\"After rounding off the value of head of water the answer is 175 ft of water.\")\n", + "dhwr=175##rounded off value of head of water\n", + "sg=0.72##specific gravity of oil\n", + "dHo=dhwr/sg\n", + "print\"%s %.2f %s \"%(' The head of oil is ',dHo,' ft of oil')\n", + "print(\"After rounding off the value of head of oil the answer is 243 ft of oil.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The pressure rise is 75.79 psi \n", + "After rounding off,pressure rise is 75.8 psi\n", + " The head of water is 174.92 ft of water \n", + "After rounding off the value of head of water the answer is 175 ft of water.\n", + " The head of oil is 243.06 ft of oil \n", + "After rounding off the value of head of oil the answer is 243 ft of oil.\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math \n", + "#determine\n", + "##This numerical is Ex 1_1S,page 10.\n", + "E=0.83##efficiency\n", + "Ps=15300.\n", + "Q=87.4\n", + "Qs=87.4/3600.##flow rate in meter cube per sec\n", + "rho=998.\n", + "g=9.81\n", + "sg=0.72\n", + "dp=E*Ps/Qs\n", + "print\"%s %.2f %s \"%('\\n The change in pressure (dp)is ',dp,'')\n", + "dpr=523000##rounded value of dp\n", + "print(\"The rounded off value of dp is 523kPa.\")\n", + "dHw=dpr/(rho*g)\n", + "print\"%s %.2f %s \"%(' dHw is equal to ',dHw,' m of water')\n", + "print(\"The rounded off value of dHw is 53.4 m of water.\")\n", + "dHwr=53.4##rounded off value of dHw\n", + "print(\"Thus we can determine head of oil.\")\n", + "dHoil=dHwr/sg\n", + "print\"%s %.2f %s \"%(' dHoil is given by ',dHoil,' m of oil')\n", + "print(\"The rounded off value of dHoil is 74.2 m of oil.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + " The change in pressure (dp)is 523070.94 \n", + "The rounded off value of dp is 523kPa.\n", + " dHw is equal to 53.42 m of water \n", + "The rounded off value of dHw is 53.4 m of water.\n", + "Thus we can determine head of oil.\n", + " dHoil is given by 74.17 m of oil \n", + "The rounded off value of dHoil is 74.2 m of oil.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#determine\n", + "##This numerical is Ex 1_2E,page 10.\n", + "Q=12000.\n", + "A=3.5\n", + "rho_a=0.0762\n", + "E=0.85\n", + "r=2.5##resistance of duct system\n", + "V=Q/(60.*A)\n", + "print\"%s %.2f %s \"%('The air flow velocity at discharge is ',V,' ft/s')\n", + "KE=(rho_a*(V**2))/(32.2*2)\n", + "print\"%s %.2f %s \"%('\\n The product is ',KE,' lb/ft^2')\n", + "##PE=KE\n", + "Hv=KE/62.4\n", + "print\"%s %.2f %s \"%('\\n The dynamic head is ',Hv,' ft')\n", + "print(\"The value of dynamic head in inches of water is 0.74.\")\n", + "Hvi=0.74##Head in inches\n", + "Ht=r+Hvi\n", + "print\"%s %.2f %s \"%('\\n The total head is ',Ht,' inches of water')\n", + "p_tot=Ht*62.4\n", + "Ps=Q*p_tot/(60.*12.*E)\n", + "print\"%s %.2f %s \"%('\\n The shaft power is ',Ps,' ft-lb/s')\n", + "print(\"The shaft power is 7.2 hp.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The air flow velocity at discharge is 57.14 ft/s \n", + "\n", + " The product is 3.86 lb/ft^2 \n", + "\n", + " The dynamic head is 0.06 ft \n", + "The value of dynamic head in inches of water is 0.74.\n", + "\n", + " The total head is 3.24 inches of water \n", + "\n", + " The shaft power is 3964.24 ft-lb/s \n", + "The shaft power is 7.2 hp.\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##This numerical is Ex 1_2S,page 11.\n", + "Q=340.\n", + "A=0.325\n", + "V=Q/(60.*A)\n", + "print\"%s %.2f %s \"%('The air flow velocity at discharge is ',V,' m/s')\n", + "rho_a=1.22\n", + "Vr=17.4\n", + "Hd=(rho_a*(Vr**2))/2.\n", + "print\"%s %.2f %s \"%('\\n The dynamic pressure head is ',Hd,' Pa')\n", + "Hdr=184.7##rounded off value of Hd\n", + "rho_w=998.##density of water=rhow\n", + "g=9.81\n", + "H=0.0635\n", + "dp=rho_w*g*H##static pressure head\n", + "print\"%s %.2f %s \"%('\\n The static pressure head is ',dp,' Pa')\n", + "dpr=621.7\n", + "p_tot=Hdr+dpr\n", + "print\"%s %.2f %s \"%('\\n The total pressure head is ',p_tot,' Pa')\n", + "p_tot=806.4\n", + "E=0.85##efficiency\n", + "Ps=Q*p_tot/(60*E)\n", + "print\"%s %.2f %s \"%('\\n The shaft power is',Ps, 'W')\n", + "print(\"The shaft power is 5.376 kW.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The air flow velocity at discharge is 17.44 m/s \n", + "\n", + " The dynamic pressure head is 184.68 Pa \n", + "\n", + " The static pressure head is 621.69 Pa \n", + "\n", + " The total pressure head is 806.40 Pa \n", + "\n", + " The shaft power is 5376.00 W \n", + "The shaft power is 5.376 kW.\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#determine \n", + "import math\n", + "##This numerical is Ex 1_3E,page 11.\n", + "H=295.##net head in ft\n", + "Q=148.##water flow rate\n", + "n=1800.##rpm\n", + "E=0.87##efficiency\n", + "a=62.4##product of density and accelaration due to gravity\n", + "omega=(n*2.*math.pi)/60.\n", + "dp=a*H\n", + "print\"%s %.2f %s \"%('The pressure is ',dp,' lb/ft^2')\n", + "Ps=E*Q*dp\n", + "print\"%s %.2f %s \"%('\\n Output power is equal to ',Ps,' lb-ft/s')\n", + "print(\"The output output power can also be written as 2.37*10^6 lb-ft/s\")\n", + "print(\"Output power in terms of horsepower is given by 4309hp.\")\n", + "Psr=2370000##rounded off value of Ps\n", + "Torque=Psr/omega\n", + "print\"%s %.2f %s \"%(' The output torque is ',Torque,' lb-ft.')\n", + "print(\"The output torque can also be written as 12.57*10^3 lb-ft\")\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The pressure is 18408.00 lb/ft^2 \n", + "\n", + " Output power is equal to 2370214.08 lb-ft/s \n", + "The output output power can also be written as 2.37*10^6 lb-ft/s\n", + "Output power in terms of horsepower is given by 4309hp.\n", + " The output torque is 12573.24 lb-ft. \n", + "The output torque can also be written as 12.57*10^3 lb-ft\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex6-pg12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#determine c\n", + "import math\n", + "##This numerical is Ex 1_3S,page 12.\n", + "H=90.\n", + "Q=4.2##water flow rate(in m^3/s)\n", + "n=1800.\n", + "E=0.87##efficiency\n", + "rho=998.\n", + "g=9.81\n", + "omega=(n*2.*math.pi)/60.\n", + "dp=rho*g*H\n", + "print\"%s %.2f %s \"%('The pressure is ',dp,' N/m^2')\n", + "Ps=E*Q*dp\n", + "print\"%s %.2f %s \"%('\\n Output power is equal to ',Ps,' N-m/s')\n", + "print(\"After rounding off the value of output power is 3220 kW.\")\n", + "Psr=3220000.##rounded off value of Ps\n", + "Torque=Psr/omega\n", + "print\"%s %.2f %s \"%(' The output torque is ',Torque,' N-m.')\n", + "print(\"After rounding off the output torque comes out to be 17.1*10^3 N-m.\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The pressure is 881134.20 N/m^2 \n", + "\n", + " Output power is equal to 3219664.37 N-m/s \n", + "After rounding off the value of output power is 3220 kW.\n", + " The output torque is 17082.63 N-m. \n", + "After rounding off the output torque comes out to be 17.1*10^3 N-m.\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/nemichand /Chapter1_1.ipynb b/sample_notebooks/nemichand /Chapter1_1.ipynb new file mode 100755 index 00000000..43f5bce4 --- /dev/null +++ b/sample_notebooks/nemichand /Chapter1_1.ipynb @@ -0,0 +1,227 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:60b1203d60983bbbb28528cd720bc31b7ac71ec9fc83b7d2e5e78e90b9f2b472" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter1-Introduction" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + "\n", + "#calculate the steady state\n", + "\n", + "\n", + "##The thickness of the slab(L) is 80mm or .08m\n", + "##The thermal conductivity(k)of the material is .20 W/(m*K)\n", + "T1=40.;\n", + "T2=20.;\n", + "L=.08;\n", + "k=.20;\n", + "##The steady state heat transfer rate per unit area through the thick slab is given by q=k(T1-T2)/L\n", + "print(\"The steady state heat transfer rate per unit area through the thick slab is given by q=k(T1-T2)/L in W/m^2 \")\n", + "q=k*(T1-T2)/L\n", + "print(q)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The steady state heat transfer rate per unit area through the thick slab is given by q=k(T1-T2)/L in W/m^2 \n", + "50.0\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + "#calculate the thickness of masonry wall\n", + "print(\"Introduction to heat transfer by S.K.Som, Chapter 1, Example 2\")\n", + "##The thermal conductivity(km)of masonry wall is .8 W/(mK)\n", + "##The thermal conductivity(kc)of composite wall is .2 W/(mK)\n", + "##The thickness of composite wall(Lc) is 100 mm or .1 m\n", + "km=.8;\n", + "kc=.2;\n", + "Lc=.1;\n", + "##The thickness of masonry wall(Lm) is to be found. \n", + "##The steady state heat flow(qm)through masonry wall is km(T1-T2)/L\n", + "## The steady state heat flow(qc)through composite wall is kc(T1-T2)/L\n", + "##As the steady rate of heat flow through masonry wall is 80% that through composite wall and both the wall have same surface area and same temp. difference so qm/qc=0.8=(km/kc)*(Lc/Lm)\n", + "##The thickness of masonry wall is Lm.\n", + "print (\"The thickness of masonry wall is Lm in m\")\n", + "Lm=(km/kc)*(Lc/(0.8))\n", + "print(Lm)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Introduction to heat transfer by S.K.Som, Chapter 1, Example 2\n", + "The thickness of masonry wall is Lm in m\n", + "0.5\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "## printlay warning for floating point exception\n", + "print(\"Introduction to heat transfer by S.K.Som Chapter 1 Example 4\")\n", + "hbr=200.;\n", + "Tinf=100.;\n", + "Ts=20.;\n", + "##The rate of heat transfer per unit area is q\n", + "print (\"The rate of heat transfer per unit area q=hbr*(Tinf-Ts) in W/m^2\")\n", + "q=hbr*(Tinf-Ts)\n", + "print(q)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Introduction to heat transfer by S.K.Som Chapter 1 Example 4\n", + "The rate of heat transfer per unit area q=hbr*(Tinf-Ts) in W/m^2\n", + "16000.0\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + "#calculat e surface area\n", + "print(\"Introduction to heat transfer by S.K.Som, Chapter 1, Example 5\")\n", + "\n", + "hbr=800.;\n", + "deltaT=(75.-25.);\n", + "Q=20.;\n", + "print(\"The heat exchanger surface area(A)in m^2 required for 20 MJ/h of heating is \")\n", + "A = (Q*10**6.)/(3600.*hbr*deltaT)\n", + "print round(A,2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Introduction to heat transfer by S.K.Som, Chapter 1, Example 5\n", + "The heat exchanger surface area(A)in m^2 required for 20 MJ/h of heating is \n", + "0.14\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex6-pg37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##The ambient temprature (Tinf) \n", + "print(\"Introduction to heat transfer by S.K.Som, Chapter 1, Example 6\")\n", + "Ts=225.;\n", + "Tinf=25.;\n", + "## |because it is modulus function and it converts negative values to positive value.\n", + "X=0.02;\n", + "A=.1;\n", + "m=4;\n", + "cp=2.8;\n", + "hbr=(m*cp*10**3*X)/(A*(Ts-Tinf))\n", + "print round(hbr,2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Introduction to heat transfer by S.K.Som, Chapter 1, Example 6\n", + "11.2\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/saikiranm/CHAPTER4.ipynb b/sample_notebooks/saikiranm/CHAPTER4.ipynb new file mode 100755 index 00000000..951201ff --- /dev/null +++ b/sample_notebooks/saikiranm/CHAPTER4.ipynb @@ -0,0 +1,196 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:77734ce79918b96bed43d7baa269682912f0f51f73bf77fadd993778504d6908" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 4 - Characteristics of AC motor" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.1 - PG NO:72" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.1, Page 72\n", + "import numpy\n", + "p1=numpy.poly1d([1, -3, 1])#Polynomial equation\n", + "print('Part a')\n", + "print('roots of the equation when slip at max torque')\n", + "x=numpy.roots(p1)\n", + "print(x)\n", + "\n", + "\n", + "p2=numpy.poly1d([1, -1.719,0.146])#polynomial equation in scilab function\n", + "y=numpy.roots(p2)\n", + "print('Part b')\n", + "print('roots of the equation when slip at max load')\n", + "print(y)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part a\n", + "roots of the equation when slip at max torque\n", + "[ 2.61803399 0.38196601]\n", + "Part b\n", + "roots of the equation when slip at max load\n", + "[ 1.62939626 0.08960374]\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.3 - PG NO:76" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.3, Page 76\n", + "import numpy\n", + "p1=numpy.poly1d([0.04, -0.0266,.0016 ])#Polynomial equation\n", + "print('Part a')\n", + "print('roots of the equation that slip will run is')\n", + "x=numpy.roots(p1)\n", + "print(x)\n", + "#answers after calculation are accurate than textbook answers due to approximations" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part a\n", + "roots of the equation that slip will run is\n", + "[ 0.59812426 0.06687574]\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.5 - PG NO:81" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.5, page 81\n", + "import math\n", + "pole=24.\n", + "Ns=245.#in rpm\n", + "N=(120.*50.)/pole#synchronous speed in rpm\n", + "f=(N-Ns)/N\n", + "p=110.#in kw\n", + "T=(p*1000.*60.)/(2.*math.pi*Ns)\n", + "v1=440./math.sqrt(3)#in v\n", + "ws=(2*math.pi*250)/60\n", + "s=0.02\n", + "R=0.03125#in ohm\n", + "x=math.sqrt(((3*R*v1**2)/(T*ws*s))-(R/s)**2)#by rearranging formula\n", + "print'%s %.5f %s' %('Stator resistance per phase is=',x,'ohm')\n", + "#calculating original resistance\n", + "\n", + "#Example 4.1, Page 72\n", + "import numpy\n", + "p1=numpy.poly1d([3190,-3235,72.78 ])#Polynomial equation\n", + "print('Part a')\n", + "print('The value of original resistance is')\n", + "x=numpy.roots(p1)\n", + "print(x)\n", + "\n", + "#Taking r=0.99108\n", + "r=(0.99108-R)/1.25**2\n", + "\n", + "print'%s %.4f %s' %('The value of resistance to be added is =',r,' ohm')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Stator resistance per phase is= 0.50358 ohm\n", + "Part a\n", + "The value of original resistance is\n", + "[ 0.99108634 0.02302024]\n", + "The value of resistance to be added is = 0.6143 ohm\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE 4.6 - PG NO:92" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Example 4.6, Page no 92\n", + "import math\n", + "print(\"Part ii\")\n", + "new_sin_delta=math.sin(math.pi/4)/.95\n", + "delta=math.asin(new_sin_delta)\n", + "x=math.degrees(delta)\n", + "print'%s %.2f %s' %('The value of delta is =',x,'degree')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Part ii\n", + "The value of delta is = 48.10 degree\n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/saikomalchanagam/AKmaini_(1).ipynb b/sample_notebooks/saikomalchanagam/AKmaini_(1).ipynb new file mode 100755 index 00000000..71b9c040 --- /dev/null +++ b/sample_notebooks/saikomalchanagam/AKmaini_(1).ipynb @@ -0,0 +1,293 @@ +{ + "metadata": { + "name": "AKmaini" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": "Chapter 11: Satellites and Satellite Communications\n" + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 1, Pg No: 567" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math\n\n# Variable Declaration\nh = 150; # height of satellite from earth in km\nG = 6.67*10**-11; # Gravitational constant\nM = 5.98*10**24; # mass of the earth in kg\nRe = 6370; # radius of earth in km\n\n# Calculations\nu = G*M\nV = math.sqrt(u/((Re + h)*10**3)) # orbital velocity\nV1 = V/1000; # orbital velocity in km/s\n\n# Result\nprint 'Orbital velocity = %3.3f'%V1,'km/s';", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Orbital velocity = 7.821 km/s\n" + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 2, Pg No: 568" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\nAp_Pe_diff = 30000; # difference between apogee and perigee in Km\na = 16000; # semi major axis of orbit\n\n# Calculations\ne = Ap_Pe_diff/float(2*a); # Eccentricity\n\n# Result\nprint 'Eccentricity = %3.2f'%e;", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Eccentricity = 0.94\n" + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 3, Pg No:568" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Decalaration\na1 = 18000; # semi major axis of the elliptical orbits of satellite 1\na2 = 24000; # semi major axis of the elliptical orbits of satellite 2\n\n# Calculations\n#T = 2*%pi*sqrt(a^3/u);\n#let K = T2/T1;\nK = (float(a2)/a1)**(3/float(2)); # Ratio of orbital periods\n\n# Result\nprint 'The orbital period of satellite-2 is %3.2f' %K,' times the orbital period of satellite-1';\n", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "The orbital period of satellite-2 is 1.54 times the orbital period of satellite-1\n" + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 4, Pg No:569" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\n\nh = 35800; # height of satellite orbit from earth in km\nG = 6.67*10**-11; # Gravitational constant\nM = 5.98*10**24; # mass of the earth in kg\nRe = 6364; # radius of earth in km\ni = 2; # inclination angle\n\n# Calculations\nu = G*M\nr = Re+h\nVi = math.sqrt(u/r*10**3)* math.tan(i*math.pi/180); # magnitude of velocity impulse\nV = Vi/1000; # magnitude of velocity impulse in m/s\n\n#Result\nprint 'Magnitude of velocity impulse = %d' %V,' m/s';", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Magnitude of velocity impulse = 107 m/s\n" + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 5, Pg No: 571" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\nh = float(13622); # ht of circular orbit from earth's surface\nRe = 6378; # Radius of earth in km\n\n# Calculations\nR = Re+h; # Radius of circular orbit\npimax = 180 - (2*math.acos(Re/R))*(180/math.pi); # Maximum shadow angle\neclipmax_time = (pimax/360)*24; # maximum daily eclipse duration\n\n# Result\nprint ' Maximum shadow angle = %3.1f\u00b0' %pimax\nprint ' Maximum daily eclipse duration = %3.2f'%eclipmax_time,' hours';", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": " Maximum shadow angle = 37.2\u00b0\n Maximum daily eclipse duration = 2.48 hours\n" + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 6, Pg No:572" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math\n\n# Variable Declaration\n\nh = 35786; # ht of geo.stationary orbit above earth surface\nT = 365; # time in days\nr = 6378 # radius of earth in km\n\n# ie(t) = 23.4*sin(2*%pi*t/T)\n# for a circular orbit of 20000 km radius ,phi = 37.4\u00b0 ,Therefore, the time from first day of eclipse to equinox is given by substituting ie(t) = 37.4/2 = 18.7\u00b0\nphi = 37.4\nie = (phi/2)*(math.pi/180)\nk = 23.4*(math.pi/180)\nt = (365/(2*math.pi))*math.asin((ie/k)) \n# for geostationary orbit\nphimax = 180 - 2*(math.acos(r/(r+h)))*(180/math.pi)\nt_geo = (365/(2*math.pi))*math.asin((8.7*math.pi/180)/k)\n\n# Result\nprint 'Total time from first day of eclipse to last day of eclipse = %3.1f' %t,' days';\nprint 'Total time from first day of eclipse to last day of eclipse for geostationary orbit = %3.2f' %t_geo, 'days'", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Total time from first day of eclipse to last day of eclipse = 53.8 days\nTotal time from first day of eclipse to last day of eclipse for geostationary orbit = 22.13 days\n" + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 7, Pg No:600" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\nm = 100; # mass of satellite\nV = 8000; # orbital velocity in m/s\nRe = 6370; # radius of earth in Km\nH = 200; # satellite height above earth surface\n\n# Calculations\nCF = (m*V**2)/((Re+H)*10**3); #centrifugal force\n\n# Result\nprint 'Centrifugal Force = %d' %CF,' Newtons';", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Centrifugal Force = 974 Newtons\n" + } + ], + "prompt_number": 25 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 8, Pg No:601" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\n\nApogee = 30000; # Apogee pt of satellite elliptical orbit\nPerige = 1000; # perigee pt of satellite elliptical orbit\n\n# Calculations\na = (Apogee + Perige)/2; # semi major axis\n\n# Result\nprint 'Semi-major axis = %d' %a,' Km';", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Semi-major axis = 15500 Km\n" + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 9, Pg No:603" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math\n\n# Variable Declaration\nfarth = 30000; # farthest point in satellite elliptic eccentric orbit\nclosest = 200; # closest point in satellite elliptic eccentric orbit\nRe = float(6370); # Radius of earth in km\n\n# Calculations\nApogee = farth + Re; # Apogee in km\nPerigee = closest + Re; # perigee in km\na = (Apogee + Perigee)/(2); # semi-major axis\ne = (Apogee - Perigee)/(2*a); # orbit eccentricity\n\n# Result\nprint 'Apogee = %d' %Apogee,' km';\nprint 'Perigee = %d' %Perigee,' km';\nprint 'Orbit eccentricity = %3.3f' %e;", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Apogee = 36370 km\nPerigee = 6570 km\nOrbit eccentricity = 0.694\n" + } + ], + "prompt_number": 29 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 10, Pg No:604" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\ne = 0.5; # orbit eccentricity\nae = 14000; # from fig. the distance from center of ellipse to the centre of earth\n\n# Calculations\na = ae/(e); # semi major axis\napogee = a*(1 + e); # Apogee in km\nperige = a*(1 - e); # perigee in km\n\n# Result\nprint 'Apogee = %d' %apogee,' km'\nprint 'Perigee = %d' %perige,' km'", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Apogee = 42000 km\nPerigee = 14000 km\n" + } + ], + "prompt_number": 34 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 11, Pg No:604" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\nG = 6.67*10**-11; # Gravitational constant\nM = 5.98*10**24; # mass of the earth in kg\nRe = 6370*10**3; # radius of earth in m\n\n# Calculations\nu = G*M\nVesc = math.sqrt(2*u/Re);\nVes = Vesc/1000; # escape velocity in km/s\n\n# Result\nprint 'Escape velocity = %3.1f' %Ves,' km/s';", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Escape velocity = 11.2 km/s\n" + } + ], + "prompt_number": 36 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 12, Pg No:605" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# variable Declartion\na = 25000*10**3; # semimajor axis in m from fig\nG = 6.67*10**-11; # Gravitational constant\nM = 5.98*10**24; # mass of the earth in kg\nh = 0\n\n# Calculations\nu = G*M;\nT = 2*math.pi*math.sqrt((a**3)/u)\nhr = T/3600 # conv. from sec to hrs and min\nt = T%3600 # conv. from sec to hrs and min\nmi = t/60 # conv. from sec to hrs and min\n\n# Result\nprint 'Orbital time period = %d' %hr,' Hours',' %d'%mi, 'minutes'", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Orbital time period = 10 Hours 55 minutes\n" + } + ], + "prompt_number": 41 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": "Example 13, Pg No:605" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "import math;\n\n# Variable Declaration\napogee = float(35000); # farthest point in kms\nperigee = 500; # closest point in kms\nr = float(6360); # radius of earth in kms\nG = 6.67*10**-11 # gravitational constant\nM = 5.98*10**24; # mass of earth in kgs\n\n# calculations\n#funcprot(0)\napogee_dist = apogee + r # apogee distance in kms\nperigee_dist= perigee+r ; # perigee distance in kms\na = (apogee_dist + perigee_dist)/2; # semi-major axis of elliptical orbit\nT = (2*math.pi)*math.sqrt((a*10**3)**3/(G*M)); # orbital time period\nhr = T/3600 # conv. from sec to hrs and min\nt = (T%3600) # conv. from sec to hrs and min\nmi = t/60 # conv. from sec to hrs and min\nu = G*M\nVapogee = math.sqrt(u*((2/(apogee_dist*10**3)) - (1/(a*10**3))))/1000; # velocity at apogee point\nVperigee = math.sqrt((G*M)*((2/(perigee_dist*10**3)-(1/(a*10**3)))))/1000 # velocity at perigee point\n\n#Result\nprint 'Orbital Time Period = %d'%hr,' Hrs'' %d'%mi,' min'\nprint 'Velocity at apogee = %3.3f' %Vapogee,' Km/s'\nprint'Velocity at perigee = %3.3f' %Vperigee,' Km/s'\nprint'Note: Calculation mistake in textbook in finding velocity at apogee point'\n", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Orbital Time Period = 10 Hrs 20 min\nVelocity at apogee = 1.656 Km/s\nVelocity at perigee = 9.987 Km/s\nNote: Calculation mistake in textbook in finding velocity at apogee point\n" + } + ], + "prompt_number": 57 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/sample_notebooks/vinodkumar/Chapter1.ipynb b/sample_notebooks/vinodkumar/Chapter1.ipynb new file mode 100755 index 00000000..0225739c --- /dev/null +++ b/sample_notebooks/vinodkumar/Chapter1.ipynb @@ -0,0 +1,339 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:cd92732b89aba9dec0c4f42de79fa75bac0a4c551a65b1e08ee3d7196bca88ee" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter1-Basic Circuit Concepts" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex1-pg9" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##Basic Circuit Concepts\n", + "##page no-1.9\n", + "##example1.1\n", + "print(\"Current through 15Ohm resistor is given by:\");\n", + "print(\"I1=30/15\");\n", + "I1=30/15\n", + "print\"%s %.2f %s \"%(\"current through 15Ohm resistor = \",I1,\" Ampere\")\n", + "print(\"Current through 5Ohm resistor is given by:\")\n", + "print(\"I2=5+2\");\n", + "I2=5+2\n", + "print\"%s %.2f %s \"%(\"current through 5ohm resistor = \",I2,\" Ampere\")\n", + "print(\"R=100-30-5*I2/I1\");\n", + "R=(100-30-5*I2)/I1\n", + "print\"%s %.2f %s \"%(\"R = \",R,\" Ohm\");" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Current through 15Ohm resistor is given by:\n", + "I1=30/15\n", + "current through 15Ohm resistor = 2.00 Ampere \n", + "Current through 5Ohm resistor is given by:\n", + "I2=5+2\n", + "current through 5ohm resistor = 7.00 Ampere \n", + "R=100-30-5*I2/I1\n", + "R = 17.00 Ohm \n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex2-pg10" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##Basic Circuit Concepts\n", + "##page no-1.10\n", + "##example1.2\n", + "import math\n", + "import numpy\n", + "print(\"from the given fig:\")\n", + "print(\"I2-I3=13\");\n", + "print(\"-20*I1+8*I2=0\");\n", + "print(\"-12*I1-16*I3=0\");\n", + "##solving these equations in the matrix form\n", + "A=numpy.matrix([[0, 1 ,-1],[-20, 8, 0],[-12 ,0 ,-16]])\n", + "B=numpy.matrix([[13], [0] ,[0]])\n", + "print(\"A=\")\n", + "print[A]\n", + "print(\"B=\")\n", + "print[B]\n", + "X=numpy.dot(numpy.linalg.inv(A),B)\n", + "print(\"X=\")\n", + "print[X]\n", + "print(\"I1 = 4Ampere\")\n", + "print(\"I2 = 10Ampere\")\n", + "print(\"I3 = -3Ampere\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "from the given fig:\n", + "I2-I3=13\n", + "-20*I1+8*I2=0\n", + "-12*I1-16*I3=0\n", + "A=\n", + "[matrix([[ 0, 1, -1],\n", + " [-20, 8, 0],\n", + " [-12, 0, -16]])]\n", + "B=\n", + "[matrix([[13],\n", + " [ 0],\n", + " [ 0]])]\n", + "X=\n", + "[matrix([[ 4.],\n", + " [ 10.],\n", + " [ -3.]])]\n", + "I1 = 4Ampere\n", + "I2 = 10Ampere\n", + "I3 = -3Ampere\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex3-pg11" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##Basic Circuit Concepts\n", + "##pg no-1.11\n", + "##example 1.3\n", + "print(\"Iaf=x\")\n", + "print(\"Ife=x-30\")\n", + "print(\"Ied=x+40\")\n", + "print(\"Idc=x-80\")\n", + "print(\"Icb=x-20\")\n", + "print(\"Iba=x-80\")\n", + "print(\"Applying KVL to the closed path AFEDCBA:\")##Applying KVL to the path AFEDCBA\n", + "print(\"x=4.1/0.1\")\n", + "x=4.1/0.1;\n", + "Iaf=x;\n", + "print\"%s %.2f %s \"%(\"\\nIaf = \",Iaf,\" Ampere\");\n", + "Ife=x-30.\n", + "print\"%s %.2f %s \"%(\"\\nIfe = \",Ife,\" Ampere\");\n", + "Ied=x+40.;\n", + "print\"%s %.2f %s \"%(\"\\nIed = \",Ied,\" Ampere\");\n", + "Idc=x-80;\n", + "print\"%s %.2f %s \"%(\"\\nIdc = \",Idc,\" Ampere\");\n", + "Icb=x-20.;\n", + "print\"%s %.2f %s \"%(\"\\nIcb = \",Icb,\" Ampere\");\n", + "Iba=x-80.;\n", + "print\"%s %.2f %s \"%(\"\\nIba = \",Iba,\" Ampere\");" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Iaf=x\n", + "Ife=x-30\n", + "Ied=x+40\n", + "Idc=x-80\n", + "Icb=x-20\n", + "Iba=x-80\n", + "Applying KVL to the closed path AFEDCBA:\n", + "x=4.1/0.1\n", + "\n", + "Iaf = 41.00 Ampere \n", + "\n", + "Ife = 11.00 Ampere \n", + "\n", + "Ied = 81.00 Ampere \n", + "\n", + "Idc = -39.00 Ampere \n", + "\n", + "Icb = 21.00 Ampere \n", + "\n", + "Iba = -39.00 Ampere \n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex4-pg12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##Basic Circuit Concepts\n", + "##pg no- 1.12\n", + "##example 1.4\n", + "import math\n", + "import numpy\n", + "print(\"Applying KVL to the closed path OBAO\");##Applying KVL to the closed path OBAO\n", + "print(\"3*x-3*y=2\");\n", + "print(\"Applying KVL to the closed path ABCA\");##Applying KVL to the closed path ABCA\n", + "print(\"9*x+12*y=4\");\n", + "a=numpy.matrix([[3, -3],[9, 12]]);\n", + "b=([[2] ,[4]])\n", + "print(\"a=\")\n", + "print[a]\n", + "print(\"b=\")\n", + "print[b]\n", + "X=numpy.dot(numpy.linalg.inv(a),b)\n", + "\n", + "print(X)\n", + "print(\"x=0.5714286 Ampere\");\n", + "print(\"y=-0.095238 Ampere\");\n", + "print(\"Ioa=0.57A\")\n", + "print(\"Iob=1-0.57\")\n", + "Iob=1-0.57;\n", + "print\"%s %.2f %s \"%(\"\\nIob = \",Iob,\" A\");\n", + "print(\"Iab = 0.095\");\n", + "Iac=0.57-0.095;\n", + "print\"%s %.2f %s \"%(\"\\nIac =\",Iac,\" A\");\n", + "print(\"Iab=1-0.57 + 0.095\")\n", + "Iab=1-0.57 + 0.095;\n", + "print\"%s %.2f %s \"%(\"\\nIob = \",Iab,\" A\") " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Applying KVL to the closed path OBAO\n", + "3*x-3*y=2\n", + "Applying KVL to the closed path ABCA\n", + "9*x+12*y=4\n", + "a=\n", + "[matrix([[ 3, -3],\n", + " [ 9, 12]])]\n", + "b=\n", + "[[[2], [4]]]\n", + "[[ 0.57142857]\n", + " [-0.0952381 ]]\n", + "x=0.5714286 Ampere\n", + "y=-0.095238 Ampere\n", + "Ioa=0.57A\n", + "Iob=1-0.57\n", + "\n", + "Iob = 0.43 A \n", + "Iab = 0.095\n", + "\n", + "Iac = 0.47 A \n", + "Iab=1-0.57 + 0.095\n", + "\n", + "Iob = 0.53 A \n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Ex5-pg12" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "##Basic Circuit Concepts\n", + "##pg no-1.12\n", + "##example 1.5\n", + "I1=2./5.;\n", + "print\"%s %.2f %s \"%(\"I1=2/5= \",I1,\" Ampere\")\n", + "I2=4./8.;\n", + "print\"%s %.2f %s \"%(\"\\nI2=4/8= \",I2,\" Ampere\")\n", + "print(\"\\nPotential difference between points x and y = Vxy = Vx-Vy\")\n", + "print(\"\\nWriting KVL equations for the path x to y\")##Writing KVL equation from x to y\n", + "print(\"\\nVs+3*I1+4-3*I2-Vy=0\")\n", + "print(\"\\nVs+3*(0.4) + 4- 3*(0.5) -Vy = 0\")\n", + "print(\"\\nVs+3*I1+4-3*I2-Vy = 0\")\n", + "print(\"\\nVx-Vy = -3.7\")\n", + "print(\"\\nVxy = -3.7V\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "I1=2/5= 0.40 Ampere \n", + "\n", + "I2=4/8= 0.50 Ampere \n", + "\n", + "Potential difference between points x and y = Vxy = Vx-Vy\n", + "\n", + "Writing KVL equations for the path x to y\n", + "\n", + "Vs+3*I1+4-3*I2-Vy=0\n", + "\n", + "Vs+3*(0.4) + 4- 3*(0.5) -Vy = 0\n", + "\n", + "Vs+3*I1+4-3*I2-Vy = 0\n", + "\n", + "Vx-Vy = -3.7\n", + "\n", + "Vxy = -3.7V\n" + ] + } + ], + "prompt_number": 5 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file -- cgit