abdoeng
Advanced Member level 2
hi i try to understand fdtd code,here 1 d code but it is error,any buddy help me
thanks regards
code
# include <math.h>
# include <stdlib.h>
# include <stdio.h>
#define ke 200
main()
{
kc = ke/2;
to = 40.0;
spread = 12;
t=0;
nsteps = 1;
float ex[ke],hy[ke];
int n,k,kc,ke,nsteps;
float t;
float to,spread,pulse;
FILE *ftp, *fopen();
for ( k = 1;k < ke;k++ )
{ ex[k] = 0;
hy[k] = 0.}
kc = ke/2;
to = 40.0;
spread = 12;
t=0;
nsteps = 1;
while ( nsteps > 0 ){
printf("nsteps-->");
scanf("%d",&nsteps);
printf("%d\n",nsteps);
n=0;
for (n=1;n<=nsteps;n++)
{
t=t+1;
for (k=1;k<ke;k++)
{ex[k]=ex[k]+.5*(hy[k-1]-hy[k]);}
pulse=exp(-.5*(pow((to-t)/spread,2)));
ex[kc]=pulse;
printf("%5.1f %6.2f\n",to-t,ex[kc]);
for (k=0;k<ke-1;k++)
{hy[k]=hy[k]+.5*(ex[k]-ex[k+1]);}
}
for (k=1;k<=ke;k++)
{print ("%3d %6.2f %6.2\n",k,ex[k],hy[k]);}
fp=fopen("ex","w");
for (k=1;k<=ke;k++)
{fprintf(fp," %6.2f \n",ex[k]);}
fclose(fp)
fp=fopen("hy","w");
for (k=1;k<=ke;k++)
{fprintf(fp," %6.2f \n",hy[k]);}
fclose(fp)
print ( "t= %5f\n",t);
}
}
thanks regards
code
# include <math.h>
# include <stdlib.h>
# include <stdio.h>
#define ke 200
main()
{
kc = ke/2;
to = 40.0;
spread = 12;
t=0;
nsteps = 1;
float ex[ke],hy[ke];
int n,k,kc,ke,nsteps;
float t;
float to,spread,pulse;
FILE *ftp, *fopen();
for ( k = 1;k < ke;k++ )
{ ex[k] = 0;
hy[k] = 0.}
kc = ke/2;
to = 40.0;
spread = 12;
t=0;
nsteps = 1;
while ( nsteps > 0 ){
printf("nsteps-->");
scanf("%d",&nsteps);
printf("%d\n",nsteps);
n=0;
for (n=1;n<=nsteps;n++)
{
t=t+1;
for (k=1;k<ke;k++)
{ex[k]=ex[k]+.5*(hy[k-1]-hy[k]);}
pulse=exp(-.5*(pow((to-t)/spread,2)));
ex[kc]=pulse;
printf("%5.1f %6.2f\n",to-t,ex[kc]);
for (k=0;k<ke-1;k++)
{hy[k]=hy[k]+.5*(ex[k]-ex[k+1]);}
}
for (k=1;k<=ke;k++)
{print ("%3d %6.2f %6.2\n",k,ex[k],hy[k]);}
fp=fopen("ex","w");
for (k=1;k<=ke;k++)
{fprintf(fp," %6.2f \n",ex[k]);}
fclose(fp)
fp=fopen("hy","w");
for (k=1;k<=ke;k++)
{fprintf(fp," %6.2f \n",hy[k]);}
fclose(fp)
print ( "t= %5f\n",t);
}
}