Using the Math.pow () Function

I am trying to make a Java program to calculate the formula for the Ricoeur wavelet:

enter image description here

But the results are not true.

This is what I use:

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 Math functions incorrectly?

+7
java math
source share
3 answers

To fit the formula,

 double lnRicker = 1 - (2 * p) * Math.exp(-p); 

should be

 double lnRicker = (1 - (2 * p)) * Math.exp(-p); 

Since * has a higher operator precedence than - , in your expression you first multiply (2 * p) by Math.exp(-p) , which is not what you want.

+11
source share

I would like to add that Math.pow(x, 2) can be written simpler (and perhaps more accurately and more efficiently) as x * x ... for any variable or constant x .

+3
source share

Look at your executable equation if you know about the BODMAS method:

You should do: (1-(2*p))* Math.exp(-p);

I just changed your equation by inserting parentheses around 1-2*p ..

+2
source share

All Articles