Sie sind auf Seite 1von 32

Integrantes:

Nelly Catherine Barbosa Caldern 2080621


David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

COMPUTACIN EN TEORA ELECTROMAGNTICA


DIFERENCIAS FINITAS EN EL DOMINIO DELTIEMPO

CAPITULO 1

1)Programa en C++
/* FD1D_1.1C. 1D FDTD simulation in free espace */

#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#define KE 200 /* KE is the number of cells to be used*/
void main ()
{
float ex [KE], hy [KE];
int n,k,kc,ke,NSTEPS;
float T;
float to, spread, pulse;
FILE *fp, *fopen (const char[3],const char[3]);

/* initialize*/
for ( k=1; k<KE; k++)
{
ex[k] =0;
hy [k] =0; }

kc=KE/2; /*Center of the problem space */


to=40.0; /* center of the incident pulse*/
spread=12; /* width of the incident pulse */
T=0;
NSTEPS=1;
while (NSTEPS>0)
{
printf ("NSTEPS -->"); /*NSTEPS is the number of times the*/
scanf ("%d", &NSTEPS); /* main loop has executed */
printf ("%d \n", NSTEPS);
n=0;

for (n=1; n<=NSTEPS; n++)


{
T=T+1; /* T keeps track of the total number */
/* T keeps track of the total number */
/* Main FDTD loop*/
/* calculate the EX field */
for (k=1; k<KE; k++)
{ ex [k]= ex[k] +.5*(hy[k-1]-hy[k]);}
/* put a gaussian pulse in the middle */
pulse = exp(-.5*(pow( (to-T)/spread,2)));
ex[kc]= pulse;
printf ("%5.1f %6.2f\n",to-T, ex[kc]);
/*Calculate the Hy filed */
for (k=0; k<KE-1; k++)
{
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

hy [k]=hy[k]+ .5*(ex[k]-ex[k+1]);}
}
/* End of the Main FDTD loop */

/* At the end of the calculation, print out the Ex and Hy fields */


for (k=1; k<= KE; k++)
{ printf ("%3d %6.2f %6.2f\n",k,ex[k],hy[k]); }

/* write the E field out to a file Ex */


fp=fopen ("Ex", "w");
for (k=1; k<= KE; k++)
{ fprintf (fp,"%6.2f \n",ex[k]); }
fclose (fp);

/* write the H field out to a file Hy */


fp=fopen ("Hy","w");
for (k=1; k<=KE; k++)
{ fprintf (fp,"%6.2f \n",hy[k]); }
fclose(fp);
printf ("T= %5.0f\n",T);
}
}

Programa en Matlab

c=1:200;
KE=200;
ex(1,200)=0;
hy(1,200)=0;
ex_low_m1=0;
ex_low_m2=0;
ex_high_m1=0;
ex_high_m2=0;
y=2;

%/* Initializate */

kc=KE/2; %/* Center of the problem space*/


t0=40; %/* Center of the incident pulse */
spread=12; %/* Width of the incident pulse */
T=0;
NSTEPS=1;
while(NSTEPS>0)

NSTEPS= input ('Ingrese el nmero de pasos: ');


for n=1:NSTEPS

T=T+1;
%/* Main FDTD loop*/
% /* Calculate of Ex field*/
for(k=2:KE)

ex(k)=ex(k)+0.5.*(hy(k-1)-hy(k));
end
%/* put a Gaussian Pulse in the midle */
pulse=exp((-0.5)*((t0-T)/spread)^y);
ex(kc)=ex(kc)+pulse;
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

%/* Absorbing boundary Conditions */


ex(1)=ex_low_m2;
ex_low_m2=ex_low_m1;
ex_low_m1=ex(2);

ex(KE)=ex_high_m2;
ex_high_m2=ex_high_m1;
ex_high_m1=ex(KE-1);
%/* Calculate of Hy field*/
for(k=1:KE-1)

