numeric.rlg 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. Tue Apr 15 00:34:16 2008 run on win32
  2. on errcont;
  3. bounds (x,x=(1 .. 2));
  4. 1 .. 2
  5. bounds (2*x,x=(1 .. 2));
  6. 2 .. 4
  7. bounds (x**3,x=(1 .. 2));
  8. 1 .. 8
  9. bounds (x*y,x=(1 .. 2),y=(-1 .. 0));
  10. - 2 .. 0
  11. bounds (x**3+y,x=(1 .. 2),y=(-1 .. 0));
  12. 0 .. 8
  13. bounds (x**3/y,{x=(1 .. 2),y=(-1 .. -0.5)});
  14. - 16 .. -1
  15. bounds (x**3/y,x=(1 .. 2),y=(-1 .. -0.5));
  16. - 16 .. -1
  17. % unbounded expression (pole at y=0)
  18. bounds (x**3/y,x=(1 .. 2),y=(-1 .. 0.5));
  19. ***** unbounded in range
  20. on rounded;
  21. bounds(e**x,x=(1 .. 2));
  22. 2.71828182846 .. 7.38905609893
  23. bounds((1/2)**x,x=(1 .. 2));
  24. 0.25 .. 0.5
  25. off rounded;
  26. bounds(abs x,x=(1 .. 2));
  27. 1 .. 2
  28. bounds(abs x,x=(-3 .. 2));
  29. 0 .. 3
  30. bounds(abs x,x=(-3 .. -2));
  31. 2 .. 3
  32. bounds(sin x,x=(1 .. 2));
  33. - 1 .. 1
  34. on rounded;
  35. bounds(sin x,x=(1 .. 2));
  36. 0.841470984808 .. 1
  37. bounds(sin x,x=(1 .. 10));
  38. - 1 .. 1
  39. bounds(sin x,x=(1001 .. 1002));
  40. 0.167266541974 .. 0.919990597586
  41. bounds(log x,x=(1 .. 10));
  42. 0 .. 2.30258509299
  43. bounds(tan x,x=(1 .. 1.1));
  44. 1.55740772465 .. 1.96475965725
  45. bounds(cot x,x=(1 .. 1.1));
  46. 0.508968105239 .. 0.642092615934
  47. bounds(asin x,x=(-0.6 .. 0.6));
  48. - 0.643501108793 .. 0.643501108793
  49. bounds(acos x,x=(-0.6 .. 0.6));
  50. 0.927295218002 .. 2.21429743559
  51. bounds(sqrt(x),x=(1 .. 1.1));
  52. 1 .. 1.04880884817
  53. bounds(x**(7/3),x=(1 .. 1.1));
  54. 1 .. 1.2490589397
  55. bounds(x**y,x=(1 .. 1.1),y=(2 .. 4));
  56. 1 .. 1.4641
  57. off rounded;
  58. % MINIMA (steepest descent)
  59. % Rosenbrock function (minimum extremely hard to find).
  60. fktn := 100*(x1^2-x2)^2 + (1-x1)^2;
  61. 4 2 2 2
  62. fktn := 100*x1 - 200*x1 *x2 + x1 - 2*x1 + 100*x2 + 1
  63. num_min(fktn, x1=-1.2, x2=1, accuracy=6);
  64. {0.00000021870243927,{x1=0.999532844813,x2=0.999068072135}}
  65. % infinitely many local minima
  66. num_min(sin(x)+x/5, x=1);
  67. { - 1.33422674663,{x= - 1.77215430279}}
  68. % bivariate polynomial
  69. num_min(x^4 + 3 x^2 * y + 5 y^2 + x + y, x=0.1, y=0.2);
  70. { - 0.832523282274,{x= - 0.889601609042,y= - 0.33989805551}}
  71. % ROOTS (non polynomial: damped Newton)
  72. num_solve (cos x -x, x=0,accuracy=6);
  73. {x=0.739085133215}
  74. % automatically randomized starting point
  75. num_solve (cos x -x,x, accuracy=6);
  76. {x=0.739085133215}
  77. % syntactical errors: forms do not evaluate to purely
  78. % numerical values
  79. num_solve (cos x -x, x=a);
  80. ***** a invalid as number
  81. num_solve (cos x -a, x=0);
  82. ***** error during function evaluation (e.g. singularity)
  83. num_solve (sin x = 0, x=3);
  84. {x=3.14159265359}
  85. % blows up: no real solution exists
  86. num_solve(sin x = 2, x=1);
  87. ***** Newton method does not converge
  88. % solution in complex plane(only fond with complex starting point):
  89. on complex;
  90. *** Domain mode rounded changed to complex-rounded
  91. num_solve(sin x = 2, x=1+i);
  92. {x=1.57079632542 + 1.31695789681*i}
  93. off complex;
  94. *** Domain mode complex-rounded changed to rounded
  95. % blows up for derivative 0 in starting point
  96. num_solve(x^2-1, x=0);
  97. ***** division by zero
  98. % succeeds because of perturbed starting point
  99. num_solve(x^2-1, x=0.1);
  100. {x=1.00000000033}
  101. % bivariate equation system
  102. num_solve({sin x=cos y, x + y = 1},{x=1,y=2});
  103. {x= - 52.1216769476,y=53.1216769476}
  104. on rounded,evallhseqp;
  105. sub(ws,{sin x=cos y, x + y = 1});
  106. { - 0.959549629985= - 0.959549629985,1=1}
  107. off rounded,evallhseqp;
  108. % temporal member of the Barry Simon test sequence
  109. sys :={sin (x) + y^2 + log(z) = 7,
  110. 3*x + 2^y - z^3 = -90,
  111. x^2 + y^2 + z^(1/2) = 16};
  112. 2
  113. sys := {sin(x) + y + log(z)=7,
  114. y 3
  115. 3*x + 2 - z =-90,
  116. 2 2 1/2
  117. x + y + z =16}
  118. sol:=num_solve(sys,{x=1,y=1,z=1});
  119. sol := {x=2.93087675819,y= - 2.29328251176,z=4.62601269017}
  120. on rounded;
  121. for each s in sys collect sub(sol,lhs s-rhs s);
  122. {0,0,0}
  123. off rounded;
  124. clear sys,sol;
  125. % 2 examples taken from Nowak/Weimann (Tech.Rep TR91-10, ZIB Berlin)
  126. % #1: exp/sin combination
  127. on rounded;
  128. sys := {e**(x1**2 + x2**2)-3, x1 + x2 - sin(3(x1 + x2))};
  129. 2 2
  130. x1 + x2
  131. sys := {e - 3,
  132. - sin(3*x1 + 3*x2) + x1 + x2}
  133. num_solve(sys,x1=0.81, x2=0.82);
  134. *** precision increased to 14
  135. *** precision increased to 18
  136. *** precision increased to 20
  137. {x1= - 0.256625076922,x2=1.01624596361}
  138. sub(ws,sys);
  139. {0,0}
  140. % 2nd example (semiconductor simulation), here computed with
  141. % intermediate steps printed
  142. alpha := 38.683;
  143. alpha := 38.683
  144. ni := 1.22e10;
  145. ni := 1.22e+10
  146. v := 100;
  147. v := 100
  148. d := 1e17;
  149. d := 1.0e+17
  150. sys := { e**(alpha*(x3-x1)) - e**(alpha*(x1-x2)) - d/ni,
  151. x2,
  152. x3,
  153. e**(alpha*(x6-x4)) - e**(alpha*(x4-x5)) + d/ni,
  154. x5 - v,
  155. x6 - v};
  156. 77.366*x1 38.683*x1 + 38.683*x2
  157. sys := {( - e - 8.19672131148e+6*e
  158. 38.683*x2 + 38.683*x3 38.683*x1 + 38.683*x2
  159. + e )/e ,
  160. x2,
  161. x3,
  162. 77.366*x4 38.683*x4 + 38.683*x5
  163. ( - e + 8.19672131148e+6*e
  164. 38.683*x5 + 38.683*x6 38.683*x4 + 38.683*x5
  165. + e )/e ,
  166. x5 - 100,
  167. x6 - 100}
  168. on trnumeric;
  169. num_solve(sys,x1=1,x2=2,x3=3,x4=4,x5=5,x6=6,iterations=100);
  170. *** computing symbolic Jacobian
  171. *** starting Newton iteration
  172. 1. residue=(1.46329673989e+33 , 0 , 0 , 1.46329673988e+33 , 0.0 , 0.0)
  173. , step length=163.473870223
  174. at ( - 1.97414885092 , 0 , 0 , 98.0258511491 , 100.0 , 100.0)
  175. 2. residue=(5.38316786938e+32 , 0.0 , 0.0 , 5.38316786935e+32 , 0.0 , 0.0)
  176. , step length=0.0365590456369
  177. at ( - 1.94829770183 , 0.0 , 0.0 , 98.0517022982 , 100.0 , 100.0)
  178. 3. residue=(1.98035678752e+32 , 0.0 , 0.0 , 1.98035678751e+32 , 0.0 , 0.0)
  179. , step length=0.0365590456369
  180. at ( - 1.92244655275 , 0.0 , 0.0 , 98.0775534473 , 100.0 , 100.0)
  181. 4. residue=(7.28532548313e+31 , 0.0 , 0.0 , 7.28532548309e+31 , 0.0 , 0.0)
  182. , step length=0.0365590456369
  183. at ( - 1.89659540367 , 0.0 , 0.0 , 98.1034045963 , 100.0 , 100.0)
  184. 5. residue=(2.68012146749e+31 , 0.0 , 0.0 , 2.68012146747e+31 , 0.0 , 0.0)
  185. , step length=0.0365590456369
  186. at ( - 1.87074425458 , 0.0 , 0.0 , 98.1292557454 , 100.0 , 100.0)
  187. 6. residue=(9.8596158773e+30 , 0.0 , 0.0 , 9.85961587725e+30 , 0.0 , 0.0)
  188. , step length=0.0365590456369
  189. at ( - 1.8448931055 , 0.0 , 0.0 , 98.1551068945 , 100.0 , 100.0)
  190. 7. residue=(3.62714997911e+30 , 0.0 , 0.0 , 3.62714997909e+30 , 0.0 , 0.0)
  191. , step length=0.0365590456369
  192. at ( - 1.81904195641 , 0.0 , 0.0 , 98.1809580436 , 100.0 , 100.0)
  193. 8. residue=(1.33435390736e+30 , 0.0 , 0.0 , 1.33435390735e+30 , 0.0 , 0.0)
  194. , step length=0.0365590456369
  195. at ( - 1.79319080733 , 0.0 , 0.0 , 98.2068091927 , 100.0 , 100.0)
  196. 9. residue=(4.90881369764e+29 , 0.0 , 0.0 , 4.90881369762e+29 , 0.0 , 0.0)
  197. , step length=0.0365590456369
  198. at ( - 1.76733965825 , 0.0 , 0.0 , 98.2326603418 , 100.0 , 100.0)
  199. 10. residue=(1.8058516399e+29 , 0.0 , 0.0 , 1.80585163991e+29 , 0.0 , 0.0)
  200. , step length=0.0365590456369
  201. at ( - 1.74148850916 , 0.0 , 0.0 , 98.2585114908 , 100.0 , 100.0)
  202. 11. residue=(6.64335692126e+28 , 0.0 , 0.0 , 6.64335692127e+28 , 0.0 , 0.0)
  203. , step length=0.0365590456369
  204. at ( - 1.71563736008 , 0.0 , 0.0 , 98.2843626399 , 100.0 , 100.0)
  205. 12. residue=(2.4439544317e+28 , 0.0 , 0.0 , 2.4439544317e+28 , 0.0 , 0.0)
  206. , step length=0.0365590456369
  207. at ( - 1.689786211 , 0.0 , 0.0 , 98.310213789 , 100.0 , 100.0)
  208. 13. residue=(8.99080590581e+27 , 0.0 , 0.0 , 8.99080590582e+27 , 0.0 , 0.0)
  209. , step length=0.0365590456369
  210. at ( - 1.66393506191 , 0.0 , 0.0 , 98.3360649381 , 100.0 , 100.0)
  211. 14. residue=(3.30753265231e+27 , 0.0 , 0.0 , 3.30753265232e+27 , 0.0 , 0.0)
  212. , step length=0.0365590456369
  213. at ( - 1.63808391283 , 0.0 , 0.0 , 98.3619160872 , 100.0 , 100.0)
  214. 15. residue=(1.21677326379e+27 , 0.0 , 0.0 , 1.21677326379e+27 , 0.0 , 0.0)
  215. , step length=0.0365590456369
  216. at ( - 1.61223276375 , 0.0 , 0.0 , 98.3877672363 , 100.0 , 100.0)
  217. 16. residue=(4.47625868315e+26 , 0.0 , 0.0 , 4.47625868316e+26 , 0.0 , 0.0)
  218. , step length=0.0365590456369
  219. at ( - 1.58638161466 , 0.0 , 0.0 , 98.4136183853 , 100.0 , 100.0)
  220. 17. residue=(1.64672354289e+26 , 0.0 , 0.0 , 1.6467235429e+26 , 0.0 , 0.0)
  221. , step length=0.0365590456369
  222. at ( - 1.56053046558 , 0.0 , 0.0 , 98.4394695344 , 100.0 , 100.0)
  223. 18. residue=(6.05795736724e+25 , 0.0 , 0.0 , 6.05795736725e+25 , 0.0 , 0.0)
  224. , step length=0.0365590456369
  225. at ( - 1.5346793165 , 0.0 , 0.0 , 98.4653206835 , 100.0 , 100.0)
  226. 19. residue=(2.2285979709e+25 , 0.0 , 0.0 , 2.2285979709e+25 , 0.0 , 0.0)
  227. , step length=0.0365590456369
  228. at ( - 1.50882816741 , 0.0 , 0.0 , 98.4911718326 , 100.0 , 100.0)
  229. 20. residue=(8.19855376131e+24 , 0.0 , 0.0 , 8.19855376132e+24 , 0.0 , 0.0)
  230. , step length=0.0365590456369
  231. at ( - 1.48297701833 , 0.0 , 0.0 , 98.5170229817 , 100.0 , 100.0)
  232. 21. residue=(3.01607937612e+24 , 0.0 , 0.0 , 3.01607937613e+24 , 0.0 , 0.0)
  233. , step length=0.0365590456369
  234. at ( - 1.45712586924 , 0.0 , 0.0 , 98.5428741308 , 100.0 , 100.0)
  235. 22. residue=(1.10955359542e+24 , 0.0 , 0.0 , 1.10955359542e+24 , 0.0 , 0.0)
  236. , step length=0.0365590456369
  237. at ( - 1.43127472016 , 0.0 , 0.0 , 98.5687252798 , 100.0 , 100.0)
  238. 23. residue=(4.08181956632e+23 , 0.0 , 0.0 , 4.08181956633e+23 , 0.0 , 0.0)
  239. , step length=0.0365590456369
  240. at ( - 1.40542357108 , 0.0 , 0.0 , 98.5945764289 , 100.0 , 100.0)
  241. 24. residue=(1.50161750102e+23 , 0.0 , 0.0 , 1.50161750102e+23 , 0.0 , 0.0)
  242. , step length=0.0365590456369
  243. at ( - 1.37957242199 , 0.0 , 0.0 , 98.620427578 , 100.0 , 100.0)
  244. 25. residue=(5.52414207128e+22 , 0.0 , 0.0 , 5.52414207133e+22 , 0.0 , 0.0)
  245. , step length=0.0365590456369
  246. at ( - 1.35372127291 , 0.0 , 0.0 , 98.6462787271 , 100.0 , 100.0)
  247. 26. residue=(2.03221829814e+22 , 0.0 , 0.0 , 2.03221829815e+22 , 0.0 , 0.0)
  248. , step length=0.0365590456369
  249. at ( - 1.32787012383 , 0.0 , 0.0 , 98.6721298762 , 100.0 , 100.0)
  250. 27. residue=(7.47611331856e+21 , 0.0 , 0.0 , 7.47611331863e+21 , 0.0 , 0.0)
  251. , step length=0.0365590456369
  252. at ( - 1.30201897474 , 0.0 , 0.0 , 98.6979810253 , 100.0 , 100.0)
  253. 28. residue=(2.75030838977e+21 , 0.0 , 0.0 , 2.75030838979e+21 , 0.0 , 0.0)
  254. , step length=0.0365590456369
  255. at ( - 1.27616782566 , 0.0 , 0.0 , 98.7238321743 , 100.0 , 100.0)
  256. 29. residue=(1.01178191348e+21 , 0.0 , 0.0 , 1.01178191349e+21 , 0.0 , 0.0)
  257. , step length=0.0365590456369
  258. at ( - 1.25031667658 , 0.0 , 0.0 , 98.7496833234 , 100.0 , 100.0)
  259. 30. residue=(3.72213764917e+20 , 0.0 , 0.0 , 3.72213764921e+20 , 0.0 , 0.0)
  260. , step length=0.0365590456369
  261. at ( - 1.22446552749 , 0.0 , 0.0 , 98.7755344725 , 100.0 , 100.0)
  262. 31. residue=(1.36929791834e+20 , 0.0 , 0.0 , 1.36929791835e+20 , 0.0 , 0.0)
  263. , step length=0.0365590456369
  264. at ( - 1.19861437841 , 0.0 , 0.0 , 98.8013856216 , 100.0 , 100.0)
  265. 32. residue=(5.03736552996e+19 , 0.0 , 0.0 , 5.03736553001e+19 , 0.0 , 0.0)
  266. , step length=0.0365590456369
  267. at ( - 1.17276322933 , 0.0 , 0.0 , 98.8272367707 , 100.0 , 100.0)
  268. 33. residue=(1.85314321614e+19 , 0.0 , 0.0 , 1.85314321616e+19 , 0.0 , 0.0)
  269. , step length=0.0365590456369
  270. at ( - 1.14691208024 , 0.0 , 0.0 , 98.8530879198 , 100.0 , 100.0)
  271. 34. residue=(6.81733290764e+18 , 0.0 , 0.0 , 6.81733290771e+18 , 0.0 , 0.0)
  272. , step length=0.0365590456369
  273. at ( - 1.12106093116 , 0.0 , 0.0 , 98.8789390688 , 100.0 , 100.0)
  274. 35. residue=(2.50795662034e+18 , 0.0 , 0.0 , 2.50795662037e+18 , 0.0 , 0.0)
  275. , step length=0.0365590456369
  276. at ( - 1.09520978207 , 0.0 , 0.0 , 98.9047902179 , 100.0 , 100.0)
  277. 36. residue=(9.2262567997e+17 , 0.0 , 0.0 , 9.22625679991e+17 , 0.0 , 0.0)
  278. , step length=0.0365590456369
  279. at ( - 1.06935863299 , 0.0 , 0.0 , 98.930641367 , 100.0 , 100.0)
  280. 37. residue=(3.39415019556e+17 , 0.0 , 0.0 , 3.39415019568e+17 , 0.0 , 0.0)
  281. , step length=0.0365590456369
  282. at ( - 1.04350748391 , 0.0 , 0.0 , 98.9564925161 , 100.0 , 100.0)
  283. 38. residue=(1.24863807717e+17 , 0.0 , 0.0 , 1.24863807725e+17 , 0.0 , 0.0)
  284. , step length=0.0365590456369
  285. at ( - 1.01765633483 , 0.0 , 0.0 , 98.9823436652 , 100.0 , 100.0)
  286. 39. residue=(4.59348278034e+16 , 0.0 , 0.0 , 4.59348278107e+16 , 0.0 , 0.0)
  287. , step length=0.0365590456369
  288. at ( - 0.991805185743 , 0.0 , 0.0 , 99.0081948143 , 100.0 , 100.0)
  289. 40. residue=(1.68984787804e+16 , 0.0 , 0.0 , 1.68984787874e+16 , 0.0 , 0.0)
  290. , step length=0.0365590456369
  291. at ( - 0.965954036664 , 0.0 , 0.0 , 99.0340459633 , 100.0 , 100.0)
  292. 41. residue=(6.21660292823e+15 , 0.0 , 0.0 , 6.21660293516e+15 , 0.0 , 0.0)
  293. , step length=0.0365590456369
  294. at ( - 0.940102887593 , 0.0 , 0.0 , 99.0598971124 , 100.0 , 100.0)
  295. 42. residue=(2.28696040906e+15 , 0.0 , 0.0 , 2.28696041594e+15 , 0.0 , 0.0)
  296. , step length=0.0365590456369
  297. at ( - 0.914251738544 , 0.0 , 0.0 , 99.0857482616 , 100.0 , 100.0)
  298. 43. residue=(8.41325715099e+14 , 0.0 , 0.0 , 8.41325721962e+14 , 0.0 , 0.0)
  299. , step length=0.0365590456369
  300. at ( - 0.888400589553 , 0.0 , 0.0 , 99.1115994107 , 100.0 , 100.0)
  301. 44. residue=(3.09506431748e+14 , 0.0 , 0.0 , 3.09506438604e+14 , 0.0 , 0.0)
  302. , step length=0.0365590456369
  303. at ( - 0.862549440721 , 0.0 , 0.0 , 99.1374505601 , 100.0 , 100.0)
  304. 45. residue=(1.13861050984e+14 , 0.0 , 0.0 , 1.13861057839e+14 , 0.0 , 0.0)
  305. , step length=0.0365590456369
  306. at ( - 0.836698292322 , 0.0 , 0.0 , 99.1633017098 , 100.0 , 100.0)
  307. 46. residue=(4.18871376415e+13 , 0.0 , 0.0 , 4.18871444947e+13 , 0.0 , 0.0)
  308. , step length=0.0365590456369
  309. at ( - 0.8108471451 , 0.0 , 0.0 , 99.1891528608 , 100.0 , 100.0)
  310. 47. residue=(1.54094146219e+13 , 0.0 , 0.0 , 1.54094214749e+13 , 0.0 , 0.0)
  311. , step length=0.0365590456369
  312. at ( - 0.784996001075 , 0.0 , 0.0 , 99.2150040149 , 100.0 , 100.0)
  313. 48. residue=(5.66880467397e+12 , 0.0 , 0.0 , 5.6688115269e+12 , 0.0 , 0.0)
  314. , step length=0.0365590456369
  315. at ( - 0.759144865742 , 0.0 , 0.0 , 99.2408551778 , 100.0 , 100.0)
  316. 49. residue=(2.08543452966e+12 , 0.0 , 0.0 , 2.08544138253e+12 , 0.0 , 0.0)
  317. , step length=0.036559045637
  318. at ( - 0.733293754037 , 0.0 , 0.0 , 99.2667063642 , 100.0 , 100.0)
  319. 50. residue=(767186323467.0 , 0.0 , 0.0 , 767193176319.0 , 0.0 , 0.0)
  320. , step length=0.0365590456375
  321. at ( - 0.70744270656 , 0.0 , 0.0 , 99.2925576149 , 100.0 , 100.0)
  322. 51. residue=(282229910057.0 , 0.0 , 0.0 , 282236762901.0 , 0.0 , 0.0)
  323. , step length=0.0365590456414
  324. at ( - 0.681591833671 , 0.0 , 0.0 , 99.3184090402 , 100.0 , 100.0)
  325. 52. residue=(103824415727.0 , 0.0 , 0.0 , 103831268569.0 , 0.0 , 0.0)
  326. , step length=0.0365590456703
  327. at ( - 0.655741435353 , 0.0 , 0.0 , 99.3442609401 , 100.0 , 100.0)
  328. 53. residue=(3.81927022457e+10 , 0.0 , 0.0 , 3.8199555087e+10 , 0.0 , 0.0)
  329. , step length=0.0365590458835
  330. at ( - 0.629892327003 , 0.0 , 0.0 , 99.3701141301 , 100.0 , 100.0)
  331. 54. residue=(1.40481443717e+10 , 0.0 , 0.0 , 1.40549972128e+10 , 0.0 , 0.0)
  332. , step length=0.0365590474585
  333. at ( - 0.604046724769 , 0.0 , 0.0 , 99.3959708274 , 100.0 , 100.0)
  334. 55. residue=(5.16585846951e+9 , 0.0 , 0.0 , 5.17271131074e+9 , 0.0 , 0.0)
  335. , step length=0.0365590590969
  336. at ( - 0.578210650353 , 0.0 , 0.0 , 99.4218370614 , 100.0 , 100.0)
  337. 56. residue=(1.89824960589e+9 , 0.0 , 0.0 , 1.90510244878e+9 , 0.0 , 0.0)
  338. , step length=0.0365591450932
  339. at ( - 0.552400454575 , 0.0 , 0.0 , 99.4477292394 , 100.0 , 100.0)
  340. 57. residue=(6.96167585052e+8 , 0.0 , 0.0 , 7.03020440594e+8 , 0.0 , 0.0)
  341. , step length=0.0365597805245
  342. at ( - 0.526660451901 , 0.0 , 0.0 , 99.4736920939 , 100.0 , 100.0)
  343. 58. residue=(2.53957444815e+8 , 0.0 , 0.0 , 2.60810394004e+8 , 0.0 , 0.0)
  344. , step length=0.0365644757288
  345. at ( - 0.501110133883 , 0.0 , 0.0 , 99.4998482048 , 100.0 , 100.0)
  346. 59. residue=(9.13074482936e+7 , 0.0 , 0.0 , 9.81610893493e+7 , 0.0 , 0.0)
  347. , step length=0.036599167075
  348. at ( - 0.476067267452 , 0.0 , 0.0 , 99.526538163 , 100.0 , 100.0)
  349. 60. residue=(3.15519019482e+7 , 0.0 , 0.0 , 3.8410646839e+7 , 0.0 , 0.0)
  350. , step length=0.0368554086395
  351. at ( - 0.452345623749 , 0.0 , 0.0 , 99.5547446298 , 100.0 , 100.0)
  352. 61. residue=(9.77481469301e+6 , 0.0 , 0.0 , 1.66708124709e+7 , 0.0 , 0.0)
  353. , step length=0.0387445972031
  354. at ( - 0.431825342687 , 0.0 , 0.0 , 99.5876089247 , 100.0 , 100.0)
  355. 62. residue=(2.23533931681e+6 , 0.0 , 0.0 , 9.38172386018e+6 , 0.0 , 0.0)
  356. , step length=0.0527640781991
  357. at ( - 0.417764764235 , 0.0 , 0.0 , 99.6384650755 , 100.0 , 100.0)
  358. 63. residue=(2.23262484734e+5 , 0.0 , 0.0 , 8.19715321429e+6 , 0.0 , 0.0)
  359. , step length=0.204739774363
  360. at ( - 0.41222548566 , 0.0 , 0.0 , 99.843129903 , 100.0 , 100.0)
  361. 64. residue=(2.23088062724e+5 , 0.0 , 0.0 , 8.19035290355e+6 , 0.0 , 0.0)
  362. , step length=0.383303021247
  363. at ( - 0.412224950141 , 0.0 , 0.0 , 100.226432924 , 100.0 , 100.0)
  364. 65. residue=(2.22216670074e+5 , 0.0 , 0.0 , 7.2288078e+6 , 0.0 , 0.0)
  365. , step length=0.129870827173
  366. at ( - 0.412222274586 , 0.0 , 0.0 , 100.356303751 , 100.0 , 100.0)
  367. 66. residue=(1.66845393097e+5 , 0.0 , 0.0 , 1.93472870727e+6 , 0.0 , 0.0)
  368. , step length=0.048267265871
  369. at ( - 0.412051690235 , 0.0 , 0.0 , 100.404570716 , 100.0 , 100.0)
  370. 67. residue=(1653.19388834 , 0.0 , 0.0 , - 3.3219398641e+5 , 0.0 , 0.0)
  371. , step length=0.00800369958771
  372. at ( - 0.411535983805 , 0.0 , 0.0 , 100.412557784 , 100.0 , 100.0)
  373. 68. residue=(0.166671264823 , 0.0 , 0.0 , - 6386.15622619 , 0.0 , 0.0)
  374. , step length=0.00100689373229
  375. at ( - 0.411530770947 , 0.0 , 0.0 , 100.411550903 , 100.0 , 100.0)
  376. 69. residue=( - 0.000000122 , 0.0 , 0.0 , - 2.48519530414 , 0.0 , 0.0)
  377. , step length=0.0000201252363669
  378. at ( - 0.411530770421 , 0.0 , 0.0 , 100.411530778 , 100.0 , 100.0)
  379. {x1= - 0.411530770421,x2=0.0,x3=0.0,x4=100.41153077,x5=100.0,x6=100.0}
  380. off trnumeric;
  381. clear alpha,ni,v,d,sys;
  382. off rounded;
  383. % INTEGRALS
  384. num_int( x**2,x=(1 .. 2),accuracy=3);
  385. 7
  386. ---
  387. 3
  388. % 1st case: using formal integral
  389. needle := 1/(10**-4 + x**2);
  390. 10000
  391. needle := --------------
  392. 2
  393. 10000*x + 1
  394. num_int(needle,x=(-1 .. 1),accuracy=3);
  395. 312.159332022
  396. % 312.16
  397. % no formal integral, but easy Chebyshev fit
  398. num_int(sin x/x,x=(1 .. 10));
  399. 0.712264523852
  400. % using a Chebyshev fit of order 60
  401. num_int(exp(-x**2),x=(-10 .. 10),accuracy=3);
  402. 1.77245387654
  403. % 1.772
  404. % cases with singularities
  405. num_int(1/sqrt x ,x=(0 .. 1),accuracy=2);
  406. 2
  407. % 1.999
  408. num_int(1/sqrt abs x ,x=(-1 .. 1),iterations=50);
  409. 3.99999231465
  410. % 3.999
  411. % simple multidimensional integrals
  412. num_int(x+y,x=(0 .. 1),y=(2 .. 3));
  413. 3.0
  414. num_int(sin(x+y),x=(0 .. 1),y=(0 .. 1));
  415. 0.773135425204
  416. % some integrals with infinite bounds
  417. on rounded;
  418. % for the error function
  419. num_int(e^(-x) ,x=(0 .. infinity));
  420. 1.00000034605
  421. % 1.000
  422. 2/sqrt(pi)* num_int(e^(-x^2) ,x=(0 .. infinity));
  423. 1.00000003784
  424. % 1.00
  425. 2/sqrt(pi)* num_int(e^(-x^2), x=(-infinity .. infinity));
  426. 2.00000007569
  427. % 2.00
  428. num_int(sin(x) * e^(-x), x=(0 .. infinity));
  429. 0.500000522701
  430. % 0.500
  431. off rounded;
  432. % APPROXIMATION
  433. %approximate sin x by a cubic polynomial
  434. num_fit(sin x,{1,x,x**2,x**3},x=for i:=0:20 collect 0.1*i);
  435. 3 2
  436. { - 0.0847539694989*x - 0.134641944765*x + 1.06263064633*x - 0.00519313406463,
  437. { - 0.00519313406463,1.06263064633, - 0.134641944765, - 0.0847539694989}}
  438. % approximate x**2 by a harmonic series in the interval [0,1]
  439. num_fit(x**2,1 . for i:=1:5 join {sin(i*x)},
  440. x=for i:=0:10 collect i/10);
  441. { - 1.3095780871*sin(5*x) + 7.1637556683*sin(4*x) - 18.549018248*sin(3*x)
  442. + 26.5601709095*sin(2*x) - 19.4492185507*sin(x) - 0.00197199704297,
  443. { - 0.00197199704297, - 19.4492185507,26.5601709095, - 18.549018248,
  444. 7.1637556683, - 1.3095780871}}
  445. % approximate a set of points by a polynomial
  446. pts:=for i:=1 step 0.1 until 3 collect i$
  447. vals:=for each p in pts collect (p+2)**3$
  448. num_fit(vals,{1,x,x**2,x**3},x=pts);
  449. 3 2
  450. {1.0*x + 5.99999999998*x + 12.0*x + 7.99999999998,{7.99999999998,12.0,
  451. 5.99999999998,1.0}}
  452. % compute the approximation error
  453. on rounded;
  454. first ws - (x+2)**3;
  455. 3 2
  456. 2.50954812486e-12*x - 0.0000000000155884194442*x + 0.0000000000306474845502*x
  457. - 0.0000000000188205007134
  458. off rounded;
  459. % ODE SOLUTION (Runge-Kutta)
  460. depend(y,x);
  461. % approximate y=y(x) with df(y,x)=2y in interval [0 : 5]
  462. num_odesolve(df(y,x)=y,y=2,x=(0 .. 5),iterations=20);
  463. {{x,y},
  464. {0.0,2.0},
  465. {0.25,2.56805083337},
  466. {0.5,3.2974425414},
  467. {0.75,4.23400003322},
  468. {1.0,5.43656365691},
  469. {1.25,6.98068591491},
  470. {1.5,8.96337814065},
  471. {1.75,11.509205352},
  472. {2.0,14.7781121978},
  473. {2.25,18.9754716726},
  474. {2.5,24.3649879213},
  475. {2.75,31.2852637682},
  476. {3.0,40.1710738461},
  477. {3.25,51.5806798341},
  478. {3.5,66.2309039169},
  479. {3.75,85.0421639995},
  480. {4.0,109.196300065},
  481. {4.25,140.210824692},
  482. {4.5,180.034262599},
  483. {4.75,231.168569052},
  484. {5.0,296.826318202}}
  485. % same with negative direction
  486. num_odesolve(df(y,x)=y,y=2,x=(0 .. -5),iterations=20);
  487. {{x,y},
  488. {0.0,2.0},
  489. {-0.25,1.55760156614},
  490. {-0.5,1.21306131943},
  491. {-0.75,0.944733105483},
  492. {-1.0,0.735758882344},
  493. {-1.25,0.573009593722},
  494. {-1.5,0.446260320298},
  495. {-1.75,0.347547886902},
  496. {-2.0,0.270670566474},
  497. {-2.25,0.210798449125},
  498. {-2.5,0.164169997249},
  499. {-2.75,0.127855722414},
  500. {-3.0,0.0995741367363},
  501. {-3.25,0.0775484156639},
  502. {-3.5,0.060394766845},
  503. {-3.75,0.0470354917124},
  504. {-4.0,0.0366312777778},
  505. {-4.25,0.0285284678182},
  506. {-4.5,0.0222179930767},
  507. {-4.75,0.0173033904064},
  508. {-5.0,0.0134758939983}}
  509. % giving a nice picture when plotted
  510. num_odesolve(df(y,x)=1- x*y**2 ,y=0,x=(0 .. 4),iterations=20);
  511. {{x,y},
  512. {0.0,0.0},
  513. {0.2,0.199600912188},
  514. {0.4,0.393714914166},
  515. {0.6,0.569482634406},
  516. {0.8,0.710657687564},
  517. {1.0,0.805480022354},
  518. {1.2,0.852604291055},
  519. {1.4,0.860563377356},
  520. {1.6,0.842333334456},
  521. {1.8,0.80999200878},
  522. {2.0,0.772211952811},
  523. {2.2,0.734163640068},
  524. {2.4,0.698433235122},
  525. {2.6,0.666019196492},
  526. {2.8,0.637070046905},
  527. {3.0,0.611341375657},
  528. {3.2,0.588447372601},
  529. {3.4,0.567985133759},
  530. {3.6,0.549587947292},
  531. {3.8,0.532942255624},
  532. {4.0,0.517787833735}}
  533. % system of ordinary differential equations
  534. depend(y,x);
  535. depend(z,x);
  536. num_odesolve(
  537. {df(z,x) = y, df(y,x)= y+x},
  538. {z=2, y=4},
  539. x=(0 .. 5),iterations=20);
  540. {{x,z,y},
  541. {0.0,2.0,4.0},
  542. {0.25,3.13887708344,5.17012708344},
  543. {0.5,4.61860635349,6.74360635349},
  544. {0.75,6.55375008305,8.83500008305},
  545. {1.0,9.09140914227,11.5914091423},
  546. {1.25,12.4204647873,15.2017147873},
  547. {1.5,16.7834453516,19.9084453516},
  548. {1.75,22.4917633799,26.0230133799},
  549. {2.0,29.9452804945,33.9452804945},
  550. {2.25,39.6574291816,44.1886791816},
  551. {2.5,52.2874698032,57.4124698032},
  552. {2.75,68.6819094205,74.4631594205},
  553. {3.0,89.9276846154,96.4276846154},
  554. {3.25,117.420449585,124.701699585},
  555. {3.5,152.952259792,161.077259792},
  556. {3.75,198.824159999,207.855409999},
  557. {4.0,257.990750164,267.990750164},
  558. {4.25,334.245811731,345.277061731},
  559. {4.5,432.460656499,444.585656499},
  560. {4.75,558.890172631,572.171422631},
  561. {5.0,721.565795506,736.065795506}}
  562. %----------------- Chebyshev fit -------------------------
  563. on rounded;
  564. func := x**2 * (x**2 - 2) * sin x;
  565. 2 2
  566. func := sin(x)*x *(x - 2)
  567. ord := 15;
  568. ord := 15
  569. cx:=chebyshev_fit(func,x=(0 .. 2),ord)$
  570. cp:=first cx;
  571. 13 12 11
  572. cp := 0.000000620105096185*x + 0.0000168737305191*x - 0.000269014332288*x
  573. 10 9 8
  574. + 0.000155646029006*x + 0.00848163760265*x + 0.000272748604876*x
  575. 7 6 5
  576. - 0.183540091904*x + 0.00010680840443*x + 1.33329694616*x
  577. 4 3 2
  578. + 0.00000770692780683*x - 2.00000091554*x + 0.0000000501515695639*x
  579. - 0.000000000784989184766*x - 4.86055640181e-13
  580. cc:=second cx;
  581. cc := {2.69320512829,
  582. 2.76751928466,
  583. 2.25642507569,
  584. 0.955452569949,
  585. 0.0509075944268,
  586. - 0.0868248678183,
  587. - 0.0170919216091,
  588. 0.00104527137626,
  589. 0.000349190502034,
  590. - 0.00000253521592323,
  591. - 0.00000280798840641,
  592. - 0.0000000157676044858,
  593. 0.0000000121753402195,
  594. 0.000000000118269801846,
  595. - 0.0000000000331230439026}
  596. for u:=0 step 0.2 until 2 do write
  597. "x:",u," true value:",sub(x=u,func),
  598. " Chebyshev eval:", chebyshev_eval(cc,x=(0 .. 2),x=u),
  599. " Chebyshev polynomial:",sub(x=u,cp);
  600. x:0 true value:0 Chebyshev eval: - 4.85167461761e-13 Chebyshev polynomial:
  601. - 4.86055640181e-13
  602. x:0.2 true value: - 0.0155756755343 Chebyshev eval: - 0.0155756755339
  603. Chebyshev polynomial: - 0.015575675548
  604. x:0.4 true value: - 0.114644759976 Chebyshev eval: - 0.114644759976
  605. Chebyshev polynomial: - 0.114644759974
  606. x:0.6 true value: - 0.333364916292 Chebyshev eval: - 0.333364916292
  607. Chebyshev polynomial: - 0.333364916295
  608. x:0.8 true value: - 0.624386741519 Chebyshev eval: - 0.624386741519
  609. Chebyshev polynomial: - 0.624386741504
  610. x:1 true value: - 0.841470984808 Chebyshev eval: - 0.841470984808
  611. Chebyshev polynomial: - 0.841470984841
  612. x:1.2 true value: - 0.751596318924 Chebyshev eval: - 0.751596318924
  613. Chebyshev polynomial: - 0.751596318876
  614. x:1.4 true value: - 0.0772592588311 Chebyshev eval: - 0.0772592588311
  615. Chebyshev polynomial: - 0.0772592588864
  616. x:1.6 true value:1.43298871732 Chebyshev eval:1.43298871732
  617. Chebyshev polynomial:1.43298871738
  618. x:1.8 true value:3.91253024182 Chebyshev eval:3.91253024182
  619. Chebyshev polynomial:3.91253024177
  620. x:2.0 true value:7.27437941461 Chebyshev eval:7.27437941461
  621. Chebyshev polynomial:7.27437941467
  622. % integral
  623. % integrate coefficients
  624. ci := chebyshev_int(cc,x=(0 .. 2));
  625. ci := {0.0310113015322,
  626. 0.2183900263,
  627. 0.453016678678,
  628. 0.367586246877,
  629. 0.130284679721,
  630. 0.00679995160359,
  631. - 0.00732251159954,
  632. - 0.00124579372222,
  633. 0.0000654879120115,
  634. 0.0000195554716911,
  635. - 0.000000125972415937,
  636. - 0.000000128189261211,
  637. - 0.000000000661911428653,
  638. 0.000000000469556279362,
  639. 4.22392149449e-12}
  640. % compare with true values (normalized absolute term)
  641. ci0:=chebyshev_eval(ci,x=(0 .. 2),x=0)$
  642. ifunc := int(func,x)$
  643. if0 := sub(x=0,ifunc);
  644. if0 := - 28.0
  645. for u:=0 step 0.2 until 2 do write
  646. {u,sub(x=u,ifunc) - if0,
  647. chebyshev_eval(ci,x=(0 .. 2),x=u) - ci0};
  648. {0,0,0}
  649. {0.2, - 0.000785836355117, - 0.00078583635293}
  650. {0.4, - 0.0119047051867, - 0.0119047051858}
  651. {0.6, - 0.0548116700418, - 0.0548116700408}
  652. {0.8, - 0.150297976106, - 0.150297976105}
  653. {1, - 0.299838223412, - 0.29983822341}
  654. {1.2, - 0.466528961073, - 0.466528961072}
  655. {1.4, - 0.561460555384, - 0.561460555383}
  656. {1.6, - 0.441445769516, - 0.441445769514}
  657. {1.8,0.0768452822437,0.0768452822437}
  658. {2.0,1.18309971762,1.18309971762}
  659. % derivative
  660. % differentiate coefficients
  661. cd := chebyshev_df(cc,x=(0 .. 2))$
  662. % compute coefficients of derivative
  663. cds := second chebyshev_fit(df(func,x),x=(0 .. 2),ord)$
  664. % compare coefficients
  665. for i:=1:ord do write {part(cd,i),part(cds,i)};
  666. {10.4140931324,10.4140931324}
  667. {9.23338917839,9.2333891784}
  668. {4.87905456308,4.87905456307}
  669. {0.207688875651,0.207688875654}
  670. { - 0.853660856614, - 0.853660856625}
  671. { - 0.199571879764, - 0.19957187976}
  672. {0.0145878215687,0.0145878215579}
  673. {0.00553117954514,0.00553117954883}
  674. { - 0.000045977698902, - 0.0000459777097756}
  675. { - 0.0000558684874082, - 0.0000558684837245}
  676. { - 0.00000034381228384, - 0.00000034382315144}
  677. {0.000000291280720039,0.00000029128440905}
  678. {0.00000000307501484799,0.00000000306414359587}
  679. { - 0.000000000927445229273, - 0.000000000923750392908}
  680. {0, - 0.0000000000109242472928}
  681. clear func,ord,cc,cx,cd,cds,ci,ci0;
  682. % One from ISSAC '97 -- should be ~ 1.10*10^36300
  683. f := x^(x^x);
  684. x
  685. x
  686. f := x
  687. num_int(f,x= (1 .. 6),iterations=40);
  688. *** ROUNDBF turned on to increase accuracy
  689. 1.10267709584e+36300
  690. off rounded;
  691. end;
  692. Time for test: 1808 ms, plus GC time: 73 ms