C/C++ Computing ln(x) with C++ Iterations

  • Thread starter Thread starter AndersHermansson
  • Start date Start date
  • Tags Tags
    C++ Computing
AI Thread Summary
The discussion centers on a C++ algorithm for calculating the natural logarithm of a number, ln(x). The algorithm uses a loop to sum fractions from 1/10^n to 1/x*10^(n+1), where n is a variable that improves the approximation with larger values. The method effectively demonstrates the relationship between integration and the natural logarithm, specifically highlighting that the integral of 1/x is ln(x). The conversation concludes with acknowledgment of the discovery.
AndersHermansson
Messages
61
Reaction score
0
I was fiddling around with C++ and iterations and I found an algorithm for computing ln(x).


n = any number, the higher, the better the approximation
ln_x = 0;
divisor = 10^n;

while ( divisor <= x*10^n ) // Where x is the ln(x) you want to find.
{

ln_x += 1 / divisor;
divisor++;

}

What it does is add all integer fractions from 1/10^n to 1/x*10^(n+1).
 
Technology news on Phys.org
You've discovered the fact that [inte](1/x) dx is ln(x). Congratulations!

- Warren
 
Thanks :)
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top