hy(k)=hy(k)+0.5*(ex(k)-ex(k+1));
end
end
%/* End of the main FDTD loop*/
%/* At the end of the calculation, print out the Ex and Hy fields*/
end

figure
plot (c,hy)
grid on;
xlabel('T');
ylabel('Hy');
title('Campo magntico vs. Numero de pasos');
figure
plot (c,ex)
grid on;
xlabel('T');
ylabel('Ex');
title('Campo elctrico vs. Numero de pasos');

Graficas
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

(NSTEPS) nmero de pasos= 100

hy Vs. T
1

0.8

0.6

0.4

0.2
hy

-0.2

-0.4

-0.6

-0.8

-1
0 20 40 60 80 100 120 140 160 180 200
T

ex Vs. T
1

0.9

0.8

0.7

0.6
ex

0.5

0.4

0.3

0.2

0.1

0
0 20 40 60 80 100 120 140 160 180 200
T

(NSTEPS) nmero de pasos= 300


Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

hy Vs. T
0.4

0.2

-0.2
hy

-0.4

-0.6

-0.8

-1
0 20 40 60 80 100 120 140 160 180 200
T

ex Vs. T
1

0.8

0.6

0.4

0.2
ex

-0.2

-0.4

-0.6

-0.8

-1
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

Diagramas de flujo
DFD

2) Programa en C++
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

/* FD1D_1.2C. 1D FDTD simulation in free espace */

#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#define KE 200 /* KE is the number of cells to be used*/
void main ()
{
float ex [KE], hy [KE];
int n,k,kc,ke,NSTEPS;
float T;
float to, spread, pulse;
float ex_low_m1,ex_low_m2,ex_high_m1,ex_high_m2;
FILE *fp, *fopen (const char[3],const char[3]);
/* initialize*/
for ( k=1; k<KE; k++)
{
ex[k] =0;
hy [k] =0; }

kc=KE/2; /*Center of the problem space */


to=40.0; /* center of the incident pulse*/
spread=12; /* width of the incident pulse */
T=0;
NSTEPS=1;
while ( NSTEPS>0)
{
printf ("NSTEPS -->"); /*NSTEPS is the number of times the*/
scanf ("%d", &NSTEPS); /* main loop has executed */
printf ("%d \n", NSTEPS);
n=0;
{
for (n=1; n<=NSTEPS; n++)
{ T=T+1;
/* Main FDTD loop*/

/* Calculate the Ex field */


for ( k=1; k< KE; k++ )
{
ex[k]=ex[k]+.5*(hy[k-1]-hy[k]); }

/* Put a gaussian pulse in the middle */

pulse= exp(-.5*(pow( (to-T)/spread,2)));


ex[kc] = ex[kc] +pulse;
float arg;
printf ( "%5.1f %6.2f cn", to-T,arg,ex[kc]);

/* Absorbing Boundary conditions */

ex[0] = ex_low_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex[1];
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

ex[ KE-1] = ex_high_m2;


ex_high_m2 = ex_high_m1;
ex_high_m1 = ex[KE-2];

/* calculate the Hy field */


for (k=0; k<KE-1; k++)
{
hy[k]=hy[k]+ .5*(ex[k]- ex[k+1]);}}
/* End of the main FDTD loop */
/* At the end of the calculation, print out the Ex and Hy fields */
for (k=1; k<= KE; k++)
{ printf ("%3d %6.2f %6.2f\n",k,ex[k],hy[k]); }

/* write the E field out to a file Ex */


fp=fopen ("Ex", "w");
for (k=1; k<= KE; k++)
{ fprintf (fp,"%6.2f \n",ex[k]); }
fclose (fp);

/* write the H field out to a file Hy */


fp=fopen ("Hy","w");
for (k=1; k<=KE; k++)
{ fprintf (fp,"%6.2f \n",hy[k]); }
fclose(fp);
printf ("T= %5.0f\n",T);
}
}
}

Programa en Matlab

