Increasing values although decreasing values were expected

Hi everybody,


I'm having difficulties in calculating values of the function f(i) to later write them out into a text file by using std::ofstream.

f(i) = cosh(-0.28863383*i)/cosh(0.29452431), i = 1,3,5,...

(cosh: hyperbolic consine)

This function f(i) is actual strictly monotonous decreasing,
why I'm wondering about increasing values for f(i > 107) in my text file.
The smallest value I get with f(i = 105) = 2.43079e-013
while the largest value that appears in the text file is f(i = 543) = 8.43677e+238.
For f(i > 544) I subsequently get "1.#INF".

Could the data type double somehow be responsible for the increasing values?

Please, could anybody give a hint?

System: 32 bit, Samsung Electronics Notebook running win7 SP1
IDE: Dev-C++ 4.9.9.2
This function f(i) is actual strictly monotonous decreasing,

Why do you think so? Wolframalpha outputs:
i | 0.958142 cosh(0.288634 i)
1 | 0.998331
2 | 1.12227
3 | 1.34035
4 | 1.67088
5 | 2.14158
6 | 2.79193
7 | 3.67649
8 | 4.86948
9 | 6.47096
10 | 8.61529
Last edited on
Hi Cubbi,


thank you, you are right. I'm sorry about posting the wrong function.
There is an i missing in the denominator. The correct function is:

f(i) = cosh(-0.28863383*i)/cosh(0.29452431*i), i = 1,3,5,...

With this function, I get the difficulties as written above.

Any ideas?
Can you show actual code then?

SProCppS wrote:
f(i = 543) = 8.43677e+238.


1
2
3
4
5
6
7
8
#include <cmath>
#include <iostream>
int main()
{

    for(int i = 540; i < 550; ++i)
                std::cout << cosh(-0.28863383*i)/cosh(0.29452431 *i ) << '\n';
}

this prints on all compilers available to me (gcc, clang, ibm, and sun)

0.0415499
0.0413059
0.0410633
0.0408221
0.0405824
0.040344
0.0401071
0.0398715
0.0396374
0.0394046


Wolframalpha.com prints the same thing: {0.0415499, 0.0413059, 0.0410633, 0.0408221, 0.0405824, 0.040344, 0.0401071, 0.0398715, 0.0396374, 0.0394046}
Last edited on
I do not know what was going on inside my brain...

The constant in the numerator was programmed not to be a constant.
This "constant" was calculated according to the scheme k = k + j*b, in which
b und k were real constants and j was stepwise increased in a higher-level loop.

I embarrassingly missed to change the denotation of the first k to something else,
which led to a decreasing nominator with increasing i and increasing values of f(i) ...

With the renamed "constant" in the lowest-level loop, my programm ran a successful calculation.

I'm sorry and very grateful for the time you spend on this!

Cheers!

SProCppS
Topic archived. No new replies allowed.