Find the ln ( X ) and log10X with the help of expansion | Function to calculate ln x using expansion ; Terminating value of the loop can be increased to improve the precision ; Function to calculate log10 x ; Driver Code ; setprecision ( 3 ) is used to display the output up to 3 decimal places
function calculateLnx ( n ) { let num , mul , cal , sum = 0 ; num = ( n - 1 ) / ( n + 1 ) ; for ( let i = 1 ; i <= 1000 ; i ++ ) { mul = ( 2 * i ) - 1 ; cal = Math . pow ( num , mul ) ; cal = cal / mul ; sum = sum + cal ; } sum = 2 * sum ; return sum ; } function calculateLogx ( lnx ) { return ( lnx / 2.303 ) ; } let lnx , logx , n = 5 ; lnx = calculateLnx ( n ) ; logx = calculateLogx ( lnx ) ; document . write ( " " + n + " " + lnx + " " ) ; document . write ( " " + n + " " + logx + " " ) ;