c=1:200;
KE=200;
ex(1,200)=0;
hy(1,200)=0;
cb(1,200)=0;

ex_low_m1=0;
ex_low_m2=0;
ex_high_m1=0;
ex_high_m2=0;

y=2;
%/* Initializate */

kc=KE/2; %/* Center of the problem space*/


t0=40; %/* Center of the incident pulse */
spread=12; %/* Width of the incident pulse */
T=0;
NSTEPS=1;

while(NSTEPS>0)

NSTEPS= input ('Ingrese el nmero de pasos: ');


for n=1:NSTEPS
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

T=T+1;
%/* Main FDTD loop*/
% /* Calculate of Ex field*/
for(k=2:KE)

ex(k)=ex(k)+0.5.*(hy(k-1)-hy(k));
end
%/* put a Gaussian Pulse in the midle */
pulse=exp((-0.5)*((t0-T)/spread)^y);
ex(kc)=ex(kc)+pulse;

%/* Absorbing boundary Conditions */


ex(1)=ex_low_m2;
ex_low_m2=ex_low_m1;
ex_low_m1=ex(2);

ex(KE)=ex_high_m2;
ex_high_m2=ex_high_m1;
ex_high_m1=ex(KE-1);
%/* Calculate of Hy field*/
for(k=1:KE-1)

hy(k)=hy(k)+0.5*(ex(k)-ex(k+1));
end
end
%/* End of the main FDTD loop*/
%/* At the end of the calculation, print out the Ex and Hy fields*/
end

figure
plot (c,hy)
grid on;
xlabel('T');
ylabel('Hy');
title('Campo magntico vs. Numero de pasos');
figure
plot (c,ex)
grid on;
xlabel('T');
ylabel('Ex');
title('Campo elctrico vs. Numero de pasos');
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

GRAFICAS
(NSTEPS) nmero de pasos= 250
Campo elctrico vs. Numero de pasos
0.8

0.7

0.6

0.5

0.4
Ex

0.3

0.2

0.1

-0.1
0 20 40 60 80 100 120 140 160 180 200
T

Campo magntico vs. Numero de pasos


0.8

0.6

0.4

0.2
Hy

-0.2

-0.4

-0.6
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

NSTEPS = 100

Campo elctrico vs. Numero de pasos


1.2

0.8

0.6
Ex

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T

Campo magntico vs. Numero de pasos


1.5

0.5
Hy

-0.5

-1

-1.5
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

NSTEPS = 225

Campo elctrico vs. Numero de pasos


1

0.8

0.6
Ex

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T

Campo magntico vs. Numero de pasos


1.5

0.5
Hy

-0.5

-1

-1.5
0 20 40 60 80 100 120 140 160 180 200
T

Diagrama de flujo
DFD 2
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

1 2
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

3) Programa en c++

PROGRAMA 3
/* FD1D_1.3.c. */
/* Simulation of a pulse hitting a dielectric medium */

