FINDING WAVENUMBER IN A RECTANGULAR WAVEGUIDE BY FINITE DIFFERENCE METHODS SELİM MİMAROĞLU Hacettepe University Electrical and Electronics Engineering Department ELE 401-ELE 402 Final Project Report Instructor: Dr. Adnan Köksal Fall, 1999 ABSTRACT Finite Difference Methods is one of the most important methods for solving electromagnetic problems. It is easily understood, more frequently used, and more universally applicable than any other methods. The finite difference techniques are based upon approximations, which permit replacing differential equations, by finite difference equations. By using the Finite Difference Methods the wavenumber k is found. Firstly initial values for TE and TM waves are defined. 1 matrix is the initial value for TM and a ramp matrix is the initial value for the TM. SOR is used in these calculations in order to increase the speed of the calculation. k values are modified and again used in the equations and programs. Also E and H fields for TM and TE waves are found and compared with the analytical solutions. LIST OF CONTENTS ABSTRACT ii LIST OF FIGURES iii 1. INTRODUCTION 1 2. FINITE DIFFERENCE METHODS 2 3. TM IN RECTANGULAR WAVEGUIDES 5 4. TE IN RECTANGULAR WAVEGUIDES 7 5. FD APPROACH 9 6. ACCURACY AND STABILITY OF FD SOLN. 12 7. RESULTS 16 LIST OF FIGURES Figure 1.1 a-rectangular grid b-skew grid c-triangular grid d-circular grid 2.1 f(x) function 3.1 rectangular W.G. 5.1 discretized W.G. 6.1 error as a function of the mesh size Page 1 2 5 10 14 1. INTRODUCTION The finite difference method (FDM) was first developed by A. Thom in the 1920s under the title “the method of squares” to solve nonlinear hydrodynamic equations. Since then, the method has found applications in solving different field problems. The finite difference techniques are based upon approximations, which permit replacing differential equations, by finite difference equations. These finite difference approximations are algebraic in form; they relate the value of the dependent variable at a point in the solution region to the values at some neighbouring points. (a) (b) (c) (d) Figure 1.1 (a) rectangular grid, (b) skew grid, (c) triangular grid, (d) circular grid. Thus a finite difference solution basically involves three steps: (1) Dividing the solution region into a grid of nodes. (2) Approximating the given differential equation by finite difference equivalent that relates the dependent variable at a point in the solution region to its values at the neighbouring points. (3) Solving the difference equations subject to the prescribed boundary conditions and/or initial conditions. The most commonly used grid patterns for two – dimensional problems are shown in Fig. 1.1 2. FINITE DIFFERENCE METHODS Given a function ƒ(x) shown in Fig.2, we can approximate its derivative, slope or the tangent at P by the slope of arc PB, giving the forward – difference formula, f(x) P B X0 X 0+x A X 0–x x Figure 2 .1 (x0) = (x0 + x) – (x0) x (2.1) or the slope of the arc AP, yielding the backward – difference formula, (x0) = (x0) – (x0 – x) x or the slope of the arc AB, resulting in the central – difference formula, (2.2) (x0) = (x0 + x) – (x0 – x) 2x (2.3) We can also estimate the second derivative ƒ(x) at P as ’(x0 + x/2) – ’(x0-x/2) (x0) = x/2x/2Yx/2) x = 1 x (x0) = (x0 + x) – (x0) (x0) – (x0 – x) – x x (x0 + x) – 2(x0) + (x0- x) (x)2 (2.4) Any approximation of a derivative in terms of values at a discrete set of points is called finite difference approximation. According to the well – known expansion, Taylor’s series approach (x0 + x) = (x0) + x (x0) + 1 1 (x)2 (x0) + (x)3(x0) + ….. 2! 3! (2.5) and (x0 – x) = (x0) – x (x0) + 1 1 (x)2 (x0) – (x)3 (x0) + . . 2! 3! (2.6) Upon adding these expansions, (x0 + x) + (x0 – x) = 2(x0) + (x)2(x0) + O(x)4 (2.7) where O(Δx)4 is the error introduced by truncating the series. Therefore, O(Δx) 4 represents terms that are not greater than (Δx) 4 . Assuming that these terms are negligible. Higher order finite difference approximations can be obtained by taking more terms in Taylor series expansion. If the infinite Taylor series were retained, an exact solution would be realized for the problem. However, for practical reasons, the infinite series is usually truncated after the second-order term. This imposes an error, which exists in all finite difference solutions. To apply the difference method to find the solution of a function Φ(x,t), we divide the solution region in the x – t plane into equal rectangles or meshes of sides Δx and Δt .We let the coordinates (x,t) of a typical grid point or node be i = 0, 1, 2, ... j = 0, 1, 2, ... x = ix, t = jt, and the value if Φ at P be ΦP = Φ(ix, jt) = Φ(i, j). (2.8) With this notation, the central difference approximations of the derivatives of Φ at the (i,j)th node are obtaıned as follows Φx i,j = Φt i,j = Φ(i + 1, j) – Φ(i – 1, j) Φ(i, j + 1) – Φ(i, j – 1) Φxx i,j = Φtt i,j = , 2x , 2t Φ(i + 1, j) – 2Φ(i, j) + Φ(i – 1, j) , (x)2 Φ(i, j + 1) – 2Φ(i, j) + Φ(i, j –1) (t)2 (2.9) 3. TM IN RECTANGULAR WAVEGUIDES TM Waves does not have a component of the magnetic field in the direction of propogation; Hz 0 The behavior of the TM wave can be analyzed by the equation: (3.1) 2 xy E z h 2 E z 0 (3.2) b y x a Fig 3.1. Rectangular W.G. z E field in the z direction can be explained interms of x, y and z and z can be expressed seperately,which we obtain; E z ( x, y, z ) E z ( x, y)e z (3.3) Solve the second –order partial diff. equation: 2 2 h 2 ) Ez( x, y ) 0 2 2 x y Using the method of seperatation of variables; ( (3.4) E z ( x, y ) X ( x)Y ( y ) ( 2 2 h 2 ) X ( x)Y ( y ) 0 2 2 x y 1 2 X ( x) 1 2Y ( y ) h2 0 2 2 X ( x) x Y ( y ) y 1 2 X ( x) 1 2Y ( y ) h2 2 2 X ( x) x Y ( y ) y (3.5) both sides must equal a constant in order for the equation to hold for all values of x and y. d 2 X ( x) 2 k x X ( x) 0 2 dx 2 d Y ( y) 2 k y Y ( y) 0 2 dy kc k x k y (3.6) The appropriate forms to be chosen must satisfy the boundary conditions.The 2 boundary condition is that : 2 2 n.H=0 (on the surface) When we apply the B.C. in the x direction E z (0, y ) 0 E z ( a, y ) 0 (3.7) X ( x) in the form of sink x x, kx m a , m 1,2,3...... (3.8) E z ( x,0) 0 (3.9) E z ( x, b ) 0 Y(y) in the form of sin k y y n , n 1,2,3... b When we apply B.C. in the y direction ky (3.10) The solution is: E z ( x, y ) E0 sin( m n x) sin( y) a b (3.11) since kc k x k y 2 2 2 m n a b 2 kc 2 2 (3.12) For the TMnm mode the cutoff frequency is : ( fc) nm 1 2 m n ( )2 ( )2 a b (3.13) And the cutoff wavelength is: (c) nm 2 m n ( )2 ( )2 a b (3.14) 4.TE WAVES IN RECTANGULAR WAVEGUIDES TE Wave must satisfy the following boundary conditions Ez 0 (4.1) 2 xy H z h 2 H z 0 (4.2) H z ( x, y, z ) H z ( x, y )e z (4.3) 2 2 2 2 h 2 H z ( x, y ) 0 y x H z ( x, y ) X ( x)Y ( y ) (4.4) . When we apply the above conditions in the x-direction, the following results are obtained: H z 0 x H z 0 x (E y 0) at x 0 (E y 0) at x a (4.5) When we apply the above conditions in the y direction, following results are obtained: H z 0 y H z 0 y (E x 0) at y 0 (E x 0) at y b (4.6) General Solution for the TE wave: m n H z ( x, y ) H 0 cos x cos y a b m n 2 kc a b 2 j j 2 ( (4.7) 2 m 2 n 2 ) ( ) a b (4.8) (4.9) If a>b the cutoff frequency is the lowest when m=1 and n=0 ( fc) TE10 1 2a u 2a (4.10) The corressponding cutoff wavelength is (c) TE10 2a (4.11) 5.FD APPROACH The solution of waveguide problems is well suited for finite difference schemes because the solution region closed. This amounts to solving the Helmholtz or wave equation 2 Φ + k2 Φ = 0 (5.1) where Φ = Ez for TM modes or Φ = H z for TE modes, while k is the wave number given by k2 = 2 c – 2 (5.2) 5. The permittivity c of the dielectric medium can be real for a lossless medium or complex for a lossy medium. We consider all fields to vary with time and axial distance as exp j(t – z). In the eigenvalue problem of Eq. (5.1), both k and Φ are to be determined. The cutoff wavelength is c = 2 / kc. For each value of the cutoff wave number kc , there is a solution for the eigenfunction Φi , which represents the field configuration of a propagating mode. To apply the finite difference method, we discretize the cross section of the waveguide by a suitable square mesh. Φ(i + 1, j) + Φ(i – 1, j) + Φ(i, j + 1) + Φ(i, j – 1) – (4 – h2k2)Φ(i, j) =0 (5.3) where Δx = Δy = h is the mesh size. Equation (5.3) applies to all the free or interior nodes. At the boundary points, we apply Dirichlet condition (Φ = 0) for the TM modes and Neumann condition (Φ/n = 0) for the TE modes. This implies that at point A in Fig.5.1, for example, ΦA = 0 (5.4) for TM modes. At point A, Φ/n = 0 implies that Φ D = ΦE so that Eq. (5.1) becomes ΦB + ΦC + 2ΦD – (4 – h2k2) ΦA = 0 (5.5) for TE modes. By applying Eq. (5.3) and either Eq. (5.4) or (5.5) to all mesh points in the waveguide cross section, we obtain m simultaneous equations involving the m unknowns (Φ1 , Φ2 , ... , Φm). These simultaneous equations may be conveniently cast into the matrix equation (A – I)Φ = 0 (5.6) or AΦ = Φ (5.7) B E D A C Figure 5.1 . where A is an m x m band matrix of known integer elements, l is an identity matrix, Φ = (Φ1 , Φ2 , ... , Φm) is the eigenvector, and = (kh)2 = 2 h c 2 (5.8) is the eigenvalue. There are several ways to determining and the corresponding Φ. We consider two of these options. The first option is the direct method. Equation (5.6) and (5.7) can be satisfied only if the determinant of (A – l) vanishes, ie., A – I= 0 (5.9) This result in a polynomial in , which can be solved for the various eigenvalues . For each , we obtained the corresponding Φ from Eq. (5.3). This method requires storing the relevant matrix elements and does not take advantage of the fact that matrix A is sparse. In favor of the method is the fact that a computer subroutine usually exists that solves the eigenvalue problem in Eq. (5.9) and that determines all the eigenvalues of the matrix. These eigenvalues give the dominant and higher modes of the waveguide, although accuracy deteriorates rapidly with mode number. The second option is the iterative method. In this case, the matrix elements are usually generated rather than stored. We begin with Φ1 = Φ2 = ... = Φm = 1 for TM we take these values randomly and a guessed value for k,. The field at the (i,j)th node in the (k+1)th iteration is obtained from its known value in the kth iteration using Rij Φk+1(i, j) = Φk(i, j) (4 – h2k2) + (5.10) where is the acceleration factor, 1 < < 2, and Rij is the residual at the (i,j)th node given by Rij = Φ(i, j) + Φ(i, j – 1) + Φ(i + 1, j) + Φ(i – 1, j) – (4 – h2k2)Φ(i, j) (5.11) After three or four scans of the complete mesh using Eq. (10), the value of = h2 k2 should be update using Raleigh formula Φ ΦdS k = Φ dS 2 S 2 (5.12) 2 S The finite difference equivalent of Eq. (5.12) is Φ(i, j) 2 k = Φ(i + 1, j) + Φ(i – 1, j) + Φ(i, j + 1) + Φ(i, j – 1) – 4Φ(i, j) i = 1j = 1 h2 Φ (i, j) 2 (5.13) i = 1j = 1 where Φs are the latest field values after three or four scans of the mesh and the summation is carried out over all points in the mesh. The new value of k obtained from Eq. (5.13) is now used in applying Eq. (5.10) over the mesh for another three or four times to give more accurate field values, which are again substituted into Eq. (5.13) to update k. This process is continued until the difference between consecutive values of k is within a specified acceptable tolerance. If the first option is to be applied, matrix A must first be found. To obtained matrix A is not easy. If there are nx and ny divisions along the x and y directions, the number of free nodes is nf = (nx – 1) (ny – 1). (5.14) Each free node must be assigned two sets of numbers, one to correspond to m in Φm and the other to correspond to (i,j) in Φ(i,j). 6.ACCURACY AND STABILITY OF FD SOLUTIONS The question of accuracy and stability of numerical methods is extremely important if solution is to be reliable and useful. Accuracy has to the with the closeness of the approximate solution of exact solutions. Stability is the requirement that the scheme does not increase the magnitude of the solution with increase in time. There are three sources of errors that are nearly unavoidable in numerical solution of physical problems: (1) modelling errors, (2) truncation (or discretization) errors, (3) round off errors. Each of these error types will affect accuracy and therefore degrade the solution. The modelling errors are due to several assumptions made in arriving at the mathematical model. For example, a nonlinear system may be represented by a linear PDE. Truncation errors arise from the fact that in numerical analysis, we can deal only with a finite number of terms from processes, which are usually described by infinite series. For example, in deriving finite difference schemes, some higher-order terms in the Taylor series expansion were neglected, there by introducing truncation error. Truncation errors may be reduced by using finer meshes, that is, by reducing the mesh size h and time increment Δt. Alternatively, truncation errors may be reduced by using a large number of terms in the series expansion of derivatives, that is, by using higher-order approximations. However, care must be exercised in applying higher-order approximations. Roundoff errors reflect the fact that computations can be done only with a finite precision on a computer. This unavoidable sources of errors is due to the limited size of registers in the arithmetic unit of the computer. Round off errors can be minimised by the use of double-precision arithmetic. The only way to avoid round off errors completely is to code all operations using integer arithmetic. This is hardly possible in most practical situations. Although it has been noted that reducing the mesh size h will increase accuracy, it is not possible to indefinitely reduce h. Decreasing the truncation error by using a finer mesh may result in increasing the round off error due to the increased number of arithmetic operations. A point is reached where the minimum total error occurs for any particular algorithm using any given word length. This is illustrated in Fig. 6.1. The concern about accuracy leads us to question whether the finite difference solution can grow unbounded, a property termed the instability of the difference scheme. A numerical algorithm is said to be stable if a small error at any stage produces a smaller cumulative error. It is unstable otherwise. The consequence of instability (producing unbounded solution) is disastrous. To determine whether a finite difference scheme is stable, an error is defined, n, which occurs at time step n, assuming that there is one independent variable. We define the amplification of this error time step n+1 as n+1 = gn (6.1) where g is known as the amplification factor. In more complex situations, Eq. (6.1) becomes []n+1 = [G][ ]n (6.2) error total error round-off error discretization error Figure 6.1 mesh size h where [G] is the amplification matrix. For the stability of the difference scheme, it is required that Eq. (6.1) satisfy. n+1 n or g 1 (6.3) For the case in Eq. (6.2) determinant of [G] must vanish, ie., det[G] = 0 (6.4) One useful and simple method of finding a stability criterion for a difference scheme is to construct a Fourier analysis of the difference equation and thereby derive the amplification factor. This technique is known as Neumann’s Method n n n Φ n+1 = (1– 2r)Φ i + r(Φ i+1 +Φ i–1 ) i (6.5) where r = Δt/k(Δx)2. Let the solution be. Φ ni = An(t)ejkix , 0 x 1 (6.6) where k is the wave number. Since the differential equation is linear it is approximated to Φ ni = A(t)ejkix (6.7) Substituting Eq. (6.7) into Eq. (6.5) gives An+1ejkix = (1 – 2r) An+1ejkix + r(ejkx + e–jkx) Anejkix (6.8) or An+1 = An[1 – 2r + 2coskx]. Hence the amplification factor is g= An+1 = 1 – 2r + 2coskx An g = 1 – 4r sin2 (6.9) kx 2 In order to satisfy Eq. (6.3), 1 – 4r sin2 kx 1 2 Since this condition must hold for every wave number k, we take the maximum value of the sine function so that 1 – 4r – 1 and r 0 or r 1 2 and r 0 Of course, r = 0 implies Δt = 0, which is impractical. Thus 1 0<r 2 (6.10) 7. RESULTS AND DISCUSSION 8.CONCLUSION 9. REFERENCES 1. Matthew N.O. Sadiku, Numerical Techniques in Electromagnetics, 1992, CRC Press Boca Raton. 2. Robert E. Collin, Foundations For Microwave Engineering, 1992, McGrawHill Singapore. 3. David K. Cheng, Field and Wave Electromagnetics, 1989, Addison-Wesley Reading,Mass. 4. D. S. Jones, Methods in Electromagnetic Wave propogation, 1991, IEEE Press New York. 10. APPENDICES Algorithm of the program S1: Enter inputs S2: Calculate necessary parameters S3: Calculate Matrix A using boundary values S4: Calculate the summation matrices for new k value S5: Enter the necessary values for n and m S6: Calculate analytical solution S7: Draw FD solution S8: Draw Analytical solution S9: Draw the difference between analytical and FD solutions Computer Programs Program1 %TE MODE WAVEGUIDE PROBLEM clear all; a=input('enter the number of rows ='); b=input('enter the number of coloumns ='); w=input('enter the acceleration number 1<w<2 ='); h=input('enter hx=hy=') %A=randn(a,b); for i=1:a for j=1:b A(i,j)=-b/2+0.5+j; end end B=A; k=80;f=0;p=1; c=4-h^2*k^2; y=a*h x=b*h while p>0.01 & f<1000 for i=1:a for j=1:b if i==1 & j==1; A(i,j)=(2*A(i,j+1)+2*A(i+1,j))/c; elseif i==1 & j~=b & j~=1; A(i,j)=(A(i,j-1)+A(i,j+1)+2*A(i+1,j))/c; elseif i==1 & j==b; A(i,j)=(2*A(i,j-1)+2*A(i+1,j))/c; elseif j==1 & i~=a & i~=1; A(i,j)=(A(i-1,j)+A(i+1,j)+2*A(i,j+1))/c; elseif i==a & j==1; A(i,j)=(2*A(i-1,j)+2*A(i,j+1))/c; elseif i==a & j~=1 & j~=b; A(i,j)=(A(i,j-1)+A(i,j+1)+2*A(i-1,j))/c; elseif i==a & j==b; A(i,j)=(2*A(i,j-1)+2*A(i-1,j))/c; elseif j==b & i~=1 & i~=a; A(i,j)=(2*A(i,j-1)+A(i-1,j)+A(i+1,j))/c; else A(i,j)=(A(i,j-1)+A(i,j+1)+A(i-1,j)+A(i+1,j))/c; end end end A=(1-w)*B+w*A; B=A; for i=1:a for j=1:b if i==1 & j==1; Z(i,j)=2*A(i,j)*(A(i,j+1)+A(i+1,j)); elseif i==1 & j~=b & j~=1; Z(i,j)=A(i,j)*(A(i,j-1)+A(i,j+1)+2*A(i+1,j)); elseif i==1 & j==b; Z(i,j)=2*A(i,j)*(A(i,j-1)+A(i+1,j)); elseif j==1 & i~=a & i~=1; Z(i,j)=A(i,j)*(A(i-1,j)+A(i+1,j)+2*A(i,j+1)); elseif i==a & j==1; Z(i,j)=2*A(i,j)*(A(i-1,j)+A(i,j+1)); elseif i==a & j~=1 & j~=b; Z(i,j)=A(i,j)*(A(i,j-1)+A(i,j+1)+2*A(i-1,j)); elseif i==a & j==b; Z(i,j)=2*A(i,j)*(A(i,j-1)+A(i-1,j)); elseif j==b & i~=1 & i~=a; Z(i,j)=A(i,j)*(2*A(i,j-1)+A(i-1,j)+A(i+1,j)); else Z(i,j)=A(i,j)*(A(i,j-1)+A(i,j+1)+A(i-1,j)+A(i+1,j)); end Y(i,j)=A(i,j)*A(i,j); end end f=f+1; c=(sum(sum(Z)))/(sum(sum(Y))); t=(sqrt(4-c))/h; p=abs((t-k)/t); k=t; end A=normalize(A); f,k kc(x,y) n=input('enter n = '); m=input('enter m = '); for i=1:a for j=1:b G(i,j)=cos(n*pi*h*(j-1)/x)*cos(m*pi*h*(i-1)/y); end end for i=1:a for j=1:b H(i,j)=abs(A(a+1-i,b+1-j)-G(i,j)); E(i,j)=A(a+1-i,b+1-j); end end figure(1); imagesc(E) colormap(gray) title('numerical solution of te') pause figure(2); imagesc(G) colormap(gray) title('TE Analytical Solution ') pause figure(3); imagesc(H) colormap(gray) pause yy=(1:a); xx=(1:b); figure(4) mesh(xx,yy,G) pause figure(5) mesh(xx,yy,E) pause figure(6) mesh(xx,yy,H) pause figure(7) subplot(2,2,1), mesh(xx,yy,G) title('Analytical TE Solution') subplot(2,2,2), mesh(xx,yy,E) title('Numerical TE Solution') subplot(2,2,3), mesh(xx,yy,H) title('Difference') Program 2 %TM MODE WAVEGUIDE PROBLEM a=input('enter the number of rows ='); b=input('enter the number of coloumns ='); w=input('enter the acceleration number 1<w<2 ='); A=ones(a,b);B=ones(a,b);Z=zeros(a,b);Y=zeros(a,b); h=input('enter hx=hy =') y=a*h x=b*h k=1;f=0;p=1; c=4-h^2*k^2; while p>0.01 & f<1000 for i=1:a for j=1:b if i==1 & j==1; A(i,j)=(A(i,j+1)+A(i+1,j))/c; elseif i==1 & j~=b & j~=1; A(i,j)=(A(i,j-1)+A(i,j+1)+A(i+1,j))/c; elseif i==1 & j==b; A(i,j)=(A(i,j-1)+A(i+1,j))/c; elseif j==1 & i~=a & i~=1; A(i,j)=(A(i-1,j)+A(i+1,j)+A(i,j+1))/c; elseif i==a & j==1; A(i,j)=(A(i-1,j)+A(i,j+1))/c; elseif i==a & j~=1 & j~=b; A(i,j)=(A(i,j-1)+A(i,j+1)+A(i-1,j))/c; elseif i==a & j==b; A(i,j)=(A(i,j-1)+A(i-1,j))/c; elseif j==b & i~=1 & i~=a; A(i,j)=(A(i,j-1)+A(i-1,j)+A(i+1,j))/c; else A(i,j)=(A(i,j-1)+A(i,j+1)+A(i-1,j)+A(i+1,j))/c; end end end A=(1-w)*B+w*A; B=A; for i=1:a for j=1:b if i==1 & j==1; Z(i,j)=A(i,j)*(A(i,j+1)+A(i+1,j)); elseif i==1 & j~=b & j~=1; Z(i,j)=A(i,j)*(A(i,j-1)+A(i,j+1)+A(i+1,j)); elseif i==1 & j==b; Z(i,j)=A(i,j)*(A(i,j-1)+A(i+1,j)); elseif j==1 & i~=a & i~=1; Z(i,j)=A(i,j)*(A(i-1,j)+A(i+1,j)+A(i,j+1)); elseif i==a & j==1; Z(i,j)=A(i,j)*(A(i-1,j)+A(i,j+1)); elseif i==a & j~=1 & j~=b; Z(i,j)=A(i,j)*(A(i,j-1)+A(i,j+1)+A(i-1,j)); elseif i==a & j==b; Z(i,j)=A(i,j)*(A(i,j-1)+A(i-1,j)); elseif j==b & i~=1 & i~=a; Z(i,j)=A(i,j)*(A(i,j-1)+A(i-1,j)+A(i+1,j)); else Z(i,j)=A(i,j)*(A(i,j-1)+A(i,j+1)+A(i-1,j)+A(i+1,j)); end Y(i,j)=A(i,j)*A(i,j); end end f=f+1; c=(sum(sum(Z)))/(sum(sum(Y))); t=sqrt(4-c)/h; p=abs((t-k)/t); k=t; end A=normalize(A); f,k kc(x,y) n=input('enter n = '); m=input('enter m = '); for i=1:a for j=1:b G(i,j)=sin(n*pi*h*(j)/x)*sin(m*pi*h*(i)/y); D(i,j)=abs(A(a+1-i,b+1-j)-G(i,j)); E(i,j)=A(a+1-i,b+1-j); end end figure(1); imagesc(E) colormap(gray) title('numerical solution TM’) pause figure(2); imagesc(D); colormap(gray); title('error in TM,error of k=%0.95'); pause figure(3); imagesc(G); colormap(gray); title('analytic sol. of TM,n=1,m=1,kc=211'); pause yy=(1:a); xx=(1:b); figure(4) mesh(xx,yy,G) pause figure(5) mesh(xx,yy,E) pause figure(6) mesh(xx,yy,D) pause figure(7) subplot(2,2,1), mesh(xx,yy,G) title('Analytical TM Solution') subplot(2,2,2), mesh(xx,yy,E) title('Numerical TM Solution') subplot(2,2,3), mesh(xx,yy,D) title('Difference')