Tue Dec 23 23:46:42 MST 1997 euler% math Mathematica 3.0 for Solaris Copyright 1988-96 Wolfram Research, Inc. -- Terminal graphics initialized -- In[1]:= In[2]:= In[3]:= (* ----------[ M a t h e m a t i c a ]---------- *) 0. Second In[4]:= (* ---------- Initialization ---------- *) 0. Second In[5]:= (* ---------- Numerical Analysis ---------- *) 0. Second In[6]:= (* This number should immediately simplify to 0.0 *) 0. Second In[7]:= 0.0/Sqrt[2] 0. Second Out[7]= 0. In[8]:= (* This number normally produces an underflow => 3.29683e-434295 *) 0. Second In[9]:= Exp[-1000000.0] 0. Second -434295 Out[9]= 3.29683148 10 In[10]:= (* Arbitrary precision floating point numbers This number is nearly an integer: 26253741 2640768743.9999999999 9925007259 7198185688 ... *) 0. Second In[11]:= N[Exp[Sqrt[163]*Pi], 50] 0.03 Second 17 Out[11]= 2.6253741264076874399999999999925007259719818568888 10 In[12]:= (* => [-2, -1] *) 0. Second In[13]:= {Floor[-5/3], Ceiling[-5/3]} 0. Second Out[13]= {-2, -1} In[14]:= (* Generate a cubic natural spline s from x = [1, 2, 4, 5] and y =\ > [1, 4, 2, 3] and then compute s(3) => 27/8 *) 0. Second In[15]:= << NumericalMath`SplineFit` 0.05 Second In[16]:= s = SplineFit[Transpose[{{1, 2, 4, 5}, {1, 4, 2, 3}}], Cubic] 0.02 Second Out[16]= SplineFunction[Cubic, {0., 3.}, <>] In[17]:= s[1.5] 0. Second Out[17]= {3., 3.15} In[18]:= Clear[s] 0. Second In[19]:= (* Translation *) 0. Second In[20]:= p = Sum[a[i]*x^i, {i, 1, n}] 0.13 Second i Out[20]= Sum[a[i] x , {i, 1, n}] In[21]:= (* Convert into FORTRAN syntax *) 0. Second In[22]:= FortranForm[p] 0. Second Out[22]= Sum(a(i)*x**i,List(i,1,n)) In[23]:= (* Convert into C syntax *) 0. Second In[24]:= CForm[p] 0.01 Second Out[24]= Sum(a(i)*Power(x,i),List(i,1,n)) In[25]:= (* Horner's rule---this is important for numerical algorithms => (a[1] + (a[2] + (a[3] + (a[4] + a[5] x) x) x) x) x *) 0. Second In[26]:= << NumericalMath`Horner` 0.16 Second In[27]:= p = Sum[a[i]*x^i, {i, 1, 5}] 0. Second 2 3 4 5 Out[27]= x a[1] + x a[2] + x a[3] + x a[4] + x a[5] In[28]:= p = Horner[p, x] 0.01 Second Out[28]= x (a[1] + x (a[2] + x (a[3] + x (a[4] + x a[5])))) In[29]:= (* Convert the result into FORTRAN syntax => p = (a(1) + (a(2) + (a(3) + (a(4) + a(5)*x)*x)*x)*x)*x *) 0. Second In[30]:= FortranForm[p] 0. Second Out[30]= x*(a(1) + x*(a(2) + x*(a(3) + x*(a(4) + x*a(5))))) In[31]:= (* Convert the result into C syntax => p = (a[1] + (a[2] + (a[3] + (a[4] + a[5]*x)*x)*x)*x)*x ; *) 0. Second In[32]:= CForm[p] 0. Second Out[32]= x*(a(1) + x*(a(2) + x*(a(3) + x*(a(4) + x*a(5))))) In[33]:= Clear[p] 0. Second In[34]:= (* Count the number of (floating point) operations needed to compute\ > an expression => {[+, n - 1], [*, (n^2 - n)/2], [f, (n^2 + n)/2]} *) 0. Second In[35]:= Sum[Product[f[i, k], {i, 1, k}], {k, 1, n}] 0.04 Second Out[35]= Sum[Product[f[i, k], {i, 1, k}], {k, 1, n}] In[36]:= (* Interval analysis (interval polynomial example): ([-4, 2] x + [1, 3])^2 => [-8, 16] x^2 + [-24, 12] x + [1, 9] *) 0. Second In[37]:= Expand[(Interval[{-4, 2}]*x + Interval[{1, 3}])^2] 0.01 Second 2 Out[37]= x Interval[{-24, 12}] + x Interval[{0, 16}] + Interval[{1, 9}] In[38]:= Expand[(Interval[{-4, 2}]*x + Interval[{1, 3}]) * (Interval[{-4, 2}]*x + Interval[{1, 3}])] 0. Second 2 Out[38]= x Interval[{-24, 12}] + x Interval[{0, 16}] + Interval[{1, 9}] In[39]:= Expand[{Interval[{-4, 2}]^2, Interval[{-4, 2}]*Interval[{-4, 2}]}] 0.01 Second Out[39]= {Interval[{0, 16}], Interval[{-8, 16}]} In[40]:= (* Discretize a PDE: for example, forward differencing time\ > (explicit Euler) and central differencing x on the heat equation => (f[i, j+1] - f[i, j])/dt = (f[i+1, j] - 2 f[i, j] + f[i-1, j])/dx^2 *) 0. Second In[41]:= D[f[x, t], t] == D[f[x, t], {x, 2}] 0. Second (0,1) (2,0) Out[41]= f [x, t] == f [x, t] In[42]:= (* ---------- Quit ---------- *) 0. Second In[43]:= Quit[] real 2.72 user 1.25 sys 0.41