#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#define KE 200 /* KE is the number of cells to be used*/
void main ()
{
float ex [KE], hy [KE];
int n,k,kc,ke,nsteps,kstart;
float ddx,dt,T,epsz,epsilon,sigma,eaf;
float ex_low_m1,ex_low_m2,ex_high_m1,ex_high_m2;
float cb[KE];
float to, spread, pulse;
FILE *fp, *fopen (const char[3],const char[3]);
/* initialize*/
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

for ( k=1; k<KE; k++)


{
ex[k] =0;
hy [k] =0; }

kc=KE/2; /*Center of the problem space */


to=40.0; /* center of the incident pulse*/
spread=12; /* width of the incident pulse */
T=0;
nsteps=1;

for (k=1; k<=KE; k++) { /* Initialize to free espace */


cb [k]=.5;
}
printf ( "Dielectric starts at - - -> ");
scanf ("%d", &kstart);
printf ("Epsilon - - > ");
scanf ("%f", &epsilon);
printf ("%d %6.2f \n", kstart, epsilon);

for (k=kstart; k<=KE; k++)


{cb[k]=.5/epsilon;
}
for (k=1; k<=KE; k++)
{ printf ("%2d %4.2f\n",k,cb[k]);}

/* Main part of the program */

while (nsteps>0)
{
printf ("nsteps- - - >");
scanf ("%d", &nsteps);
printf ("%d \n", nsteps);

for (n=1; n<=nsteps; n++)


{
T=T+1;
/*calculate the Ex field*/
for (k=0; k<KE; k++)
{ ex[k]=ex[k]+cb[k]*(hy[k-1]-hy[k] );}

/* Put a Gaussian pulse at the low end */


pulse = exp(-.5*(pow( (to-T)/spread,2)));
ex[5]=ex[5]+pulse;
printf ("%5.1f %6.2f %6.2f\n", T,pulse, ex[5]);

/* Absorbing Boundary conditions */

ex[0] = ex_low_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex[1];

ex[ KE-1] = ex_high_m2;


ex_high_m2 = ex_high_m1;
ex_high_m1 = ex[KE-2];

/* calculate the Hy field */


for (k=0; k<KE-1; k++)
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

{
hy[k]=hy[k]+ .5*(ex[k]- ex[k+1]);}}
/* End of the main FDTD loop */
/* At the end of the calculation, print out the Ex and Hy fields */
for (k=1; k<= KE; k++)
{ printf ("%3d %6.2f %6.2f\n",k,ex[k],hy[k]); }

/* write the E field out to a file Ex */


fp=fopen ("Ex", "w");
for (k=1; k<= KE; k++)
{ fprintf (fp,"%6.2f \n",ex[k]); }
fclose (fp);

/* write the H field out to a file Hy */


fp=fopen ("Hy","w");
for (k=1; k<=KE; k++)
{ fprintf (fp,"%6.2f \n",hy[k]); }
fclose(fp);
printf ("T= %5.0f\n",T);
}
}
}

Programa (matlab)

c=1:200;
KE=200;
ex(1,200)=0;
hy(1,200)=0;
cb(1,200)=0;
y=2;
ex_low_m1=0;
ex_low_m2=0;
ex_high_m1=0;
ex_high_m2=0;

%%Initializate to free space

for k=2:KE

cb(k)=0.5;
end

kstart= input ('Constante dielectrica de inicio: ');


Epsilon= input ('Epsilon: ');

for(k=kstart:KE)

cb(k)=((0.5)./Epsilon);
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

end

kc=KE/2; % Center of the problem space


t0=40; % Center of the incident pulse
spread=12; % Width of the incident pulse
T=0;
NSTEPS=1;

% Main part of the program

while(NSTEPS>0)

NSTEPS = input ('Ingrese el nmero de pasos: ');

for(n=1:NSTEPS)

T=T+1;

%Calculate of Ex field

for k=2:KE,
ex(k)= ex(k)+ (0.5).*(hy(k-1)-hy(k));
end

% put a Gaussian Pulse at the low end

pulse=exp((-.5)*((t0-T)/spread)^y);
ex(6)=ex(6)+pulse;

% Absorbing boundary Conditions1*/

ex(1)=ex_low_m2;
ex_low_m2=ex_low_m1;
ex_low_m1=ex(2);

ex(KE)= ex_high_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex(KE-1);

% Calculate of Hy field*/

for k=1:KE-1,
hy(k)= hy(k)+ (0.5).*(ex(k)-ex(k+1));
end

end
end

%End of the main FDTD loop


Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

figure
plot(c,hy)
grid on;
xlabel('T');
ylabel('Hy');
title('Campo magntico vs. Numero de pasos');
figure
plot (c,ex)
grid on;
xlabel('T');
ylabel('Ex');
title('Campo elctrico vs. Numero de pasos');

GRAFICAS
K DIELECTRICA = 4
EPSILON = 4
NSTEPS = 100

Campo elctrico vs. Numero de pasos


