|
|
e = 2.71828182845904523536028747135266249775724709369995 ... and on ...
e is defined as being the sum as n goes to infinity of 1/n! — which works out fine when programmed as an iterative sum in a loop with increments n from 1 to a finite relatively small integer, say 20.
Results are less well defined when it comes to programming the formula, ( 1 + 1/n ) ^ n where, theoretically, the larger the integer n, the more accurate the result. In this instance the result of 1 + 1/n is raised to the power of n instead of using a sum.
For e = 1 + 1/n!
For e = ( 1 + ( 1/n ) ) ^ n
<style type="text/css">
div.out input { font: 11px Verdana ; color: #C60000 ; text-align: center ; width: 300px ; font-weight: bold ; height: 12px ; border: 0 ; background-color: transparent ; }
a.x:link { font: 12px Verdana ; color: #0000FF ; text-decoration: none ; background-color: transparent ; border: 1px solid #A6B9FB ; padding: 2px ; font-weight: bold ; }
a.x:visited { font: 12px Verdana ; color: #0000FF ; text-decoration: none ; background-color: transparent ; border: 1px solid #A6B9FB ; padding: 2px ; font-weight: bold ; }
a.x:hover { font: 12px Verdana ; color: #FFFFFF ; text-decoration: none ; background-color: #A6B9FB ; border: 1px solid #909090 ; padding: 2px ; font-weight: bold ; }
a.x:active { font: 12px Verdana ; color: #909090 ; text-decoration: none ; background-color: #DDE4F1; border: 1px solid #909090 ; padding: 2px ; font-weight: bold ; }
</style>
<script type="text/javascript">
function ToggleDisplay( d ) {
var obj = document.getElementById( d ) ;
obj.style.display = ( obj.style.display == 'none' ) ? 'block' : 'none' ;
}
</script>
<center>
<br> <br>
<p style="font: 18px Georgia ; color: #C60000 ; " >e = 2.71828182845904523536028747135266249775724709369995 ... and on ...</p>
<br> <br>
<p style="font: 10px Verdana ; margin-left: 2% ; margin-right: 2% ; " >
<b>e</b> is defined as being the sum as <b>n</b> goes to infinity of <b>1/n!</b> — which works out fine when programmed as an iterative sum in a loop with increments <b>n</b> from 1 to a finite relatively small integer, say 20. <br><br>
Results are less well defined when it comes to programming the formula, <b>( 1 + 1/n ) ^ n</b><br>where, theoretically, the larger the integer <b>n</b>, the more accurate the result. In this instance the result of <b>1 + 1/n</b> is raised to the power of <b>n</b> instead of using a sum. <br> </p>
For e = 1 + 1/n! <br><br>
<form name="e1" >
<input name="n1" maxlength="10" size="10" type="text" value=" " >
<input class="form" value="set n" onClick="getE1() ; " name="button" type="button">
</form>
<script type="text/javascript">
function getE1() {
var nm = document.e1.n1.value ;
var e = 1 ;
var n = 1 ;
var nFac = 1 ;
while ( n <= nm ) { nFac = nFac * n ; e = e + ( 1 / nFac ) ; n ++ ; }
var eStr = e.toFixed( 17 ) ;
eStr = eStr.substr( 0, 17 ) ;
var comment1 = 'for ' + nm + ' iterations e = ' + eStr ;
document.forms[ "result1" ].out1.value = eStr ;
}
</script>
<div align="center" class="out" >
<form id="result1" ><br>
<input type="text" name="out1" readonly >
</form>
</div>
<p><br> </p>
For e = ( 1 + ( 1/n ) ) ^ n <br><br>
<form name="e2" >
<input name="n2" maxlength="10" size="10" type="text" value=" " >
<input class="form" value="set n" onClick="getE2() ; " name="button" type="button">
</form>
<script type="text/javascript">
document.e2.n2.focus() ;
function getE2() {
var n = document.e2.n2.value ;
var f = 1 + ( 1 / n ) ;
var e = Math.pow( f, n ) ;
var eStr = e.toFixed( 17 ) ;
eStr = eStr.substr( 0, 17 ) ;
var comment2 = 'for power of ' + n + ' e = ' + eStr ;
document.forms[ "result2" ].out2.value = eStr ;
}
</script>
<div align="center" class="out" >
<form id="result2" ><br>
<input type="text" name="out2" readonly >
</form>
</div>
<p><br><br> </p>
<hr>
<p> </p>
<?php
$n1 = $_REQUEST[ 'n1' ] ;
$n2 = $_REQUEST[ 'n2' ] ;
if ( ( $n1 == '' ) & ( $n2 == '' ) ) { ; }
else {
print ( '
<script type="text/javascript">
' ) ;
if ( $n1 <> '' ) {
print ( '
document.e1.n1.value = '.$n1.' ;
getE1() ;
' ) ; }
if ( $n2 <> '' ) {
print ( '
document.e2.n2.value = '.$n2.' ;
getE2() ;
' ) ; }
print ( '
</script>
' ) ;
}
function displaySource() {
$jw = '/home/esand/public_html' ;
print( '<div style="margin-left: 10% ; text-align: left ; font: 11px Courier ; " >' ) ;
$root = $jw.'/FranklinSeiberling/rightPanel' ;
if ( ( $sc = fopen( $root.'/e.php', 'r' ) ) != false ) {
while ( ( $record = fgets( $sc ) ) != false ) {
$record = str_replace( '&', '&', $record ) ;
$record = str_replace( '<', '<', $record ) ;
$record = str_replace( '>', '>', $record ) ;
print( $record.'<br>' ) ;
}
fclose( $sc ) ;
}
else { print( 'File not found in '.$root.'<br>' ) ; }
print( '</div>' ) ;
}
?>
<div align="center" id="SourceButton" style="display: block ; " >
<a href="javascript: ToggleDisplay( 'SourceCode' ) ; ToggleDisplay( 'SourceButton' ) ; " class="u" >Display source</a><br> <br>
</div>
<div align="left" id="SourceCode" style="display: none ; " >
<?php
displaySource() ;
?>
</div>
|
|