Hi everyone:
I'm a c++ newbie. I have used Matlab to do calculations that require an initial condition that is a gaussian pulse. When I write the expression for the gaussian pulse in C++, the pulse is messed up. I think I may be missing something about the order of operations in C++, but I'm not certain that this is the problem. I would very much appreciate it if someone could take a look at my code for the gaussian pulse expression (below) and alert me to any problems!
// Gaussian pulse of amplitude amp at x = x0, with width sigma. cOld is the initial condition vector.
amp = 3;
x0 = 10;
sigma = 1;
double st, num;
num = (1 + 4. * d_dt) / (sigma * sigma);
st = sqrt(num); // time dependent amplitude component
for(int i = 0 ; i < d_xi; i++)
{
double num2;
num2 = ((i - x0)/(sigma * st));
double pow = num2 * num2;
cOld = 1 + (amp - 1)/st * exp(-(pow)); // diffused gaussian IC
}
I'm a c++ newbie. I have used Matlab to do calculations that require an initial condition that is a gaussian pulse. When I write the expression for the gaussian pulse in C++, the pulse is messed up. I think I may be missing something about the order of operations in C++, but I'm not certain that this is the problem. I would very much appreciate it if someone could take a look at my code for the gaussian pulse expression (below) and alert me to any problems!
// Gaussian pulse of amplitude amp at x = x0, with width sigma. cOld is the initial condition vector.
amp = 3;
x0 = 10;
sigma = 1;
double st, num;
num = (1 + 4. * d_dt) / (sigma * sigma);
st = sqrt(num); // time dependent amplitude component
for(int i = 0 ; i < d_xi; i++)
{
double num2;
num2 = ((i - x0)/(sigma * st));
double pow = num2 * num2;
cOld = 1 + (amp - 1)/st * exp(-(pow)); // diffused gaussian IC
}