1.2

0.8

0.6
Ex

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

Campo magntico vs. Numero de pasos


1.2

0.8

0.6
Hy

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T

K DIELECTRICA = 4
EPSILON = 4
NSTEPS = 220

Campo elctrico vs. Numero de pasos


1.2

0.8

0.6
Ex

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

Campo magntico vs. Numero de pasos


1.2

0.8

0.6
Hy

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T

K DIELECTRICA = 4
EPSILON = 4
NSTEPS = 320

Campo elctrico vs. Numero de pasos


1.2

0.8

0.6
Ex

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

Campo magntico vs. Numero de pasos


1.2

0.8

0.6
Hy

0.4

0.2

-0.2
0 20 40 60 80 100 120 140 160 180 200
T

Diagramas de flujo
DFD
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

1 2
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

4) Programa en c++

/* FD1D_1.4.c. */
/* Simulation of a sinusoidal wave hitting a dielectric mdium */

#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#define KE 200 /* KE is the number of cells to be used*/
void main ()
{
int n,k,kc,ke,nsteps,kstart;
float ddx,dt,T,epsz,epsilon,sigma,eaf;
float freq_in;
float ex [KE], hy [KE];
float cb[KE];
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

float to, spread, pulse;


ddx=.01; /* set the cell size to 1cm*/
dt=ddx/(2*3e8); /* calculate the time step*/

/* These parameter sepecify the input pulse*/


printf ("Input freq (MHz) - - -> ");
scanf ("%f", &freq_in);
freq_in=freq_in*1e6;
printf ("%8.0f \n", freq_in);

T=0;
nsteps =1;

/*Main part of the program */

while (nsteps>0) {
printf ("nsteps - -> ");
scanf ("%d", &nsteps);
printf ("%d \n", nsteps);

for (n=1; n<=nsteps; n++)


{
T=T+1;

/* Calculate the Ex field */


for (k=0; k<KE; k++)
{ ex[k]=ex[k]+ cb[k]*(hy[k-1]-hy[k]); }

/* put a sinusoidal source at cell 5 po*/

pulse = sin(2*3.14159*freq_in*dt*T);
ex[5]=ex[5]+pulse;
printf ("%5.1f %6.2f %6.2f\n", T,pulse, ex[5]);

/* Absorbing Boundary conditions */

ex[0] = ex_low_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex[1];

ex[ KE-1] = ex_high_m2;


ex_high_m2 = ex_high_m1;
ex_high_m1 = ex[KE-2];

/* calculate the Hy field */


for (k=0; k<KE-1; k++)
{
hy[k]=hy[k]+ .5*(ex[k]- ex[k+1]);}}
/* End of the main FDTD loop */
/* At the end of the calculation, print out the Ex and Hy fields */
for (k=1; k<= KE; k++)
{ printf ("%3d %6.2f %6.2f\n",k,ex[k],hy[k]); }

/* write the E field out to a file Ex */


fp=fopen ("Ex", "w");
for (k=1; k<= KE; k++)
{ fprintf (fp,"%6.2f \n",ex[k]); }
fclose (fp);
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

/* write the H field out to a file Hy */


fp=fopen ("Hy","w");
for (k=1; k<=KE; k++)
{ fprintf (fp,"%6.2f \n",hy[k]); }
fclose(fp);
printf ("T= %5.0f\n",T);
}}}

Programa en Matlab

c=1:200;
KE=200;
ex(1,200)=0;
hy(1,200)=0;
cb(1,200)=0;
ex_low_m1=0;
ex_low_m2=0;
ex_high_m1=0;
ex_high_m2=0;
y=2;
ddx=0.01;
dt=ddx./(2.*3e8);

freq_in = input ('Ingrese la frecuencia (MHz): ');


freq_in= freq_in.*(1e6);

%% Initializate to free space

for(k=2:KE)

cb(k)=0.5;
end

kstart= input ('Constante dielectrica: ');


