mm-619 === Subject: Re: Java -> Mathematica -> Java Todd is the one who can give a definite answer. NETLink and JaveLink is implemented based on the reflection feature of .net and java, isn't it? VCL also has some reflection function. And I think it is possible for Mathematica to use VCL classes' published properties without too much hard coding. -- Li Zhengji ------------------------------------------------------------- If all you have is a hammer, everything is a nail. ------------------------------------------------------------- === Subject: Re: question about matrix > I have a matrix and it may have rows and columns which are > zeros. I > can drop the rows and columns manually but it is troublesome. So my > question is that how to drop the rows and columns that are zeros > automatically. Here's one approach In[4]:= testZero[a_]:=Equal@@Append[a,0] dropZeroRows[a_?MatrixQ]:=Select[a,!testZero[#]&] dropZeroColumns[a_?MatrixQ]:=Transpose[Select[Transpose[a],!testZero [#]&]] dropZeroRows[{{1,2,3},{0,0,0},{1,2,3}}] dropZeroColumns[{{1,0,1},{2,0,2},{3,0,3}}] Out[7]= {{1,2,3},{1,2,3}} Out[8]= {{1,1},{2,2},{3,3}} === Subject: Re: question about matrix m={{a[1,1],0,a[1,3],0,a[1,5]}, {a[2,1],0,a[2,3],0,a[2,5]}, {a[3,1],0,a[3,3],0,a[3,5]}, {0,0,0,0,0}, {a[5,1],0,a[5,3],0,a[5,5]}}; fm=Transpose[Select[Transpose[ Select[m,Union[#]!={0}&]], Union[#]!={0}&]] {{a[1, 1], a[1, 3], a[1, 5]}, {a[2, 1], a[2, 3], a[2, 5]}, {a[3, 1], a[3, 3], a[3, 5]}, {a[5, 1], a[5, 3], a[5, 5]}} fm==Transpose[DeleteCases[Transpose[ DeleteCases[m,{(0)..}]],{(0)..}]] True fm==Transpose[Transpose[m/. {(0)..}:>Sequence[]]/. {(0)..}:>Sequence[]] True Bob Hanlon === > Subject: question about matrix > I have a matrix and it may have rows and columns which are zeros. I > can drop the rows and columns manually but it is troublesome. So my > question is that how to drop the rows and columns that are zeros > automatically. > Tun Myint Aung > Graduate Student > National University of Singapore > E1A #02-18 > Kent Ridge, 119260, Singapore > E-mail g0202015@nus.edu.sg === Subject: Re: JLink / VTK problem I added a class to the vtk jar (which is in the classpath) and this class just loads the vtk JNI libraries. The main reason I was thinking about writting my own mathlink interface to vtk is that vtk is a c++ library. Currently using JLink, I'm using the java wrapper around vtk, and the mathematica wrapper around java, so there are quite a few layers and my general belief is that the more complex you make something, the more likely it is for something to go wrong. However, java and jlink have been around for some time, and both have a fairly large user base so it would stand to reason that they are fairly stable. === >Subject: JLink / VTK problem >Hello All >I'm trying to get Mathematica to call some VTK (visulization toolkit) >classes using the java VTK wrapper. I've tried the same example using >plain >java and it works fine. >Here is the original java code: >import vtk.*; >public class Cone { > public static void main (String []args) { > System.loadLibrary(vtkCommonJava); > System.loadLibrary(vtkFilteringJava); > System.loadLibrary(vtkIOJava); > System.loadLibrary(vtkImagingJava); > System.loadLibrary(vtkGraphicsJava); > System.loadLibrary(vtkRenderingJava); > vtkConeSource cone = new vtkConeSource() >... >And here is the Mathematica code: >Needs[JLink`] >(* use the correct version of java, this is the version I build VTK with >In[23]:= InstallJava[CommandLine->C:Program >FilesJavajdk1.5.0_05jrebinjavaw.exe] >Out[23]=LinkObject[C:Program >FilesJavajdk1.5.0_05jrebinjavaw.exe,6,2] >(* add the location of the vtk jar *) >In[24]:=AddToClassPath[D:/src/vtk_build/bin]; >(* load System to create the context *) >In[25]:=LoadJavaClass[java.lang.System] >Out[25]=JavaClass[java.lang.System,0] >(* load the VTK native libraries, all works fine *) >In[26]:=System`loadLibrary[vtkCommonJava] >In[27]:=System`loadLibrary[vtkFilteringJava] >In[28]:=System`loadLibrary[vtkIOJava] >In[29]:=System`loadLibrary[vtkImagingJava] >In[30]:=System`loadLibrary[vtkGraphicsJava] >In[31]:=System`loadLibrary[vtkRenderingJava] >(* create a new vtk object, this is where I get into trouble *) >In[32]:=cone = JavaNew[vtk.vtkConeSource] >java.lang.UnsatisfiedLinkError: >VTKInit > at vtk.vtkConeSource.VTKInit(Native Method) > at vtk.vtkObject.(vtkObject.java:98) > at vtk.vtkProcessObject.(vtkProcessObject.java:78) > at vtk.vtkSource.(vtkSource.java:82) > at vtk.vtkPolyDataSource.(vtkPolyDataSource.java:30) > at vtk.vtkConeSource.(vtkConeSource.java:114) > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native > Method) > at sun.reflect.NativeConstructorAccessorImpl.newInstance( >NativeConstructorAccessorImpl.java:39) > at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( >DelegatingConstructorAccessorImpl.java:27) > at >java.lang.reflect.Constructor.newInstance(Constructor.java:494). >JavaNew::fail: Error calling constructor for class vtk.vtkConeSource. >Out[32]=$Failed >As you can see, the Mathematica code is doing the exact same thing as the >java code, and the java code works fine. >BTW, I run the java example like: >javaw -classpath ../../../../bin/vtk.jar;. Cone >Has anyone here had much experience with JLink, how reliable / stable is >it? >Reason that I ask is that I'm starting to work on a binding from >Mathematica >to VTK and I'm debating writting my own MathLink interface directly or >using >java with the VTK java wrapper. >Andy, >This is a bit tricky, as it involves classloading issues. Java native >libraries are loaded by a classloader. When the System.loadLibrary() Java >method is called, the Java runtime has to pick a classloader to load the >library. It chooses the one that loaded the class that happens to be >calling System.loadLibrary(). When you execute >System`loadLibrary[vtkCommonJava] from Mathematica, the code that is >calling loadLibrary() is in the internals of J/Link, and thus the native >library is loaded by the classloader that loaded J/Link itself. However, >when you call JavaNew[vtk.vtkConeSource] in Mathematica, that class is >loaded by the JLinkClassLoader, a special loader in J/Link that is >responsible for loading all classes requested by Mathematica code. Because >this is a different classloader than the one that loaded the vtkCommonJava >native library, it cannot see that native library and thus you get an >UnsatisfiedLinkError. >J/Link gets a lot of benefit from having a special loader for all >user-loaded classes (for example, the ability to dynamically add >directories and jar files while Java is running), but in this case it is a >drawback to have user code loaded by a different classloader than >J/Link's internal implementation. >Luckily, there is an easy fix, although you have to understand something >about the internals of J/Link to recognize it. You simply write a tiny Java >class with one method that calls System.loadLibrary() for you, and then >load and invoke this new method from Mathematica. In this way, the >loadLibrary() method is called from Java code that is loaded by the >JLinkClassLoader, the same classloader that will be used when you later >invoke JavaNew[vtk.vtkConeSource]. Here is a class that does what you >need: > public class MyLibraryLoader { > public static void loadLibrary(String name) throws Exception { > System.loadLibrary(name); > } > } >Use it from Mathematica like this: > LoadJavaClass[MyLibraryLoader]; > MyLibraryLoader`loadLibrary[vtkCommonJava] > MyLibraryLoader`loadLibrary[vtkFilteringJava] > MyLibraryLoader`loadLibrary[vtkIOJava] > MyLibraryLoader`loadLibrary[vtkImagingJava] > MyLibraryLoader`loadLibrary[vtkGraphicsJava] > MyLibraryLoader`loadLibrary[vtkRenderingJava] > JavaNew[vtk.vtkConeSource] (* This will now work. *) >As for the reliability and stability of J/Link, my (unbiased) opinion is >that it will not be a concern. I strongly recommend that you use J/Link >instead of writing your own MathLink interface to VTK. J/Link exists >precisely so that developers won't have to write their own MathLink code. >Todd Gayley >Wolfram Research === Subject: Problem plotting high-order Laguerre polynomials Hi folks, I'm doing some work which involves plotting fairly high-order Laguerre polynomials, up to 200 or so. I've been getting some very strange and obviously incorrect results which seem to have to do with the order of evaluation. (I'm using Mathematica 5.0, but I've checked it in 5.2 and I get the same problems.) Here are some examples with a simple form of the type of function I'm working with: func = 1/Pi Exp[- q^2] LaguerreL[n, 2 q^2] These commands work, displaying the expected oscillatory result: Plot[func /. n -> 40, {q, 0, 30}, PlotRange -> All] Plot[Evaluate[func] /. n -> 40, {q, 0, 30}, PlotRange -> All] This form, however, results in a big mess which isn't even bounded correctly: Plot[Evaluate[func /. n -> 40], {q, 0, 30}, PlotRange -> All] I don't know whether this is a bug or if there's a subtlety of Plot/Evaluate/etc. which I don't understand. I would very much like to be able to use Evaluate on my functions before plotting them, because my actual calculations involve complicated sums over expressions like that above and take a LONG time to plot. (With Evaluate, a single plot takes about 20 minutes; without it the same plot takes nearly 4 hours.) Could anyone shed some light on this problem? I have more examples, including some involving sums, which I can give if needed. I've been fighting with this issue for a long time... Elinor ______________________________ Elinor K. Irish Dept. of Physics and Astronomy University of Rochester Rochester, NY 14627 USA eirish@pas.rochester.edu === Subject: Re: mac os x 10.4.4 breaks mathematica 5.2 (again) Me too. 10.4.4 and Mathematica 5.2, no problem. maybe you can try to repair the permission of the disk? > Mitch, > I have been running 10.4.4 and Mathematica 5.2 for the last few days > with no problems. > Dean > it appears mac os x 10.4.4 update breaks 64-bit application > Mathematica 5.2, just like 10.4.2 did. i'm surprised that i haven't > seen any reports on this yet. last time, wolfram was on the case the > same day 10.4.2 was released. > Exception: EXC_BAD_ACCESS (0x0001) > Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000004 > Thread 0 Crashed: > 0 com.wolfram.Mathematica 0x000567b4 0x1000 + 350132 > 1 com.wolfram.Mathematica 0x00087450 0x1000 + 549968 > 2 com.wolfram.Mathematica 0x0008a220 0x1000 + 561696 > 3 com.wolfram.Mathematica 0x00088724 0x1000 + 554788 > 4 com.wolfram.Mathematica 0x00008cd0 0x1000 + 31952 > 5 dyld 0x8fe01048 _dyld_start + 60 > Thread 1: > 0 libSystem.B.dylib 0x9001f20c select + 12 > 1 com.apple.CoreFoundation 0x9076f9a8 __CFSocketManager + 472 > 2 libSystem.B.dylib 0x9002b200 _pthread_body + 96 > cheers, > Mitch === Subject: Re: question about matrix > I have a matrix and it may have rows and columns which are zeros. I > can drop the rows and columns manually but it is troublesome. So my > question is that how to drop the rows and columns that are zeros > automatically. > Tun Myint Aung > Graduate Student > National University of Singapore > E1A #02-18 > Kent Ridge, 119260, Singapore > E-mail g0202015@nus.edu.sg it depends on the matrix. If it is an normal array, then DeleteCases[Transpose[DeleteCases[Transpose[matrix], {0 .. }]], {0 .. }]] comes to mind. Let's have a closer look at SparseArrays: First we construct a matrix represented as Table and as SparseArray: SeedRandom[1]; n = 3000; mnormal = Table[(If[#1 > 0.7/n, 0, n*#1*0.7] & )[Random[]], {n}, {n}]; msparse = SparseArray[mnormal, {n, n}]; AbsoluteTiming[Dimensions[ m2 = DeleteCases[Transpose[DeleteCases[Transpose[mnormal], {(0)..}]], {(0)..}]]] --> {0.953125*Second, {1533, 1501}} For SparseArrays, lets change the array rules. Each index is replaced by its position in the union of the indices: AbsoluteTiming[Dimensions[m3 = Module[{ml, mr, mru}, ml = Transpose[Most[First /@ (mr = ArrayRules[msparse])]]; mru = (MapIndexed[#1 -> #2[[1]] & , Union[#1]] & ) /@ ml; mr[[All,1]] = Append[Transpose[MapThread[ReplaceAll, {ml, mru}]], {_, _}]; SparseArray[mr]]]] --> {0.265625*Second, {1533, 1501}} Converting the sparse arry to a normal one and applying method 1 looks easier but is much slower: AbsoluteTiming[Dimensions[ m4 = SparseArray[DeleteCases[Transpose[DeleteCases[ Transpose[Normal[msparse]], {(0)..}]], {(0)..}]]]] --> {1.375*Second, {1533, 1501}} Of course the results are all the same: m2 == m3 == m4 --> True hth, Peter === Subject: Re: question about matrix Transpose[ Transpose[ yourMatrix /. {0..}:> Sequence[] ] /. {0..}:> Sequence[] ] ?? Jens Tun Myint Aung schrieb im | | | I have a matrix and it may have rows and columns which are zeros. I | can drop the rows and columns manually but it is troublesome. So my | question is that how to drop the rows and columns that are zeros | automatically. | | | Tun Myint Aung | Graduate Student | National University of Singapore | E1A #02-18 | Kent Ridge, 119260, Singapore | E-mail g0202015@nus.edu.sg | | | | === Subject: Re: question about matrix Suppose your matrix is called myMatrix. Then to delete columns of zeros use myMatrix=Transpose[DeleteCases[Transpose[myMatrix], Table[0, {First[Dimensions[ myMatrix]]}]]] Then to delete rows of zeros myMatrix=DeleteCases[myMatrix, Table[0, {Last[Dimensions[ myMatrix]]}]] Brian === Subject: Re: finding Fourier Series. Use FourierTransform: FourierTransform[a^n*UnitStep[n],n,k] to obtain I/(Sqrt[2*Pi]*(k - I*Log[a])) Steve Luttrell > Hi buddies, > Which command (in MATHEMATICA) should I use to evaluate the > so-called Discrete-Time Fourier Series ? > Another bug: --- > The command FOURIER[ { list } ] finds the FFT (Fast Fourier > Transform) of a list. How can I evaluate FFT symbolically (instead of a > numerical list ) ? > Specifically , > find the FFT of a^n * UnitStep[n] , n belongs to integer > and Abs[a] < 1 === Subject: Re: finding Fourier Series. a discrete Fourier-transform is for discrete data and Fourier[] does this. FourierTransform[] does this symbolical for a continuous independet variable and otherwise you can try Sum[] with the full definition of your transform to find a symbolic result. Jens bd satish schrieb im | | Hi buddies, | | Which command (in MATHEMATICA) should I use to evaluate the | so-called Discrete-Time Fourier Series ? | | Another bug: --- | | | The command FOURIER[ { list } ] finds the FFT (Fast Fourier | Transform) of a list. How can I evaluate FFT symbolically (instead of a | numerical list ) ? | | Specifically , | | find the FFT of a^n * UnitStep[n] , n belongs to integer | and Abs[a] < 1 | | === Subject: General--Plotting complex functions and branch cuts Given that complex variables are used throughout physics and engineering, for example, for fluid flow, electrostatics, stress and in linear systems theory it seems to me that it is a pity there are so few methods for improving visualization. Below I give two examples where I plot on the complex plane using the natural nonrectangular, but orthogonal, grid provided by complex numbers. I use modulus and argument (phase) as my two sets of grid lines. (Strictly it should be log modulus and argument but I think this makes little difference.) The plotting is spoilt by the branch cut introduced by plotting the argument. This is inevitable but I need a way to tidy this up. I wish to get rid of the bunch of contours located on the cliff face of the branch cut. Any ideas? The first function, f1, has two branch cuts introduced by the method I am using to get the argument contours. The second function, f2, has a natural branch cut that should be there and my method of plotting adds two unwanted additional cuts. I also show that I can move my additional branch cuts, but leave the natural branch cut alone. I am not clear if this always works but it might be a way to identify branch cuts that are artifacts of the graphing method. I also raise the plots to give 3D representations using a method given by David Park in a previous MathGroup question. The nasty bunch of additional lines remain a problem. Hugh Goyder f1[z_] := 1/(1 + 0.1*I*z - z^2); f2[z_] := 1/(1 + 5*(I*z)^(3/2) - z^2); p1 = ContourPlot[Abs[f1[x + I*y]], {x, -2, 2}, {y, -1, 1}, AspectRatio -> 1/2, ContourShading -> False, PlotPoints -> {100, 50}, Contours -> Table[h, {h, 0, 5, 0.5}]]; p2 = ContourPlot[Arg[f1[x + I*y]], {x, -2, 2}, {y, -1, 1}, AspectRatio -> 1/2, ContourShading -> False, PlotPoints -> {100, 50}, Contours -> Table[h, {h, -Pi, Pi, Pi/10}]]; Show[p1, p2]; p3 = ContourPlot[Abs[f2[x + I*y]], {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1, ContourShading -> False, PlotPoints -> {100, 100}, Contours -> Table[h, {h, 0, 5, 0.5}]]; p4 = ContourPlot[Arg[f2[x + I*y]], {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1, ContourShading -> False, PlotPoints -> {100, 100}, Contours -> Table[h, {h, -Pi, Pi, Pi/10}]]; Show[p3, p4]; ClearAll[GetContourLines]; GetContourLines[gg_] := Module[{clines, clines2}, clines = Cases[First[Graphics[gg]], Line[_], Infinity]; clines2 = clines /. Line[{begin___List, a_List, b_List, end___List}] /; Sqrt[(a - b) . (a - b)] < 1.*^-9 -> Line[{begin, end}] /. Line[{}] -> Sequence[] /. Line[{a_}] -> Sequence[]; clines2] c1 = GetContourLines[p1]; c2 = GetContourLines[p2]; c3 = GetContourLines[p3]; c4 = GetContourLines[p4]; Show[Graphics3D[{ c1 /. Line[b_] :> Line[b /. {x_, y_} :> {x, y, Abs[f1[x + I*y]]}], c2 /. Line[b_] :> Line[b /. {x_, y_} :> {x, y, Abs[f1[x + I*y]]}]}], BoxRatios -> {2, 1, 0.5}, Axes -> True, PlotRange -> {All, All, {0, 5}}, ViewPoint -> {-1.734, -2.386, 1.659}]; Show[Graphics3D[{ c3 /. Line[b_] :> Line[b /. {x_, y_} :> {x, y, Abs[f2[x + I*y]]}], c4 /. Line[b_] :> Line[b /. {x_, y_} :> {x, y, Abs[f2[x + I*y]]}]}], BoxRatios -> {1, 1, 0.5}, Axes -> True, PlotRange -> {All, All, {0, 5}}, ViewPoint -> {-1.734, -2.386, 1.659}]; (* move the branch cuts by introducing a phase angle and then taking it away *) p5 = ContourPlot[Arg[f2[x + I*y]*E^(I*(Pi/4))] - Pi/4, {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1, ContourShading -> False, PlotPoints -> {100, 100}, Contours -> Table[h, {h, -Pi - 2*(Pi/10), Pi, Pi/10}]]; Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=7724#p7724 === Subject: Format menu problem OK, here's what happened (I think -- seeking enlightenment as usual): I did some editing on the Default.nb style sheet using the Edit Style Sheet menu command, and then, when I Saved the changes and Closed the Default.nb notebook, I accidentally left one of the modification cells for the style Subsection open in Show Expression mode rather than cancelling the Show Expression for it. The net result, when I went back to my working notebook, was that the Subsubsection style, which is normally cmd-6 in the Format >> Style menu, had completely disappeared from that menu, so that Text was now cmd-6, Small Text was cmd-7, Input was cmd-8, and so on (the Subsection style, cmd 5, was still there -- it was the following one that had disappeared). And, in other notebooks, those lower-down key commands functioned with their new values. This persisted even after Quitting Mathematica and reopening it. I then went back, re-edited the Default style sheet, discovered my error, and reversed Show Expression on the Subsection cell; that's all I did; and everything seems back to normal. But it doesn't seem it should have worked this way (if in fact I'm correctly interpreting how it did happen). Doesn't a cell evaluate normally even when displayed in Show Expression mode? Might it be more sensible for cells to auto drop out of Show Expression mode when the notebook is closed? === Subject: Re: Visualization site updates Jeff, Good stuff. Unfortunately, the USGS link to the Mars data is busted. Keep up the good work though. Kevin > I have added a new GIS data example to add to the earlier Mount Saint > Helens example. This new example uses Mars data obtained from the USGS. > http://members.wri.com/jeffb/visualization/mars-gis.shtml > Also, I've added a more abgstract entry that was more fun than it was > applied. It uses 3D text primitives that represent the symbolics and > numerics in Mathematica and shows them coming together into a coherent > system. > http://members.wri.com/jeffb/visualization/symbolicsnumerics.shtml > Enjoy! > -Jeff === Subject: Re: finding Fourier Series. >Which command (in MATHEMATICA) should I use to evaluate the >so-called Discrete-Time Fourier Series ? >Another bug: --- >The command FOURIER[ { list } ] finds the FFT (Fast Fourier >Transform) of a list. How can I evaluate FFT symbolically >(instead of a numerical list ) ? >Specifically , >find the FFT of a^n * UnitStep[n] , n belongs to integer >and Abs[a] < 1 I would have answered your first question above by suggesting the use of Fourier. However, from what you written it is clear you are already aware of this command. So, it seems I don't understand what you mean by discrete time Fourier series and how that differs from what Fourier returns. But as to your second question, the answer is FourierTransform, i.e., In[1]:= FourierTransform[a^n*UnitStep[n], t, w] Out[1]= a^n*Sqrt[2*Pi]*DiracDelta[w]*UnitStep[n] which can be inverted with InverseFourierTransform, i.e., In[2]:= InverseFourierTransform[%, w, t] Out[2]= a^n*UnitStep[n] -- To reply via email subtract one hundred and four === Subject: Beginner--Exporting formatted text files I am trying to create a formatted text file for input into another program. CSV or standard Table output will not work. I need columns at specific places in the file and for them to be right-aligned. The following prints to the screen the way I need it: PaddedForm[ TableForm[data1, TableAlignments -> Right, TableHeadings -> {None, {Col. 1;, Col. 2;, Col. 3;, Col. 4;, Col. 5;}}], {6, 2}] I just can't figure out how to write it to a file so that this format is retained. I tried Export and Write but I lose the formatting. Please help before I become despondent and harm myself. Mcq Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=7725#p7725 === Subject: associative arrays ok, i know from this group that to see keys in a hash (as in per keys %hash) in would use keys[hash_] := Map[#[[1, 1, 1]] &, DownValues[hash]]; however, what if i have multiple levels of keys, like a[levelone][leveltwo]={1,2,3} a[levelone][level2]={4,5,6} a[levelA][levelB]={7,8,9} I need keys[a] to give me {levelone, levelA} and keys[a[levelone]] to give me {leveltwo, level2}, etc. Any ideas? Please post. Thx. === Subject: Question regarding replacement Often, when manipulating symbolic results, one might want to replace some symbols with simpler expressions, and typically, I've managed this with /.. However, suppose that In[1]: a = b c/d and I know that d/(b c) = theta. Unfortunately, In[2]: params={d/(b c)->theta}; a/.params does *not* yield 1/theta. How can I achieve this simply *without* redefining params? (This (too) simple example is meant to demonstrate some difficulties that I typically encounter when trying to replace symbols in *much* more complicated expressions, where, sometimes, the symbols that I am trying to replace are inverted ... :( ) My apologies in advance, since this seems embarassingly simple, but any help or suggestions would be greatly appreciated! Michael === Subject: Re: NIntegrate and Plot Since you give no description of the function at hand I can only speculate from my past experience.... The Plot function is sampling the range of interest with $MachinePrecision. I encountered a problem in the past with this effecting Integrate (not NIntegrate as in your case) but I wonder if such effect can cause that in your case too. This is easy to check. Crate a set of accurate samples (high precision or rational numbers) in the range of interest and then use these points with your NIntegrate. If this is OK use ListPlot in place of Plot for the results you calculated above. I hope it helps yehuda > Hello. I have a 3D function that I am integrating numerically, and it has > parameter, q. As far as I can tell, the integrand is never infinite or > complex. When I use NIntegrate for a particular value of q, it does the > numerical integral and gives me a reasonable value for the result (for q = > it gives me the expected analytic value). I can do this for many values of > q, and it seems to work just fine. > However... when I try to Plot the numerical integral as a function of q, > though it does actually give me a reasonable plot, it also gives me this > message: > It gives the message repeatedly, always at the same values of k, X, and > gamma (the variables of integration). There is nothing weird or singular > at > those points, and if I ask the numerical integral to skip any or all of > those points, it gives the same message at some slightly different points . > This makes me think that the problem does not have to do with those > particular points. (It does this weird behavior even if I just use the > Real > part of the integrand, so it can't be that the value of the integrand is > complex anywhere.) > So my question is, why does Mathematica let me do NIntegrate for a single > value of q, but get upset if I try to Plot the numerical integral over a > range of values of q (even though it actually ends up doing what I asked > it > to do)? > I'm suspecting this is some simple but subtle quality of Mathematica that > has to do with using the function NIntegrate inside the function Plot. > Peter Rolnick > Peter Rolnick, prolnick@truman.edu > 216 N New St, Kirksville MO 63501, 660-665-2703 > http://www2.truman.edu/~prolnick === Subject: NIntegrate and Plot Hello. I have a 3D function that I am integrating numerically, and it has a parameter, q. As far as I can tell, the integrand is never infinite or complex. When I use NIntegrate for a particular value of q, it does the numerical integral and gives me a reasonable value for the result (for q = 0 it gives me the expected analytic value). I can do this for many values of q, and it seems to work just fine. However... when I try to Plot the numerical integral as a function of q, though it does actually give me a reasonable plot, it also gives me this message: It gives the message repeatedly, always at the same values of k, X, and gamma (the variables of integration). There is nothing weird or singular at those points, and if I ask the numerical integral to skip any or all of those points, it gives the same message at some slightly different points. This makes me think that the problem does not have to do with those particular points. (It does this weird behavior even if I just use the Real part of the integrand, so it can't be that the value of the integrand is complex anywhere.) So my question is, why does Mathematica let me do NIntegrate for a single value of q, but get upset if I try to Plot the numerical integral over a range of values of q (even though it actually ends up doing what I asked it to do)? I'm suspecting this is some simple but subtle quality of Mathematica that has to do with using the function NIntegrate inside the function Plot. Peter Rolnick Peter Rolnick, prolnick@truman.edu 216 N New St, Kirksville MO 63501, 660-665-2703 http://www2.truman.edu/~prolnick === Subject: Kernel uses excessive CPU time *after* giving result. I tried this: In[1]:= N[1000000!] 5565708 Out[1]= 8.263931688331240 10 on Mathematica 5.2 on my quad processor Sun Ultra 80 (4 x 450 MHz, Solaris 10). Mathematica gives the result in about 20 seconds, but then the kernel goes on using 25% of my CPU time (there are 4 processors, so it is using one of them), *after* returning the result. I can then calculate something else, but the cpu usage stays pegged at 25% usage. Here is the output from top a minute or two after the result has been returned. load averages: 0.90, 0.75, 0.70 08:11:26 115 processes: 111 sleeping, 4 on cpu CPU states: % idle, % user, % kernel, % iowait, % swap Memory: 4096M real, 2473M free, 832M swap in use, 4412M swap free 22543 drkirkby 3 30 0 0K 0K cpu/1 1:22 24.48% MathKernel 22318 drkirkby 3 59 0 159M 90M sleep 6:45 1.54% mozilla-bin 543 drkirkby 1 59 0 231M 129M cpu/2 160:48 1.23% Xsun 798 drkirkby 2 59 0 92M 30M cpu/0 27:51 0.60% gnome-termin Here is the output from prstat sparrow /export/home/drkirkby % prstat 22543 drkirkby 79M 34M cpu2 20 0 0:01:09 24% MathKernel/3 543 drkirkby 231M 129M sleep 59 0 2:40:47 0.4% Xsun/1 798 drkirkby 92M 30M sleep 59 0 0:27:50 0.4% gnome-terminal/2 22318 drkirkby 159M 90M sleep 59 0 0:06:43 0.1% mozilla-bin/3 If I repeast this using the comment line 'math' rather than the GUI, the kernel's CPU usage drops back to zero after the result is returned. -- Dave K http://www.southminster-branch-line.org.uk/ Please note my email address changes periodically to avoid spam. It is always of the form: month-year@domain. Hitting reply will work for a couple of months only. Later set it manually. The month is always written in 3 letters (e.g. Jan, not January etc)