Re: NIntegrate: <XXX> should be a machine-size complex number??.
- To: mathgroup at smc.vnet.net
- Subject: [mg19709] Re: NIntegrate: <XXX> should be a machine-size complex number??.
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Sat, 11 Sep 1999 16:36:11 -0400
- Organization: University of Western Australia
- References: <7r7jjs$ciq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Alessandro Simonetto wrote: > I'm stuck with strange messages from Mathematica. > I have ff[x,y] as the ListInterpolation of a Table of Complex numbers > e.g. > ff[x,y]=ListInterpolation[Table[E^((i+j)/20.*(I+1)),{i,1,51},{j,1,51}],{xx,yy}], > where xx,yy are the arrays of the x,y values. This does not make sense unless your xx and yy arrays are evenly spaced and correspond correctly to the sampling of the exp function. > I can't understand any of the messages. Especially the one complaining > about the function not evaluating to a Complex number, whereas it does. > > Can you shed light on the question? I assume NIntegrate can handle Complex > numbers, otherwise it shoould complain about the numbers not being Real... I think the following appended Notebook might answer your questions. Notebook[{ Cell[TextData[{ "Define the ", Cell[BoxData[ \(TraditionalForm\`x\)]], "-grid," }], "Text"], Cell[BoxData[ \(TraditionalForm\`\(xgrid = {1}~ Join~\((Table[Random[Real, {1, 10}], {25}] // Sort)\)~ Join~{10};\)\)], "Input"], Cell[TextData[{ "and ", Cell[BoxData[ \(TraditionalForm\`y\)]], "-grid," }], "Text"], Cell[BoxData[ \(TraditionalForm\`\(ygrid = {1}~ Join~\((Table[Random[Real, {1, 10}], {25}] // Sort)\)~ Join~{10};\)\)], "Input"], Cell["\<\ Evaluate the function on this (unevenly spaced) rectangular grid,\ \ \>", "Text"], Cell[BoxData[ \(TraditionalForm\`\(dat = Apply[Function[{x, y}, \[ExponentialE]\^\(\(\((x + y)\)\ \((\[ImaginaryI] + 1)\)\)\ \/20. \)], Outer[List, xgrid, ygrid], {2}];\)\)], "Input"], Cell["and then interpolate the result:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(TraditionalForm\`f = ListInterpolation[dat, {xgrid, ygrid}]\)], "Input"], Cell[BoxData[ FormBox[ TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1.`", "10.`"}, {"1.`", "10.`"} }, ColumnAlignments->{Decimal}], "\[NoBreak]", ")"}], ",", "\<\"<>\"\>"}], "]"}], False, Editable->False], TraditionalForm]], "Output"] }, Open ]], Cell["Numerically integrate the function over the domain:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(TraditionalForm\`NIntegrate[ f(x, y), {x, 1, 10}, {y, 1, 10}]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`\(\(117.15796434300714`\)\(\[InvisibleSpace]\)\) + 77.38755692218363`\ \[ImaginaryI]\)], "Output"] }, Open ]], Cell["In this case we can compute the integral exactly,", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(TraditionalForm\`\[Integral]\_1\%10\(\[Integral]\_1\%10\( \ \[ExponentialE]\^\(1\/20\ \((x + y)\)\ \((\[ImaginaryI] + 1)\)\)\) \[DifferentialD]y \[DifferentialD]x\)\)], \ "Input"], Cell[BoxData[ \(TraditionalForm\`200\ \[ImaginaryI]\ \((\(-\ at \[ExponentialE]\%20\) + \ \[ExponentialE]\^\(1\/2 + \(9\ \[ImaginaryI]\)\/20\))\)\ \[ExponentialE]\^\(1\ \/20 + \[ImaginaryI]\/10\) - 200\ \[ImaginaryI]\ \((\(-\ at \[ExponentialE]\%20\) + \ \[ExponentialE]\^\(1\/2 + \(9\ \[ImaginaryI]\)\/20\))\)\ \[ExponentialE]\^\(1\ \/2 + \(11\ \[ImaginaryI]\)\/20\)\)], "Output"] }, Open ]], Cell["\<\ and check to see how well it agress with the numerical result\ \>", \ "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(TraditionalForm\`N[%]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`\(\(117.1579684038847`\)\(\[InvisibleSpace]\)\) + 77.38755891718002`\ \[ImaginaryI]\)], "Output"] }, Open ]], Cell["\<\ A plot shows how well the interpolated function agrees with the \ exact function:\ \>", "Text"], Cell[BoxData[ \(TraditionalForm\`\(Plot3D[ Abs[f[x, y]] - Abs[\[ExponentialE]\^\(\(\((x + y)\)\ \((\[ImaginaryI] + 1)\)\)\/20\ \)], {x, 1, 10}, {y, 1, 10}];\)\)], "Input"] } ] ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________