epsilon= input ('Ingrese el valor de epsilon: ');

for(k=kstart:KE)

cb(k)=0.5/epsilon;

end
kc=KE/2;% Center of the problem space*/
t0=40; % Center of the incident pulse */
spread=12; % Width of the incident pulse */
T=0;
NSTEPS=1;

% Main part of the program */

while(NSTEPS>0)

NSTEPS= input ('Ingrese el numero de pasos: ');

for(n=1:NSTEPS)

T=T+1;
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

for(k=2:KE)
ex(k)=ex(k)+cb(k)*(hy(k-1)-hy(k));
end

%%/* put a sinusoidal Pulse at the cell 5 p0 */

pulse=sin(2*pi*freq_in*dt*T);
ex(6)=ex(6)+pulse;

%/* Absorbing boundary Conditions */

ex(1)=ex_low_m2;
ex_low_m2=ex_low_m1;
ex_low_m1=ex(2);

ex(KE)=ex_high_m2;
ex_high_m2=ex_high_m1;
ex_high_m1=ex(KE-1);

%% /* Calculate of Hy field*/

for(k=2:KE-1)

hy(k)=hy(k)+0.5*(ex(k)-ex(k+1));

end
end
end

%%/* End of the main FDTD loop*/


figure
plot(c,ex)
grid on;
xlabel('T');
ylabel('Ex');
title('Campo electrico vs. T');
figure
plot(c,hy)
grid on;
xlabel('Hy');
ylabel('T');
title('Campo magnetico vs. T');

GRAFICAS
NSTEPS=425
Epsilon=4
Kdielectrica = 4
Frecuencia (MHz)=700
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

Campo electrico vs. T


3

0
Ex

-1

-2

-3

-4
0 20 40 60 80 100 120 140 160 180 200
T

Campo magnetico vs. T


5

0
T

-1

-2

-3

-4

-5
0 20 40 60 80 100 120 140 160 180 200
Hy

5) Programa c++

/*FD1D_1.5.c. 1D FDTD simulation of a lossy dielectric mdium */


#include<iostream>
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

#include<conio.h>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#define KE 200 /* KE is the number of cells to be used*/
using namespace System;
using namespace std;
void main ()
{
float ex [KE], hy [KE];
int n,k,kc,ke,nsteps,kstart;
float ddx,dt,T,epsz,epsilon,sigma,eaf;
float to, spread, pulse;
float ca[KE], cb[KE];
float ex_low_m1,ex_low_m2,ex_high_m1,ex_high_m2;
epsz=8.85419e-12;

for (k=1; k<=KE; k++)


{ /* Initialize to free space */
ca[k]=1.,
cb[k]= .5;
}
printf ( "Dielectric starts at - - -> ");
scanf ("%d", &kstart);
printf ("Epsilon - - > ");
scanf ("%f", &epsilon);
printf ( "conductivity- - ->");
scanf ("%f", &sigma);
printf ("%d %6.2f %6.2f \n", kstart, epsilon, sigma);

eaf=dt*sigma/(2*epsz*epsilon);
printf (" %6.4f \n", eaf);
for (k=kstart; k<=KE; k++)
{
ca[k]=(1.-eaf)/(1+eaf);
cb[k]=(.5/epsilon*(1+eaf));
}

while (NSTEPS>0)
{
printf ("NSTEPS -->"); /*NSTEPS is the number of times the*/
scanf ("%d", &NSTEPS); /* main loop has executed */
printf ("%d \n", NSTEPS);
n=0;

for (n=1; n<=NSTEPS; n++)


{
T=T+1; /* T keeps track of the total number */
/* T keeps track of the total number */

/*Main part of the program */


/*calculated the Ex field */

for (k=0; k<KE; k++)


{
ex[k]=ca[k]*ex[k]+cb[k]*(hy[k-1]-hy[k]);}
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

/* Absorbing Boundary conditions */

ex[0] = ex_low_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex[1];

ex[ KE-1] = ex_high_m2;


ex_high_m2 = ex_high_m1;
ex_high_m1 = ex[KE-2];

/* calculate the Hy field */


for (k=0; k<KE-1; k++)
{
hy[k]=hy[k]+ .5*(ex[k]- ex[k+1]);}}
/* End of the main FDTD loop */
/* At the end of the calculation, print out the Ex and Hy fields */
for (k=1; k<= KE; k++)
{ printf ("%3d %6.2f %6.2f\n",k,ex[k],hy[k]); }

/* write the E field out to a file Ex */


fp=fopen ("Ex", "w");
for (k=1; k<= KE; k++)
{ fprintf (fp,"%6.2f \n",ex[k]); }
fclose (fp);

/* write the H field out to a file Hy */


fp=fopen ("Hy","w");
for (k=1; k<=KE; k++)
{ fprintf (fp,"%6.2f \n",hy[k]); }
fclose(fp);
printf ("T= %5.0f\n",T);
}}}

