V
vj
Hi!
I have a piece of code (shown below) involving complex numbers. The
code is not running and giving error ("Invalid floating point
operation" and "SQRT
omain error"). I would be very thankful
if someone can tell me where is the problem. I am aware that my code is
far from being efficient and organized, and also there are many extra
#include statements not really required for the code. I am a novice
programmer, as you can see ! At this time, I would just like to have
advice just to get the code running by doing minimum changes/additions,
and not on making the code efficient or on using advanced features.
Please help.
(I am using C++Builder5, if this info is required by you).
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
#include <complex.h>
#include <iostream.h>
#include <fstream.h>
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
#define PI 3.14159265
#define c 2.997924591e8
#define double_complex complex<double>
main()
{
ofstream outfile("MyProg.dat", ios:
ut);
double_complex j(0,1);
double lambda_0 = 1.5e-6;
double L = 100000.0e-3;
double n = 1.5;
double dn=0.001;
double prd=lambda_0/2.0/n;
double cc=PI*dn/(2.0*n*prd);
double_complex r;
for (double x=lambda_0-1.4e-6; x<=lambda_0; x=x+(2.0*1.4e-6/500.0)){
double detuning = (2.0*PI*n/x)-(PI/prd);
r =
-cc/(sqrt(cc*cc-detuning*detuning)*(1.0/tanh(sqrt(cc*cc-detuning*detuning)*L))-j*detuning);
outfile<<x<<"\t"<<abs(r)<< endl;
}
outfile.close();
}
I have a piece of code (shown below) involving complex numbers. The
code is not running and giving error ("Invalid floating point
operation" and "SQRT
if someone can tell me where is the problem. I am aware that my code is
far from being efficient and organized, and also there are many extra
#include statements not really required for the code. I am a novice
programmer, as you can see ! At this time, I would just like to have
advice just to get the code running by doing minimum changes/additions,
and not on making the code efficient or on using advanced features.
Please help.
(I am using C++Builder5, if this info is required by you).
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
#include <complex.h>
#include <iostream.h>
#include <fstream.h>
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
#define PI 3.14159265
#define c 2.997924591e8
#define double_complex complex<double>
main()
{
ofstream outfile("MyProg.dat", ios:
double_complex j(0,1);
double lambda_0 = 1.5e-6;
double L = 100000.0e-3;
double n = 1.5;
double dn=0.001;
double prd=lambda_0/2.0/n;
double cc=PI*dn/(2.0*n*prd);
double_complex r;
for (double x=lambda_0-1.4e-6; x<=lambda_0; x=x+(2.0*1.4e-6/500.0)){
double detuning = (2.0*PI*n/x)-(PI/prd);
r =
-cc/(sqrt(cc*cc-detuning*detuning)*(1.0/tanh(sqrt(cc*cc-detuning*detuning)*L))-j*detuning);
outfile<<x<<"\t"<<abs(r)<< endl;
}
outfile.close();
}