ÿþ<HTML> <HEAD> <TITLE>Integration program</TITLE> <META http-equiv=Content-Type content="text/html"> <style type="text/css"> v\:* { behavior: url(#default#VML); } </style> <!-- XYGraph v2.3 code author --> <meta name="author" content="J. Gebelein" /> <!--integral.htm author --> <meta name="author" content="Liu, HsinHan ‰Rk”"o &#21129;&#37995;&#28450;" /> <script type="text/javascript"> <!-- //2009-08-23-11-48 //If one function defined twice in a html file //MSIE accept the last definition, //MSIE ignore older definition //Netscape accept the first definition //Netscape ignore newer definition //LiuHH's file structure use MSIE method. //Netscape method not compatible with LiuHH's //file structure. //LiuHH's file structure define one function //twice on purpose. //LiuHH do not know what code to select browser //If user use Netscape to view this page, some //function can never work. For example gamma() //2009-08-23-11-56 // // //If can not load jsgraph2.js next definition is //effective, tell user where to get jsgraph2.js var msg01='document.getElementById("gotoFM2msg").innerHTML+=\''; var msg02=' goto online to get http://freeman2.com/jsgraph2.js<br>\';'; function stepf(t0,bgn0) //9712091955 {eval(msg01+'01'+msg02);} function loggamma(x) {eval(msg01+'02'+msg02);} function gamma(x) {eval(msg01+'03'+msg02);} function factorial(n) {eval(msg01+'04'+msg02);} function wipeCurve(d3) {eval(msg01+'05'+msg02);} function DrawGraf2(argd2) {eval(msg01+'06'+msg02);} function closeStr(klozID) {eval(msg01+'07'+msg02);} function toSyntax(inStr1) {eval(msg01+'08'+msg02);} function x2t(in0) {eval(msg01+'09'+msg02);} function deleteData(workID,probID) {eval(msg01+'10'+msg02);} function delAll(probID) {eval(msg01+'11'+msg02);} function openTable(drawID,table01) {eval(msg01+'12'+msg02);} function open0lxr(xx) {eval(msg01+'13'+msg02);} function closelxr(yy) {eval(msg01+'14'+msg02);} //9712092032 //if receive http://freeman2.com/jsgraph2.js // jsgraph2.js redefine above functions, //otherwise tell where to find jsgraph2.js function XYGraph(yy) {eval(msg01+'101'+msg02);} //9801260855 function XYLine(yy) {eval(msg01+'102'+msg02);} //9801260857 function Label(yy) {eval(msg01+'103'+msg02);} //9801260859 //function tutelink() //9806231220 function tuteLink() //9811151029 change to 'Link' { document.getElementById("gotoFM2msg").innerHTML+= '50 goto online to get http://freeman2.com/tutelink.js<br>'; } function initial0(linkNum, plotNum) { tuteLink(0); //9806231221 //http://freeman2.com/tutelink.js //if use tutelink(0) when offline, get error 9711252125 } function alert0() //9806161720 { document.write('<font color=red>' +'This file is personal home work. No one <br>' +'proofread. Cannot promise correctness. <br>' +'If you suspect any view point wrong, <br>' +'please ask a math expert near by. <br>' +'Freeman 2009-06-19-10-46</font><br>' ); } //9806161724 function alert1() //9806261745 { document.write('' +'<br><font color=red size=+3>' +'Following is exercise hint and solution. <br>' +'Suggest reader solve problem first, then <br>' +'use your solution compare with LiuHH&#39;s <br>' +'solution. LiuHH&#39;s sol. has no guarantee. <br>' +'Your solution could be better and correct. <br>' +'2009-07-28-10-16<br>' +'</font><br>\n<br>\n<br>\n' ); } //function alert1() 9806261748 function alert2() //9806261808 { document.write('' +'0<font color=red size=+3>' +'LiuHH&#39;s sol. has no guarantee!</font>' ); } //function alert2() 9806261809 function alert3() //9810281727 { document.write('' +'<font color=red><br>' +'Questionable words or incorrect words <br>' +'change to silver color. 2009-10-28-13-50<br>' +'</font>' ); } //function alert3() 9810281729 /** <script language="javascript">alert0()</script> <script language="javascript">alert3()</script> /**/ function alert4() //9812060000 { document.write('<font color=red>' +'Output may contain error, Please verify first. <br>' +'Program environment is MSIE 6.0, please use MSIE<br>' +'</font>' ); } //function alert4() 9812060002 //--> </SCRIPT> <script src="http://freeman2.com/tutelink.js" language="javascript"></script><!--9806111210--> <script src="tutelink.js" language="javascript"></script><!--9806111211--> <script type="text/javascript" src=jsgraph2.js> </script><!--9808261915--> </HEAD> <body link="#FF0000" vlink="#0000FF" alink="#50A000" bgcolor="#ccfcfc" onload="javascript:initial0()" > <span id="gotoFM2msg"></span><!--9712091951--> <font size=+2> Numerical Integration </font> &nbsp; <a href="#docB037"> Update 2010-02-09 </a> <br> <a href="#NumIntegral">Integration</a> 0 <a href="#differentiate">Differentiation</a> 0 <a href=integral.htm#docB007> How to use </a> 0 <a href=integral.htm#docB030> Link </a> 0 <br> <a href=http://www.structura.info/XYGraph/XYGraphDemo.htm> XYGraph v2.3 - web page graph </a> &nbsp; <!--9506231219 add link--> <a href=http://www.structura.info/XYGraph/Links.htm> && <!--##9756;##9758;--> </a> &nbsp; <!--9506231216 add link--> <a href=http://www.structura.info/XYGraph/Purchase.htm> donate<!--9801031950 use donate ##9829;##9835; e&k&--> </a> &nbsp; <a href="http://www.structura.info/XYGraph/XYGraph.zip"> get code</a> <!-- 2006-06-12-18-21 download http://www.structura.info/XYGraph/XYGraph.zip C:\$fm\js\xygraph\XYGraph.zip 2006-06-19-08-21 record --> <br> <a href=http://www-stat.wharton.upenn.edu/~steele/Publications/Books/CSMC/CSMC_index.html> The Cauchy-Schwarz Master Class </a> &nbsp; <a href=http://www-stat.wharton.upenn.edu/~steele/index.html> J. Michael</a> <a href=http://www.wharton.upenn.edu/faculty/steele.html> Steele</a> &nbsp; <a href=http://www.amazon.com/review/product/052154677X/ref=cm_cr_dp_all_helpful?%5Fencoding=UTF8&coliid=&showViewpoints=1&colid=&sortBy=bySubmissionDateDescending> &&&&& </a><!--9806081839 add link--> <br> <font color=red> This file is personal home work. No one <br> proofread. Cannot promise correctness. <br> If you suspect any view point wrong, <br> please ask a math expert near by. <br> Freeman 2009-06-19-10-46</font> <br> Please use MSIE browser to read this file. <br> Did not test other browser. This file is <br> <!--9806081846--> written under MSIE 6.0 <br> <span id="tuteLink1"></span> <br> <script src="http://freeman2.com/rocsitee.js" language="javascript"></script> <br> <pre><font size=+2> <a name="docA001">&lt;a name="docA001"&gt;</a> 2010-01-30-12-11 start 2009-06-09-10-09 begin read The Cauchy-Schwarz Master Class written by Prof. J. Michael Steele ISBN 978-0-521-54677-5 2010-01-22 <a href=http://freeman2.com/tute0027.htm>done chapter six</a> <a href=tute0027.htm>Convexity</a> ~~ The Third Pillar <a name="docA002">&lt;a name="docA002"&gt;</a> Start chapter seven Integral Intermezzo LiuHH need a program to calculate function integration value to aid reading chapter seven. Before begin chapter seven, write a program integral.htm as a tool. Program is done. Upload integral.htm let every one use this program. 2010-01-30-12-18 stop <hr> </font></pre> <a name="NumIntegral">&lt;a name="NumIntegral"&gt;</a> 2010-01-28-20-20 <br>  %0Numerical Integration0(<a href="#differentiate">Differentiation</a>) <br> <font color=red><b> Output may contain error, Please verify first <br> Program environment is MSIE 6.0, please use MSIE <br> <!--9901132047-->If you save this file integral.htm to your computer <br> and open local integral.htm, it can not draw figure. <br> You need also save http://freeman2.com/jsgraph2.js <br> to your computer stay in same folder as integral.htm. </b></font> <br> x min: <INPUT id=QBboxXmin10 value="-6" size=3 > , x max: <INPUT id=QBboxXmax10 value="6" size=3 > ; y min: <INPUT id=QBboxYmin10 value="-30" size=3 > , y max: <INPUT id=QBboxYmax10 value="30" size=3 > ; <br> x min, x max, y min, y max is coordinate axis range <br> Drawing board size W: <INPUT id=QBboxWidth10 value="300" size=5 onchange="javascript:if(QBboxWidth10.value<100)QBboxWidth10.value=100; else if(QBboxWidth10.value>800)QBboxWidth10.value=800;" > H: <INPUT id=QBboxHeight10 value="300" size=5 onchange="javascript:if(QBboxHeight10.value<100)QBboxHeight10.value=100; else if(QBboxHeight10.value>800)QBboxHeight10.value=800;" > <br> <a name="IntegralBgn"></a> <font color=red><b> Next 7 lines are for integration. Variable must be x. </b></font> <br> Example: <input onclick="javascript:QBboxf0Int.value= 'x*x*x-2*x*x+7*x-5'; QBboxf0xBgn.value='1'; QBboxf0xEnd.value='3'; QBboxf0xStp.value='4'; RadioNCF[1].checked=1; //[1] goto '2' in '1,3,4,2,0' QBspanIntegral.innerHTML= integralf1('x*x*x-2*x*x+7*x-5',1,3,4,2,0);" title="SBN 471-13507-0 page 74 example" type="button" value="1" /><!--9901291528--> <input onclick="javascript:QBboxf0Int.value= 'sin(x)'; QBboxf0xBgn.value='0'; QBboxf0xEnd.value='PI'; QBboxf0xStp.value='10'; RadioNCF[5].checked=1; //[5] goto '6' in '0,3.141592653589793,10,6,0' QBspanIntegral.innerHTML= integralf1('sin(x)',0,3.141592653589793,10,6,0);" title="x in [0,PI]. 'PI' can be used." type="button" value="2" /> <!--9901291530 calling integralf1('sin(x)',0,3.141592653589793,10,6,0) parameters are 'sin(x)' function definition 0 x begin value 3.14159 x end value 10 step=10, from xbgn to xend, divide to 10 intervals, each interval do one Newton-Cotes formula evaluation. 6 Newton-Cotes formula n=6 method 0 short output to page <span ...> (1 is longer output to box 21) 2010-01-29-19-02 --> <input onclick="javascript:QBboxf0Int.value= '1/(1+x*x)'; QBboxf0xBgn.value='-4'; QBboxf0xEnd.value='+4'; QBboxf0xStp.value='1'; RadioNCF[5].checked=1; //[5] goto '6' in '-4,4,1,6,0' QBspanIntegral.innerHTML= integralf1('1/(1+x*x)',-4,4,1,6,0);" title="ISBN 0-471-02985-8 page 229 example. 2*atan(4)=2.651635327336065" type="button" value="3" /><!--9901291615--> <input onclick="javascript:QBboxf0Int.value= 'sin(x)*sqrt(1-x*x)'; QBboxf0xBgn.value='0'; QBboxf0xEnd.value='1'; QBboxf0xStp.value='1'; RadioNCF[5].checked=1; //[5] goto '6' in '0,1,1,6,0' QBspanIntegral.innerHTML= integralf1('sin(x)*sqrt(1-x*x)',0,1,1,6,0);" title="ISBN 0-471-02985-8 page 268 line -2. dg(x)/dx singular at x=1" type="button" value="4" /><!--9901291646--> <input onclick="javascript:QBboxf0Int.value= '2*sin(1-x*x)*x*x*sqrt(2-x*x)'; QBboxf0xBgn.value='0'; QBboxf0xEnd.value='1'; QBboxf0xStp.value='1'; RadioNCF[5].checked=1; //[5] goto '6' in '0,1,1,6,0' QBspanIntegral.innerHTML= integralf1('2*sin(1-x*x)*x*x*sqrt(2-x*x)',0,1,1,6,0);" title="ISBN 0-471-02985-8 page 268 line -2. dg(x)/dx OK at x=1" type="button" value="5" /><!--9901291650--> <input onclick="javascript:QBboxf0Int.value= '1/x'; QBboxf0xBgn.value='x=0;exp(x)'; QBboxf0xEnd.value='E'; QBboxf0xStp.value='2'; RadioNCF[5].checked=1; //[5] goto '6' in '1,6,0' QBspanIntegral.innerHTML= integralf1('1/x',1,2.718281828459045,2,6,0);" title="From x=1 to x=E Integral of 1/x = 1" type="button" value="6" /><!--9902022328--> <input onclick="javascript:QBboxf0Int.value= 'exp(-x)'; QBboxf0xBgn.value='exp(0)-sin(1)*sin(1)-cos(1)*cos(1)'; QBboxf0xEnd.value='1.E3'; QBboxf0xStp.value='200'; RadioNCF[5].checked=1; //[5] goto '6' in '1,6,0' QBspanIntegral.innerHTML= integralf1('exp(-x)',0,1000,200,6,0);" title="Exact solution=1, need large steps." type="button" value="7" /><!--9902052354--> &nbsp; <a href="#box21">debug</a> &nbsp; <a href="#docB007">help1</a> &nbsp; <input onclick=" QBboxfunc0x.value=QBboxf0Int.value; QBboxfunc1x.value=QBboxfunc2x.value= QBboxfunc3x.value=''" type="button" value="g2f" /><!--9901301400--> &nbsp; <a href="#docB028">help2</a> <br> g(x)<!-- value="x*x*x-2*x*x+7*x-5" SBN 471-13507-0 page 74 example--> <INPUT id=QBboxf0Int value="x*x*x-2*x*x+7*x-5" size=60 > <input onclick="QBboxf0Int.value=''" type="button" value="d" /> <br> <!--9901291455 distinguish integral g(x) A //output to QBspanIntegral.innerHTML from integral g(x) B //output to box21 click button [integral g(x) A] use QBspanIntegral.innerHTML=integralf1(parameters...) click button [integral g(x) B] use QBboxd21.value=integralf1(parameters...) --> <font color=red><b> RUN</b></font> <input onclick="javascript:var ncfPick=-1;for(var w0=0;w0<RadioNCF.length;w0++)if(RadioNCF[w0].checked){ncfPick=w0;break;}ncfPick++;QBspanIntegral.innerHTML=integralf1(QBboxf0Int.value,QBboxf0xBgn.value,QBboxf0xEnd.value,QBboxf0xStp.value,ncfPick,0)" type="button" value="integral g(x) A" /> &nbsp; <a href="#docB015"> steps</a> <INPUT id=QBboxf0xStp value="5"; size=3 > <input onclick="QBboxf0xStp.value=''" type="button" value="ds" /> <input onclick="QBboxf0xBgn.value=QBboxf0xEnd.value=''" type="button" value="dx" /> <input onclick="QBspanIntegral.innerHTML='<br>'" type="button" value="da" /> <br> <!--9902091619 use larger box for xbgn, xend--> x-bgn <INPUT id=QBboxf0xBgn value="1"; size=22 > x-end <INPUT id=QBboxf0xEnd value="3"; size=22 > <br> Newton-Cotes formula n=1 <!--9901281831 use radio--> <INPUT name="RadioNCF" type="radio">, 2<INPUT name="RadioNCF" type="radio" checked >, 3<INPUT name="RadioNCF" type="radio">, 4<INPUT name="RadioNCF" type="radio">, 5<INPUT name="RadioNCF" type="radio">, 6<INPUT name="RadioNCF" type="radio"> <br> <font color=red><b> <span id=QBspanIntegral> draw f(x) must use x as independent variable, <br> draw x(t),y(t) must use t as independent variable. </span> </b></font> <br> <a name="clickFig0605"></a> <a name="GraphBgn"></a> Graph title: <INPUT id=QBboxTitle10 value="input title here; below graph, above integral."; size=50 > <input onclick="QBboxTitle10.value=''" type="button" value="d" /> <br> x/t begin <INPUT id=QBboxXbegin value="-6" size=20 > , x/t end <INPUT id=QBboxXend value="6" size=20 > <input onclick="QBboxXbegin.value=QBboxXend.value=''" type="button" value="d" /> <br> Draw curve in <INPUT id=QBboxSteps value="180" size=3 > steps <input onclick="QBboxSteps.value=''" type="button" value="d" /> 0<a href="#JSMathList">math function</a> 0<a href="#docB035">x^5</a> <br><font color=red>  %</font>f0(x)<!--9901241407 define f(x)--> <INPUT id=QBboxfunc0x value="gatef(x,-7,0)*(9*pow(abs(x),4/3)/4+9*pow(abs(x),1/3))+gatef(x,0,7)*(9*pow(abs(x),4/3)/4-9*pow(abs(x),1/3))"; size=50 > <font color=red>x1(t)</font> <input onclick="QBboxfunc0x.value=''" type="button" value="d" /> <br><font color=black>  %</font>f1(x) <INPUT id=QBboxfunc1x value="gatef(x,-7,0)*(-3*pow(abs(x),1/3)-3*pow(abs(x),-2/3))+gatef(x,0,7)*(3*pow(abs(x),1/3)-3*pow(abs(x),-2/3))"; size=50 > <font color=red>y1(t)</font> <input onclick="QBboxfunc1x.value=''" type="button" value="d" /> <br><font color=blue>  %</font>f2(x) <INPUT id=QBboxfunc2x value="gatef(x,-7,0)*(pow(abs(x),-2/3)-2*pow(abs(x),-5/3))+gatef(x,0,7)*(pow(abs(x),-2/3)+2*pow(abs(x),-5/3))"; size=50 > <font color=blue>x2(t)</font> <input onclick="QBboxfunc2x.value=''" type="button" value="d" /> <br><font color=purple>  %</font>f3(x) <INPUT id=QBboxfunc3x value=""; size=50 > <font color=blue>y2(t)</font> <input onclick="QBboxfunc3x.value=''" type="button" value="d" /> <input onclick="QBboxfunc0x.value=QBboxfunc1x.value=QBboxfunc2x.value=QBboxfunc3x.value=''" type="button" value="dA" /> <br> <input onclick="javascript:generalDrawf(1)" type="button" value="Draw f0(x) to f3(x)" title="f0(x) to f3(x) must use 'x' as variable" /> &nbsp; <input onclick="javascript:generalDrawf(101)" type="button" value="x1(t), y1(t) x2(t), y2(t)" title="x1(t) y1(t) must use 't' as variable" /> &nbsp; <input onclick="QBdivGraph10.innerHTML=QBspanEqnDoc10.innerHTML=''" type="button" value="wipe" /> <br> Above big button run user equation. Below run program equation. <br> f(x) <input onclick="javascript:generalDrawf(11)" type="button" value="11" /> <input onclick="javascript:generalDrawf(12)" type="button" value="12" /> p1 <INPUT id=QBboxPara01 value="1"; size=5 ><!--9901261529--> p2 <INPUT id=QBboxPara02 value="2"; size=5 > ; x(t),y(t) <input onclick="javascript:generalDrawf(54)" type="button" value="54" /> <input onclick="javascript:generalDrawf(55)" type="button" value="55" /> <br> <font color=red> <span id=QBspanAlert10> </span> </font> <br> <div id=QBdivGraph10></div> <br> <span id=QBspanEqnDoc10> <!--98111108361--> </span> <br> <a name="box21">&lt;a name="box21"&gt;</a> Click "integral g(x) B", debug output to box21. <br> Box 21,<!--9901072050 use box21--> <INPUT onclick='javascript:window.clipboardData.setData("Text",document.getElementById("QBboxd21").value.toString())' type=button value="copy21"> <INPUT onclick='document.getElementById("QBboxd21").value=""' type=button value="del21"> <!--9901291455 distinguish click button [integral g(x) A] use QBspanIntegral.innerHTML=integralf1(parameters...,0) click button [integral g(x) B] use QBboxd21.value=integralf1(parameters...,1) --> <input onclick="javascript:var ncfPick=-1;for(var w0=0;w0<RadioNCF.length;w0++)if(RadioNCF[w0].checked){ncfPick=w0;break;}ncfPick++;QBboxd21.value=integralf1(QBboxf0Int.value,QBboxf0xBgn.value,QBboxf0xEnd.value,QBboxf0xStp.value,ncfPick,1)" type="button" value="integral g(x) B" /> &nbsp; <a href="#IntegralBgn">Control Center</a> <br> <TEXTAREA id=QBboxd21 name=QBboxd21 rows=6 cols=60 > Box 21 record debug data. Please click "integral g(x) B" button. </TEXTAREA> <br> You can not draw other curve here. But you can <br> goto <a href="tute0013.htm#ch02c023">[Modify 606]</a> define your equation <br> and click [Draw] within yellow stripe. <br> (Do not click [Draw 606]) 2009-10-08-17-08 <br> <script lang="javascript"> <!-- var ncfCoef= //9901281755 [ //ncfCoef is used in calculation [1/2, 1, 1, -1/12], [1/3, 1, 4, 1, -1/90], [3/8, 1, 3, 3, 1, -3/80], [2/45, 7,32,12,32,7,-8/945], [5/288,19,75,50,50,75,19,-275/12096], [1/140,41,216,27,272,27,216,41,-9/1400] ]; var ncfCoef2= //9901292155 [ //ncfCoef2 is used in document '1/2; 1, 1 ; -1/12', '1/3; 1, 4, 1 ; -1/90', '3/8; 1, 3, 3, 1 ; -3/80', '2/45; 7, 32, 12, 32, 7 ; -8/945', '5/288; 19, 75, 50, 50, 75, 19 ; -275/12096', '1/140; 41, 216, 27, 272, 27, 216, 41 ; -9/1400' ]; /** function integralf1() use Newton-Cotes formula n=1 to 6 to find function integration value. int{f(x)dx}, must use 'x' as independent variable. function integralf1() receive six parameters inArg1=integrand equation definition inArg2=xbegin value inArg3=xend value inArg4=steps value, positive integer inArg5=ncfchoice value, 1 to 6 inArg6=output method if(inArg6==0) //9901291451 output to QBspanIntegral.innerHTML only two lines, use <br> change line if(inArg6==1) //9901291452 output to box21 for detail output many lines. Use '\n' change line. Two example calls are QBspanIntegral.innerHTML= integralf1('1/(1+x*x)',-4,4,1,6,0); QBboxd21.value= integralf1(QBboxf0Int.value,QBboxf0xBgn.value,QBboxf0xEnd.value,QBboxf0xStp.value,ncfPick,1) QBboxf0Int, QBboxf0xBg, ... are web page specific. You can use different element ID. Must match right. 9901300548 /**/ function integralf1(inArg1,inArg2,inArg3,inArg4,inArg5,inArg6) {//9901281800 //integration function 1st method var w0,w1,w2,w3,w4; var msg0=''; var intSum=0; //answer, integration value var eqnfx=inArg1; //integrand equation definition //x_begin, x_end domain two ends var xbgn=parseFloat(eval('with(Math){'+inArg2+'}')); var xend=parseFloat(eval('with(Math){'+inArg3+'}')); //"with(Math){...}" main goal is allow //user input "PI" as domain end value. //also allow "x=2;sin(x)" or //"vv=0.5;exp(vv)" as domain end value. var stps=parseInt(inArg4); //if stps=2, whole domain cut to two //equal interval. Each interval do //one Newton-Cotes formula integration. if(isNaN(xbgn)) {return 'xbgn wrong:'+inArg2+'<br>';} if(isNaN(xend)) {return 'xend wrong:'+inArg3+'<br>';} if(isNaN(stps)) {return 'step wrong:'+inArg4+'<br>';} if(stps<=0) {return 'step wrong:'+inArg4+', must be positive.<br>';} if(stps>100&&inArg6==1) //9902060019 {inArg6=0; alert('debug output allow at most steps=100\nNow steps='+stps+'\nChange to regular output, no debug.')} var ncfchoice=inArg5; if(isNaN(ncfchoice)) {return 'Newton-Cotes formula selection wrong:'+inArg5+'<br>';} //This page never wrong. But for general //consideration, include guarding code. if(ncfchoice<1)ncfchoice=1 else if(ncfchoice>6)ncfchoice=6 //total stps interval, each interval //create ncfchoice function values var xCount=ncfchoice*stps var xdelta=(xend-xbgn)/xCount; //xdelta is 'h' in (h/3)*[f(x0)+4*f(x1)+f(x2)] //function evaluation times=xCount+1 //record function value var farray=[0,0,0,0,0,0,0]; var oneSum=0; //in (h/3)*[f(x0)+4*f(x1)+f(x2)] //oneSum is "[f(x0)+4*f(x1)+f(x2)]" //(h/3)*oneSum is one section integration //value. There are total 'stps' sections. var fvalue; //eqnfx use 'x' as independent variable. //before each "eval('with(Math){'+eqnfx+'}')" //must update x value x=xbgn fvalue=farray[0]= eval('with(Math){'+eqnfx+'}'); //next line is last error code before correct answer. //oneSum+=eval(eqnfx); //9901291257 delete //9901291257 deleted then get correct answer //integral[x=1,3]{xdx} = 4 right!! 9901291258 var echoDebug=0; //return answer only, no debug detail if(arguments.length>=6&&inArg6==1) echoDebug=1; //9901291801, return msg0=debug detail if(echoDebug) // print debug detail { msg0+='' +'equation="'+eqnfx+'"\n' +'ncfchoice=Newton-Cotes formula user choice [1 to 6]\n' +'program count start from 0, ncfchoice-1='+(ncfchoice-1)+'\n' +'Program use the following coefficients:\n' +ncfCoef2[ncfchoice-1]+'\n' //9901292159 use this line +'First coefficient is for x_interval length.\n' +'Last coefficient is for error estimation.\n' +'First is used at integral value evaluation point.\n' +'Last is not used in program.\n' +'Middle terms are coefficients for function values.\n' +'First coefficient modify domain x value.\n' +'Middle coefficient modify range function values.\n' +'Simple example:\n' +'for n=2 (Simpson\'s Rule), h=(x2-x0)/2\n' +'Integral[x=x0,x2]f(x)dx=\n' +'(h/3)*[f(x0)+4*f(x1)+f(x2)] - h^5*f(4)(¾)/90\n' +'"f(4)" is f(x) differential four times. not f(x=4)\n' +'Above is polynomial formula for any integrated\n' +'function. Program store coefficients as next\n' +'[1/3, 1, 4, 1, -1/90]\n' +'Program allow user integrate f(x) in many steps.\n' +'If step=1, whole domain apply Simpson Rule once.\n' +'If step=2, whole domain divide to two smaller\n' +'sections, Each section apply Simpson Rule once.\n' +'Variable oneSum sum [f(x0)+4*f(x1)+f(x2)] which \n' +'is NOT integral of one section. Missing "(h/3)"\n' +'(h/3)*oneSum is partial intSum in one step.\n' +'Add all (h/3)*oneSum get final answer intSum\n' +'Echo debug information start.\n' +'\n' ; } //if stps=2, whole domain cut to two //equal interval. Each interval do //one Newton-Cotes formula integration. // for(w0=0;w0<stps;w0++) // 9901282118 correct { //w0=number of steps //stps=total number of steps //Assume domain=[1,5], assume //Newton-Cotes formula n=2 selected //assume number of steps=2 //First step calculate x=1,2,3 three //function values. (Simpson's Rule) //Second step calculate x=3,4,5 three //function values. x=3 is previous step //last evaluation. Use it for this step //9901300505 write note. if(w0>0) //first step no previous. { if(echoDebug) { msg0+='\n' +'Start a new step. New step first function value\n' +'is previous step last function value as following\n' +bye09(fvalue)+' &&& '; } farray[0]=fvalue; //farray[0], [1], [2] store current x=3,4,5 //three function values. fvalue is previous //step last function value. USE IT. 9901300512 } //in (h/3)*[f(x0)+4*f(x1)+f(x2)] //oneSum is "[f(x0)+4*f(x1)+f(x2)]" //for n=2, coefficients are //[1/3, 1, 4, 1, -1/90] = ncfCoef[1] //ncfCoef[2-1][0] is 1/3 for "(h/3)*" //ncfCoef[2-1][1] is first 1 for "f(x0)" //Next line is fvalue*ncfCoef[2-1][1] //9901300517 oneSum+=fvalue*ncfCoef[ncfchoice-1][1];//9901291216 if(echoDebug) { msg0+='x='+x+'\n'; msg0+='ncfCoef[ncfchoice-1][1]='+ncfCoef[ncfchoice-1][1]+'\n'; msg0+='fvalue='+bye09(fvalue)+' ;;; '; msg0+='oneSum#='+bye09(oneSum)+'\n\n'; } //Above oneSum get value from "f(x0)" //in "[f(x0)+4*f(x1)+f(x2)]" //below find 4*f(x1)+f(x2) //9901300520 for(w1=0;w1<ncfchoice;w1++) { //before each "eval('with(Math){'+eqnfx+'}')" //must update x value x=xbgn+xdelta*(w0*ncfchoice+w1+1) //find x value, start from xbgn //for ncfchoice steps done, there are //w0*ncfchoice previous xdelta used //go over used xdelta, "w1+1" is //current new xdelta. "+1" in "w1+1" //is current first function value //which copied from previous last one. //current first is done. go over it. farray[w1+1]= fvalue=eval('with(Math){'+eqnfx+'}'); //9901291246 change from [w1+1] to [w1+2] oneSum+=fvalue*ncfCoef[ncfchoice-1][w1+2] //ncfCoef[ncfchoice-1][w1+0] used at 9901291220 //ncfCoef[ncfchoice-1][w1+1] used at 9901291216 //[w1+1] is an error code. [w1+2] OK. //in [1/3, 1, 4, 1, -1/90] //[w1+0] is '1/3' it is for (h/3) in //(h/3)*[f(x0)+4*f(x1)+f(x2)] //[w1+1] is first '1', it is used at //"copied from previous last one", then //[w1+2] is correct '4' in [1/3, 1, 4, 1, -1/90] //in (h/3)*[f(x0)+4*f(x1)+f(x2)], 'h' is xdelta //9901300530 if(echoDebug) msg0+='' +'x='+bye09(x)+', ' +'w1='+w1+', ' +'ncfchoice='+ncfchoice+'\n' +'ncfCoef[ncfchoice-1][w1+2]='+ncfCoef[ncfchoice-1][w1+2]+'\n' +'fvalue='+bye09(fvalue)+', ' +'oneSum%=old_oneSum+'+ncfCoef[ncfchoice-1][w1+2] +'*fvalue='+bye09(oneSum)+'\n\n' } //for(w1=0;w1<ncfchoice;w1++) //in (h/3)*[f(x0)+4*f(x1)+f(x2)], //'h' is xdelta //'1/3' is ncfCoef[ncfchoice-1][0] //'[f(x0)+4*f(x1)+f(x2)]' is oneSum intSum+=xdelta*ncfCoef[ncfchoice-1][0]*oneSum; //9901291220 if(echoDebug) { msg0+='' +(ncfchoice+1)+' function values used are next\n'; for(w1=0;w1<=ncfchoice;w1++) { //9901291048 msg0+=farray[w1]+'; '; } msg0+='\n' msg0+='' +'xdelta='+xdelta+'\n' +'ncfCoef[ncfchoice-1][0]='+ncfCoef[ncfchoice-1][0]+'\n' +'oneSum&='+oneSum+'\n' +'intSum+=xdelta*ncfCoef[ncfchoice-1][0]*oneSum;\n' +'intSum+=this intSum='+(xdelta*ncfCoef[ncfchoice-1][0]*oneSum)+'\n' +'upto now intSum='+intSum+'\n' //9901291233 msg0+='\n\n=====\n'; //9901291050 } //done one step, reset oneSum oneSum=0; //9901291221 } //for(w0=0;w0<stps;w0++) //intSum is final answer, present to user. //if answer is 2.0000000000003 //bye09() change answer to 2 //if answer is 6.2999999999999 //bye09() change answer to 6.3 //if answer is 7.3333333333333 //bye09() NOT change answer //9901300538 intSum=bye09(intSum); //9901292233 if(echoDebug) { msg0+='\n\n'; msg0+='eqnfx='+eqnfx+'\n'; msg0+='xbgn='+xbgn+'\n'; msg0+='xend='+xend+'\n'; msg0+='stps='+stps+'\n'; msg0+='Newton-Cotes formula choice=ncfchoice='+ncfchoice+'\n'; msg0+='Total function evaluation=ncfchoice*stps+1='+(xCount+1)+'\n';//9901282009 msg0+='xdelta=(xend-xbgn)/(ncfchoice*stps)='+xdelta+'\n'; } if(echoDebug) //return to box21, long string { return 'Answer : intSum='+intSum+'\n' //9901291222 +msg0; //9901281805 } else //return to web page <span> two lines. return 'From x='+xbgn+' to x='+xend+'<br>' +'integration value is '+intSum; } //function integralf1(inArg1) 9901291258_first_OK //9901300540 done document notes. function generalDrawf(rtArg1) //9901061920 { QBspanAlert10.innerHTML=''; var b0,b1,b2,b3,b4,b5,b6,b7,b8,b9; var ii,jj,kk; var fpar01=parseFloat(QBboxPara01.value); //9901251536 var fpar02=parseFloat(QBboxPara02.value); if(isNaN(fpar01))fpar01=QBboxPara01.value=0; if(isNaN(fpar02))fpar02=QBboxPara02.value=0; if(rtArg1==11) { //9901251600 QBboxXbegin.value='sin(0)' QBboxXend.value='a=0;b=2;c=1;cos(a)*pow(b,c)' QBboxXmin10.value=-2 QBboxXmax10.value=+2 QBboxYmin10.value=-2 QBboxYmax10.value=+2 QBboxfunc0x.value='x*('+fpar02+')/((1-x)*('+fpar01+')+x*('+fpar02+'))'; //9901251533 //QBspanAlert10.innerHTML= //9901251604 QBboxfunc1x.value='('+fpar02+')/((1-x)*('+fpar01+')+x*('+fpar02+'))-x*('+fpar02+')*(-('+fpar01+')+('+fpar02+'))/((1-x)*('+fpar01+')+x*('+fpar02+'))/((1-x)*('+fpar01+')+x*('+fpar02+'))' QBboxfunc2x.value= QBboxfunc3x.value=''; QBboxTitle10.value='www.cms.math.ca/cjm/v28/cjm1976v28.0793-0804.pdf'; //return; //9901251605 } else if(rtArg1==12) { //9901251148 QBboxXmin10.value=-6 QBboxXmax10.value=6 QBboxYmin10.value=-30 QBboxYmax10.value=30 QBboxXbegin.value=-6 QBboxXend.value=6 QBboxSteps.value=180 QBboxfunc0x.value ='gatef(x,-7,0)*(9*pow(abs(x),4/3)/4+9*pow(abs(x),1/3))+gatef(x,0,7)*(9*pow(abs(x),4/3)/4-9*pow(abs(x),1/3))' QBboxfunc1x.value ='gatef(x,-7,0)*(-3*pow(abs(x),1/3)-3*pow(abs(x),-2/3))+gatef(x,0,7)*(3*pow(abs(x),1/3)-3*pow(abs(x),-2/3))' QBboxfunc2x.value ='gatef(x,-7,0)*(pow(abs(x),-2/3)-2*pow(abs(x),-5/3))+gatef(x,0,7)*(pow(abs(x),-2/3)+2*pow(abs(x),-5/3))' //9901251154 QBboxTitle10.value='marauder.millersville.edu/~bikenaga/calculus/conc/conc.pdf'; } //rtArg1>50 is for x(t), y(t) //must use 't' as independent variable //must NOT use 'x'. 9901071100 else if(rtArg1==54) { //9901202050 QBboxXbegin.value='-PI' QBboxXend.value='+PI' QBboxSteps.value=180 QBboxXmin10.value=-30 QBboxXmax10.value=+30 QBboxYmin10.value=-30 QBboxYmax10.value=+30 QBboxfunc0x.value='18*cos(t)*cos(2*t)*cos(t)'; QBboxfunc1x.value='18*cos(t)*cos(PI*t)*sin(t)'; QBboxfunc2x.value='13*cos(t)+sin(8*t)'; QBboxfunc3x.value='13*sin(t)+cos(8*t)'; QBboxTitle10.value=""; } else if(rtArg1==55) { //9901202057 QBboxXbegin.value=0.5 QBboxXend.value=+15 QBboxSteps.value=180 QBboxXmin10.value=-2 QBboxXmax10.value=+2 QBboxYmin10.value=-2 QBboxYmax10.value=+2 QBboxfunc0x.value='cos(t)*cos(t)/t'; QBboxfunc1x.value='sin(t)*sin(t)/t'; QBboxfunc2x.value='1*cos(t)*cos(t)*cos(t)'; QBboxfunc3x.value='1*sin(t)*sin(t)*sin(t)'; QBboxTitle10.value=""; } //9902050040 add "with(Math)..." var xbgn=parseFloat(eval('with(Math){'+QBboxXbegin.value+'}')) var xend=parseFloat(eval('with(Math){'+QBboxXend.value+'}')) var step5=parseFloat(QBboxSteps.value); if(isNaN(xbgn)) { //9901062323 QBspanAlert10.innerHTML='' +'x begin must be defined. Now it is [' +QBboxXbegin.value+']'; return; } if(isNaN(xend)) { //9901062324 QBspanAlert10.innerHTML='' +'x end must be defined. Now it is [' +QBboxXend.value+']'; return; } if(xbgn>xend) { //9901062326 QBspanAlert10.innerHTML='' +'x begin must be < x end. Now ' +'x begin='+QBboxXbegin.value +', x end='+QBboxXend.value; return; } if(isNaN(step5)) { //9901062327 QBspanAlert10.innerHTML='' +'steps must be defined. Now it is [' +QBboxSteps.value+']'; return; } if(step5<2)step5=QBboxSteps.value=2; var MyGraph = new XYGraph(); var MyLine1 = new XYLine(); var MyLine2 = new XYLine(); MyLine1.VMLpointshapetype="none"; MyLine2.VMLpointshapetype="none"; status=''; MyGraph.ymax=QBboxYmax10.value; MyGraph.ymin=QBboxYmin10.value; MyGraph.xmax=QBboxXmax10.value; MyGraph.xmin=QBboxXmin10.value; MyGraph.gheight=QBboxHeight10.value; MyGraph.gwidth=QBboxWidth10.value; MyGraph.title=QBboxTitle10.value; QBspanAlert10.innerHTML=''; QBdivGraph10.innerHTML = ""; QBspanEqnDoc10.innerHTML = ""; //above routine for all graph if(rtArg1==21) { //9901171832 MyGraph.ymax=+3; MyGraph.ymin=-2; MyGraph.xmax=+2; MyGraph.xmin=-3; MyGraph.title='Exercise 6.14 complex roots in unit disk'; xbgn=0; step0=60 delta=2*Math.PI/step0; for(b0=0;b0<=step0;b0++) { t=xbgn+delta*b0; MyLine1.x[b0] =Math.cos(t) MyLine1.y[b0] =Math.sin(t) } MyLine1.VMLstroke="weight='1pt'; color='red'; dashstyle='solid';"; MyGraph.Plot(MyLine1); MyLine2.x[0] =-0.5 MyLine2.y[0] =-0.866025 MyLine2.x[1] =-2 MyLine2.y[1] = 0 MyLine2.x[2] =-0.5 MyLine2.y[2] = 0.866025 MyLine2.x[3] = 0. MyLine2.y[3] = 0. MyLine2.VMLstroke="weight='1pt'; color='blue'; dashstyle='solid';"; MyGraph.Plot(MyLine2); // draw intercept points var MyLabel = new Label(); MyLabel.labelsize = "10"; //9506172108 try next MyLabel.VMLpointshapetype="circle"; MyLabel.labelcolor="black"; MyLabel.x =0.2; MyLabel.y =0.8; MyLabel.label = 'A'; MyGraph.Drawlabel(MyLabel); MyLabel.x =0.4; MyLabel.y =-0.6; MyLabel.label = 'B'; MyGraph.Drawlabel(MyLabel); MyLabel.x =0.7; MyLabel.y =0.3; MyLabel.label = 'C'; MyGraph.Drawlabel(MyLabel); MyLabel.pointfillcolor="blue"; MyLabel.x =-2; MyLabel.y =0.; MyLabel.label = 'z'; MyGraph.Drawlabel(MyLabel); MyLabel.VMLpointshapetype="none"; MyLabel.x =-1.8; MyLabel.y =-0.08; MyLabel.label = 'È'; MyGraph.Drawlabel(MyLabel); QBdivGraph21.innerHTML = MyGraph; return; } //9901171841 var delta=(xend-xbgn)/step5; var x; var eqn00=eqn01=eqn02=eqn03=''; eqn00=QBboxfunc0x.value; //9901061928 eqn01=QBboxfunc1x.value; eqn02=QBboxfunc2x.value; eqn03=QBboxfunc3x.value; //9901071046 if(rtArg1>50) { //9901071051 var t; //9901071053 if(eqn00.length>0&&eqn01.length>0) { for(b0=0;b0<=step5;b0++) { //9901071054 t=xbgn+delta*b0; MyLine1.x[b0] =eval('with(Math){'+eqn00+'}'); MyLine1.y[b0] =eval('with(Math){'+eqn01+'}'); } //for(b0=0;b0<=step5;b0++) MyLine1.VMLstroke="weight='1pt'; color='red'; dashstyle='solid';"; MyGraph.Plot(MyLine1); } if(eqn02.length>0&&eqn03.length>0) { for(b0=0;b0<=step5;b0++) { //9901071055 t=xbgn+delta*b0; MyLine1.x[b0] =eval('with(Math){'+eqn02+'}'); MyLine1.y[b0] =eval('with(Math){'+eqn03+'}'); } //for(b0=0;b0<=step5;b0++) MyLine1.VMLstroke="weight='1pt'; color='blue'; dashstyle='solid';"; MyGraph.Plot(MyLine1); } QBdivGraph10.innerHTML = MyGraph; QBspanEqnDoc10.innerHTML = "" +"2010-01-07-11-09 create code<br>" +"No document for this drawing.<br>" return; } //if(rtArg1>50) if(eqn00.length>0) //9901090805 use if() { for(b0=0;b0<=step5;b0++) { //9812131606 x=xbgn+delta*b0; //9812131609 MyLine1.x[b0] =x; MyLine1.y[b0] =eval('with(Math){'+eqn00+'}'); //9901061931 } //for(b0=0;b0<=step5;b0++) MyLine1.VMLstroke="weight='1pt'; color='red'; dashstyle='solid';"; MyGraph.Plot(MyLine1); } //if(eqn00.length>0) if(eqn01.length>0) { for(b0=0;b0<=step5;b0++) { //9812131638 x=xbgn+delta*b0; //9812131609 MyLine1.x[b0] =x; MyLine1.y[b0] =eval('with(Math){'+eqn01+'}'); //9901061932 } //for(b0=0;b0<=step5;b0++) MyLine1.VMLstroke="weight='1pt'; color='black'; dashstyle='solid';"; MyGraph.Plot(MyLine1); } //if(eqn01.length>0) if(eqn02.length>0) { for(b0=0;b0<=step5;b0++) { //9812131643 x=xbgn+delta*b0; MyLine1.x[b0] =x; MyLine1.y[b0] =eval('with(Math){'+eqn02+'}'); //9901061933 } //for(b0=0;b0<=step5;b0++) MyLine1.VMLstroke="weight='1pt'; color='blue'; dashstyle='solid';"; MyGraph.Plot(MyLine1); } //if(eqn02.length>0) if(eqn03.length>0) { for(b0=0;b0<=step5;b0++) { //9901071048 x=xbgn+delta*b0; MyLine1.x[b0] =x; MyLine1.y[b0] =eval('with(Math){'+eqn03+'}'); //9901071049 } //for(b0=0;b0<=step5;b0++) MyLine1.VMLstroke="weight='1pt'; color='purple'; dashstyle='solid';"; MyGraph.Plot(MyLine1); } //if(eqn03.length>0) if(rtArg1==11) { QBspanEqnDoc10.innerHTML = "" +"www.cms.math.ca/cjm/v28/cjm1976v28.0793-0804.pdf<br>" +"page 794 (2/12) Lemma equation <br>" +"p=lambda*y/[(1-lambda)*x+lambda*y]<br>" +"above 'x' change to code fpar01<br>" +"above 'y' change to code fpar02<br>" +"above 'lambda' change to code x<br>" +"fpar01 from p1 box, "+fpar01+"<br>" +"fpar02 from p2 box, "+fpar02+"<br>" +"Red curve: "+QBboxfunc0x.value+"<br>" +"Black curve: "+QBboxfunc1x.value+"<br>" +"Curve are defined for x in [0,1]<br>" +"x outside of [0,1] may cause 1/0<br>" +"2010-01-25-16-10<br>" } else if(rtArg1==12) { QBspanEqnDoc10.innerHTML = "" +"2010-01-24-15-00 start<br>" +"How to create a Javascript code to draw above red<br>" +"curve? <font color=red>Alert red curve has -infinite slope at x=0<br>" +"Function pow(x,power) not allow x be negative.</font><br>" +"2010-01-22-19-47 LiuHH access<br>" +"http://marauder.millersville.edu/~bikenaga/calculus/conc/conc.pdf<br>" +"found f0(x)=9*pow(x,4/3)/4-9*pow(x,1/3) example<br>" +"Red curve f0(x)=9*pow(x,4/3)/4-9*pow(x,1/3)<br>" +"Black curve f'0(x)=3*pow(abs(x),1/3)-3*pow(abs(x),-2/3)<br>" +"Blue curve f''0(x)=pow(abs(x),-2/3)+2*pow(abs(x),-5/3)<br>" +"Write Javascript code, pow(x,1/3) change to pow(abs(x),1/3)<br>" +"Use gatef(x,-7,0) to draw -x part<br>" +"Use gatef(x,0,7) to draw +x part<br>" +"<br>" +"cubic root of -27 is -3 ( -3 cube is -27)<br>" +"<font color=red>pow() use abs() and take away '-', we must make up '-'</font><br>" +"When draw -x part, ODD fraction reverse +/- sign<br>" +"For example f'0(x) is the sum of next two parts<br>" +"gatef(x,-7,0)*(<font color=red size=+3><b>-3</b></font>*pow(abs(x),1/3)-3*pow(abs(x),-2/3))<br>" +"+gatef(x,0,7)*(3*pow(abs(x),1/3)-3*pow(abs(x),-2/3))<br>" +"Odd number '1' and '3' in '1/3' make 3 reverse to -3<br>" +"Under 'gatef(x,-7,0)', abs() take away '-', reverse put '-' back.<br>" +"Under 'gatef(x,0,7)', do not worry. Positive x, no trouble.<br>" +"For better illustration, use abs(), did not replace by -x / +x<br>" +"<br>" +"f''0(x) is the sum of next two parts<br>" +"gatef(x,-7,0)*(pow(abs(x),-2/3)<font color=red size=+3><b>-2</b></font>*pow(abs(x),-5/3))<br>" +"+gatef(x,0,7)*(pow(abs(x),-2/3)+2*pow(abs(x),-5/3))<br>" +"Odd number '5' and '3' in '-5/3' make 2 reverse to -2<br>" +"<br>" +"2010-01-24-15-12 record<br>" } else if(rtArg1==13) { //9901181940 QBdivGraph13.innerHTML = MyGraph; QBspanEqnDoc13.innerHTML = "" +"2010-01-18-19-42 start<br>" +"Textbook exercise 6.16, page 104/252<br>" +"Red curve is f(x)=1/x<br>" +"Black curve f'(x)=-1/x/x<br>" +"Blue curve is f''(x)=2/x/x/x<br>" +"Red curve is convex. Because blue<br>" +"curve f''(x) > 0 for x > 0<br>" +"2010-01-18-19-46 stop<br>" return; } QBdivGraph10.innerHTML = MyGraph; return; } //function generalDrawf() //9812131648 //9901072310 include isAlpha(ch) to tute0026.htm function isAlpha(ch) //9809151101 { if((ch>='a'&&ch<='z') ||(ch>='A'&&ch<='Z') ) return true; return false; } // 9507121343 function stepf(t0,bgn0) { if(t0<bgn0) return 0.; return 1.; } // end function // 9507121346 // 9507121356 // stepf(t,3) get t<3 value 0 // stepf(t,3) get t>=3 value 1 // // (1-stepf(t,3)) get t<3 value 1 // (1-stepf(t,3)) get t>=3 value 0 // // (stepf(t,2)-stepf(t,3)) // get 2<=t<3 value 1 // t<2 and t>=3 value 0 // 9507121400 //9804281114 gate function function gatef(t0,bgn0,end0) { if(arguments.length==0)return 0; if(arguments.length==1)return 0; if(arguments.length==2) //9804281141 { if(t0<bgn0) return 0;else return 1;} if(t0<bgn0) return 0.; if(t0>end0) return 0.; return 1.; // 9804281117 } // end function // gatef(t,3.2,5.6) if t<3.2 get 0 // gatef(t,3.2,5.6) if t>5.6 get 0 // gatef(t,3.2,5.6) if 3.2<=t<=5.6 get 1 // 9804281119 /* 95,07,08,14,55,00 http://www.univie.ac.at/future.media/moe/JavaCalc/jcintro.html c:\$fm\js\math9507\JavaCalc-jcintro.html 95,07,08,15,00 http://www.univie.ac.at/future.media/moe/JavaCalc/parser.js c:\$fm\js\math9507\JavaCalc-jcintro-parser.js Return to MathCollections Ken Kikuchi Comment me: kikuchi@mix.or.jp Last updated: 2/29/2000 9507132210 include function loggamma(x) and function gamma(x) /**/ // Ab hier (17. 3. 2000) von Ken's Script \áernommen: function factorial(n) { /* factorial */ with(Math) { if (n<0) /* if negative */ return gamma(n+1); else if ((n == 0) || (n == 1)) return 1; else if (abs(n)-floor(abs(n))==0 ) /* if positive integer */ return n * factorial(n-1) ; else /* if non-integer */ return gamma(n+1); } } function loggamma(x) { /* log gamma */ var u0; //9507142008 with(Math) { var v=1; var w=0; var z=0; while ( x<8 ) { v*=x; x++ } w=1/(x*x); u0= //9507142009 ((((((((-3617/122400)*w + 7/1092)*w -691/360360)*w + 5/5940)*w -1/1680)*w + 1/1260)*w -1/360)*w + 1/12)/x + 0.5 * log(2*PI)-log(v)-x+(x-0.5)*log(x) ; //status='x=['+x+']; w=['+w+']; u0=['+u0+'] 9507142010'; return u0; } } function gamma(x) { /* gamma */ //9507141940 var i0; var y0=''; var g0,g1,g2; //9507142019 for(i0=0;i0<(x+'').length;i0++) { if(i0==0&&(x+'').charAt(i0)=='(')continue; if((x+'').charAt(i0)==')')break; //9507141944 y0+=(x+'').charAt(i0); } x=parseFloat(y0); with(Math) { if ( x <= 0 ) { if (abs(x)-floor(abs(x))==0 ) return "ComplexInfinity" ; else { g0=loggamma(1-x); g1=PI/( sin(PI*x) * exp( g0 ) ); return g1; } } else { g0=loggamma(x); g1=exp( g0 ) ; return g1 ; } } } //ISBN 0-12-059820-5 page 307 line -4 // LiuHH 200904271706 //function binomialCoef(arg1,arg2) //function binoCoef(arg1,arg2) function bicof(arg1,arg2) { //9804271706 arg1=parseInt(arg1); arg2=parseInt(arg2); if(arg1<arg2)return 0; return factorial(arg1)/(factorial(arg2)*factorial(arg1-arg2)); } //9804271718 //function factorialDouble(arg1) //ISBN 0-12-059820-5 page 545 eqn. 10.33c // LiuHH 200904271746 //function factorialDouble(arg1) //function factorDbl(arg1) // // Double factorial facdb(arg1) // 9!!=9*7*5*3*1 // 8!!=8*6*4*2 function facdb(arg1) { //9804271746 arg1=parseInt(arg1); var i0,i1,i2; var n; if(arg1%2) { n=parseInt(arg1/2); for(i0=0,i1=1;i0<n;i0++) i1=i1*2; return factorial(arg1)/factorial(n)/i1; } //9804271752 n=arg1/2; for(i0=0,i1=1;i0<n;i0++) i1=i1*2; return factorial(n)*i1; } //9804271754 //2010-01-06-19-56 inclide gamma function to tute0026.htm //Main purpose is to add gatef() function to tute0026.htm /** 2010-01-29-22-22 include function bye09(in09) to integral.htm 2009-06-12-15-31 start Javascript use float number for calculation. Answer may contain long string of '000000' or '999999', for example 2.00000000000001 -25.999999999999996 On 2009-06-12-11-58 write a function function bye09(in09) //9806121158 To use this function, call as following coef2=bye09(coef2); where coef2 is a number. After call 2.00000000000001 change to 2 -25.999999999999996 change to -26 It is handy, you can use it too. If number is 1.23111111111 there is no change. function bye09(in09) handle output number for better looking. Do not call bye09() during calculation, that is just slow down process. If expect answer to be irrational Do not call bye09(). If expect answer to be integer or short decimal number like 1.2. In these case you can call bye09(). 2009-06-12-15-40 stop 2009-06-17-19-05 bye09() process only one number at a time. If you have a string of several numbers. Do not put number string as input argument bye09() will send string back immediately. This file has sample code at time stamp '9806171858' 2009-06-17-19-09 stop /**/ function bye09(in09) //9806121158 { // in09 is input number, // for example 2.0000000001 // If input is not a number, return here if(isNaN(in09)) return in09; // where is decimal point '.' ? var dotLoc=(in09+'').indexOf('.',0); // no decimal point? integer? return. if(dotLoc==-1) return in09; // change input string to number in09=parseFloat(in09); // if number has '000000' ÿ var zeroLoc=(in09+'').indexOf('000000',dotLoc); // find '000000' ÿcut start '000000' if(zeroLoc>0) //9806121216 return parseFloat((in09+'').substring(0,zeroLoc)); //9806121209 // if number has '999999' ÿ var nineLoc=(in09+'').indexOf('999999',dotLoc); // find '999999' ÿ cut start '999999' if(nineLoc>0) //9806121223 here { // copy number left to '999999' //but immediately neighbor digit not copy // nineLoc-1 because '999999' need increase // digit by one. //If input is 1.23999999999 copy only 1.2 //not copy 1.23 , because 3 will change to 4. var nine0=(in09+'').substring(0,nineLoc-1); //between '.' and '999999' has other digit. if(nineLoc-dotLoc>1) //9806121220 { //neighbor digit add one, paste to end nine0+=(parseInt((in09+'').charAt(nineLoc-1))+1); } else //between '.' and '999999' no other digit. {// modified number is an integer nine0=parseInt(nine0); //9806121313 if(nine0<0)nine0--; // negative integer minus one else nine0++; //9806121314 positive integer add one } return parseFloat(nine0); //9806121213 return new number } // no '000000' no '999999' return original form return parseFloat(in09); //9806121224 } //function bye09(in09) //--> </script> <br> <hr> <a name="differentiate">&lt;a name="differentiate"&gt;</a> <br> 2010-02-09-22-32 differentiation0(<a href="#NumIntegral">Integration</a>) <br> f(x) is necessary, d[f(x)]/dx is arbitrary. <br> f(x) <INPUT id=QEboxf0 value="exp(x)" size=50 > <input onclick="javascript:QEboxf0.value=''" type="button" value="d" /> <br> d[f(x)]/dx <INPUT id=QEboxf1 value="exp(x)" size=42 > <input onclick="javascript:QEboxf1.value=''" type="button" value="d" /> <br> <input onclick="javascript:QEspanDiffAns.innerHTML=dif1Man()" type="button" value="Differentiate" /> x0 <INPUT id=QEboxX0 value="1.2" size=8 > ; dx <INPUT id=QEboxdx value="0.00001" size=8 > <input onclick="javascript:QEboxX0.value=QEboxdx.value=''" type="button" value="d" /> , <input onclick="QEspanDiffAns.innerHTML='<br>'" type="button" value="dA" /> <br> <font face='Courier New'> <span id=QEspanDiffAns><br></span> </font> <br> 2010-02-09-22-39 <input onclick="javascript: QEboxf0.value='exp(x)'; QEboxf1.value='exp(x)'; QEboxX0.value='1.2'; QEboxdx.value='1.e-6'; QEspanDiffAns.innerHTML=dif1Man()" type="button" value="51" /><!--9902101032--> <input onclick="javascript: QEboxf0.value='tan(x)'; QEboxf1.value='1/cos(x)/cos(x)'; QEboxX0.value='PI/2'; QEboxdx.value='-1.e-8'; QEspanDiffAns.innerHTML=dif1Man()" type="button" value="52" /><!--9902101033--> <input onclick="javascript: QEboxf0.value='pow((1+exp(x)),(-0.5))'; QEboxf1.value='-0.5*exp(x)*pow((1+exp(x)),(-1.5))'; QEboxX0.value='log(2)'; QEboxdx.value='1.e-6'; QEspanDiffAns.innerHTML=dif1Man()" type="button" value="53" /><!--9902101035--> <input onclick="javascript: QEboxf0.value='log(1+exp(x))'; QEboxf1.value='exp(x)/(1+exp(x))'; QEboxX0.value='1.2'; QEboxdx.value='1.e-6'; QEspanDiffAns.innerHTML=dif1Man()" type="button" value="54" /><!--9902101047--> <input onclick="javascript: QEboxf0.value='log(cos(x))'; QEboxf1.value='-sin(x)/cos(x)'; QEboxX0.value='1.2'; QEboxdx.value='1.e-6'; QEspanDiffAns.innerHTML=dif1Man()" type="button" value="55" /><!--9902101048--> <br> <script lang="javascript"> <!-- //9902100941 // differentiatef1() manager // function dif1Man() { var f0=QEboxf0.value; var f1=QEboxf1.value; var x0=QEboxX0.value; var dx=QEboxdx.value; x0=eval('with(Math){'+x0+'}'); //9902101159 dx=parseFloat(dx); if(f0.length==0) return 'need define function equation.<br>' if(isNaN(x0)) return 'x0 must be a number.<br>' if(isNaN(dx)) return 'increment dx must be a number.<br>' var ans0=differentiatef1(f0,x0,dx); //9902100945 var fdx0=''; // df/dx answer var x; if(f1.length>0) { x=x0; fdx0=eval('with(Math){'+f1+'}')+''; } return "Numerical Answer : "+ans0+"<br>" +(f1.length?"Analytic Solution: "+fdx0:"") +""; } //9902101004 /** 99,02,09,22,09 eqn00='sin(x)*cos(x)' = function definition x0 =0.55 = evaluate point x0 dx =0.0001 = delta_x fx0 =20.2 = f(x0) program evaluate second function value at f(x0+dx) use two function values f(x0+dx)-f(x0) use two domain values x0+dx - x0 to find differentiate value at x=x0 d[f(x)]/dx = [f(x0+dx)-f(x0)] / dx 99,02,09,22,15 /**/ function differentiatef1(dfArg1,dfArg2,dfArg3,dfArg4) { var eqn00=dfArg1; var x0=parseFloat(dfArg2); var dx=parseFloat(dfArg3); var fx0=parseFloat(dfArg4); if(eqn00.length==0) return 'need define function equation.' if(isNaN(x0)) return 'x0 must be a number.' if(isNaN(dx)) return 'increment dx must be a number.' if(arguments.length>3&&isNaN(fx0)) return 'f(x0) must be a number.' var x=x0+dx; var fx1=eval('with(Math){'+eqn00+'}') if(arguments.length<=3) { x=x0; var fx0=eval('with(Math){'+eqn00+'}') } return (fx1-fx0)/dx; //9902092228 } //--> </script> <hr> <a name="JSMathList">&lt;a name="JSMathList"&gt;</a> <br> <font color=red><b> Equation definition must use Javascript language </b></font> <br> &#9679;&#9679;Javascript math function <INPUT name=FuncButton type="button" value="definition" onclick=javascript:open0lxr(101)> <!--9506291021--> <br> <!--ta ble+2a--> <TABLE cellSpacing=1 cellPadding=0 width="100%" align=center border=0> <TBODY> <TR> </TR> <TR id="showlxr101" style="DISPLAY: none" bgColor=#ccfcfc> <TD colSpan=7> <!--ta ble+3a--> <TABLE width="100%" align=left border=0> <TBODY> <TR> <TD align=right bgColor=#FFFF00 border=0 onclick=open0lxr(101)> C <br>L <br>O <br>S <br>E </TD> <TD width="100%"> <!--ta ble+4--> <table > <tr> <td height="0%"> <pre><font size=3> 2010-01-30-11-32 add Javascript math functions definition to integral.htm 95,06,13,23,44 Javascript support the following math functions [[ Math.E 2.718281828459045091 Euler's constant Math.LN2 0.6931471805599452862 Natural log of 2 Math.LN10 2.302585092994045901 Natural log of 10 Math.LOG2E 1.442695040888963387 Log base-2 of E Math.LOG10E 0.4342944819032518167 Log base-10 of E Math.PI 3.141592653589793116 PI Math.SQRT1_2 0.7071067811865475 Square root of 0.5 Math.SQRT2 1.414213562373095145 Square root of 2 Math.random() method takes no parameters Math.abs(val) Absolute value of val Math.acos(val) Arc cosine (in radians) of val Math.asin(val) Arc sine (in radians) of val Math.atan(val) Arc tangent (in radians) of val Math.atan2(val1, val2) Angle of polar coordinates Math.ceil(val) Next integer greater than or equal Math.cos(val) Cosine of val Math.exp(val) Euler's constant to the power of val Math.floor(val) Next integer less than or equal to Math.log(val) Natural logarithm (base e) of val Math.max(val1, val2) The greater of val1 or val2 Math.min(val1, val2) The lesser of val1 or val2 Math.pow(val1, val2) Val1 to the val2 power Math.random() Random number between 0 and 1 Math.round(val) N+1 when val >= n.5; otherwise N Math.sin(val) Sine (in radians) of val Math.sqrt(val) Square root of val Math.tan(val) Tangent (in radians) of val ]] for hyperbolic cosine, use 0.5*(Math.exp(x)+Math.exp(-x)) hyperbolic sine, use 0.5*(Math.exp(x)-Math.exp(-x)) Step function: stepf(a,b) If a&lt;b return 0 (close) otherwise return 1 (open) Any number multiply by 0 get 0 that is to close. Any number multiply by 1 get itself that is to open. Above is to multiply stepf() If add or subtract stepf() then it is shift curve up/down. One of a,b must be variable. If both a and b are constant, then stepf() has no meaning. 9507211227 Gamma function gamma(t) If t is an integer gamma(t) is (t-1)! gamma(t) let factorial become continuous. gamma(t) is searched from Internet. 9507211232 // gatef(t,3.2,5.6) if t<3.2 get 0 // gatef(t,3.2,5.6) if t>5.6 get 0 // gatef(t,3.2,5.6) if 3.2<=t<=5.6 get 1 // 9804281119 <hr> 2006-06-23-12-41 start This program is received on 2006-06-12 2006-06-12-18-14<a href=http://www.bigwebmaster.com/3051.html> http://www.bigwebmaster.com/3051.html</a> 2006-06-12-18-21<a href=http://www.structura.info/XYGraph/XYGraph.zip> http://www.structura.info/XYGraph/XYGraph.zip</a> ===== 2006-10-23-09-08 start Start from 2006-10-17 write this program. Its URL is<a href=http://freeman2.com/graph09e.htm> http://freeman2.com/graph09e.htm</a> This file has same source as previous<a href=http://freeman2.com/graph03e.htm> http://freeman2.com/graph03e.htm</a> Both from XYGraph v2.3<a href=http://www.structura.info/XYGraph/XYGraphDemo.htm> http://www.structura.info/XYGraph/XYGraphDemo.htm</a> Freeman take their source code write a better version. graph03e.htm is mainly introduction All graph use one drawing board. graph09e.htm is for application. Each graph has its own drawing board. "has its own drawing board" is Freeman's need. This function allow user to draw multiple graph in one web page. Now upload this program to Internet let everyone use. Please click "Draw 606" to see how to use. graph09e.htm can dynamically create input form and also one more change graph03e.htm must use "Math.cos(t)" Where "Math." can not drop. graph09e.htm allow to use cos(t) "Math." can be dropped. Because graph09e.htm add [[ 9510222211 use 'with(Math){' and '}' ]] graph03e.htm follow XYGraph v2.3 must use "Math." graph09e.htm modified by Freeman no need to use "Math." graph09e.htm still has limitation. Curve allow maximum 5. Arrow allow maximum 1. Label allow maximum 1. Equation can not be modified Especially equation constant and number of terms. graph03e.htm allow variable constant 'a', 'b' to have five different values. (one equation family five members) graph09e.htm broader this property to five arbitrary functions. If you need function exceed above limitation, you must write code for it. Examples can be found at<a href=http://freeman2.com/graph03e.htm> http://freeman2.com/graph03e.htm</a> find function Calculate0(PlotID){.....} five examples. Expect graph09e.htm will be used in<a href=http://freeman2.com/tutc0004.htm> http://freeman2.com/tutc0004.htm</a> This is Freeman's tutor page in Chinese. Welcome visit Freeman site often. Freeman 2006-10-24-18-01 </font></pre> </td> </tr> <tr> <td ></td> </tr> </table> <!--ta ble-4--> </TD> </TR> </TBODY> </TABLE> <!--ta ble-3a--> </TBODY> </TABLE> <!--ta ble-2a--> <br> To open Javascript math function [definition] <br> need external javascript file. If you can not <br> click open, use a text editor open integral.htm <br> search for the string <br> "2010-01-30-11-32 add Javascript" <br> and read from source file. <br> 2010-01-30-11-35 <pre><font size=+2> <a name="docB001">&lt;a name="docB001"&gt;</a> 2010-01-27-00-01 create integral.htm 2010-01-27-00-08 start Applied Numerical Methods, by Brice Carnahan, H.A. Luther, James O. Wilkes 1969 by John Wiley & Sons, Inc. SBN 471-13507-0 (It is SBN, NOT ISBN) <a name="docB002">&lt;a name="docB002"&gt;</a> Page 73 Numerical Integration formula equal space, close ends n=1 (trapezoidal Rule), h=(x1-x0)/1 Integral[x=x0,x1]f(x)dx= (h/2)*[f(x0)+f(x1)] - h^3*f''(¾)/12 <a name="docB003">&lt;a name="docB003"&gt;</a> Page 74 Numerical Integration formula equal space, close ends n=2 (Simpson's Rule), h=(x2-x0)/2 Integral[x=x0,x2]f(x)dx= (h/3)*[f(x0)+4*f(x1)+f(x2)] - h^5*f<sup>(4)</sup>(¾)/90 <a name="docB004">&lt;a name="docB004"&gt;</a> n=3 (Simpson's Second Rule), h=(x3-x0)/3 Integral[x=x0,x3]f(x)dx= (3*h/8)*[f(x0)+3*f(x1)+3*f(x2)+f(x3)] - h^5*f<sup>(4)</sup>(¾)*3/80 n=4, h=(x4-x0)/4 Integral[x=x0,x4]f(x)dx= (2*h/45)*[7*f(x0)+32*f(x1)+12*f(x2) +32*f(x3)+ 7*f(x4)] - h^7*f<sup>(6)</sup>(¾)*8/945 <a name="docB005">&lt;a name="docB005"&gt;</a> n=5, h=(x5-x0)/5 Integral[x=x0,x5]f(x)dx= (5*h/288)*[19*f(x0)+75*f(x1)+50*f(x2) +50*f(x3)+75*f(x4)+19*f(x5)] - h^7*f<sup>(6)</sup>(¾)*275/12096 <a name="docB006">&lt;a name="docB006"&gt;</a> n=6, h=(x6-x0)/6 Integral[x=x0,x6]f(x)dx= (h/140)*[41*f(x0)+216*f(x1)+27*f(x2) +272*f(x3)+27*f(x4)+216*f(x5) +41*f(x6)] - h^9*f<sup>(8)</sup>(¾)*9/1400 2010-01-27-00-29 stop <a name="docB007">&lt;a name="docB007"&gt;</a> 2010-01-30-09-53 start This file http://freeman2.com/integral.htm use Newton-Cotes formula n=1 to 6 calculate integration value for a given function f(x) [box use g(x)] Please goto <a href="#IntegralBgn">integration panel</a> <a name="docB008">&lt;a name="docB008"&gt;</a> It has the following arrangement [[ Example: 1 2 3 4 5 6 debug g(x) [ x*x*x-2*x*x+7*x-5 ] x bgn [1] end [3] steps [5] Newton-Cotes formula n=1 , 2, 3, 4, 5, 6 message two lines ]] <a name="docB009">&lt;a name="docB009"&gt;</a> User need input function definition at g(x) box. Program use 'x' as independent variable, then 'sin(x)' will work, but 'sin(t)' do not work. Integration need domain bounds, x begin and x end. For example, <a name="docB010">&lt;a name="docB010"&gt;</a> if need integral[x=0,x=PI]{sin(x)dx} input as following [[ g(x) [ sin(x) ] x bgn [0] end [PI] steps [5] ]] <a name="docB011">&lt;a name="docB011"&gt;</a> Uppercase 'PI' and 'E' are defined PI = 3.141592653589793 E = 2.718281828459045 x bgn and end allow mathematics expression. Next input x bgn [x=1;sin(x)] end [vv=1.2;exp(vv)] program will automatically convert to x bgn =0.8414709848078965 x end =3.3201169227365472 <a name="docB012">&lt;a name="docB012"&gt;</a> Next is about steps [ ] box. Newton-Cotes formula coefficients from n=1 to 6 are defined in program. Assume choose n=3, program use 3/8; 1, 3, 3, 1 ; -3/80 <a name="docB013">&lt;a name="docB013"&gt;</a> for calculation [[ n=3 (Simpson's Second Rule), h=(x3-x0)/3 Integral[x=x0,x3]f(x)dx= (3*h/8)*[f(x0)+3*f(x1)+3*f(x2)+f(x3)] - h^5*f(4)(¾)*3/80 ]] <a name="docB014">&lt;a name="docB014"&gt;</a> Apply Simpson's Second Rule (n=3) (Newton-Cotes Formula ncfchoice=3) need four points, x=x0,x1,x2,x3 evaluate to f(x0),f(x1),f(x2),f(x3) oneSum to f(x0)+3*f(x1)+3*f(x2)+f(x3) one integration to (3*h/8)*[f(x0)+3*f(x1)+3*f(x2)+f(x3)] <a name="docB015">&lt;a name="docB015"&gt;</a> "steps [ ] box" is better understand as "sub-intervals [ ] box". Because "steps" is shorter. Choose "steps".<!--9902091641--> If set steps [ ] box to one, whole domain do Newton-Cotes formula once. If set steps [ ] box to ten (stps=10). Whole domain cut to ten equal section do Newton-Cotes formula in each. If Newton-Cotes formula n=3 and steps=2, two equal section each need 4 points. Whole domain divide to ncfchoice*stps 3*2=6 equal length xdelta xdelta=(xend-xbgn)/(ncfchoice*stps) Total function evaluation = ncfchoice*stps+1 <a name="docB016">&lt;a name="docB016"&gt;</a> steps [ ] box must use a positive integer. no other limit. In most case set to 1 is enough. <!--9902091642 start-->Other's program no steps choice, that is same as set steps=1. Larger steps number, increase computing time, and increase answer accuracy. If increase steps number, answer do not change accuracy any more. That is reached best answer. Test with known answer problem, you will find how steps number help.<!--9902091649 stop--> <a name="docB017">&lt;a name="docB017"&gt;</a> In [[ Newton-Cotes formula n=1 , 2, 3, 4, 5, 6 ]] specify one number. '1' indicate use polynomial of degree 1 to approximate integration value. '2' indicate use polynomial of degree 2 to approximate integration value. up to '6' are the same. <a name="docB018">&lt;a name="docB018"&gt;</a> Click button is [integral g(x) A] //output answer, no debug [integral g(x) B] //output answer and debug <!--9902091716 bgn-->User can set "steps" as large as possible. But large step debug output too long. Program set limit at steps=100 or below do debug. If steps=101 or greater and if click [integral g(x) B] program pop-up alert window and not return debug data. Simply because computer can not afford a debug request with step number of 1000+.<!--9902091720 end--> 2010-01-30-10-40 here <a name="docB019">&lt;a name="docB019"&gt;</a> There are six example button 1 2 3 4 5 6 [1] is int[x=1,3]{x*x*x-2*x*x+7*x-5}dx steps=4, Newton-Cotes formula n=2 answer 20.666666666666664 is exact. steps=1 is enough to get exact ans. SBN 471-13507-0 page 74 example. <a name="docB020">&lt;a name="docB020"&gt;</a> [2] is int[x=0,PI]{sin(x)}dx steps=10, Newton-Cotes formula n=6 answer 2 is exact. steps=1 is not enough to get exact ans. <a name="docB021">&lt;a name="docB021"&gt;</a> [3] is int[x=0,PI]{1/(1+x*x)}dx steps=1, Newton-Cotes formula n=6 answer 3.3287981274701663 is far away from 2*atan(4) steps=1 get answer 3.3287981274701663 steps=10 get answer 2.651632548447489 steps=20 get answer 2.651635326208792 steps=30 get answer 2.651635327335626 steps=40 get answer 2.651635327336065 exact ans 2*atan(4)=2.651635327336065 <a name="docB022">&lt;a name="docB022"&gt;</a> g(x)=1/(1+x*x) is an example that Newton-Cotes formula may not converge to real answer. g(x)=1/(1+x*x) is from ISBN 0-471-02985-8 page 229 example. <a name="docB023">&lt;a name="docB023"&gt;</a> An Introduction to Numerical Analysis by Professor Kendall E. Atkinson John Wiley & Sons Inc. 1978 This is LiuHH's textbook and Professor K. E. Atkinson is instructor <a name="docB024">&lt;a name="docB024"&gt;</a> [4] is int[x=0,1]{sin(x)*sqrt(1-x*x)}dx steps=1, Newton-Cotes formula n=6 answer 0.30644618846846266 ISBN 0-471-02985-8 page 268 line -2. d[sin(x)*sqrt(1-x*x)]/dx singular at x=1 <a name="docB025">&lt;a name="docB025"&gt;</a> [5] is int[x=0,1]{2*sin(1-x*x)*x*x*sqrt(2-x*x)}dx steps=1, Newton-Cotes formula n=6 answer 0.3117417395331833 ISBN 0-471-02985-8 page 268 line -2. d[g(x)]/dx is OK at x=1 [4] equation change of variable get [5] <a name="docB026">&lt;a name="docB026"&gt;</a> [6] is<!--was int[x=sin(1),exp(2)]{x}dx 2010-02-02-23-30 change to --> int[x=1,E]{1/x}dx steps=2, Newton-Cotes formula n=6 answer 1.0 Main point is to illustrate that x upper bound E and lower bound exp(0) can be mathematics expression. <a name="docB026a">&lt;a name="docB026a"&gt;</a> Original goal is allow user input PI as bounds. The code structure allow general mathematics expression.<font color=red><b> int[x=1,E]{1/x}dx=1 is an important integration, Euler use it found the unknown number E=2.718281828459045</b></font> <a name="docB026b">&lt;a name="docB026b"&gt;</a> Why use integral value=1 to define E Why not use integral value=2 or other value to define E? Because log function always hang a tail. Only if use integral value=1<!--tutc0005.htm#a06b14--> we get a tail "/1". Who bother to write a "/1" after a equation? Euler determined E value, let us use E base log function and tail is invisible. You hide my tail ! Thank you Euler! <!--2010-02-03-00-12 change stop--> <a name="docB027">&lt;a name="docB027"&gt;</a> As usual:<font color=red><b> Output may contain error, Please verify first. Program environment is MSIE 6.0, please use MSIE.</b></font> Thank you for visiting Freeman's web site. Hope you find integral.htm interesting and useful. Freeman (Liu,Hsinhan) 2010-01-30-11-15 stop <a name="docB028">&lt;a name="docB028"&gt;</a> 2010-01-30-14-01 start Added "g2f" button, copy g(x) box function to f0(x) box. Also delete f1(x) f2(x) f3(x) boxes values. User modify x min: , x max: ; y min: , y max: and Curve start x/t begin , Curve end x/t end then click [Draw f0(x) to f3(x)] button to see g(x) curve. <a name="docB029">&lt;a name="docB029"&gt;</a> If you want to compare two curves, second function must hand copy and paste to f1(x) box. At most draw 4 curves f2(x) and f3(x) 2010-01-30-14-10 stop 2010-02-01-14-51 start <a name="docB030">&lt;a name="docB030"&gt;</a> 2010-01-30-17-56 LiuHH accessed next page<a href=http://www.zweigmedia.com/RealWorld/integral/integral.html> http://www.zweigmedia.com/RealWorld/integral/integral.html</a> This page has adaptive quadrature method option. Which is better than Newton-Cotes formula. You can save the source file and keep program in your computer. 2010-02-01-14-56 here <a name="docB031">&lt;a name="docB031"&gt;</a> 2010-01-30-18-32 LiuHH accessed next page<a href=http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Numerical/Integration/> http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Numerical/Integration/</a> This page has document and display codes. Page end has input boxes for f(x)= [ ]x^4+ [ ]x^3+ [ ]x^2+ [ ]x^1+ [ ] You can save the source file and keep program in your computer. 2010-02-01-15-06 stop <a name="docB032">&lt;a name="docB032"&gt;</a> 2010-02-06-14-07 start "Update 2010-02-06" has following changes 1. Add <a href="#docB030">link</a>. 2. "x-bgn", "x-end", "x/t begin", "x/t end" four boxes accept "PI" or "E" or math expression like "a=0;b=2;c=1;cos(a)*pow(b,c)" <a name="docB033">&lt;a name="docB033"&gt;</a> 3. add example [7] button example [7] integrate f(x)=exp(-x) From x=0 to x=1000 simulate infinity. Taylor series expansion for exp(x) has x^infinity, then exp(-x) has x^(-infinity). Newton-Cotes formula <a name="docB034">&lt;a name="docB034"&gt;</a> n=6 use x^6 to integrate exp(-x) need large number of steps (division) to get exact answer +"[x=0,infinity]exp(-x)dx = 1 Other integration method (other than Newton-Cotes) may do better job. 2010-02-06-14-28 stop <a name="docB035">&lt;a name="docB035"&gt;</a> 2010-02-06-14-32 start How to use power function? for example x^5 (x*x*x*x*x) Some author spend time write code convert from x^5 to pow(x,5). Javascript accept only pow(x,5). pow(2.345,6.789)=325.76152441868 pow(negative,fraction) get NaN pow(negative,integer) get number <a name="docB036">&lt;a name="docB036"&gt;</a> This file no conversion code. User must write pow() function directly. For base^power, write pow(base, power) Both base and power two variables must contain a numerical value. 2010-02-06-14-37 stop <a name="docB037">&lt;a name="docB037"&gt;</a> 2010-02-09-17-01 start "Update 2010-02-09" make x-bgn and x-end <a href="#IntegralBgn">boxes</a> larger for longer formula. Add comments about '<a href="#docB015">steps</a>' 2010-02-09-17-06 stop <a name="docB038">&lt;a name="docB038"&gt;</a> 2010-02-10-10-15 start "Update 2010-02-09" add <a href="#differentiate"> differentiate</a> function. 2010-02-10-10-15 stop </font></pre> <hr><br> Javascript index <br> <a href=http://freeman2.com/jsindex2.htm> http://freeman2.com/jsindex2.htm </a> &nbsp; <a href=jsindex2.htm> local </a> <!--9810201450 add local link--> <br> Save graph code to same folder as htm files. <br> <a href=http://freeman2.com/jsgraph2.js> http://freeman2.com/jsgraph2.js </a> &nbsp; <a href=jsgraph2.js> local </a> <br> <script src="jslist1e.js" language="javascript"></script> <br> <br> This page, integral.htm <br> <a href=http://freeman2.com/integral.htm> http://freeman2.com/integral.htm </a> <br> First Upload 2010-01-30 <br> <br> Thank you for visiting Freeman's page.0 <br> Freeman 02010-01-30-11-39 <br> <br><br> <span id="tuteLink2"></span> </BODY> </HTML>