Reputation: 509
I'm trying to make a program in Java to calculate the formula for the Ricker wavelet:
But the results are not matching to the real ones.
This is what I'm using:
private static double rickerWavelet(double t, double f){
double p = (Math.pow(Math.PI, 2))*(Math.pow(f, 2))*(Math.pow(t, 2));
double lnRicker = 1 - (2 * p) * Math.exp(-p);
return lnRicker;
}
Am I using the Math functions wrongly?
Upvotes: 7
Views: 6139
Reputation: 719386
I'd just like to add that Math.pow(x, 2)
can be written more simply (and possibly more accurately and more efficiently) as x * x
... for any variable or constant x
.
Upvotes: 3
Reputation: 47
Look at your executing equation if you know about BODMAS method:
You should do: (1-(2*p))* Math.exp(-p);
I just changed your equation by inserting round brackets around 1-2*p
..
Upvotes: 2
Reputation: 63378
To match the formula,
double lnRicker = 1 - (2 * p) * Math.exp(-p);
needs to be
double lnRicker = (1 - (2 * p)) * Math.exp(-p);
Since *
has higher operator precedence than -
, in your expression the multiplication of (2 * p)
with Math.exp(-p)
will be done first, which is not what you want.
Upvotes: 11