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?
The pow() function returns the value of x to the power of y (xy). If a third parameter is present, it returns x to the power of y, modulus z.
pow() is function to get the power of a number, but we have to use #include<math. h> in c/c++ to use that pow() function. then two numbers are passed. Example – pow(4 , 2); Then we will get the result as 4^2, which is 16.
The pow() function in PHP is used to calculate a base raised to the power of exponent. It is a generic function which can be used with number raised to any value.It takes two parameters which are the base and exponent and returns the desired answer.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With