Escolar Documentos
Profissional Documentos
Cultura Documentos
Kshirsagar1
Created by Jumana Mp btech Electronics Engineering VNIT NAGPUR College Teacher Dr.A.S.Gandhi Cross-Checked by Mukul R. Kulkarni August 10, 2013
by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilab codes written in it can be downloaded from the Textbook Companion Project section at the website http://scilab.in
1 Funded
Book Description
Title: A Textbook Of Engineering Physics Author: M. N. Avadhanulu, And P. G. Kshirsagar Publisher: S. Chand And Company, New Delhi Edition: 9 Year: 2011 ISBN: 81-219-0817-5
Scilab numbering policy used in this document and the relation to the above book. Exa Example (Solved example) Eqn Equation (Particular equation of the above book) AP Appendix to Example(Scilab Code that is an Appednix to a particular Example of the above book) For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means a scilab code whose theory is explained in Section 2.3 of the book.
Contents
List of Scilab Codes 4 Electron Ballistics 5 Electron Optics 6 Properties of Light 7 Interference and Diraction 8 Polarization 11 Architectural Acoustics 12 Ultrasonics 13 Atomic Physics 14 Lasers 15 Atomic nucleus and nuclear energy 16 Structure of Solids 17 The Band Theory of Solids 18 Semiconductors 19 PN Junction Diode 5 9 14 17 19 22 24 27 29 36 39 49 52 54 59
61 64 66 71 76
Exa 13.1 Exa 13.2 Exa 13.3 Exa 13.4 Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa 13.5 13.6 13.7 13.8 14.1 14.2 14.3 14.4 14.5 15.1 15.2 15.3 15.4 15.5 15.6 15.7 15.8 15.9 15.10 15.11 15.12 15.13 15.14 15.15 16.1 16.2 16.3 16.4 17.1 17.2 17.3
calculation of rate of ow of photons . . . . . . . . . . calculation of threshold wavelength and stopping potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . calculation of momentum of Xray photon undergoing scattering . . . . . . . . . . . . . . . . . . . . . . . . . calculation of wavelength of scattered radiation and velocity of recoiled electrone . . . . . . . . . . . . . . . . calculation of wavelength of light emitted . . . . . . . calculation of de Broglie wavelength . . . . . . . . . . calculation of uncertainty in position . . . . . . . . . . Energy states of an electron and grain of dust . . . . . calculation of intensity of laser beam . . . . . . . . . . calculation of intensity of laser beam . . . . . . . . . . calculation of coherence length bandwidth and line width calculation of frequency dierence . . . . . . . . . . . calculation of frequency dierence . . . . . . . . . . . calculation of binding energy per nucleon . . . . . . . calculation of energy . . . . . . . . . . . . . . . . . . . calculation of binding energy . . . . . . . . . . . . . . calculation of binding energy . . . . . . . . . . . . . . calculation of halife . . . . . . . . . . . . . . . . . . . calculation of activity . . . . . . . . . . . . . . . . . . calculation of age of mineral . . . . . . . . . . . . . . . calculation of age of wooden piece . . . . . . . . . . . calculation of energy released . . . . . . . . . . . . . . calculation of crossection . . . . . . . . . . . . . . . . calculation of nal energy . . . . . . . . . . . . . . . . calculation of amount of fuel . . . . . . . . . . . . . . calculation of power output . . . . . . . . . . . . . . . calculation of power developed . . . . . . . . . . . . . calculation of amount of dueterium consumed . . . . . calculation of density . . . . . . . . . . . . . . . . . . calculation of no of atoms . . . . . . . . . . . . . . . . calculation of distance . . . . . . . . . . . . . . . . . . calculation of interatomic spacing . . . . . . . . . . . . calculation of velocity of fraction of free electrone . . . calculation of velocity of e . . . . . . . . . . . . . . . . calculation of velocity of fraction of free electrones . . 6
29 30 30 31 32 32 33 34 36 36 37 38 38 39 39 40 41 41 42 42 43 44 44 45 45 46 47 47 49 49 50 51 52 52 53
Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa
18.2 18.3 18.4 18.5 18.6 18.7 18.8 19.1 19.2 21.1 21.2 21.3 22.1 22.2 22.3 23.1 23.2 23.3
Exa 23.4 Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa 23.5 23.6 23.7 24.1 24.2 24.3 24.4 24.5 24.6 24.7 25.1 25.2 25.3 25.4 25.5
calculation of probability . . . . . . . . . . . . . . . . calculation of fraction of e in CB . . . . . . . . . . . . calculation of fractionional change in no of e . . . . . . calculation of resistivity . . . . . . . . . . . . . . . . . calculation of conductivity of intrinsic and doped semiconductors . . . . . . . . . . . . . . . . . . . . . . . . calculation of hole concentration . . . . . . . . . . . . calculation of Hall voltage . . . . . . . . . . . . . . . . calculation of potential barrier . . . . . . . . . . . . . calculation of current . . . . . . . . . . . . . . . . . . calculation of magnetizing force and relative permeability calculation of magnetization and magnetic ux density calculation of relative permeability . . . . . . . . . . . calculation of magnetic eld . . . . . . . . . . . . . . . calculation of transition temperature . . . . . . . . . . calculation of temp at which there is max critical eld calculation of relative permittivity . . . . . . . . . . . calculation of electronic polarizability . . . . . . . . . calculation of electronic polarizability and relative permittivity . . . . . . . . . . . . . . . . . . . . . . . . . calculation of electronic polarizability and relative permittivity . . . . . . . . . . . . . . . . . . . . . . . . . calculation of ionic polarizability . . . . . . . . . . . . calculation of frequency and phase dierence . . . . . calculation of frequency . . . . . . . . . . . . . . . . . Fiber optics numerical aperture calculation . . . . . . calculation of acceptance angle . . . . . . . . . . . . . calculation of normailsed frequency . . . . . . . . . . . calculation of normailsed frequency and no of modes . calculation of numerical aperture and maximum acceptance angle . . . . . . . . . . . . . . . . . . . . . . . . calculation of power level . . . . . . . . . . . . . . . . calculation of power loss . . . . . . . . . . . . . . . . . sum of two binary numbers . . . . . . . . . . . . . . . sum of two binary numbers . . . . . . . . . . . . . . . sum of two binary numbers . . . . . . . . . . . . . . . dierence of two binary numbers . . . . . . . . . . . . dierence of two binary numbers . . . . . . . . . . . . 7
54 54 55 56 56 57 57 59 59 61 61 62 64 64 65 66 66 67 68 68 69 69 71 72 72 73 73 74 74 76 77 77 78 78
Exa 25.6 Exa 25.7 Exa 25.8 Exa 25.9 Exa 25.10 Exa 25.11 Exa 25.12 Exa 25.13 Exa 25.14 Exa 25.15 Exa 25.16 Exa 25.17 Exa 25.18 Exa 25.19 Exa 25.20 Exa 25.21 Exa 25.22 Exa 25.23 Exa 25.24 Exa 25.25 Exa 25.26 Exa 25.27 Exa 25.28 Exa 25.29 Exa 25.30 AP 1 AP 2
dierence of two binary numbers . . . . . . . . . . . . product of two binary numbers . . . . . . . . . . . . . binary multiplication . . . . . . . . . . . . . . . . . . . binary division . . . . . . . . . . . . . . . . . . . . . . binary division . . . . . . . . . . . . . . . . . . . . . . octal addition . . . . . . . . . . . . . . . . . . . . . . . octal multiplication . . . . . . . . . . . . . . . . . . . hexadecimal addition . . . . . . . . . . . . . . . . . . binary to decimal conversion . . . . . . . . . . . . . . decimal to binary conversion . . . . . . . . . . . . . . decimal to binary conversion . . . . . . . . . . . . . . decimal to octal conversion . . . . . . . . . . . . . . . octal to binary conversion . . . . . . . . . . . . . . . . octal to binary conversion . . . . . . . . . . . . . . . . binary to octal conversion . . . . . . . . . . . . . . . . hexa to decimal conversion . . . . . . . . . . . . . . . decimal to hexadecimal conversion . . . . . . . . . . . hexa to binary conversion . . . . . . . . . . . . . . . . binary to hexa conversion . . . . . . . . . . . . . . . . Substraction by ones complement method . . . . . . . Substraction by ones complement method . . . . . . . Substraction by ones complement method . . . . . . . nding twos complement . . . . . . . . . . . . . . . . Addition of negative number by twos complement method Substraction by twos complement method . . . . . . . Binary to Decimal convertor . . . . . . . . . . . . . . Decimal to Base 2 Converter . . . . . . . . . . . . . .
Scilab code Exa 4.1 Calculation of acceleration time taken and distance covered and kinetic energy of an accelerating proton
1 clc ; clear ; 2 // Example 4 . 1 3 // C a l c u l a t i o n
4 5 // g i v e n v a l u e s 6 m =1.67*10^ -27; // mass o f p r o t o n i n kg 7 q =1.602*10^ -19; // c h a r g e o f p r o t o n i n Coulomb 8 v1 =0; // i n i t i a l v e l o c i t y i n m/ s 9 v2 =2.5*10^6; // f i n a l v e l o c i t y i n m/ s 10 E =500; // e l e c t r i c f i e l d s t r e n g t h i n V/m 11 // c a l c u l a t i o n 12 a = E * q / m ; // a c c e l e r a t i o n 13 disp (a , a c c e l e r a t i o n o f p r o t o n i n (m/ s 2 ) i s : ) ; 14 t = v2 / a ; // t i m e 15 disp (t , t i m e ( i n s ) t a k e n by p r o t o n t o r e a c h t h e
f i n a l v e l o c i t y i s : ); 16 x = a * t ^2/2; // d i s t a n c e 17 disp (x , d i s t a n c e ( i n m) c o v e r e d by p r o t o n i n t h i s 9
time i s : ); 18 KE = E * q * x ; // k i n e t i c e n e r g y 19 disp ( KE , k i n e t i c e n e r g y ( i n J ) a t t h e t i m e i s : ) ;
which e l e c t r o n
6 l =.04; // l e n g t h o f 7 d =.015; // d i s t a n c e 8 V =50; // p o t e n t i a l 9 // c a l c u l a t i o n s 10 alpha = atan ( l * V /(2* d * V1 ) ) *(180/ %pi ) ; // i n d e g r e e s 11 disp ( alpha , a n g l e o f d e f l e c t i o n o f e l e c t r o n beam i s :
Scilab code Exa 4.3 electron projected at an angle into a uniform electric eld
1 clc ; clear ; 2 // Example 4 . 3 3 // e l e c t r o n p r o j e c t e d a t an a n g l e
into a uniform
electric
field
in degrees
10
7 8 9 10 11 12 13 14 15 16
E =200; // e l e c t r i c f i e l d i n t e n s i t y i n N/C e =1.6*10^ -19; // i n C m =9.1*10^ -31; // i n kg a = e * E / m ; // a c c e l e r a t i o n i n m/ s 2 t =2* v1 * sin ( alpha ) / a ; // t i m e i n s disp (t , t i m e t a k e n by e l e c t r o n t o r e t u r n t o i t s i n i t i a l level is : ) H =( v1 ^2* sin ( alpha ) * sin ( alpha ) ) /(2* a ) ; // h e i g h t i n m disp (H , maximum h e i g h t r e a c h e d by e l e c t r o n i s : ) s =( v1 ^2) *(2* sin ( alpha ) * cos ( alpha ) ) /(2* a ) ; // displacement in m disp (s , h o r i z o n t a l d i s p l a c e m e n t ( i n m) when i t r e a c h e s maximum h e i g h t i s : )
i s accelerated in volts B =0.01; // m a g n e t i c f i e l d i n e =1.6*10^ -19; // i n C m =9.1*10^ -31; // i n kg v = sqrt (2* e * V / m ) ; // e l e c t r o n disp (v , e l e c t r o n v e l o c i t y r = m * v /( e * B ) ; // i n m disp (r , r a d i u s o f p a t h ( i n
wb/m2
v e l o c i t y i n m/ s is : ) m) i s : )
Scilab code Exa 4.5 motion of an electron in a uniform magnetic eld acting at an angle 11
in a uniform magnetic f i e l d
a c t i n g a t an a n g l e
4 // g i v e n v a l u e s 5 v =3*10^7; // e l e c t r o n s p e e d 6 B =.23; // m a g n e t i c f i e l d i n wb/m2 7 q =45* %pi /180; // i n d e g r e e s , a n g l e i n which e l e c t r o n 8 9 10 11 12 13
enter f i e l d e =1.6*10^ -19; // i n C m =9.1*10^ -31; // i n kg R = m * v * sin ( q ) /( e * B ) ; // i n m disp (R , r a d i u s o f h e l i c a l p a t h i s : ) p =2* %pi * m * v * cos ( q ) /( e * B ) ; // i n m disp (p , p i t c h o f h e l i c a l p a t h ( i n m) i s : )
clc ; clear ; // Example 4 . 6 // M a g n e t o s t a t i c d e f l e c t i o n // g i v e n v a l u e s D =.03; // d e f l e c t i o n i n m m =9.1*10^ -31; // i n kg e =1.6*10^ -19; // i n C L =.15; // d i s t a n c e b e t w e e n CRT and anode i n m l = L /2; V =2000; // i n v o l t s i n wb/ B = D * sqrt (2* m * V ) /( L * l * sqrt ( e ) ) ; // i n wb/m2 disp (B , t r a n s v e r s e m a g n e t i c f i e l d a c t i n g ( i n wb/m 2 ) is : )
Scilab code Exa 4.7 electric and magnetic elds in crossed conguration 12
f i e l d s in crossed
configuration // g i v e n v a l u e s B =2*10^ -3; // m a g n e t i c f i e l d i n wb/m2 E =3.4*10^4; // e l e c t r i c f i e l d i n V/m m =9.1*10^ -31; // i n kg e =1.6*10^ -19; // i n C v = E / B ; // i n m/ s disp (v , e l e c t r o n s p e e d i s : ) R = m * v /( e * B ) ; // i n m disp (R , r a d i u s o f c i r c u l a r p a t h ( i n m) when e l e c t r i c f i e l d i s switched o f f )
13
calculation of potential
difference
4 5 6 7 8 9 10 11 12 13
// g i v e n v a l u e s V1 =250; // p o t e n t i a l by which e l e c t r o n s a r e accelerated in Volts alpha1 =50* %pi /180; // i n d e g r e e alpha2 =30* %pi /180; // i n d e g r e e b = sin ( alpha1 ) / sin ( alpha2 ) ; // c a l c u l a t i o n V2 =( b ^2) * V1 ; a = V2 - V1 ; disp (a , p o t e n t i a l d i f f e r e n c e ( i n v o l t s ) i s : ) ;
14
of magnetic induction ,
maximum e n e r g y
4 5 // g i v e n v a l u e s 6 f =12*(10^6) ; // o s c i l l a t o r f r e q u e n c y i n H e r t z 7 r =.53; // r a d i u s o f t h e d e e i n m e t r e 8 q =1.6*10^ -19; // D e u t e r o n c h a r g e i n C 9 m =3.34*10^ -27; // mass o f d e u t e r o n i n kg 10 // c a l c u l a t i o n 11 B =2* %pi * f * m / q ; // 12 disp (B , m a g n e t i c i n d u c t i o n ( i n T e s l a ) i s : ) ; 13 E = B ^2* q ^2* r ^2/(2* m ) ; 14 disp (E , maximum e n e r g y t o which d e u t e r o n s can be
Scilab code Exa 5.4 calculation of linear separation of lines formed on photographic plates
1 clc ; clear ; 2 // Example 5 . 4 3 // Mass s p e c t r o g r a p h , 4 5 6 7 8 9
calculation of linear s e p a r a t i o n o f l i n e s f o r m e d on p h o t o g r a p h i c p l a t e s
// g i v e n v a l u e s E =8*10^4; // e l e c t r i c f i e l d i n V/m B =.55 // m a g n e t i c i n d u c t i o n i n Wb/m 2 q =1.6*10^ -19; // c h a r g e o f i o n s m1 =20*1.67*10^ -27; // a t o m i c mass o f an i s o t o p e o f neon 10 m2 =22*1.67*10^ -27; // a t o m i c mass o f o t h e r i s o t o p e o f 15
16
calculation
17
18
clc ; clear ; // Example 7 . 1 // p l a n e p a r a l l e l t h i n f i l m // g i v e n v a l u e s x =5890*10^ -10; // w a v e l e n g t h o f l i g h t i n m e t r e n =1.5; // r e f r a c t i v e i n d e x r =60* %pi /180; // a n g l e o f r e f r a c t i o n i n d e g r e e // c a l c u l a t i o n t = x /(2* n * cos ( r ) ) ; disp ( t *10^6 , t h i c k n e s s o f p l a t e ( i n m i c r o m e t r e ) i s : );
film 19
4 5 6 7 8 9 10 11 12
// g i v e n v a l u e s x =5893*10^ -10; // w a v e l e n g t h o f l i g h t i n m e t r e n =1.5; // r e f r a c t i v e i n d e x y =.1*10^ -3; // f r i n g e s p a c i n g // c a l c u l a t i o n z = x /(2* n * y ) ; // a n g l e o f wedge alpha = z *180/ %pi ; // c o n v e r s i o n o f r a d i a n i n t o d e g r e e disp ( alpha , a n g l e o f wedge ( i n d e g r e e ) i s : ) ;
of
r e f r a c t i v e index
4 5 // g i v e n v a l u e s 6 D1 =1.5; // d i a m e t r e ( i n cm ) o f t e n t h d a r k r i n g i n a i r 7 D2 =1.27; // d i a m e t r e ( i n cm ) o f t e n t h d a r k r i n g i n
liquid
8 9 10 // c a l c u l a t i o n 11 n = D1 ^2/ D2 ^2; 12 disp (n , r e f r a c t i v e
index of l i q u i d
i s );
film
20
5 6 7 8 9 10 11 12 13
// g i v e n v a l u e s l =5500*10^ -10; // w a v e l e n g t h o f l i g h t n1 =1.33; // r e f r a c t i v e i n d e x o f w a t e r n2 =1.52; // r e f r a c t i v e i n d e x o f g l a s s window pane x = sqrt ( n1 ) ; // t o c h e c k i f i t i s n o n r e f l e c t i n g // c a l c u l a t i o n t = l /(4* n1 ) ; // t h i c k n e s s o f w a t e r f i l m r e q u i r e d disp ( t *10^6 , minimum t h i c k n e s s o f f i l m ( i n m e t r e ) i s );
21
Chapter 8 Polarization
( i n d e g r e e ) i s );
i s );
23
Scilab code Exa 11.1 calculation of total absorption and average absorption coecient
1 clc ; clear ; 2 // Example 1 1 . 1 3 // c a l c u l a t i o n o f 4 5 6 7 8 9 10 11 12 13 14
t o t a l a b s o r p t i o n and a v e r a g e absorption c o e f f i c i e n t
1 2 3 4 5 6 7 8 9 10 11 12 13 14
clc ; clear ; // Example 1 1 . 2 // c a l c u l a t i o n o f a v e r a g e a b s o r p t i o n c o e f f i c i e n t // g i v e n v a l u e s V =10*8*6; // volume o f h a l l i n m3 t =1.5; // r e v e r b e r a t i o n t i m e o f empty h a l l i n s e c A =20; // a r e a o f c u r t a i n c l o t h i n m2 t1 =1; // new r e v e r b e r a t i o n t i m e i n s e c // c a l c u l a t i o n a1 =.161* V / t ; // t o t a l a b s o r p t i o n o f empty h a l l a2 =.161* V / t1 ; // t o t a l a b s o r p t i o n a f t e r a c u r t a i n c l o t h i s suspended
15 16 k =( a2 - a1 ) /(2*20) ; 17 disp (k , t h e a v e r a g e a b s o r p t i o n
coefficient
i s );
Scilab code Exa 11.3 calculation of average absorption coecient and area
1 clc ; clear ; 2 // Example 1 1 . 3 3 // c a l c u l a t i o n o f a v e r a g e a b s o r p t i o n
c o e f f i c i e n t and
area
4 5 6 7 8 9 10 11 12 13
with c u r t a i n 16 a = t1 *( a2 - a1 ) /( t1 * k2 ) ; 17 disp (a , a r e a o f w a l l t o be c o v e r e d w i t h c u r t a i n ( i n m 2) i s : )
26
Chapter 12 Ultrasonics
clc ; clear ; // Example 1 2 . 1 // c a l c u l a t i o n o f n a t u r a l f r e q u e n c y , m a g n e t o s t r i c t i o n // g i v e n v a l u e s l =40*10^ -3; // l e n g t h o f p u r e i r o n r o d d =7.25*10^3; // d e n s i t y o f i r o n i n kg /m3 Y =115*10^9; // Young s modulus i n N/m2 // c a l c u l a t i o n f =(1* sqrt ( Y / d ) ) /(2* l ) ; disp ( f *10^ -3 , t h e n a t u r a l f r e q u e n c y ( i n kHz ) i s ) ;
27
3 4 5 6 7 8 9 10 11 12 13 14
clc ; clear ; // Example 1 2 . 3 // c a l c u l a t i o n o f d e p t h and w a v e l e n g t h // g i v e n v a l u e s f =.07*10^6; // f r e q u e n c y i n Hz t =.65; // t i m e t a k e n f o r p u l s e t o r e t u r n v =1700; // v e l o c i t y o f sound i n s e a w a t e r i n m/ s // c a l c u l a t i o n d = v * t /2; // disp (d , t h e d e p t h o f s e a ( i n m) i s ) ; l = v / f ; // w a v e l e n g h t o f p u l s e i n m disp ( l *10^2 , w a v e l e n g t h o f p u l s e ( i n cm ) i s ) ;
28
l =5893*10^ -10; // w a v e l e n g t h o f l i g h t i n m P =40; // power o f sodium lamp i n W d =10; // d i s t a n c e from t h e s o u r c e i n m s =4* %pi * d ^2; // s u r f a c e a r e a o f r a d i u s i n m2 c =3*10^8; // v e l o c i t y o f l i g h t i n m/ s h =6.626*10^ -34; // Planck s c o n s t a n t i n J s // c a l c u l a t i o n E = P *1; // disp (E , t o t a l e n e r g y e m i t t e d p e r s e c o n d ( i n J o u l e ) i s ); 16 n = E * l /( c * h ) ; // t o t a l no o f p h o t o n s 17 R = n / s ; 18 disp (R , r a t e o f f l o w o f p h o t o n s p e r u n i t a r e a ( i n /m 2) i s )
29
Scilab code Exa 13.2 calculation of threshold wavelength and stopping potential
1 clc ; clear ; 2 // Example 1 3 . 2 3 // c a l c u l a t i o n o f
t h r e s h o l d w a v e l e n g t h and s t o p p i n g
potential
4 5 6 7 8 9 10 11 12 13 14 15 16
// g i v e n v a l u e s l =2000; // w a v e l e n g t h o f l i g h t i n a r m s t r o n g e =1.6*10^ -19; // c h a r g e o f e l e c t r o n W =4.2; // work f u n c t i o n i n eV c =3*10^8; // v e l o c i t y o f l i g h t i n m/ s h =6.626*10^ -34; // Planck s c o n s t a n t i n J s // c a l c u l a t i o n x =12400/( W ) ; // h c =12400 eV disp (x , t h r e s h o l d w a v e l e n g t h ( i n Armstrong ) i s ) ; Vs =(12400/ l - W ) ; // disp ( Vs , s t o p p i n g p o t e n t i a l ( i n VOLTS) i s )
Scilab code Exa 13.3 calculation of momentum of Xray photon undergoing scattering
1 clc ; clear ; 2 // Example 1 3 . 3 3 // c a l c u l a t i o n o f momentum o f X r a y p h o t o n u n d e r g o i n g
scattering
4 5 6 7
8 9 10 11 12 13 14 15
e =1.6*10^ -19; // c h a r g e o f e l e c t r o n e W =12273; // work f u n c t i o n i n eV c =3*10^8; // v e l o c i t y o f l i g h t i n m/ s h =6.626*10^ -34; // Planck s c o n s t a n t i n J s hc =12400; // i n eV m =9.1*10^ -31 // r e s t m a s s o f p h o t o n i n kg // c a l c u l a t i o n x = hc /( W ) ; // w a v e l e n g t h o f p h o t o n u n d e r g o i n g m o d o f i e d s c a t t e r i n g in armstrong 16 y =x -( h /( m * c ) ) *(1 - cos ( alpha ) ) ; 17 p = h / y *10^10; 18 disp (p , momentum o f p h o t o n ( i n kg m/ s ) i s ) ;
Scilab code Exa 13.4 calculation of wavelength of scattered radiation and velocity of recoiled electrone
1 clc ; clear ; 2 // Example 1 3 . 4 3 // c a l c u l a t i o n o f w a v e l e n g t h o f
4 5 // g i v e n v a l u e s 6 7 alpha =30* %pi /180; // s c a t t e r i n g a n g l e i n r a d i a n 8 e =1.6*10^ -19; // c h a r g e o f e l e c t r o n 9 x =1.372*10^ -10; // w a v e l e n g t h o f i n c i d e n t r a d i a t i o n 10 11 12 13 14 15 16 y =(( x +( h /( m * c ) ) *(1 - cos ( alpha ) ) ) ) *10^10; 17 disp (y , w a v e l e n g t h o f s c a t t e r e d r a d i a t i o n ( i n
in
31
18 19 20 21 22
clc ; clear ; // Example 1 3 . 5 // c a l c u l a t i o n o f w a v e l e n g t h o f l i g h t e m i t t e d // g i v e n v a l u e s e =1.6*10^ -19; // c h a r g e o f e l e c t r o n e c =3*10^8; // v e l o c i t y o f l i g h t h =6.626*10^ -34; // Planck s c o n s t a n t i n J s E1 =5.36; // e n e r g y o f f i r s t s t a t e i n eV E2 =3.45; // e n e r g y o f s e c o n d s t a t e i n eV
32
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
clc ; clear ; // Example 1 3 . 7 // c a l c u l a t i o n o f u n c e r t a i n t y i n p o s i t i o n // 1 ) g i v e n v a l u e s h =6.626*10^ -34; // Planck s c o n s t a n t i n J s v1 =220; // v e l o c i t y o f e i n m/ s m =9.1*10^ -31; // mass o f e i n kg A =0.065/100; // a c c u r a c y
33
13 14 15 16 17 18 19 20 21 22
Scilab code Exa 13.8 Energy states of an electron and grain of dust
1 clc ; clear ; 2 // Example 1 3 . 8 3 // c a l c u l a t i o n o f e n e r g y 4 5 // 1 ) g i v e n v a l u e s 6 L1 =10*10^ -10; // w i d t h o f 7
s t a t e s o f an e l e c t r o n and g r a i n o f d u s t and c o m p a r i n g
p o t e n t i a l w e l l i n which e i s confined L2 =.1*10^ -3; // w i d t h o f p o t e n t i a l w e l l i n which g r a i n of dust i s confined h =6.626*10^ -34; // Planck s c o n s t a n t i n J s v1 =10^6; // v e l o c i t y o f g a r i n o f d u s t i n m/ s m1 =9.1*10^ -31; // mass o f e i n kg m2 =10^ -9; // mass o f g r a i n i n kg
energy s t a t e of
18 19 20 21
electron disp ( Ee2 , s e c o n d e n e r g y s t a t e o f e i s ) ; Ee3 =3^2* h ^2/(8* m1 * L1 ^2) ; // t h i r d e n e r g y s t a t e o f electron disp ( Ee3 , t h i r d e n e r g y s t a t e o f e i s ) ; disp ( Energy l e v e l s o f an e l e c t r o n i n an i n f i n i t e p o t e n t i a l w e l l a r e q u a n t i s e d and t h e e n e r g y d i f f e r e n c e between the s u c c e s s i v e l e v e l s i s q u i t e l a r g e . E l e c t r o n c a n n o t jump from one l e v e l t o o t h e r on s t r e n g t h o f t h e r m a l e n e r g y . Hence quantization of energy plays a s i g n i f i c a n t r o l e in case of electron ) energy s t a t e of grain of dust disp ( Eg1 , f i r s t e n e r g y s t a t e o f g r a i n o f d u s t i s ) ; Eg2 =2^2* h ^2/(8* m2 * L2 ^2) ; // s e c o n d e n e r g y s t a t e o f grain of dust disp ( Eg2 , s e c o n d e n e r g y s t a t e o f g r a i n o f d u s t i s ) ; Eg3 =3^2* h ^2/(8* m2 * L2 ^2) ; // t h i r d e n e r g y s t a t e o f grain of dust disp ( Eg3 , t h i r d e n e r g y s t a t e o f grain of dust i s ) ; KE = m2 * v1 ^2/2; // k i n e t i c e n e r g y o f g r a i n o f d u s t ; disp ( KE , k i n e t i c e n e r g y o f g r a i n o f d u s t i s ) ; disp ( The e n e r g y l e v e l s o f a g r a i n o f d u s t a r e s o near to each other that they c o n s t i t u t e a continuum . These e n e r g y l e v e l s a r e f a r s m a l l e r t h a n t h e k i n e t i c e n e r g y p o s s e s s e d by t h e g r a i n o f d u s t . I t can move t h r o u g h a l l t h e s e e n e r g y l e v e l s w i t h o u t an e x t e r n a l s u p p l y o f e n e r g y . Thus q u a n t i z a t i o n o f energy l e v e l s i s not at a l l s i g n i f i c a n t in case of macroscopic bodies . )
35
Chapter 14 Lasers
clc ; clear ; // Example 1 4 . 1 // c a l c u l a t i o n o f i n t e n s i t y o f l a s e r beam // g i v e n v a l u e s P =10*10^ -3; // Power i n Watt d =1.3*10^ -3; // d i a m e t r e i n m A = %pi * d ^2/4; // a r e a i n m2
36
3 4 5 6 7 8 9 10 11 12 13
Scilab code Exa 14.3 calculation of coherence length bandwidth and line width
1 clc ; clear ; 2 // Example 1 4 . 3 3 // c a l c u l a t i o n o f c o h e r e n c e l e n g t h , bandwidth and l i n e
width
4 5 6 7 8 9 10 11 12 13 14 15 16
// g i v e n v a l u e s c =3*10^8; // v e l o c i t y o f l i g h t i n m/ s t =.1*10^ -9; // t i m e d i v i s i o n i n s l =6238*10^ -10; // w a v e l e n g t h i n m // c a l c u l a t i o n x=c*t; disp (x , c o h e r e n c e l e n g t h ( i n m) i s ) ; d =1/ t ; disp (d , bandwidth ( i n Hz ) i s ) ; y = l ^2* d / c ; // l i n e w i d t h i n m disp ( y *10^10 , l i n e w i d t h ( i n a r m s t r o n g ) i s ) ;
37
clc ; clear ; // Example 1 4 . 5 // c a l c u l a t i o n o f no o f c a v i t y modes // g i v e n v a l u e s c =3*10^8; // v e l o c i t y o f l i g h t i n m/ s n =1.75; // r e f r a c t i v e i n d e x l =2*10^ -2; // l e n g t h o f ruby r o d i n m x =6943*10^ -10; // w a v e l e n g t h i n m y =5.3*10^ -10; // s p r e a d o f w a v e l e n g t h i n m // c a l c u l a t i o n d=c/n/l; f = c * y / x ^2; m=f/d; disp (m , no o f modes i s ) ;
38
clc ; clear ; // Example 1 5 . 1 // c a l c u l a t i o n o f b i n d i n g e n e r g y p e r n u c l e o n // g i v e n v a l u e s Mp =1.00814; // mass o f p r o t o n i n amu Mn =1.008665; // mass o f n u c l e o n i n amu M =7.01822; // mass o f L i t h i u m n u c l e u s i n amu amu =931; //amu i n MeV n =7 -3; // no o f n e u t r o n s i n l i t h i u m n u c l e u s // c a l c u l a t i o n ET =(3* Mp +4* Mn - M ) * amu ; // t o t a l b i n d i n g e n e r g y i n MeV E = ET /7; // 7 1 s t h e mass number disp (E , B i n d i n g e n e r g y p e r n u c l e o n i n MeV i s ) ;
39
clc ; clear ; // Example 1 5 . 2 // c a l c u l a t i o n o f e n e r g y // g i v e n v a l u e s M1 =15.00001; // a t o m i c mass o f N15 i n amu M2 =15.0030; // a t o m i c mass o f O15 i n amu M3 =15.9949; // a t o m i c mass o f O16 i n amu amu =931.4; //amu i n MeV mp =1.0072766; // r e s t m a s s o f p r o t o n mn =1.0086654; // r e s t m a s s o f n e u t r o n
// c a l c u l a t i o n Q1 =( M3 - mp - M1 ) * amu ; disp ( Q1 , e n e r g y r e q u i r e d t o remove one p r o t o n from O16 i s ) ; 16 Q2 =( M3 - mn - M2 ) * amu ; 17 disp ( Q2 , e n e r g y r e q u i r e d t o remove one n e u t r o n from O16 i s ) ;
clc ; clear ; // Example 1 5 . 3 // c a l c u l a t i o n o f b i n d i n g e n e r g y // g i v e n v a l u e s Mp =1.00758; // mass o f p r o t o n i n amu Mn =1.00897; // mass o f n u c l e o n i n amu M =4.0028; // mass o f Helium n u c l e u s i n amu amu =931.4; //amu i n MeV // c a l c u l a t i o n 40
clc ; clear ; // Example 1 5 . 4 // c a l c u l a t i o n o f amount o f unchanged m a t e r i a l // g i v e n v a l u e s T =2; // h a l f l i f e i n y e a r s k =.6931/ T ; // d e c a y c o n s t a n t M =4.0028; // mass o f Helium n u c l e u s i n amu amu =931.4; //amu i n MeV No =1; // i n i t i a l amount i n g // c a l c u l a t i o n N = No *( %e ^( - k *2* T ) ) ; disp (N , amount o f m a t e r i a l r e m a i n i n g unchanged a f t e r f o u r y e a r s ( i n gram ) i s ) ;
clc ; clear ; // Example 1 5 . 5 // c a l c u l a t i o n o f amount o f h a l f l i f e // g i v e n v a l u e s t =5; // t i m e p e r i o d i n y e a r s amu =931.4; //amu i n MeV No =5; // i n i t i a l amount i n g 41
after 5 years
clc ; clear ; // Example 1 5 . 6 // c a l c u l a t i o n o f a c t i v i t y // g i v e n v a l u e s t =28; // h a l f l i f e i n y e a r s m =10^ -3; // mass o f s a m p l e M =90; // a t o m i c mass o f s t r o n t i u m NA =6.02*10^26; // a v o g a d r o s number
42
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// g i v e n v a l u e s t =4.5*10^9; // h a l f l i f e i n y e a r s M1 =238; // a t o m i c mass o f Uranium i n g m =.093; // mass o f l e a d i n 1 g o f uranium i n g NA =6.02*10^26; // a v o g a d r o s number M2 =206; // a t o m i c mass o f l e a d i n g // c a l c u l a t i o n n = NA / M1 ; // no o f n u c l e i i n 1 g o f uranium s a m p l e n1 = m * NA / M2 ; // no o f n u c l e i i n m mass o f l e a d c = n1 / n ; k =.693/ t ; // d e c a y c o n s t a n t T =(1/ k ) * log (1+ c ) ; disp (T , a g e o f m i n e r a l i n y e a r s i s ) ;
// g i v e n v a l u e s t =5730; // h a l f l i f e o f C14 i n y e a r s M1 =50; // mass o f wooden p i e c e i n g A1 =320; // a c t i v i t y o f wooden p i e c e ( d i s i n t e g r a t i o n per minute per g ) 9 A2 =12; // a c t i v i t y o f l i v i n g t r e e
10 11 // c a l c u l a t i o n 12 k =.693/ t ; // d e c a y c o n s t a n t 13 A = A1 / M1 ; // a c t i v i t y a f t e r d e a t h 14 15 T =(1/ k ) * log ( A2 / A ) ; 16 disp (T , a g e o f m i n e r a l i n y e a r s
i s );
43
clc ; clear ; // Example 1 5 . 9 // c a l c u l a t i o n o f e n e r g y r e l e a s e d // g i v e n v a l u e s M1 =10.016125; // a t o m i c mass o f Boron i n amu M2 =13.007440; // a t o m i c mass o f C13 i n amu M3 =4.003874; // a t o m i c mass o f Helium i n amu mp =1.008146; // mass o f p r o t o n i n amu amu =931; //amu i n MeV // c a l c u l a t i o n Q =( M1 + M3 -( M2 + mp ) ) * amu ; // t o t a l b i n d i n g e n e r g y i n M disp (Q , B i n d i n g e n e r g y p e r n u c l e o n i n MeV i s ) ;
clc ; clear ; // Example 1 5 . 1 0 // c a l c u l a t i o n o f c r o s s s e c t i o n // g i v e n v a l u e s t =.01*10^ -3; // t h i c k n e s s i n m n =10^13; // no o f p r o t o n s bombarding t a r g e t p e r s NA =6.02*10^26; // a v o g a d r o s number M =7; // a t o m i c mass o f l i t h i u m i n kg d =500; // d e n s i t y o f l i t h i u m i n kg /m3 n0 =10^8; // no o f n e u t r o n s p r o d u c e d p e r s // c a l c u l a t i o n 44
13 n1 = d * NA / M ; // no o f t a r g e t n u c l e i p e r u n i t volume 14 n2 = n1 * t ; // no o f t a r g e t n u c l e i p e r a r e a 15 A = n0 /( n * n2 ) ; 16 disp (A , c r o s s s e c t i o n ( i n m 2 ) f o r t h i s r e a c t i o n i s ) ;
clc ; clear ; // Example 1 5 . 1 1 // c a l c u l a t i o n o f f i n a l e n e r g y // g i v e n v a l u e s B =.4; //max m a g n e t i c f i e l d i n Wb/m2 c =3*10^8; e =1.6*10^ -19; d =1.52; // d i a m e t r e i n m r = d /2; // c a l c u l a t i o n E = B * e * r * c ; //E=pc , p=mv=Ber disp (E , f i n a l e n e r g y o f e ( i n J ) i s ) ; E1 =( E / e ) /10^6; disp ( E1 , f i n a l e n e r g y o f e ( i n MeV) i s ) ;
45
8 9 10 11 12 13 14 15 16
clc ; clear ; // Example 1 5 . 1 3 // c a l c u l a t i o n o f power o u t p u t // g i v e n v a l u e s M =235; // a t o m i c mass o f Uranium i n kg e =5/100; // r e a c t o r e f f i c i e n c y m =25/1000; // amount o f uranium consumed p e r day i n kg E =200*10^6*1.6*10^ -19; // e n e r g y r e l e a s e d p e r f i s s i o n t =8.64*10^4; // day i n s e c o n d s NA =6.02*10^26; // a v o g a d r o s number // c a l c u l a t i o n n = NA * m / M ; // no o f n u c l e i i n 25 g E1 = n * E ; // e n e r g y p r o d u c e d by n n u c l e i E2 = E1 * e ; // e n e r g y c o n v e r t e d t o power P = E2 / t ; // power o u t p u t i n Watt disp ( P /10^6 , power o u t p u t i n M W i s );
46
clc ; clear ; // Example 1 5 . 1 4 // c a l c u l a t i o n o f power d e v e l o p e d // g i v e n v a l u e s M =235; // a t o m i c mass o f Uranium i n kg m =20.4; // amount o f uranium consumed p e r day i n kg E =200*10^6*1.6*10^ -19; // e n e r g y r e l e a s e d p e r f i s s i o n t =3600*1000; // t i m e o f o p e r a t i o n NA =6.02*10^26; // a v o g a d r o s number // c a l c u l a t i o n n = NA * m / M ; // no o f n u c l e i i n 2 0 . 4 kg E1 = n * E ; // e n e r g y p r o d u c e d by n n u c l e i P = E1 / t ; // i n Watt disp ( P /10^6 , power d e v e l o p e d i n M W i s );
clc ; clear ; // Example 1 5 . 1 5 // c a l c u l a t i o n o f amount o f d u e t e r i u m consumed // g i v e n v a l u e s M1 =2.01478; // a t o m i c mass o f Hydrogen i n amu M2 =4.00388; // a t o m i c mass o f Helium i n amu amu =931; //amu i n MeV e =30/100; // e f f i c i e n c y P =50*10^6; // o u t p u t power NA =6.026*10^26; // a v o g a d r o number t =8.64*10^4; // s e c o n d s i n a day // c a l c u l a t i o n 47
15 Q =(2* M1 - M2 ) * amu ; // e n e r g y
r e l e a s e d i n a DD r e a c t i o n
i n MeV
16 O = Q * e *10^6/2; // a c t u a l o u t p u t p e r d u e t e r i u m atom i n
eV
17 n = P /( O *1.6*10^ -19) ; // no o f D atoms r e q u i r e d 18 m = n * M1 / NA ; // e q u i v a l e n t mass o f D r e q u i r e d p e r s 19 X = m * t ; 20 21 disp (X , D euteri um r e q u i r e m e n t p e r day i n kg i s ) ;
48
clc ; clear ; // Example 1 6 . 1 // c a l c u l a t i o n o f d e n s i t y // g i v e n v a l u e s a =3.36*10^ -10; // l a t t i c e c o n s t a n t i n m M =209; // a t o m i c m a s s o f p o l o n i u m i n kg N =6.02*10^26; // a v o g a d r o s number z =1; // no o f atom // c a l c u l a t i o n d = z * M /( N * a ^3) disp (d , d e n s i t y ( i n kg /m 3 ) i s ) ;
49
3 4 5 6 7 8 9 10 11 12 13 14
// c a l c u l a t i o n o f no o f atoms // g i v e n v a l u e s a =4.3*10^ -10; // e d g e o f u n i t c e l l i n m d =963; // d e n s i t y i n kg /m3 M =23; // a t o m i c m a s s o f sodium i n kg N =6.02*10^26; // a v o g a d r o s number // c a l c u l a t i o n z = d * N * a ^3/ M ; disp (z , no o f atoms i s ) ;
clc ; clear ; // Example 1 6 . 3 // c a l c u l a t i o n o f d i s t a n c e // g i v e n v a l u e s z =4; // no o f atoms i n f c c d =2180; // d e n s i t y i n kg /m3 M =23+35.3; // a t o m i c m a s s o f sodium c h l o r i d e i n kg N =6.02*10^26; // a v o g a d r o s number // c a l c u l a t i o n a1 = z * M /( N * d ) ; a = a1 ^(1/3) ; l = a /2; // i n m disp ( l *10^10 , d i s t a n c e b e t w e e n a d j a c e n t c h l o r i n e and sodium atoms i n a r m s t r o n g i s ) ;
50
clc ; clear ; // Example 1 6 . 4 // c a l c u l a t i o n o f i n t e r a t o m i c s p a c i n g // g i v e n v a l u e s alpha =30* %pi /180; // Bragg a n g l e i n d e g r e e h =1; k =1; l =1; m =1; // o r d e r o f r e f l e c t i o n x =1.75*10^ -10; // w a v e l e n g t h i n m // c a l c u l a t i o n d = m * x /(2* sin ( alpha ) ) ; a = d * sqrt ( h ^2+ k ^2+ l ^2) ; // i n m disp ( a *10^10 , i n t e r a t o m i c s p a c i n g i n a r m s t r o n g i s ) ;
51
velocity of e 52
4 5 6 7 8 9 10 11 12 13
electrons
4 5 // g i v e n v a l u e s 6 E =5.5; // f e r m i l e v e l i n eV 7 kT =.026; // t e m p e r t u r e e q u i v a l e n t a t room temp i n e 8 9 // c a l c u l a t i o n 10 f =2* kT / E ; 11 12 disp (f , f r a c t i o n o f f r e e e l e c t r o n e \ s u p t o w i d t h kT
on e i t h e r s i d e o f Ef i s ) ;
53
Chapter 18 Semiconductors
clc ; clear ; // Example 1 8 . 2 // c a l c u l a t i o n o f p r o b a b i l i t y // g i v e n v a l u e s T =300; // temp i n K kT =.026; // t e m p e r t u r e e q u i v a l e n t a t room temp i n eV Eg =5.6; // f o r b i d d e n gap i n eV // c a l c u l a t i o n f =1/(1+ %e ^( Eg /(2* kT ) ) ) ; disp (f , p r o b a b i l i t y o f an e b e i n g t h e r m a l l y promoted t o c o n d u c t i o n band i s ) ;
54
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Example 1 8 . 3 // c a l c u l a t i o n o f f r a c t i o n o f e i n CB // g i v e n v a l u e s T =300; // temp i n K kT =.026; // t e m p e r t u r e e q u i v a l e n t a t room temp i n eV Eg1 =.72; // f o r b i d d e n gap o f germanium i n eV Eg2 =1.1; // f o r b i d d e n gap o f s i l i c o n i n eV Eg3 =5.6; // f o r b i d d e n gap o f diamond i n eV // c a l c u l a t i o n f1 = %e ^( - Eg1 /(2* kT ) ) ; disp ( f1 , f r a c t i o n o f e i n germanium i s ) ; f2 = %e ^( - Eg2 /(2* kT ) ) ; disp ( f2 , f r a c t i o n o f e i n s i l i c o n i s ); f3 = %e ^( - Eg3 /(2* kT ) ) ; disp ( f3 , f r a c t i o n o f e i n diamond i s );
c o n d u c t i o n band o f
c o n d u c t i o n band o f
c o n d u c t i o n band o f
clc ; clear ; // Example 1 8 . 3 // c a l c u l a t i o n o f f r a c t i o n i o n a l c h a n g e i n no o f e // g i v e n v a l u e s T1 =300; // temp i n K T2 =310; // temp i n K Eg =1.1; // f o r b i d d e n gap o f s i l i c o n i n eV k =8.6*10^ -5; // boltzmann s c o n s t a n t i n eV/K // c a l c u l a t i o n n1 =(10^21.7) *( T1 ^(3/2) ) *10^( -2500* Eg / T1 ) ; // no o f 55
Scilab code Exa 18.6 calculation of conductivity of intrinsic and doped semiconductors
1 clc ; clear ; 2 // Example 1 8 . 6 3 // c a l c u l a t i o n o f 4 5
// g i v e n v a l u e s 56
6 7 8 9 10 11 12 13 14 15 16
h =4.52*10^24; // no o f h o l e s p e r m3 e =1.25*10^14; // no o f e l e c t r o n s p e r m3 ue =.38; // e m o b i l i t y uh =.18; // h o l e m o b i l i t y q =1.6*10^ -19; // c h a r g e o f e i n C // c a l c u l a t i o n ni = sqrt ( h * e ) ; // i n t r i n s i c c o n c e n t r a t i o n ci = q * ni *( ue + uh ) ; disp ( ci , c o n d u c t i v i t y o f s e m i c o n d u c t o r ( i n S /m) i s ) ; cp = q * h * uh ; disp ( cp , c o n d u c t i v i t y o f doped s e m i c o n d u c t o r ( i n S /m ) i s );
57
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
V = B * J * w /( ND * e ) ; // i n v o l t s disp ( V *10^3 , H a l l v o l t a g e i n mv i s ) ;
58
clc ; clear ; // Example 1 9 . 1 // c a l c u l a t i o n o f p o t e n t i a l b a r r i e r // g i v e n v a l u e s e =1.6*10^ -19; n =4.4*10^28; // no o f atoms p e r m3 kT =.026* e ; // temp e q v l n t a t room temp ni =2.4*10^19; // no o f i n t r i n s i c c a r r i e r s p e r m3 NA = n /10^6; // no o f a c c e p t o r s ND = n /10^6; // no o f d o n o r s // c a l c u l a t i o n V =( kT / e ) * log ( NA * ND / ni ^2) ; disp (V , p o t e n t i a l b a r r i e r i n v o l t s i s ) ;
59
1 2 3 4 5 6 7 8 9 10 11 12 13
clc ; clear ; // Example 1 9 . 2 // c a l c u l a t i o n o f c u r r e n t // g i v e n v a l u e s e =1.6*10^ -19; kT =.026* e ; // temp e q v l n t a t room temp Io =2*10^ -7; // c u r r e n t f l o w i n g a t room temp i n A V =.1; // f o r w a r d b i a s v o l t a g e i n v o l t s // c a l c u l a t i o n I = Io *( %e ^( e * V / kT ) -1) ; // i n Ampere disp ( I *10^6 , c u r r e n t f l o w i n g when f o r w a r d b i a s a p p l i e d ( i n microampere ) i s );
60
Scilab code Exa 21.1 calculation of magnetizing force and relative permeability
1 clc ; clear ; 2 // Example 2 1 . 1 3 // c a l c u l a t i o n o f m a g n e t i z i n g
f o r c e and r e l a t i v e
permeability
4 5 6 7 8 9 10 11 12 13 14
// g i v e n v a l u e s M =2300; // m a g n e t i z a t i o n i n A/m B =.00314; // f l u x d e n s i t y i n Wb/m2 u =12.57*10^ -7; // p e r m e a b i l i t y i n H/m // c a l c u l a t i o n H =( B / u ) -M ; disp (H , m a g n e t i z i n g f o r c e ( i n A/m) i s ) ; Ur = B /( u * H ) ; disp ( Ur , r e l a t i v e p e r m e a b i l i t y i s )
density
4 5 6 7 8 9 10 11 12 13 14
// g i v e n v a l u e s H =10^5; // e x t e r n a l f i e l d i n A/m X =5*10^ -5; // s u s c e p t i b i l i t y u =12.57*10^ -7; // p e r m e a b i l i t y i n H/m // c a l c u l a t i o n M=X*H; disp (M , m a g n e t i z a t i o n ( i n A/m) i s ) ; B = u *( M + H ) ; disp (B , m a g n e t i c f l u x d e n s i t y ( i n wb/m 2 ) i s )
clc ; clear ; // Example 2 1 . 3 // c a l c u l a t i o n o f r e l a t i v e p e r m e a b i l i t y // g i v e n v a l u e s X =3.7*10^ -3; // s u s c e p t i b i l i t y a t 300 k T =300; // temp i n K T1 =200; // temp i n K T2 =500; // temp i n K // c a l c u l a t i o n C = X * T ; // c u r i e c o n s t a n t XT1 = C / T1 ; disp ( XT1 , r e l a t i v e p e r m e a b i l i t y a t T1 i s ) ; XT2 = C / T2 ; disp ( XT2 , r e l a t i v e p e r m e a b i l i t y a t T2 i s ) 62
63
Chapter 22 Superconductivity
);
64
2 3 4 5 6 7 8 9 10 11 12 13
// Example 2 2 . 2 // c a l c u l a t i o n o f t r a n s i t i o n t e m p e r a t u r e // g i v e n v a l u e s T =8; // temp i n K Hc =1*10^5; // c r i t i c a l m a g n e t i c f i e l d a t T i n A/m Hc0 =2*10^5; // m a g n e t i c f i e l d a t 0 K i n A/m // c a l c u l a t i o n Tc = T /( sqrt (1 - Hc / Hc0 ) ) ; disp ( Tc , t r a n s i t i o n temp i n K i s ) ;
Scilab code Exa 22.3 calculation of temp at which there is max critical eld
1 clc ; clear ; 2 // Example 2 2 . 3 3 // c a l c u l a t i o n o f temp a t which t h e r e
is
max
critical
4 5 6 7 8 9 10 11 12 13
field
// g i v e n v a l u e s Tc =7.26; // c r i t i c a l temp i n K Hc =8*10^5; //max c r i t i c a l m a g n e t i c f i e l d a t T i n A/m H =4*10^4; // s u b j e c t e d m a g n e t i c f i e l d a t i n A/m // c a l c u l a t i o n T = Tc *( sqrt (1 - H / Hc ) ) ; disp (T , max temp f o r s u p e r c o n d u c t i v i t y i n K i s ) ;
65
Chapter 23 Dielectrics
clc ; clear ; // Example 2 3 . 1 // c a l c u l a t i o n o f r e l a t i v e p e r m i t t i v i t y // g i v e n v a l u e s E =1000; // e l e c t r i c f i e l d i n V/m P =4.3*10^ -8; // p o l a r i z a t i o n i n C/m2 e =8.85*10^ -12; // p e r m i t t i v i t y i n F/m
);
66
2 // Example 2 3 . 2 3 // c a l c u l a t i o n o f e l e c t r o n i c p o l a r i z a b i l i t y 4 5 // g i v e n v a l u e s 6 7 e =8.85*10^ -12; // p e r m i t t i v i t y i n F/m 8 er =1.0024; // r e l a t i v e p e r m i t t i v i t y a t NTP 9 N =2.7*10^25; // atoms p e r m3 10 11 12 // c a l c u l a t i o n 13 alpha = e *( er -1) / N ; 14 disp ( alpha , e l e c t r o n i c p o l a r i z a b i l i t y ( i n F/m 2 ) i s
);
Scilab code Exa 23.3 calculation of electronic polarizability and relative permittivity
1 clc ; clear ; 2 // Example 2 3 . 3 3 // c a l c u l a t i o n o f
p o l a r i z a b i l i t y and
4 5 // g i v e n v a l u e s 6 7 e =8.85*10^ -12; // p e r m i t t i v i t y i n F/m 8 N =9.8*10^26; // atoms p e r m3 9 r =.53*10^ -10; // r a d i u s i n m 10 11 12 // c a l c u l a t i o n 13 alpha =4* %pi * e * r ^3; 14 disp ( alpha , e l e c t r o n i c p o l a r i z a b i l i t y
( i n F/m 2 ) i s
);
15 er =1+(4* %pi * N * r ^3) ;
67
16
disp ( er , r e l a t i v e p e r m i t t i v i t y i s )
Scilab code Exa 23.4 calculation of electronic polarizability and relative permittivity
1 clc ; clear ; 2 // Example 2 3 . 4 3 // c a l c u l a t i o n o f
p o l a r i z a b i l i t y and
i n F .m
2 10 e =8.854*10^ -12; // p e r m i t t i v i y 11 // c a l c u l a t i o n
12 13 n = NA * d / w ; 14 k = n * alpha /(3* e ) ; 15 er =(1+2* k ) /(1 - k ) ; 16 disp ( er , r e l a t i v e p e r m i t t i v i t y
is )
68
p o l a r i z a b i l i t y ( i n %) ) i s
o f complx d i e l e c t r i c c o n s t a n t a r e e q u a l i s ) ; 11 alpha = atan (1) *180/ %pi ; // p h a s e d i f f e r e n c e b e t w e e n c u r r e n t and v o l t a g e ( 1 b e c a u s e r e a l and i m a g i n r y parts are equal of the d i e l e c t r i c constant ) 12 disp ( alpha , p h a s e d i f f e e r e n c e ( i n d e g r e e ) i s ) ;
69
i s );
70
clc ; clear ; // Example 2 4 . 1 // F i b e r o p t i c s // g i v e n v a l u e s n =1.5; // r e f r a c t i v e i n d e x x =.0005; // f r a c t i o n a l i n d e x d i f f e r e n c e // c a l c u l a t i o n u = n *(1 - x ) ; disp (u , c l a d d i n g i n d e x i s ) ; alpha = asin ( u / n ) *180/ %pi ; disp ( alpha , c r i t i c a l i n t e r n a l r e f l e c t i o n a n g l e ( i n d e g r e e ) i s ); theta = asin ( sqrt ( n ^2 - u ^2) ) *180/ %pi ; disp ( theta , c r i t i c a l a c c e p t a n c e a n g l e ( i n d e g r e e ) i s ); N = n * sqrt (2* x ) ; disp (N , n u m e r i c a l a p e r t u r e i s ) ;
71
// g i v e n v a l u e s n =1.59; // c l a d d i n g r e f r a c t i v e i n d e x u =1.33; // r e f r a c t i v e i n d e x o f w a t e r N =.20; // n u m e r i c a l a p e r t u r e o f f i b r e // c a l c u l a t i o n x = sqrt ( N ^2+ n ^2) ; // i n d e x o f f i b r e N1 = sqrt ( x ^2 - n ^2) / u ; // n u m e r i c a l a p e r t u r e when f i b r e i s in water 12 alpha = asin ( N1 ) *180/ %pi ; 13 disp ( alpha , a c c e p t a n c e a n g l e i n d e g r e e i s ) ;
clc ; clear ; // Example 2 4 . 3 // c a l c u l a t i o n o f n o r m a l i s e d f r e q u e n c y // g i v e n v a l u e s n =1.45; // c o r e r e f r a c t i v e i n d e x d =.6; // c o r e d i a m e t r e i n m N =.16; // n u m e r i c a l a p e r t u r e o f f i b r e l =.9*10^ -6; // w a v e l e n g t h o f l i g h t // c a l c u l a t i o n u = sqrt ( n ^2+ N ^2) ; // i n d e x o f g l a s s f i b r e V = %pi * d * sqrt ( u ^2 - n ^2) / l ; 72
14
disp (V , n o r m a l i s e d f r e q u e n c y i s ) ;
modes
4 5 6 7 8 9 10 11 12 13 14 15 16
// g i v e n v a l u e s n =1.52; // c o r e r e f r a c t i v e i n d e x d =29*10^ -6; // c o r e d i a m e t r e i n m l =1.3*10^ -6; // w a v e l e n g t h o f l i g h t x =.0007; // f r a c t i o n a l r e f r a c t i v e i n d e x // c a l c u l a t i o n u = n *(1 - x ) ; // i n d e x o f g l a s s f i b r e V = %pi * d * sqrt ( n ^2 - u ^2) / l ; disp (V , n o r m a l i s e d f r e q u e n c y i s ) ; N = V ^2/2; disp (N , no o f modes i s ) ;
Scilab code Exa 24.5 calculation of numerical aperture and maximum acceptance angle
1 clc ; clear ; 2 // Example 2 4 . 5 3 // c a l c u l a t i o n o f n u m e r i c a l a p e r t u r e and maximum
acceptance angle
4 5 // g i v e n v a l u e s 6 n =1.480; // c o r e r e f r a c t i v e 7 u =1.47; // i n d e x o f g l a s s
index
73
8 9 10 11 12 13 14 15 16 17
l =850*10^ -9; // w a v e l e n g t h o f l i g h t V =2.405; //Vnumber // c a l c u l a t i o n r = V * l / sqrt ( n ^2 - u ^2) / %pi /2; // i n m disp ( r *10^6 , c o r e r a d i u s i n m i c r o m e t r e i s ) ; N = sqrt ( n ^2 - u ^2) ; disp (N , n u m e r i c a l a p e r t u r e i s ) ; alpha = asin ( N ) *180/ %pi ; disp ( alpha , max a c c e p t a n c e a n g l e i s ) ;
clc ; clear ; // Example 2 4 . 6 // c a l c u l a t i o n o f power l e v e l // g i v e n v a l u e s a =3.5; // a t t e n u a t i o n i n dB/km Pi =.5*10^ -3; // i n i t i a l power l e v e l i n W l =4; // l e n g t h o f c a b l e i n km // c a l c u l a t i o n Po = Pi *10^6/(10^( a * l /10) ) ; disp ( Po , power l e v e l a f t e r km( i n m i c r o w a t t ) i s ) ;
74
6 7 8 9 10 11 12
75
clc ; clear ; // Example 2 5 . 1 // c a l c u l a t i o n o f sum o f two b i n a r y numbers // g i v e n v a l u e s X = 0 0 1 1 ; // f i r s t b i n a r y number Y = 0 1 0 1 ; // s e c o n d b i n a r y number // c a l c u l a t i o n x = bin2dec ( X ) ; // d e c i m a l e q u i v a l e n t y = bin2dec ( Y ) ; // d e c i m a l e q u i v a l e n t z=x+y; Z = dec2bin ( z ) ; disp (Z , Sum o f t h e g i v e n b i n a r y numbers i s check Appendix AP 1 for dependency: bin21dec.sci check Appendix AP 2 for dependency: dec21bin.sci 76
a =1010.00; // f i r s t number b =0011.11; // s e c o n d number A = bin21dec ( a ) ; // c o n v e r t i n g a i n t o d e c i m a l number B = bin21dec ( b ) ; // c o n v e r t i n g b i n t o d e c i m a l number S=A+B; // a d d i n g t h e two d e c i m a l numbers temp = dec21bin ( S ) ; // c o n v e r t i n g t h e d e c i m a l sum back to binary 12 format ( v ,10) ; // c h a n g i n g t h e d e f a u l t p r e c i s i o n to 8 13 disp ( temp , sum i s ) ; // d i s p l a y i n g t h e f i n a l o u t p u t check Appendix AP 1 for dependency: bin21dec.sci check Appendix AP 2 for dependency: dec21bin.sci
77
a =1011.01; // f i r s t number b =1101.11; // s e c o n d number A = bin21dec ( a ) ; // c o n v e r t i n g a i n t o d e c i m a l number B = bin21dec ( b ) ; // c o n v e r t i n g b i n t o d e c i m a l number S=A+B; // a d d i n g t h e two d e c i m a l numbers temp = dec21bin ( S ) ; // c o n v e r t i n g t h e d e c i m a l sum back to binary 12 format ( v ,10) ; // c h a n g i n g t h e d e f a u l t p r e c i s i o n to 8 13 disp ( temp , sum i s ) ; // d i s p l a y i n g t h e f i n a l output
6 7 8 9 10 11
clc ; clear ; // Example 2 5 . 4 // c a l c u l a t i o n o f d i f f e r e n c e o f two b i n a r y numbers // g i v e n v a l u e s X = 1 0 1 1 ; // f i r s t b i n a r y number Y = 0 1 0 1 ; // s e c o n d b i n a r y number // c a l c u l a t i o n x = bin2dec ( X ) ; // d e c i m a l e q u i v a l e n t y = bin2dec ( Y ) ; // d e c i m a l e q u i v a l e n t z =x - y ; Z = dec2bin ( z ) ; disp (Z , d i f f e r e n c e o f t h e g i v e n b i n a r y numbers ) ;
78
3 4 5 6 7 8 9 10 11 12 13 14
// c a l c u l a t i o n o f d i f f e r e n c e o f two b i n a r y numbers // g i v e n v a l u e s X = 1 0 0 0 ; // f i r s t b i n a r y number Y = 0 0 1 1 ; // s e c o n d b i n a r y number // c a l c u l a t i o n x = bin2dec ( X ) ; // d e c i m a l e q u i v a l e n t y = bin2dec ( Y ) ; // d e c i m a l e q u i v a l e n t z =x - y ; Z = dec2bin ( z ) ; disp (Z , d i f f e r e n c e o f t h e g i v e n b i n a r y numbers ) check Appendix AP 1 for dependency: bin21dec.sci check Appendix AP 2 for dependency: dec21bin.sci
clc ; clear ; // e x a m p l e 2 5 . 6 // b i n a r y s u b s t r a c t i o n format ( v ,8) ; // c h a n g i n g t h e d e f a u l t p r e c i s i o n t o 8 a =1001.01; // f i r s t number b =0011.10; // s e c o n d number A = bin21dec ( a ) ; // c o n v e r t i n g a i n t o d e c i m a l number B = bin21dec ( b ) ; // c o n v e r t i n g b i n t o d e c i m a l number S =A - B ; // m u l t i p l y t h e two d e c i m a l numbers temp = dec21bin ( S ) ; // c o n v e r t i n g t h e d e c i m a l p r o d u c t back t o b i n a r y
79
14
i s ) ; // d i s p l a y i n g t h e f i n a l
// c a l c u l a t i o n x = bin2dec ( X ) ; // d e c i m a l e q u i v a l e n t y = bin2dec ( Y ) ; // d e c i m a l e q u i v a l e n t z=x*y; Z = dec2bin ( z ) ; disp (Z , p r o d u c t o f t h e g i v e n b i n a r y numbers i s check Appendix AP 1 for dependency: bin21dec.sci check Appendix AP 2 for dependency: dec21bin.sci
80
3 4 5 6 7 8 9 10 11 12 13 14
// e x a m p l e 2 5 . 8 // b i n a r y m u l t i p l i c a t i o n format ( v ,8) ; // c h a n g i n g t h e d e f a u l t p r e c i s i o n t o 8 a =10101.01; // f i r s t number b =110.10; // s e c o n d number A = bin21dec ( a ) ; // c o n v e r t i n g a i n t o d e c i m a l number B = bin21dec ( b ) ; // c o n v e r t i n g b i n t o d e c i m a l number S=A*B; // m u l t i p l y t h e two d e c i m a l numbers temp = dec21bin ( S ) ; // c o n v e r t i n g t h e d e c i m a l p r o d u c t back t o b i n a r y disp ( temp , p r o d u c t i s ) ; // d i s p l a y i n g t h e f i n a l output
clc ; clear ; // Example 2 5 . 9 // c a l c u l a t i o n o f q u o t i e n t o f two b i n a r y numbers // g i v e n v a l u e s X = 1 1 0 1 0 0 1 ; // d i v i d e n t Y = 101 ; // d i v i s o r // c a l c u l a t i o n x = bin2dec ( X ) ; // d e c i m a l e q u i v a l e n t y = bin2dec ( Y ) ; // d e c i m a l e q u i v a l e n t z=x/y; Z = dec2bin ( z ) ; disp (Z , q u o t i e n t o f t h e g i v e n b i n a r y numbers w i t h l a s t two d i g i t s i n f r a c t i o n a l p a r t i s ) check Appendix AP 1 for dependency: bin21dec.sci 81
clc ; clear ; // e x a m p l e 2 5 . 1 0 // b i n a r y d i v i s i o n format ( v ,8) ; // c h a n g i n g t h e d e f a u l t p r e c i s i o n t o 8 a =11001; // f i r s t number b =100; // s e c o n d number A = bin21dec ( a ) ; // c o n v e r t i n g a i n t o d e c i m a l number B = bin21dec ( b ) ; // c o n v e r t i n g b i n t o d e c i m a l number S=A/B; // m u l t i p l y t h e two d e c i m a l numbers temp = dec21bin ( S ) ; // c o n v e r t i n g t h e d e c i m a l p r o d u c t back t o b i n a r y disp ( temp , q u o t i e n t i s ) ; // d i s p l a y i n g t h e f i n a l output
82
9 10 11 12 13 14
clc ; clear ; // Example 2 5 . 1 2 // c a l c u l a t i o n o f p r o d u c t o f two o c t a l numbers // g i v e n v a l u e s X = 15 ; // d i v i d e n t Y = 24 ; // d i v i s o r // c a l c u l a t i o n x = oct2dec ( X ) ; // d e c i m a l e q u i v a l e n t y = oct2dec ( Y ) ; // d e c i m a l e q u i v a l e n t z=x*y; Z = dec2oct ( z ) ; // b i n a r y e q u i v a l e n t disp (Z , p r o d u c t o f t h e g i v e n o c t a l numbers i s )
83
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
X3 = E ; Y1 = 3 ; Y2 = 2 ; Y3 = D ;
// c a l c u l a t i o n x1 = hex2dec ( X1 ) ; // d e c i m a l e q u i v a l e n t x2 = hex2dec ( X2 ) ; // d e c i m a l e q u i v a l e n t x3 = hex2dec ( X3 ) ; // d e c i m a l e q u i v a l e n t y1 = hex2dec ( Y1 ) ; // d e c i m a l e q u i v a l e n t y2 = hex2dec ( Y2 ) ; // d e c i m a l e q u i v a l e n t y3 = hex2dec ( Y3 ) ; // d e c i m a l e q u i v a l e n t z1 = x1 + y1 ; z2 = x2 + y2 ; z3 = x3 + y3 ; Z1 = dec2hex ( z1 ) ; // b i n a r y e q u i v a l e n t o f sum Z2 = dec2hex ( z2 ) ; // b i n a r y e q u i v a l e n t o f sum Z3 = dec2hex ( z3 ) ; // b i n a r y e q u i v a l e n t o f sum disp ( Z1 , sum o f t h e f i r s t s e t o f h e x a d e c i m a l numbers i s ); 27 disp ( Z2 , sum o f t h e s e c o n d s e t o f h e x a d e c i m a l numbers i s ) ; 28 disp ( Z3 , sum o f t h e t h i r d m s e t o f h e x a d e c i m a l numbers i s ) ;
84
number i s )
number i s ) ;
p r c i s i o n t o 20
significant
digits
expressed in binary 85
temp2 = floor ( dec ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number 12 temp4 = modulo ( dec ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number
11 13 14
while ( temp2 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r for convenience p ( i ) =( modulo ( floor ( temp2 ) ,2) ) temp2 = floor ( temp2 /2) ; i = i +1; end
p o s i t i o n v a l u e s and a d d i n g
24 temp2 = temp2 +( p ( j ) *10^( j -1) ) ; 25 end 26 27 while ( temp4 ~=0) // s t o r i n g e a c h d e c i m a l
d i g i t in
p o s i t i o n v a l u e s and a d d i n g
38 temp5 = temp5 +(10^( -1* j ) * d ( j ) ) 39 end 40 41 temp3 = temp2 + temp5 ; 42 // f i n a l l y a d d i n g b o t h t h e i n t e g e r and d e c i m a l p a r t s
86
p r e c i s i o n to 8 significant digits i =1; w =1; dec =375.23; // g i v e n d e c i m a l number which s h o u l d be expressed in base 8 temp = modulo ( dec ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number temp2 = floor ( dec ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number
while ( temp2 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r for convenience p ( i ) =( modulo ( floor ( temp2 ) ,8) ) temp2 = floor ( temp2 /8) ; i = i +1; end
87
25 26
while ( temp ~=0) // s t o r i n g e a c h d e c i m a l d i g i t i n vector for convenience temp = temp *8; q ( w ) = floor ( temp ) ; w = w +1; temp = modulo ( temp ,1) ; end
1 clc ; // c l e a r s t h e command window 2 clear ; // c l e a r s a l l t h e v a r i a b l e s 3 // e x a m p l e 2 5 . 1 9 4 // o c t a l t o b i n a r y c o n v e r s i o n 5 6 format ( v ,8) ; // s e t t i n g t h e d e f a u l t p r e c i s i o n t o 8 7 8 i =1; w =1; 9 10 bin =34.56; // Given o c t a l number which we n e e d t o be 11 12 13 14 15 16 17 18 19 20
convert into binary temp1 = floor ( bin ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number temp0 = modulo ( bin ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number temp2 = temp0 *10^2; // c o n v e r t i n g d e c i m a l v a l u e t o interger for convenience while ( temp1 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n vector for convenience p ( i ) = modulo ( temp1 ,10) ; temp1 = round ( temp1 /10) ; i = i +1; end
while ( temp2 >0) // s t o r i n g e a c h d e c i m a l d i g i t i n vector for convenience 21 q ( w ) = modulo ( temp2 ,10) ; 22 temp2 = floor ( temp2 /10) ; 23 w = w +1;
24 25 end 26 temp1 =0; // c l e a r i n g t e m p o r a r y v a r i a b l e temp1 27 28 for i =1:2 29 // m u l t i p l i y i n g b i t s o f d e c i m a l p a r t w i t h t h e i r 30 31 end
89
32 33 temp2 =0; // c l e a r i n g t e m p o r a r y v a r i a b l e temp2 34 for z =1:2 35 // m u l t i p l i y i n g b i t s o f d e c i m a l p a r t w i t h t h e i r 36 37 38 end 39 40 temp = temp1 + temp2 ; 41 // a d d i n g b o t h i n t e g e r and d e c i m a l p a r t s t o g e t
total
deciaml value .
42 dec = temp ; 43 44 temp2 = floor ( dec ) ; // s e p a r a t i n g
i n t e g e r p a r t from t h e
d i g i t in vector
51 52 53 54 end 55 56 temp2 =0; // c l e a r s t e m p o r a r y v a r i a b l e temp2 57 58 for j =1: length ( p ) 59 // m u l t i p l i y i n g b i t s o f i n t e g e r p a r t w i t h t h e i r 60 61 end 62 63 temp4 = modulo ( temp3 ,1) ;
for convenience p ( i ) =( modulo ( floor ( temp2 ) ,2) ) temp2 = floor ( temp2 /2) ; i = i +1;
90
64 65
while ( temp4 ~=0) // s t o r i n g e a c h d e c i m a l d i g i t i n vector for convenience temp4 = temp4 *2; d ( x ) = floor ( temp4 ) ; x = x +1; temp4 = modulo ( temp4 ,1) ; end
p o s i t i o n v a l u e s and a d d i n g
76 temp5 = temp5 +(10^( -1* j ) * d ( j ) ) 77 end 78 79 temp = temp2 + temp5 ; 80 // f i n a l l y a d d i n g b o t h t h e i n t e g e r and d e c i m a l p a r t s 81
t o be c o n v e r t i n t o o c t a l // c o n v e r s i o n t o d e c i m a l f i r s t temp1 = floor ( bin ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number 8 temp2 = modulo ( bin ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number 91
5 6 7
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
temp2 = temp2 *10^5; // c o n v e r t i n g d e c i m a l v a l u e t o integer for convenience while ( temp1 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r for convenience p ( i ) = modulo ( temp1 ,10) ; temp1 = floor ( temp1 /10) ; i = i +1; end while ( temp2 >0) // s t o r i n g e a c h d e c i m a l d i g i t i n v e c t o r for convenience q ( w ) = modulo ( temp2 ,2) ; temp2 =( temp2 /10) ; temp2 = floor ( temp2 ) ; w = w +1; end temp1 =0; // f l a g b i t for i =1: length ( p ) // c h e c k i n g w h e t h e r i t i s a b i n a r y number o r n o t if ( p ( i ) >1) then disp ( n o t a b i n a r y number ) ; abort ; end end for i =1: length ( p ) // m u l t i p l i y i n g b i t s o f i n t e g e r p a r t w i t h t h e i r p o s i t i o n v a l u e s and a d d i n g temp1 = temp1 +( p ( i ) *2^( i -1) ) ; end temp2 =0; // f l a g b i t for z =1: length ( q ) // m u l t i p l i y i n g b i t s o f d e c i m a l p a r t w i t h t h e i r p o s i t i o n v a l u e s and a d d i n g temp2 = temp2 +( q ( z ) *2^( -1*(6 - z ) ) ) ; end dec = temp1 + temp2 ; // f i n a l l y a d d i n g b o t h t h e i n t e g e r and d e c i m a l p a r t s to get decimal e q u i v a l e n t
92
40 41 42
// c o n v e r s i o n from d e c i m a l t o o c t a l
temp = modulo ( dec ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number 46 temp2 = floor ( dec ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number
47 48 49
50 51 52 53 54 55 temp2 =0; // c l e a r i n g t e m p o r a r y v a r i a b l e temp2 56 57 for j =1: length ( r ) 58 // m u l t i p l i y i n g b i t s o f i n t e g e r p a r t w i t h t h e i r 59 60 end 61 62 while ( temp ~=0) // s t o r i n g e a c h d e c i m a l 63 64 65 66 67 end 68 69 temp1 =0; // f l a g b i t 70 for k =1: length ( s ) 71 // m u l t i p l i y i n g b i t s
while ( temp2 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r for convenience r ( i ) =( modulo ( floor ( temp2 ) ,8) ) temp2 = floor ( temp2 /8) ; i = i +1; end
d i g i t in
vector for convenience temp = temp *8; s ( w ) = floor ( temp ) ; w = w +1; temp = modulo ( temp ,1) ;
to 8
temp2 = modulo ( dec ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number 11 x = dec2hex ( temp1 ) ; // h e x a d e c i m a l e q u i v a l e n t o f i n t e g e r part 12 s =0;
10 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
while ( temp2 ~=0) // s t o r i n g e a c h d e c i m a l d i g i t i n vector for convenience temp2 = temp2 *16; q ( w ) = floor ( temp2 ) ; s = s +1; // c o u n t e r o f a a ( w ) = dec2hex ( q ( w ) ) ; w = w +1; temp2 = modulo ( temp2 ,1) ; end f = a (1) ; for i =2: s f=f+a(i); end b = . ; // f o r c o n c a t e n a t i n g t o g e t t h e d e c i m a l p a r t o f hexadecimal hex = x + b + f ; // c o n c a t e n a t i n g i n t e g e r and d e c i m a l p a r t disp ( hex , h e x a d e c i m a l e q u i v a l e n t i s ) ;
95
);
h a s t o be s u b s t r a c t e d : ) ; bb =14; aaa = -7; // s u b s t r a c t i o n i s a d d i t i o n o f n e g a t i v e number if aaa <0 then aa = -1* aaa ; else aa = aaa ; 96
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
end a =0; b =0; q =0; for i =1:5 // c o n v e r t i n g from d e c i m a l t o binary x = modulo ( aa ,2) ; a = a + (10^ q ) * x ; aa = aa /2; aa = floor ( aa ) ; q = q +1; end q =0; for i =1:5 // c o n v e r t i n g from d e c i m a l t o b i n a r y y = modulo ( bb ,2) ; b = b + (10^ q ) * y ; bb = bb /2; bb = floor ( bb ) ; q = q +1; end for i =1:5 a1 ( i ) = modulo (a ,10) ; a = a /10; a = round ( a ) ;
end for i =1:5 b1 ( i ) = modulo (b ,10) ; b = b /10; b = round ( b ) ; end ; if aaa <0 then // making one s complement i f number i s l e s s than z e r o 44 for i =1:5 45 a1 ( i ) = bitcmp ( a1 ( i ) ,1) ; 46 end
47 48
49 50 for i =1:5 51 c1 ( i ) = a1 ( i ) + b1 ( i ) + car ( i ) ; 52 if c1 ( i ) == 2 then 53 car ( i +1) = 1; 54 c1 ( i ) =0; 55 elseif c1 ( i ) ==3 then 56 car ( i +1) = 1; 57 c1 ( i ) =1; 58 else 59 car ( i +1) =0; 60 end ; 61 end ; 62 car2 (1) = car (6) ; 63 re =0; 64 format ( v ,18) ; 65 for i =1:5 66 re = re +( c1 ( i ) *(10^( i -1) ) ) // r e s u l t
o f one s
complement a d d i t i o n
67 end ; 68 69 70 71 for i =1:5 72 s ( i ) = modulo ( re ,10) ; 73 re = re /10; 74 re = round ( re ) ; 75 end ; 76 77 for i =1:5 78 re1 ( i ) = s ( i ) + car2 ( i ) ; // a d d i t i o n 79 80 81 82 83 84
o f c a r r y a f t e r one s
complement a d d i t i o n if re1 ( i ) == 2 then car2 ( i +1) = 1; re1 ( i ) =0; elseif re1 ( i ) ==3 then car2 ( i +1) = 1; re1 ( i ) =1; 98
85 else 86 car2 ( i +1) =0; 87 end ; 88 end ; 89 90 re2 =0; 91 format ( v ,18) ; 92 for i =1:5 93 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 94 end ; 95 96 disp ( re , d i f f e r e n c e i s )
no h a s
99
for i =1:5 c1 ( i ) = a1 ( i ) + b1 ( i ) + car ( i ) ; if c1 ( i ) == 2 then car ( i +1) = 1; c1 ( i ) =0; elseif c1 ( i ) ==3 then car ( i +1) = 1; c1 ( i ) =1; else car ( i +1) =0; end ; end ; car2 (1) = car (6) ; re =0; format ( v ,18) ; for i =1:5 re = re +( c1 ( i ) *(10^( i -1) ) ) // r e s u l t o f one s complement a d d i t i o n 46 end ;
47 48 49 for i =1:5 50 s ( i ) = modulo ( re ,10) ; 51 re = re /10; 52 re = round ( re ) ; 53 end ; 54 if car2 (1) ==1 then // c h e c k i n g c a r r y 55
100
o f c a r r y a f t e r one s
58 59 60 61 62 63 64 65 66 67 end ; 68 69 re2 =0; 70 format ( v ,18) ; 71 for i =1:5 72 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 73 end ; 74 disp ( re2 , d i f f e r e n c e i s ) ; 75 76 else 77 for i =1:5 78 re1 ( i ) = bitcmp ( s ( i ) ,1) ; 79 end 80 re2 =0; 81 for i =1:5 82 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 83 end ; 84 re2 = -1* re2 ; 85 disp ( re2 , d i f f e r e n c e i s ) ; 86 end ;
complement a d d i t i o n if re1 ( i ) == 2 then car2 ( i +1) = 1; re1 ( i ) =0; elseif re1 ( i ) ==3 then car2 ( i +1) = 1; re1 ( i ) =1; else car2 ( i +1) =0; end ;
101
1 2 clc ; 3 clear ; 4 // e x a m p l e 2 5 . 2 7 5 // s u b s t r a c t i o n by one s complement method 6 // a=i n p u t ( E n t e r t h e f i r s t no ( b i n a r y ) : ) ; 7 // b=i n p u t ( E n t e r t h e number from which f i r s t
no h a s
for i =1:5 a1 ( i ) = modulo (a ,10) ; a = a /10; a = round ( a ) ; end for i =1:5 b1 ( i ) = modulo (b ,10) ; b = b /10; b = round ( b ) ; end ; for i =1:5 // making one s complement o f number t o be substracted 23 a1 ( i ) = bitcmp ( a1 ( i ) ,1) ; 24 end
25 26 car (1) =0; 27 28 for i =1:5 29 c1 ( i ) = a1 ( i ) + b1 ( i ) + car ( i ) ; 30 if c1 ( i ) == 2 then 31 car ( i +1) = 1; 32 c1 ( i ) =0; 33 elseif c1 ( i ) ==3 then 34 car ( i +1) = 1; 35 c1 ( i ) =1; 36 else
102
37 car ( i +1) =0; 38 end ; 39 end ; 40 car2 (1) = car (6) ; 41 re =0; 42 format ( v ,18) ; 43 for i =1:5 44 re = re +( c1 ( i ) *(10^( i -1) ) ) // r e s u l t
o f one s
complement a d d i t i o n
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
end ; for i =1:5 s ( i ) = modulo ( re ,10) ; re = re /10; re = round ( re ) ; end ; if car2 (1) ==1 then // c h e c k i n g c a r r y for i =1:5 re1 ( i ) = s ( i ) + car2 ( i ) ; // a d d i t i o n o f c a r r y a f t e r one s complement a d d i t i o n if re1 ( i ) == 2 then car2 ( i +1) = 1; re1 ( i ) =0; elseif re1 ( i ) ==3 then car2 ( i +1) = 1; re1 ( i ) =1; else car2 ( i +1) =0; end ; end ; re2 =0; format ( v ,18) ; for i =1:5 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) end ; re2 = -1* re2 ; 103
73 disp ( re2 , d i f f e r e n c e i s ) ; 74 75 else 76 for i =1:5 77 re1 ( i ) = bitcmp ( s ( i ) ,1) ; 78 end 79 re2 =0; 80 for i =1:5 81 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 82 end ; 83 re2 = -1* re2 ; 84 disp ( re2 , d i f f e r e n c e i s ) ; 85 86 end ;
clc ; clear ; // e x a m p l e 2 5 . 2 8 // f i n i d i n g two s complement // a=i n p u t ( E n t e r t h e number ( b i n a r y ) : ) ; a =1010; for i =1:4 a1 ( i ) = modulo (a ,10) ; a = a /10; a = round ( a ) ; end for i =1:4 // making one s complement o f number a1 ( i ) = bitcmp ( a1 ( i ) ,1) ; end for i =1:4 car (1) =1; re ( i ) = a1 ( i ) + car ( i ) ; // a d d i t i o n o f one t o one s 104
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
complement t o c o n t a i n two s complement if re ( i ) == 2 then car ( i +1) = 1; re ( i ) =0; elseif re ( i ) ==3 then car ( i +1) = 1; re ( i ) =1; else car ( i +1) =0; end ; end ; re2 =0; format ( v ,18) ; for i =1:4 re2 = re2 +( re ( i ) *(10^( i -1) ) ) end ; disp ( re2 , two s complement i s ) ;
Scilab code Exa 25.29 Addition of negative number by twos complement method
1 2 clc ; 3 clear ; 4 // Example 2 5 . 2 9 5 // a d d i t i o n o f n e g a t i v e number by by two s complement 6 7 8 9 10 11
method // bb=i n p u t ( E n t e r t h e f i r s t no ( i n d e c i m a l ) : ) ; // aaa=i n p u t ( E n t e r t h e n e g a t i v e number t h a t h a s t o be added ) ; bb =14; aaa = -7; if aaa <0 then aa = -1* aaa ; 105
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
else aa = aaa ; end a =0; b =0; q =0; for i =1:5 // c o n v e r t i n g from d e c i m a l t o binary x = modulo ( aa ,2) ; a = a + (10^ q ) * x ; aa = aa /2; aa = floor ( aa ) ; q = q +1; end q =0; for i =1:5 // c o n v e r t i n g from d e c i m a l t o b i n a r y y = modulo ( bb ,2) ; b = b + (10^ q ) * y ; bb = bb /2; bb = floor ( bb ) ; q = q +1; end for i =1:5 a1 ( i ) = modulo (a ,10) ; a = a /10; a = round ( a ) ;
end for i =1:5 b1 ( i ) = modulo (b ,10) ; b = b /10; b = round ( b ) ; end ; if aaa <0 then // making one s complement o f t h e n e g a t i v e number 44 for i =1:5 45 a1 ( i ) = bitcmp ( a1 ( i ) ,1) ; 46 end
47
106
48 car (1) =0; 49 50 for i =1:5 51 c1 ( i ) = a1 ( i ) + b1 ( i ) + car ( i ) ; 52 if c1 ( i ) == 2 then 53 car ( i +1) = 1; 54 c1 ( i ) =0; 55 elseif c1 ( i ) ==3 then 56 car ( i +1) = 1; 57 c1 ( i ) =1; 58 else 59 car ( i +1) =0; 60 end ; 61 end ; 62 re =0; 63 format ( v ,18) ; 64 for i =1:5 65 re = re +( c1 ( i ) *(10^( i -1) ) ) // r e s u l t
o f one s
complement a d d i t i o n
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
end ; for i =1:5 s ( i ) = modulo ( re ,10) ; re = re /10; re = round ( re ) ; end ; if car (6) ==1 then // c h e c k i n g c a r r y car2 (1) =1; for i =1:5 re1 ( i ) = s ( i ) + car2 ( i ) ; // a d d i t i o n o f c a r r y a f t e r one s complement a d d i t i o n if re1 ( i ) == 2 then car2 ( i +1) = 1; re1 ( i ) =0; elseif re1 ( i ) ==3 then car2 ( i +1) = 1; re1 ( i ) =1; else 107
84 car2 ( i +1) =0; 85 end ; 86 end ; 87 88 re2 =0; 89 format ( v ,18) ; 90 for i =1:5 91 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 92 end ; 93 94 disp ( re2 , d i f f e r e n c e i s ) ; 95 96 else 97 for i =1:5 98 re1 ( i ) = bitcmp ( s ( i ) ,1) ; 99 end 100 re2 =0; 101 for i =1:5 102 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 103 end ; 104 re2 = -1* re2 ; 105 disp ( re2 , d i f f e r e n c e i s ) ; 106 end ;
no h a s
t o be s u b s t r a c t e d : ) ;
8 a =10011;
108
for i =1:5 a1 ( i ) = modulo (a ,10) ; a = a /10; a = round ( a ) ; end for i =1:5 b1 ( i ) = modulo (b ,10) ; b = b /10; b = round ( b ) ; end ; for i =1:5 // making one s complement o f number t o be substracted 23 a1 ( i ) = bitcmp ( a1 ( i ) ,1) ; 24 end
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
9 10 11 12 13 14 15 16 17 18 19 20 21 22
b =10001; q =0;
car (1) =0; for i =1:5 c1 ( i ) = a1 ( i ) + b1 ( i ) + car ( i ) ; if c1 ( i ) == 2 then car ( i +1) = 1; c1 ( i ) =0; elseif c1 ( i ) ==3 then car ( i +1) = 1; c1 ( i ) =1; else car ( i +1) =0; end ; end ; re =0; format ( v ,18) ; for i =1:5 re = re +( c1 ( i ) *(10^( i -1) ) ) // r e s u l t o f one s complement a d d i t i o n 109
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
end ; for i =1:5 s ( i ) = modulo ( re ,10) ; re = re /10; re = round ( re ) ; end ; if car (6) ==1 then // c h e c k i n g c a r r y for i =1:5 re1 ( i ) = s ( i ) + car2 ( i ) ; // a d d i t i o n o f c a r r y a f t e r one s complement a d d i t i o n if re1 ( i ) == 2 then car2 ( i +1) = 1; re1 ( i ) =0; elseif re1 ( i ) ==3 then car2 ( i +1) = 1; re1 ( i ) =1; else car2 ( i +1) =0; end ; end ; re2 =0; format ( v ,18) ; for i =1:5 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) end ; re2 = -1* re2 ; disp ( re2 , d i f f e r e n c e i s ) ; else for i =1:5 re1 ( i ) = bitcmp ( s ( i ) ,1) ; end re2 =0; for i =1:5 re2 = re2 +( re1 ( i ) *(10^( i -1) ) ) 110
is ) ;
111
Appendix
Scilab code AP 1 Binary to Decimal convertor // b i n 2 1 d e c i s a f u n c t i o n whcih c o n v e r t s any b i n a r y number g i v e n t o i t w i l l o u t p u t i t s e q u i v a l e n t d e c i m a l number 2 // p a s s t h e b i n a r y number a s an argument t o t h e function 3 // For e g : b i n 2 1 d e c i m a l ( 1 0 1 0 ) 4 // W i l l g i v e an o u t p u t o f 10
1 5 6 7 8 9
function [ temp ]= bin21dec ( bin ) i =1; w =1; temp1 = floor ( bin ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number temp2 = modulo ( bin ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number temp2 = temp2 *10^3; // c o n v e r t i n g decimal value to i n t e r g e r f o r convenience while ( temp1 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r f o r convenience p ( i ) = modulo ( temp1 ,10) ; temp1 = floor ( temp1 /10) ; 112
10
11
12 13
14 15
16 17 18 19
i = i +1; end while ( temp2 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r f o r convenience q ( w ) = modulo ( temp2 ,2) ; temp2 =( temp2 /10) ; temp2 = floor ( temp2 ) ; w = w +1; end temp1 =0; // c l e a r i n g t h e t e m p o r a r y v a r i a b l e
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
temp2
for i =1: length ( p ) // c h e c k i n g w h e t h e r i t i s b i n a r y o r n o t . if ( p ( i ) >1) then disp ( n o t a b i n a r y number ) ; abort ; end end for i =1: length ( p ) // m u l t i p l i y i n g t h e b i t s o f i n t e g e r p a r t w i t h t h e i r p o s i t i o n v a l u e s and a d d i n g temp1 = temp1 +( p ( i ) *2^( i -1) ) ; end temp2 =0; // c l e a r i n g t h e t e m p o r a r y v a r i a b l e
36 37 38 39 40 41
temp2
42 43 44
113
45
temp = temp1 + temp2 ; // f i n a l l y a d d i n g b o t h t h e i n t e g e r and d e c i m a l parts to get t o t a l output . 46 endfunction Scilab code AP 2 Decimal to Base 2 Converter // d e c 2 1 b i n i s a f u n c t i o n whcih c o n v e r t s any d e c i m a l number g i v e n t o i t w i l l o u t p u t i t s e q u i v a l e n t b i n a r y number 2 // p a s s t h e d e c i m a l number a s an argument t o t h e function 3 // For e g : d e c 2 1 b i n ( 1 0 ) 4 // W i l l g i v e an o u t p u t o f 1 0 1 0
1 5 6 7
function [ temp ]= dec21bin ( dec ) temp2 = floor ( dec ) ; // s e p a r a t i n g i n t e g e r p a r t from t h e g i v e n number temp4 = modulo ( dec ,1) ; // s e p a r a t i n g d e c i m a l p a r t from t h e g i v e n number format ( v ,18) ; // c h a n g i n g t h e d e f a u l t p r e c i s i o n t o 18
9 10
11 12
13 14
15 16 17 18
while ( temp2 >0) // s t o r i n g e a c h i n t e g e r d i g i t i n v e c t o r f o r convenience p ( i ) =( modulo ( floor ( temp2 ) ,2) ) temp2 = floor ( temp2 ) /2; i = i +1; end 114
19 20 21 22
temp2 =0; // c l e a r i n g t h e t e m p o r a r y v a r i a b l e
temp2
23 24 25 26
for j =1: length ( p ) // m u l t i p l i y i n g t h e b i t s o f i n t e g e r p a r t w i t h t h e i r p o s i t i o n v a l u e s and a d d i n g temp2 = temp2 +( p ( j ) *10^( j -1) ) ; end while ( temp4 ~=0) // s t o r i n g each i n t e g e r d i g i t in v e c t o r f o r convenience temp4 = temp4 *2; d ( x ) = floor ( temp4 ) ; x = x +1; temp4 = modulo ( temp4 ,1) ; end temp5 =0; // c l e a r i n g t h e t e m p o r a r y v a r i a b l e
27 28 29 30 31 32 33 34 35
temp2
36 37 38 39
for j =1: x -1 // m u l t i p l i y i n g the b i t s o f decimal part with t h e i r p o s i t i o n v a l u e s and a d d i n g temp5 = temp5 +(10^( -1* j ) * d ( j ) ) end temp = temp2 + temp5 ;
115