summaryrefslogtreecommitdiff
path: root/Antenna_and_Wave_Propagation/chapter2.ipynb
blob: fd9e78b2e715bc59bbc97e7a6a36353e7eb2ab4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 : Maxwell's Equations and Electromagnetic Waves"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8,Page Number 112"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "magnetic field in region 2 in A/m: [ 2.4  1.5 -3. ]\n",
      "magnitude of magnetic field in region 2 in A/m: 4.124\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "from math import pi\n",
    "\n",
    "#variable delaration\n",
    "mu_0 = 4*pi*10**(-7)  #  permeability in free space\n",
    "mu_r1 = 3  #  region 1 relative permeability\n",
    "mu_r2 = 5  #  region 2 relative permeability\n",
    "mu_1 = mu_r1*mu_0  #  region 1 permeability\n",
    "mu_2 = mu_r2*mu_0  #  region 2 permeability\n",
    "\n",
    "#calculations\n",
    "H1  = np.array([4,1.5,-3])  #  magnetic field in region 1 in A/m\n",
    "Ht1 = np.array([0,1.5,-3])  #  tangential component of magnetic field H1\n",
    "Hn1 = np.array([4,0,0])     #  normal component of magnetic field H1\n",
    "Ht2 = np.array([0,1.5,-3])  #  as tangential componenet of magnetic field H2 = tangential component of magnetic field H1\n",
    "Hn2 = (mu_1/mu_2)*Hn1       #  normal component of magnetic field H2\n",
    "H2  = Ht2+Hn2               #  magnetic field in region 2 in A/m\n",
    "h2  = np.linalg.norm(H2)    #  magnitude of the magnetic field H2 in A/m\n",
    "\n",
    "#results\n",
    "print \"magnetic field in region 2 in A/m:\",np.around(H2,2)\n",
    "print \"magnitude of magnetic field in region 2 in A/m:\",round(h2,3) \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.9,Page Number 113"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "electric field in region 2 in V/m: [ 0.5  2.   3. ]\n",
      "electric flux density in region 2 in C/m**2: [  8.85400000e-12   3.54160000e-11   5.31240000e-11]\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "\n",
    "#variable Declaration\n",
    "epsilon_0 = 8.854*10**(-12) # permittivity in free space\n",
    "sigma_1 = 0 #conductivity of medium 1\n",
    "sigma_2 = 0 #conductivity of medium 2\n",
    "epsilon_r1 = 1 # region 1 relative permittivity\n",
    "epsilon_r2 = 2 # region 2 relative permittivity\n",
    "\n",
    "#calculations\n",
    "epsilon_1 = epsilon_r1*epsilon_0 # region 1 permittivity\n",
    "epsilon_2 = epsilon_r2*epsilon_0 # region 2 permittivity\n",
    "E1  = np.array([1,2,3])  # Electric field in region 1 in V/m\n",
    "Et1 = np.array([0,2,3])  # tangential component of electric field E1\n",
    "En1 = np.array([1,0,0])  # normal component of electric field E1\n",
    "Et2 = np.array([0,2,3])  # as tangential componenet of electric field E2 = tangential component of electric field E1\n",
    "En2 = (epsilon_1/epsilon_2)*En1 # normal component of electric field E2\n",
    "E2  = Et2+En2 # electric field in region 2 in V/m\n",
    "Dt1 = epsilon_0*Et1  # tangential component of electric flux density D1\n",
    "D2  = epsilon_2*E2   # electric flux density in region 2 in C/m**2\n",
    "\n",
    "\n",
    "#Results\n",
    "print \"electric field in region 2 in V/m:\",np.around(E2,2)\n",
    "print \"electric flux density in region 2 in C/m**2:\",D2 \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.12,Page Number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "eta_0 =  E/H  =  377*cos(10**8*t-Beta*z)/cos(10**8*t-Beta*z)  = > E/H = 377\n",
      "intrinsic impedence in ohm: 377\n",
      "frequency in MHz: 15.915\n",
      "phase constant in rad/m: 0.333\n",
      "wavelength in m: 18.85\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "from math import pi\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "#  H = cos(10**8*t-Beta*z)ay       #  magnetic field in A/m\n",
    "#  E = 377*cos(10**8*t-Beta*z)ax   #  electric field in V/m\n",
    "omega = 10**8    #  angular frequency in Hz\n",
    "v_0 = 3*10**8    #  speed of light in m/s\n",
    "\n",
    "\n",
    "#calculations\n",
    "f = omega/(2*pi) #  frequency in Hz\n",
    "lamda = v_0/f    #  wavelength in m\n",
    "Beta = (2*pi)/lamda #  phase constant in rad/m\n",
    "print \"eta_0 =  E/H  =  377*cos(10**8*t-Beta*z)/cos(10**8*t-Beta*z)  = > E/H = 377\"\n",
    "eta_0 = abs(377) #  intrinsic impedence in ohm\n",
    "\n",
    "\n",
    "\n",
    "#Results\n",
    "print \"intrinsic impedence in ohm:\",eta_0\n",
    "print \"frequency in MHz:\",round(f/(10**6),3)\n",
    "print \"phase constant in rad/m:\",round(Beta,3)\n",
    "print \"wavelength in m:\",round(lamda,3)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.14,Page Number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "propagation constant in m**-1: 2.094j\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "import numpy as np\n",
    "\n",
    "#Variable Declaration\n",
    "f = 100        #  frequency in MHz\n",
    "f = 100*10**6  #  frequency in Hz\n",
    "v_0=3*10**8    #  speed of light in m/s\n",
    "\n",
    "\n",
    "#  formula : Gamma = omega(j)*sqrt(mu_0*epsilon_0)=omega(j)/v_0 =(2j*pi*f)/v_0\n",
    "Gamma =(2j*pi*f)/(v_0)  # propagation constant\n",
    "\n",
    "\n",
    "#result\n",
    "print \"propagation constant in m**-1:\",np.around(Gamma,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.15,Page Number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "amplitude of the magnetic field in A/m: 48\n",
      "frequency in MHz: 15.915\n",
      "phase constant in rad/m: 40.0\n",
      "wavelength in m: 0.157\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "# H(z,t) =  48*cos(10**8*t+40*z)ay  #  equation of magnetic field \n",
    "A = 48  #  amplitude of the magnetic field in A/m\n",
    "omega = 10**8  #  angular frequency in radians/sec\n",
    "Beta = 40  #  phase constant in rad/m\n",
    "\n",
    "#Calculations\n",
    "f = omega/(2*pi)  #  frequency in Hz\n",
    "lamda = (2*pi)/Beta  #  wavelength in m\n",
    "\n",
    "\n",
    "#results\n",
    "print \"amplitude of the magnetic field in A/m:\",A\n",
    "print \"frequency in MHz:\",round(f/10**6,3)\n",
    "print \"phase constant in rad/m:\",round(Beta,3)\n",
    "print \"wavelength in m:\",round(lamda,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.16,Page Number 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "magnitude of electric field in V/m in free space: 753.982\n",
      "magnitude of electric field in V/m: 376.734\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "H = 2  #  ampliutude of magnetic field in A/m\n",
    "sigma = 0  #  conductivity\n",
    "mu_0 = 4*pi*10**-7  #  permeability in free space in H/m\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "\n",
    "#calculations\n",
    "mu = mu_0  #  permeability in F/m\n",
    "epsilon = 4*epsilon_0  #  permittivity in F/m\n",
    "Eta_0 = 120*pi  #  intrinsic impedence in free space in ohm\n",
    "E_free = Eta_0*H  #  electric field in V/m\n",
    "\n",
    "\n",
    "#results\n",
    "print \"magnitude of electric field in V/m in free space:\",round(E_free,3)\n",
    "Eta = sqrt(mu/epsilon)  #  intrinsic impedence in ohm\n",
    "E = Eta*H  #  magnitude of electric field\n",
    "print \"magnitude of electric field in V/m:\",round(E,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.17,Page Number 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "propagation constant im m**-1: 18.862j\n",
      "intrinsic impedence in ohm: 125.578\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "sigma = 0  #  conductivity in mho/m\n",
    "f = 0.3  #  frequency in GHz\n",
    "f = 0.3*10**9  #  frequency in Hz\n",
    "omega = 2*pi*f  #  angular frequency in rad/sec\n",
    " #  formula : Gamma = sqrt(1j*omega*mu*(sigma+1j*omega*epsilon)) = 1j*omega*sqrt(mu*epsilon)\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "epsilon = 9*epsilon_0  #  permittivity in F/m\n",
    "mu_0 = 4*pi*10**-7  #   permeability in free space in H/m\n",
    "mu = mu_0  #  permeability in H/m\n",
    "Gamma = 1j*omega*sqrt(mu*epsilon)  #  propagation constant im m**-1\n",
    "\n",
    "\n",
    "#results\n",
    "\n",
    "print \"propagation constant im m**-1:\",np.around(Gamma,3)\n",
    " #  formula : eta = sqrt((1j*omega*mu)/(sigma+omega*epsilon)) = sqrt(mu/epsilon)\n",
    "eta = sqrt(mu_0/(9*epsilon_0))  #  intrinsic impedence in ohm\n",
    "print \"intrinsic impedence in ohm:\",round(eta,3)\n",
    "\n",
    "\n",
    "\n",
    "# note : answer in the book is wrong.\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.18,Page Number 118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frequecy in MHz: 600.0\n",
      "relative permittivity: 4.0\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "lamda = 0.25    #  wavelength in m\n",
    "v = 1.5*10**10  #  velocity of propagation of wave in cm/sec\n",
    "v = 1.5*10**8   #  velocity of propagation of wave in m/sec\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7         #   permeability in free space in H/m\n",
    "mu = mu_0      #  permeability in H/m\n",
    "v_0 = 3*10**8  #  speed of light in m/s\n",
    "f = v/lamda     #  frequency in Hz\n",
    " #  formula : v = 1/(mu*epsilon) = 1/(mu_0*epsilon_0*epsilon_r) = v_0/sqrt(epsilon_r)\n",
    "epsilon_r = (v_0/v)**2  #  relative permittivity\n",
    "\n",
    "\n",
    "#results\n",
    "print \"frequecy in MHz:\",round(f/10**6,3)\n",
    "print \"relative permittivity:\",epsilon_r\n",
    "\n",
    "\n",
    " # note : answer in the book is wrong.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.19,Page Number 118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frequency in MHz: 15.915\n",
      "phase constant in rad/m: 4.0\n",
      "wavelength in m: 18.85\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration and calculations\n",
    "\n",
    "#E = 5*sin(10**8*t+4*x)az  #  equation of electric field \n",
    "\n",
    "A = 5  #  amplitude of the electric field\n",
    "omega = 10**8  #  angular frequency in radians/sec\n",
    "f = omega/(2*pi)  #  frequency in Hz\n",
    "Beta = 4  #  phase constant in rad/m\n",
    "v_0 = 3*10**8  #  speed of light in m/s\n",
    "lamda = v_0/f  #  wavelength in m\n",
    "\n",
    "\n",
    "#results\n",
    "print \"frequency in MHz:\",round(f/10**6,3)\n",
    "print \"phase constant in rad/m:\",round(Beta,3)\n",
    "print \"wavelength in m:\",round(lamda,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.20,Page Number 119"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "When frequency = 50Hz:\n",
      "K1 is equal to 360000.0\n",
      "since k1>>1 hence it behaves like a good conductor:\n",
      "When frequency = 1kHz:\n",
      "K2 is equal to 18000.0\n",
      "since k2>>1 hence it behaves like a good conductor:\n",
      "When frequency = 1MHz:\n",
      "K3 is equal to 18.0\n",
      "since k3 = 18 hence it behaves like a moderate conductor:\n",
      "When frequency = 100MHz:\n",
      "K4 is equal to 0.18\n",
      "since k4 = 0.18 hence it behaves like a quasi-dielectric:\n",
      "When frequency = 10GHz:\n",
      "K5 is equal to 0.0018\n",
      "since k5<<1 hence it behaves like a good dielectric:\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "\n",
    "sigma = 10**-2  #  conductivity of earth in mho/m\n",
    "epsilon_r = 10  #  relative permittivity\n",
    "mu_r = 2  #  relative permeability\n",
    "epsilon_0 = (1/(36*pi))*10**-9  #  permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0  #  permittivity\n",
    "f1 = 50  #  frequency in Hz\n",
    "omega1 = 2*pi*f1  #  angular frequency in rad/sec\n",
    "print \"When frequency = 50Hz:\"\n",
    "k1 = sigma/(omega1*epsilon)\n",
    "print \"K1 is equal to\",k1\n",
    "print \"since k1>>1 hence it behaves like a good conductor:\"\n",
    "f2 = 1  #  frequency in kHz\n",
    "f2 = 1*10**3  #  frequency in Hz\n",
    "omega2 = 2*pi*f2  #  angular frequency in rad/sec\n",
    "print \"When frequency = 1kHz:\"\n",
    "k2 = sigma/(omega2*epsilon)\n",
    "print \"K2 is equal to\",k2\n",
    "print \"since k2>>1 hence it behaves like a good conductor:\"\n",
    "f3 = 1  #  frequency in MHz\n",
    "f3 = 1*10**6  #  frequency in Hz\n",
    "omega3 = 2*pi*f3  #  angular frequency in rad/sec\n",
    "print \"When frequency = 1MHz:\"\n",
    "k3 = sigma/(omega3*epsilon)\n",
    "print \"K3 is equal to\",k3\n",
    "print \"since k3 = 18 hence it behaves like a moderate conductor:\"\n",
    "f4 = 100  #  frequency in MHz\n",
    "f4 = 100*10**6  #  frequency in Hz\n",
    "omega4 = 2*pi*f4  #  angular frequency in rad/sec\n",
    "print \"When frequency = 100MHz:\"\n",
    "k4 = sigma/(omega4*epsilon)\n",
    "print \"K4 is equal to\",k4\n",
    "print \"since k4 = 0.18 hence it behaves like a quasi-dielectric:\"\n",
    "f5 = 10  #  frequency in GHz\n",
    "f5 = 10*10**9  #  frequency in Hz\n",
    "omega5 = 2*pi*f5  #  angular frequency in rad/sec\n",
    "print \"When frequency = 10GHz:\"\n",
    "k5 = sigma/(omega5*epsilon)\n",
    "print \"K5 is equal to\",k5\n",
    "print \"since k5<<1 hence it behaves like a good dielectric:\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.21,Page Number 120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ratio k is equal to 1.73763020468e+16\n",
      "since k>>1 therefore it is very good conductor:\n",
      "attenuation constant in m**-1: 117.21\n",
      "phase constant in m**-1: 117.21\n",
      "propagation constant in m**-1: (117.21+117.21j)\n",
      "intrinsic impedence in ohm: (2.0209e-06+2.0209e-06j)\n",
      "wavelength in cm: 5.36\n",
      "phase velocity of wave in m/s: 3.216\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "import cmath\n",
    "import numpy as np\n",
    "\n",
    "#variable declaration\n",
    "f = 60  # frequency in Hz\n",
    "omega = 2*pi*f  # angular frequency in rad/sec\n",
    "sigma = 5.8*10**7  # conductivity in mho/m\n",
    "epsilon_0 = 8.854*10**-12  # permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7  #  permeability in free space in H/m\n",
    "epsilon_r = 1  # relative permittivity\n",
    "mu_r = 1  # relative permeability\n",
    "\n",
    "\n",
    "#calculations\n",
    "epsilon = epsilon_r*epsilon_0  # permittivity\n",
    "mu = mu_0*mu_r  # permeability\n",
    "k = sigma/(omega*epsilon)  # ratio\n",
    "print \"ratio k is equal to\",k\n",
    "print \"since k>>1 therefore it is very good conductor:\"\n",
    "alpha = sqrt(omega*mu*sigma/2)  # attenuation constant in m**-1\n",
    "Beta = sqrt(omega*mu*sigma/2)  # phase constant in m**-1\n",
    "Gamma = alpha+(1j*Beta)  # propagation constant in m**-1\n",
    "lamda = (2*pi)/Beta  # wavelength\n",
    "eta = cmath.sqrt(((1j*omega*mu)/sigma))  # intrinsic impedence in ohm\n",
    "v = lamda*f  # phase velocity of wave in m/s\n",
    "\n",
    "\n",
    "#result\n",
    "print \"attenuation constant in m**-1:\",round(alpha,2)\n",
    "print \"phase constant in m**-1:\",round(Beta,2)\n",
    "print \"propagation constant in m**-1:\",np.around(Gamma,2)\n",
    "print \"intrinsic impedence in ohm:\",np.around(eta,10)\n",
    "print \"wavelength in cm:\",round(lamda*100,2)\n",
    "print \"phase velocity of wave in m/s:\",round(v,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.22,Page Number 120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "At f = 60Hz\n",
      "ratio k is equal to 1.73763020468e+16\n",
      "since k>>1 therefore it is very good conductor at f = 60Hz:\n",
      "depth of penetration delta1 in m: 0.00853160047351\n",
      "At f = 100Hz\n",
      "ratio k is equal to 10425781228.1\n",
      "since k2>>1 therefore it is very good conductor at f = 100Hz:\n",
      "depth of penetration delta2 in m: 6.60854931008e-06\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "f1 = 60  #  frequency in Hz\n",
    "omega1 = 2*pi*f1  #  angular frequency in Hz\n",
    "f2 = 100          #  frequency in MHz\n",
    "f2 = 100*10**6    #  frequency in Hz\n",
    "omega2 = 2*pi*f2  #  angular frequency in Hz\n",
    "sigma = 5.8*10**7 #  conductivity in mho/m\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7         #  permeability in free space in H/m\n",
    "epsilon_r = 1    #  relative permittivity\n",
    "mu_r = 1         #  relative permeability\n",
    "epsilon = epsilon_r*epsilon_0  #  permittivity\n",
    "mu = mu_0*mu_r   #  permeability\n",
    "\n",
    "print \"At f = 60Hz\"\n",
    "k1 = (sigma)/(omega1*epsilon)  #  ratio\n",
    "print \"ratio k is equal to\",k1\n",
    "print \"since k>>1 therefore it is very good conductor at f = 60Hz:\"\n",
    "delta1 = (sqrt(2/(omega1*mu*sigma)))  #  depth of penetration in m\n",
    "print \"depth of penetration delta1 in m:\",delta1\n",
    "\n",
    "print \"At f = 100Hz\"\n",
    "k2 = sigma/(omega2*epsilon)  #  ratio\n",
    "print \"ratio k is equal to\",k2\n",
    "print \"since k2>>1 therefore it is very good conductor at f = 100Hz:\"\n",
    "delta2 = (sqrt(2/(omega2*mu*sigma)))  #  depth of penetration in m\n",
    "print \"depth of penetration delta2 in m:\",delta2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.23,Page Number 121"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "when f = 1MHz\n",
      "displacement current when f = 1MHz in A: 9.59160736375e-12\n",
      "when f = 100MHz\n",
      "displacement current when f = 100MHz in A: 9.59160736375e-10\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "Ic = 10  #  conduction current in ampere\n",
    "epsilon_r = 1  #  relative permittivity\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0  #  permittivity\n",
    "sigma = 5.8*10**7  #  conductivity in mho/m\n",
    "\n",
    "print \"when f = 1MHz\"\n",
    "f = 1  #  frequency in MHz\n",
    "f = 1*10**6  #  frequency in Hz\n",
    "Id = (2*pi*f*epsilon*Ic)/sigma  #  printlacement current\n",
    "print \"displacement current when f = 1MHz in A:\",Id\n",
    "print \"when f = 100MHz\"\n",
    "f = 100  #  frequency in MHz\n",
    "f = 100*10**6  #  frequency in Hz\n",
    "Id = (2*pi*f*epsilon*Ic)/sigma  #  printlacement current\n",
    "print \"displacement current when f = 100MHz in A:\",Id\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.25,Page Number 122"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ratio k is equal to:\n",
      "ratio: 221.92\n",
      "K is >>1 so sea water is a good conductor\n",
      "depth in the sea that can be reached by the aeroplane in m: 1.41095\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,sin,cos,radians,log\n",
    "\n",
    "#variable declaration\n",
    "Em = 20          # minimum signal level required for vessel under sea water in microV/m\n",
    "Em = 20*10**-6   # minimum signal level required for vessel under sea water in V/m\n",
    "E = 100          # electric intensity of wave in V/m\n",
    "v = 3*10**8      # speed of light in m/s\n",
    "f = 4            # frequency in MHz\n",
    "f = 4*10**6      # frequency in Hz\n",
    "omega = 2*pi*f   # angular frequency in Hz\n",
    "sigma = 4        # conductivity of sea water in mho/m\n",
    "epsilon_r = 81   # relative permittivity\n",
    "epsilon_0 = 8.854*10**-12     # permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0 # permittivity\n",
    "mu_r = 1             # relative permeability\n",
    "mu_0 = 4*pi*10**(-7) # permeability in free space\n",
    "mu = mu_r*mu_0    # permeability\n",
    "k = (sigma)/(omega*epsilon)  #ratio\n",
    "print \"ratio k is equal to:\"\n",
    "print \"ratio:\",round(k,3)\n",
    "print \"K is >>1 so sea water is a good conductor\"\n",
    "eta_1 = 377   # intrinsic impedance in free space in ohm\n",
    "alpha_1 = 0   # attenuation constant in free space in m**-1\n",
    "\n",
    "\n",
    "#calculations\n",
    "beta_1 = omega/v  # phase constant in m**-1\n",
    "mageta_2 = sqrt((omega*mu)/sigma)   # magnitude of eta_2(intrinsic impedance of sea water in ohm) \n",
    "argeta_2 = 45                     # argument of eta_2 in degrees\n",
    "eta_2 = mageta_2*cos(radians(argeta_2))+(1j*mageta_2*sin(radians(argeta_2)))    #intrinsic impedance in complex form (r*cos(theta)+1j*r*sin(theta))\n",
    "TC = 2*eta_2/(eta_1+eta_2)          # transmission cofficient\n",
    "Et = abs(TC)*E                      # transmitted electric field in V/m\n",
    "alpha_2 = sqrt((omega*mu*sigma)/2)  # attenuation constant for sea water in m**-1\n",
    "# formula: Et*exp(-alpha_2*d) = Em\n",
    "d = -(1/alpha_2)*(log(Em/Et))   # depth in the sea that can be reached by the aeroplane in m\n",
    "\n",
    "\n",
    "#result\n",
    "print \"depth in the sea that can be reached by the aeroplane in m:\",round(d,5)\n",
    "\n",
    "\n",
    "# note 1: the value of alpha_2 in book is 7.905 but it is \"7.94\" exactly calculated by python.\n",
    "#note 2 : The correct answer of the Depth(d) is \"1.41095\" the answer in the book is wrong.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.27,Page Number 124"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "E=sin(omega*t-beta*z)ax+2*sin(omega*t-beta*z+75)ay  #  electric field in V/m\n",
      "power per unit area conveyed by the wave in free space in mW/m**2: 6.631\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "eta_0=377  #  intrinsic impedance in free space in ohm\n",
    "print \"E=sin(omega*t-beta*z)ax+2*sin(omega*t-beta*z+75)ay  #  electric field in V/m\"\n",
    "Ex=1  #  magnitude of Ex\n",
    "Ey=2  #  magnitude of Ey\n",
    "\n",
    "#calculations\n",
    "E=sqrt(Ex**2+Ey**2)       #  resultant magnitude\n",
    "Pav=((1/2)*E**2)/(eta_0)  #  power per unit area conveyed by the wave in free space\n",
    "\n",
    "#results\n",
    "print \"power per unit area conveyed by the wave in free space in mW/m**2:\",round(Pav*1000,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.28,Page Number 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average power in micro*w/m**2: 2354.59\n",
      "maximum energy density of the wave in PJ/m*3: 31.416\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "epsilon_0 = 8.854*10**-12  # permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7  #  permeability in free space in H/m\n",
    "epsilon_r = 4  # relative permittivity\n",
    "mu_r = 1  # relative permeability\n",
    "epsilon = epsilon_r*epsilon_0  # permittivity\n",
    "mu = mu_0*mu_r  # permeability\n",
    "H = 5  # magnitude of magnetic field in mA/m\n",
    "H = 5*10**-3  # magnitude of magnetic field in A/m\n",
    "\n",
    "#calculations\n",
    "eta = sqrt(mu/epsilon) # intrinsic impedence in ohm\n",
    "E = H*sqrt(mu/epsilon)  # magnitude of electric field\n",
    "P_av = E**2/(2*eta)  # average power\n",
    "W_E = epsilon*E**2  # maximum energy density of the wave\n",
    "\n",
    "\n",
    "#results\n",
    "print \"Average power in micro*w/m**2:\",round(P_av*10**6,2)\n",
    "print \"maximum energy density of the wave in PJ/m*3:\",round(W_E*10**12,3)\n",
    "\n",
    "\n",
    "#note: P_av is =  2353.75 in book but it is 2354.58 correctly calculated by python.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.29,Page Number 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "electric energy density of the wave in nJ/m**3: 139.078\n",
      "magnetic energy density of wave in nJ/m**3: 139.078\n",
      "Total energy density in nJ/m**3: 278.157\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "epsilon_0 = 8.854*10**-12 #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7 #   permeability in free space in H/m\n",
    "epsilon_r = 1 #  relative permittivity\n",
    "mu_r = 1 #  relative permeability\n",
    "epsilon = epsilon_r*epsilon_0 #  permittivity\n",
    "mu = mu_0*mu_r #  permeability\n",
    "E = 100*sqrt(pi) #  magnitude of electric field in V/m\n",
    "\n",
    "\n",
    "#calculations\n",
    "W_E = (1/2)*epsilon*E**2 #  electric energy density of the wave\n",
    "W_H = W_E #  as the energy density is equal to that of magnetic field for a pla`ne travelling wave\n",
    "W_T = W_E+W_H #  total energy density\n",
    "\n",
    "#results\n",
    "print \"electric energy density of the wave in nJ/m**3:\",round(W_E*10**9,3)\n",
    "print \"magnetic energy density of wave in nJ/m**3:\",round(W_H*10**9,3)\n",
    "print \"Total energy density in nJ/m**3:\",round(W_T*10**9,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.30,Page Number 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "when frequency = 25kHz\n",
      "transmitted distance in m: 3.274\n",
      "when frequency = 25MHz\n",
      "transmitted distance in m: 0.105\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "sigma = 5 #  conductivity of sea water in mho/m\n",
    "f1 = 25 #  frequency in kHz\n",
    "f1 = 25*10**3 #  frequency in Hz\n",
    "omega1 = 2*pi*f1 #  angular frequency in Hz\n",
    "f2 = 25 #  frequency in MHz\n",
    "f2 = 25*10**6 #  frequency in Hz\n",
    "omega2 = 2*pi*f2 #  angular frequency in Hz\n",
    "epsilon_r = 81 #  relative permittivity\n",
    "epsilon_0 = 8.854*10**(-12) #  permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0 #  permittivity\n",
    "mu_r = 1 #  relative permeability\n",
    "mu_0 = 4*pi*10**(-7) #  permeability in free space\n",
    "mu = mu_r*mu_0 #  permeability\n",
    "\n",
    "#calculations and results\n",
    "\n",
    "print \"when frequency = 25kHz\"\n",
    "alpha_1 = omega1*sqrt((mu*epsilon)/2*(sqrt(1+(sigma**2/(omega1**2*epsilon**2)))-1)) #  attenuation constant when f = 25kHz\n",
    "# formula: exp(-alpha*x) = 0.1\n",
    "x1 = 2.3/alpha_1 #  transmitted distance in m\n",
    "print \"transmitted distance in m:\",round(x1,3)\n",
    "print \"when frequency = 25MHz\"\n",
    "alpha_2 = omega2*sqrt((mu*epsilon)/2*(sqrt(1+(sigma**2/(omega2**2*epsilon**2)))-1)) #  attenuation constant when f = 25MHz\n",
    "x2 = 2.3/alpha_2 #  transmitted distance in m\n",
    "print \"transmitted distance in m:\",round(x2,3)\n",
    "\n",
    "\n",
    "# note: the values of epsilon_r = 81 and of mu_r = 1 for sea water which are not given in the book.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.31,Page Number 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reflection cofficient of electric field in mV/m: 0.489\n",
      "incident cofficient of magnetic field in micro*A/m: 7.739\n",
      "reflection cofficient of magnetic field in micro*A/m: 3.786\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,radians,asin,cos,sin,degrees\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "E_i = 1  #  magnitude of incident electric field in mV/m\n",
    "E_i = 1*10**-3  #  magnitude of incident electric field in V/m\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7  #   permeability in free space in H/m\n",
    "theta_i = 15  #  incident angle in degrees\n",
    "epsilon_r1 = 8.5  #  relative permittivity of medium 1\n",
    "mu_r1 = 1  #  relative permeability of medium 1\n",
    "epsilon1 = epsilon_r1*epsilon_0  #  permittivity\n",
    "mu1 = mu_0*mu_r1  #  permeability\n",
    "eta1 = sqrt(mu1/epsilon1)  #  intrinsic impedence of medium 1 in ohm\n",
    "epsilon2 = epsilon_0  #  permittivity of medium 2\n",
    "mu2 = mu_0  #  permeability of medium 2\n",
    "eta2 = sqrt(mu2/epsilon2)  #  intrinsic impedence of medium 2 in ohm\n",
    "\n",
    "#calculations and result\n",
    "\n",
    "# formula : sin(theta_i)/sin(theta_t) = sqrt(epsilon2/epsilon1)\n",
    "theta_t = asin(sin(radians(theta_i)))/(sqrt(epsilon2/epsilon1))  #  transmitted angle in degrees\n",
    "E_r = (E_i*(((eta2*cos(radians(theta_i))))-(eta1*cos(radians((theta_i))))))/((eta2*cos(radians(theta_i)))+(eta1*cos(radians(theta_i))))  #  reflection cofficient of electric field\n",
    "print \"reflection cofficient of electric field in mV/m:\",round(E_r*1000,3)\n",
    "H_i = E_i/eta1  #  incident cofficient of magnetic field\n",
    "print \"incident cofficient of magnetic field in micro*A/m:\",round(H_i*10**6,3)\n",
    "H_r = E_r/eta1  #  reflection cofficient of electric field\n",
    "print \"reflection cofficient of magnetic field in micro*A/m:\",round(H_r*10**6,3)\n",
    "\n",
    "\n",
    "#note : minute difference in decimel in the value of H_i and H_r.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.32,Page Number 127"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "average power density absorbed by copper in mW/m**2: 3.83\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "sigma = 5.8*10**7 #  conductivity in mho/m\n",
    "f = 2 #  frequency in MHz\n",
    "f = 2*10**6 #  frequency in Hz\n",
    "omega = 2*pi*f #  angular frequency in rad/sec\n",
    "E = 2 #  magnitude of electric field in mV/m\n",
    "E = 2*10**-3 #  magnitude of electric field in V/m\n",
    "epsilon_0 = 8.854*10**-12 #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7 #   permeability in free space in H/m\n",
    "epsilon_r = 1 #  relative permittivity\n",
    "mu_r = 1 #  relative permeability\n",
    "epsilon = epsilon_r*epsilon_0 #  permittivity\n",
    "mu = mu_0*mu_r #  permeability\n",
    "\n",
    "# calculations\n",
    "eta = sqrt(mu*omega/sigma) #  intrinsic impedence in ohm\n",
    "P_av = (1/2)*E**2/eta #  average power density anbsorbed by copper\n",
    "\n",
    "#result\n",
    "print \"average power density absorbed by copper in mW/m**2:\",round(P_av*1000,2)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}