Programa en MATLAB

c=1:200;
KE = 200;
ex(1,200)=0;
hy(1,200)=0;
cb(1,200)=1;
ca(1,200)=1;
ex_low_m1 = 0;
ex_low_m2 = 0;
ex_high_m1 = 0;
ex_high_m2 = 0;
epsz = 8.85419e-12;

% These parameters specify the input pulse

freq_in = input('Ingrese frecuencia (MHz)=');


freq_in = freq_in.*1e6;

% Initializate to free space


cb = 0.5;
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

ca=1;
ddx = 0.01;
dt = ddx./(2.*3e8);

kstart=input('Constante dielectrica de inicio --> ');


epsilon=input('Epsilon --> ');
sigma=input('Conductividad --> ');

eaf = dt.*sigma/(2.*epsz.*epsilon);
for (k=kstart:KE)
cb(k) = 0.5./epsilon;
ca(k) = (1-eaf)./(1+eaf);
end

kc = KE/2;% Center of the problem space


t0 = 40; % Center of the incident pulse
spread = 12; % Width of the incident pulse
T = 0;
NSTEPS = 1;

%Main part of the program


while NSTEPS > 0
NSTEPS=input('Ingrese numero de pasos: ');
for n = 1:1:NSTEPS;
T = T+1;
%Calculate of Ex field
for k=2:1:(KE);
ex(k) = ca(k).*ex(k) + cb(k).*(hy(k-1)-hy(k));
end
% put a sinusoidal Pulse at the cell 5 p0
pulse = sin(2.*pi.*freq_in.*dt.*T);
ex(6) = ex(6) + pulse;
%Absorbing boundary Conditions

ex(1) = ex_low_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex(2);

ex(KE) = ex_high_m2;
ex_low_m2 = ex_low_m1;
ex_low_m1 = ex(KE-1);

%Calculate of Hy field
for k=1:1:(KE-1);
hy(k) = hy(k) + 0.5.*(ex(k)-ex(k+1));
end
end
end
figure();
plot(c,ex);
grid on;
xlabel('T');
ylabel('Campo electrico');
title('Campo electrico vs. T');
figure
plot(c,hy);
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

grid on;
xlabel('T');
ylabel('Campo magnetico');
title('Campo magnetico vs.T');

GRAFICAS
NSTEPS=500
Epsilon=4
Kdielectrica = 4
Conductividad = 0.04
Frecuencia (MHz)=700

Campo electrico vs. T


2

1.5

0.5
Campo electrico

-0.5

-1

-1.5

-2

-2.5
0 20 40 60 80 100 120 140 160 180 200
T
Integrantes:
Nelly Catherine Barbosa Caldern 2080621
David Andrs Sarmiento Nova 2080281
Ivn Daro Corredor Garca 2081537

Campo magnetico vs.T


8

4
Campo magnetico

-2

-4

-6
0 20 40 60 80 100 120 140 160 180 200
T

Das könnte Ihnen auch gefallen