numeric.rlg 29 KB

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