NUMERIC.LOG 27 KB

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