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.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top