I am writing a program to calculate the spindown frequencies of certain celestial objects.
the variable a is their age.
the variable p is their period
prefrequency is the frequency of the waves emitted by the objects
postfrequency is supposed to be the frequeuncy of the waves emitted by the objects after time "a" has elapsed.
However, when I run the program, I get THE EXACT SAME NUMBERS for pre and post frequency. This completely boggles my mind. Even when I change some numbers around, it makes no difference, I just get the same values.
Halp?
1 2 3 4
double a = AgeComponents.GetAge()*10000000;
double p = abs (PeriodComponents.GetPeriod()); //This grabs the period anoesn'td gives a variable to be calculated; p and P are measured in seconds
double prefrequency = 2/p; //Note that this is the frequency of the gravitational waves, which is twice the frequency of the spinning gravitar
double postfrequency = pow(pow(prefrequency,-4.0)+(20*(300000000))/(32*(pow ( (3.1415), 4.0))*(6.673*.000000000001)*(pow(10.0,45.0))*(pow(E,2.0))*a), -.25);
double a = AgeComponents.GetAge() * 10000000.0;
double p = abs (PeriodComponents.GetPeriod());
double prefrequency = 2.0 / p;
//WARNING: This assumes E is the mathematical constant e.
//Store this in a non-const if that's not the case.
constdouble E2=E*E,
pi=3.1415926535897932384626433832795,
pi4=pi*pi*pi*pi,
G=6.673E-11;
double divisor= 32.0 * pi4 * G * 1E+45 * E2 * a;
double postfrequency = pow( pow(prefrequency,-4.0) + 6E+9 / divisor, -.25 );
The likely problem: 20*300000000 is an operation on integers. This was probably overflowing. I replaced it with the equivalent 6E+9. Another possibility is 20.0*300000000.0. Those zeroes make a huge difference.
A few notes:
* Don't use pow() for scientific notation. The language already has a handy syntax for that.
* In general, don't call pow(a,b) where a and b are constants. Compute it by hand and write down the result instead.
* When writing complex expressions, it helps to declare more variables or constants. It's much easier to see how the expression is structured the way I wrote it, isn't it?
Sorry! E is not the mathematical constant e. I forgot to define what E was. E is the ellipticity of the gravitar, which is just a constant that is determined earlier in the program. Very sorry.
But yes, your way is a much better way of writing programming. I guess my program looks ridiculously messy. Thanks for taking the time to help me out.
Is the difference supposed to be big or very small? If the latter, it's possible that the printing mechanism is simply not displaying enough digits for you to know that the numbers are different.
Well, working it out by hand, the limit as 6E+9 / divisor tends to zero of pow( pow(prefrequency,-4.0) + 6E+9 / divisor, -.25 ); is equal to the prefrequency.
With the divisor quantity having a factor of 1E+45 on top of a value of a presumably in the order of 10^20, divisor is probably in the order of 10^36 (that's after taking G and E^2 into account). That's bringing the quantity 6E+9 / divisor awfully close to zero.