D-109 === Subject: Re: Export as PDF without for strings The method suggested by Rob was exactly the thing I was looking for. The first one does not work for me, because I oversimplified the problem, since a is actually a figure, so ToString won't work. === Subject: Re: SetDelayed >Why does Mathematica reply with: ..Integrand [(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5 is not numerical at >{y}={1.5708}, to the following: >Clear[f] >f[x_]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]; >Plot[Evaluate[f[x],{x,0,2}] >How should it be written? f[x_?NumericQ]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}] This will prevent calling NIntegrate with something that cannot be evaluated numerically. Note, there really is no need to follow an expression using SetDelayed with a ; That is f[x_]:=2 x and f[x_]:=2 x; will evaluate exactly the same with neither producing an output until used later. === Subject: Re: What is the compatibility guide? >I have downloaded the updated package NumericalMath to use it in >Mathematica 5 is not running when I call the function ><the corresponding directory the corresponding file that I downloaded >from the MathematicaWeb...PLEASE HELP!!! It is very difficult to determine precisely what the issue is when you have posted no code to show what you have tried or what you are trying to do. I can offer the following observations. First, it is not necessary to download this package to use it. It should be installed in the LegacyPackage directory. If you look at the list of directories stored in $Path, one of them should match the directory returned by ToFileName[$InstallationDirectory,AddOns,LegacyPackages] Doing < 1] Or evaluate symbolically f2[x_] = Assuming[{x > 0}, Integrate[(x - Cos[y])/ (1 + x^2 - 2*x*Cos[y])^(3/2), {y, 0, Pi}, GenerateConditions -> False]] // Simplify ((x + 1)*EllipticE[(4*x)/(x + 1)^2] + (x - 1)*EllipticK[(4*x)/(x + 1)^2])/(x*(x^2 - 1)) Plot[f2[x], {x, 0, 2}, Exclusions -> 1] Why does Mathematica reply with: ..Integrand [(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5 is not numerical at {y}={1.5708}, to the following: Clear[f] f[x_]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]; Plot[Evaluate[f[x],{x,0,2}] How should it be written? -- === Subject: Hubble's Constant I am using the PhysicalConstants and Units packages. Hubble's constant yields HubbleConstant 3.2 x 10^-18/Second however Convert[HubbleConstant, (Kilo Meter/Second)/(Mega Parsec)] gives 98.7424 Kilo Meter/(Mega Parsec Second) The accepted value is 70 km/s/Mpc. Am I missing something? Kevin === Subject: Reduce Question Hi My question concerns how mathematica arrives at the following result: In:= Reduce[ Root[8 m - 16 m #1 - 8 x #1 + 2 m #1^2 + 16 m #1^3 + 8 x #1^3 - 7 m #1^4 - 8 m #1^5 - 4 x #1^5 + 3 m #1^6 + 2 m #1^7 + x #1^7 & 2] < (1/2) (((-((m + x)/m)) + (8 + ((m + x))^2/m^2))) && m > 0 && x > 0] Out:= m > 0 && x > 0 I think that the answer is the CylindricalDecomposition algorithm (since the same input into that function arrives at the same conclusion) but I am not sure what that algorithm is doing beyond the broadest terms. Specifically my questions are: (1) is there any way to replicate this conclusion by hand (that is to derive that the one expression is less than the other)? (2) if not is there a satisfactory way to describe how the conclusion was reached? I appreciate your attention. Chris Metcalf _ === Subject: Re: FindFit, Weibull > I found some data which seemed to fit a WeibullDistribution. The data are: > pr= {16, 34, 53, 75, 93, 120}; > After adding the median rank to the data: > praxis={{16, 0.109101}, {34, 0.26445}, {53, 0.421407}, {75, 0.578593}, {93, 0.73555}, {120, 0.890899}}; > I checked with LeastSquares the parameters: > [Alpha]=1.4301;[Beta] = 76.318. > So far ok. > But the following did not work: > fit2 = {a, b} /. FindFit[praxis, CDF[WeibullDistribution[a, b], x], {a ,b}, {x}] So, I used the parameters in the Weibull CDF and the times from pr to get: > praxis1= {{16, 0.106157}, {34, 0.27559}, {53, 0.451308}, {75, 0.623149}, {93, 0.73256}, {120, 0.848082}} > (something went wrong with editing, so maybe I sent a by accident an unfinished message) > I checked with FindFit and it worked. But then I gave extra some variations: > praxis2 = {#, RandomReal[{0.95, 1.05}] CDF[WeibullDistribution[1.4, 76.318], #]} & /@ pr; > fit4 = {a,b} /. FindFit[praxis2, CDF[WeibullDistribution[a,b], x], {a,b}, {x}] > After a few times trying the two above lines FindFit did not work. > It could be ok. But it seems to me that FindFit with a such a small relative variation in the data from 0.95 to 1.05 should still work. > How can I use FindFit in the case of praxis in a safe way? > P_ter > There are two problems I can see. First, a and b need to be constrained to be positive. The FindFit::nrlnum message and failure happen because the algorithm reaches a negative value of b, which results in complex values. Second, the default starting values of 1 for each parameter are far from the optimum curve. With better non-default starting values a good result can be obtained. In[1]:= praxis = {{16, 0.109101}, {34, 0.26445}, {53, 0.421407}, {75, 0.578593}, {93, 0.73555}, {120, 0.890899}}; In[2]:= fit2 = FindFit[ praxis, {CDF[WeibullDistribution[a, b], x], a > 0 && b > 0}, {{a, 1}, {b, 80}}, {x}] Out[2]= {a -> 1.52051, b -> 77.4766} Note that the result given is different from the least squares result quoted in your message. In[3]:= ls = {a -> 1.4301, b -> 76.318} Out[3]= {a -> 1.4301, b -> 76.318} If we check the sum of squared errors, we see that the FindFit result gives a smaller value and so is a better fit in the sense of distance from the cdf curve. In[4]:= Map[((CDF[WeibullDistribution[a, b], #[[1]]] /. fit2) - #[[2]])^2 &, praxis] // Total Out[4]= 0.0032187 In[5]:= Map[((CDF[WeibullDistribution[a, b], #[[1]]] /. ls) - #[[2]])^2 &, praxis] // Total Out[5]= 0.00426419 I suspect the least squares solution given solves a slightly different problem, that is to say the condition for optimality for that solution is probably something other than minimizing the sum of squared errors from the cdf. Darren Glosemeyer Wolfram Research === Subject: Re: FindFit, Weibull >I found some data which seemed to fit a WeibullDistribution. The >data are: pr= {16, 34, 53, 75, 93, 120}; After adding the median >rank to the data: praxis={{16, 0.109101}, {34, 0.26445}, {53, >0.421407}, {75, 0.578593}, {93, 0.73555}, {120, 0.890899}}; I >checked with LeastSquares the parameters: [Alpha]=1.4301;[Beta] = >76.318. So far ok. But the following did not work: >fit2 = {a, b} /. FindFit[praxis, CDF[WeibullDistribution[a, b], x], >{a ,b}, {x}] There are several things that can be done. First, with complete data it is probably better to use a different approach than non-linear regression to find estimates for the Weibull parameters. For example: In[1]:= meanLog = ExpectedValue[Log[x], WeibullDistribution[a, b], x] Out[1]= Log[b] - EulerGamma/a In[2]:= logMedian = Log@Quantile[WeibullDistribution[a, b], 1/2] // PowerExpand Out[2]= log(b)+log(log(2))/a In[3]:= pr = {16, 34, 53, 75, 93, 120}; NSolve[{meanLog == Mean[Log[pr // N]], logMedian == Log[Median[pr // N]]}, {a, b}] Out[3]= {{a->1.20807,b->86.6841}} Note, instead of using the median of the original data there are other statistics that could be used to find the parameters which would lead to somewhat different estimated values. Another approach would be to maximize the loglikelihood function. For example, In[5]:= logP = Log@PDF[WeibullDistribution[a, b], x] // PowerExpand; ll = Total[logP /. x -> pr // N]; NMaximize[{ll, 0 < a && 0 < b}, {a, b}] Out[7]= {-29.5849,{a->1.93268,b->73.5261}} But if you prefer the estimates you get from doing a regression analysis, you can avoid the problem you are encountering by placing constraints on a and b as well as providing better starting values. That is, In[8]:= FindFit[praxis, {CDF[WeibullDistribution[a, b], x], a > 0 && b > 0}, {{a, 1}, {b, 100}}, {x}] Out[8]= {a->1.52051,b->77.4766} Note, it is important to use reasonably good estimates with the constraints since using constraints only results in In[9]:= FindFit[praxis, {CDF[WeibullDistribution[a, b], x], a > 0 && b > 0}, {a, b}, {x}] Out[9]= {a->0.999501,b->1.00018} which are clearly not very good estimates. Alternatively, since In[10]:= Assuming[a > 0 && b > 0 && x > 0, Log[-Log[1 - CDF[WeibullDistribution[a, b], x]]] // FullSimplify] Out[10]= a*Log[x/b] The problem can be linearized by taking logarithms and avoiding the problems inherent in non-linear fitting. Doing this will avoid the problem of finding good initial starting points for the non-linear regression problem. >So, I used the parameters in the Weibull CDF and the times from pr >to get: praxis1= {{16, 0.106157}, {34, 0.27559}, {53, 0.451308}, >{75, 0.623149}, {93, 0.73256}, {120, 0.848082}} (something went >wrong with editing, so maybe I sent a by accident an unfinished >message) I checked with FindFit and it worked. But then I gave extra >some variations: praxis2 = {#, RandomReal[{0.95, 1.05}] >CDF[WeibullDistribution[1.4, 76.318], #]} & /@ pr; fit4 = {a,b} /. >FindFit[praxis2, CDF[WeibullDistribution[a,b], x], {a,b}, {x}] After >a few times trying the two above lines FindFit did not work. It >could be ok. But it seems to me that FindFit with a such a small >relative variation in the data from 0.95 to 1.05 should still work. It looks like your intent was to generate some random numbers from a Weibull Distribution to use as a test for FindFit here. But you have set up a problem that will not be correctly solved using a standard regression analysis. In the standard problem statistical error is an additive term. Here, you have made it a multiplicative term. Doing this doesn't make it significantly more difficult for FindFit to get a solution. But it will make it much more likely the solution is different from what you expect and harder for you to interpret. Simply doing RandomReal[WeibullDistribution[1.5,77.5],{6}] will give you an adequate sample for testing. === Subject: ListPlot Problem work: In[76]:= Clear[x, a, b, c, d] In[65]:= a = N[Dynamic[ Simplify[(8000*35 - 4000*(65 - x))*0.11 + (10000*35 - 2000*(65 - x))*0.11 + (12000*100 - 12000*65)*0.28 + (12000*100 - 12000*65)*0.22 + (12000*100 - 12000*65)*0.18 + (12000*100 - 12000*65)*0.1]], 10] In[66]:= b = Dynamic[Simplify[(8000*100 + 6000*x - 14000*65)*0.11 + (10000*100 + 4000*x - 14000*65)*0.11 + (12000*100 + 2000*x - 14000*65)*0.28 + (14000*100 - 14000*65)*0.22 + (14000*100 - 14000*65)*0.18 + (14000*100 - 14000*65)*0.1]]; In[67]:= c = Dynamic[Simplify[(8000*100 + 8000*x - 16000*65)*0.11 + (10000*100 + 6000*x - 16000*65)*0.11 + (12000*100 + 4000*x - 16000*65)*0.28 + (14000*100 + 2000*x - 16000*65)*0.22 + (16000*100 - 16000*65)*0.18 + (16000*100 - 16000*65)*0.1]]; In[68]:= d = Dynamic[Simplify[ (8000*100 + 10000*x - 18000*65)*0.11 + (10000*100 + 8000*x - 18000*65)*0.11 + (12000*100 + 6000*x - 18000*65)*0.28 + (14000*100 + 4000*x - 18000*65)*0.22 + (16000*100 + 2000*x - 18000*65)*0.18 + (18000*100 - 18000*65)*0.1]]; In[69]:= f = {{12000, a}, {14000, b}, {16000, c}, {18000, d}} x= 10; In[77]:= ListPlot[{f}] and surprisingly i get no plot and also no error message, just a chart without any point on it!! I have worked on it for a while, reading the list plot options, but I am not able to get out of the mess. I would appreciate if you could help me out. Bests, Jonas === Subject: Re: Variable amount of Buttons in Mathematica > I'm pretty new to this... I'm trying to write a function that will create a variable number of buttons (based on some input) and relate each button to a function call with a unique parameter value. For example: array = {1, 2, 3, 4, 5}; > Column[{Row[ > Table[Button[array[[n]], Print[n], ImageSize -> {50, 50}], {n, 1,Length[array], 1}]]}] Gives me five buttons, labeled 1-5, but each prints 'n' when clicked on. > How would I change this to print the value of n? My best guess at this point is that there is a scoping issue with n, but I don't have enough Mathematica experience to know how to assign static values... > The issue here is that the expression to be evaluated in the Button construct is not evaluated until the button is pressed (which makes good sense when you think about it!). At this point, n does not have a value. One easy way to solve this is to use 'With' to inject the value of n inside the expression on each iteration of the Table construct: array = {1, 2, 3, 4, 5}; Column[{Row[ Table[With[{n = n}, Button[array[[n]], Print[n], ImageSize -> {50, 50}]], {n, 1, Length[array], 1}]]}] Note that you can confirm that Button only evaluates its first argument by evaluating: Attributes[Button] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Variable amount of Buttons in Mathematica > On Oct 13, 12:17 pm, sjoerd.c.devr...@gmail.com >> It can be done with: >> array = {1, 2, 3, 4, 5}; >> Row[Table[ >> With[{n = n}, >> Button[array[[n]], Print[n], ImageSize -> {50, 50}]], {n, 1, >> Length[array], 1}]] >> This uses the somewhate puzzling With[{n = n} construction, which >> replaces every occurance of the *variable* n (which doesn't make sense >> after the Table command has finished) with the succesive *values* it >> had during the table execution. Indeed Sjoerd, it is a very puzzling construct especially for a > newcomer like SDY. > I was amazed to see that all the With answers used n=n . > If this were a class exercise I would have suspected copying :-) > Then Eric mentioned that this was shown in the Button documentation > (they use i=i). > Ah, ah, so it was indeed copying :-) The point is: n=n is not necessary and frankly not recommended. > Mathematica syntax colouring shows the 2 n's with slightly different colours, > but it is hard to tell and not very illuminating for a newbie. I would suggest the following syntax: array = {1, 2, 3, 4, 5}; > Column[{Row[ > Table[With[{k = n}, > Button[array[[k]], Print[k], ImageSize -> {50, 50}]], {n, > Length[array]}]]}] > where I use With[{k=n}, ..... > Here the concept is clearer: each element in the table is built using > the With-local k. > In turn, k takes the current value of the Table-looping n. Perhaps some people are like me. I write such code without the 'With', and it doesn't work, so I use an expletive and add the 'With' without changing the name of the variable :) David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: labeling axes in a ContourPlot > Mathmatica ver 6/Mac Leopard How do you label the axes in ContourPlot? For a simple 3D plot Plot3D[Sin[x] Cos[y], {x, -Pi, Pi}, {y, -Pi, Pi}, > AxesLabel -> {X, Y, Sin[x] Cos[y]}] Works well. But why doesn't the following work? ContourPlot[Sin[x] Cos[y], {x, -Pi, Pi}, {y, -Pi, Pi}, > AxesLabel -> {X, Y, Sin[x] Cos[y]}] I also tried removing the 'z' label with no change. I have looked throughout the ContourPlot documentation and the options > available and I don't see AxesLabel available. You can label the > individual contours with their values, etc. Do you have to go to > graphic primitives and do it manually? Second question: how would you change the font size for the numbers > on the axes? I tried some the ways demonstrated for plot with no luck. try global command: $TextStyle = {FontSize -> 15} === Subject: Re: Import[http://..] wackiness.... ? For Posterity, the problem here was that the target http service is running a php engine called CodeIgnitor that defaults to denying any cookies with a $ in their name. According to RFC2109, that would be broken. Mathematica's Import[] works the first time against the servlet then fails the second time.. the reason is that on the first Import, the servlet sets a cookie so Mathematica requests $Path, $Domain, $Version on follow-up queries. It looks like the appropriate response for the webserver would be to return Path, Domain and Version on the next response but instead it [CodeIgnitor] defaults to denying the request. -jbl > Looks like it was the servlet providing the service that is broken, not > Import -- sorry for the intrusion. > Folk, >> I've written a notebook that allows me to process a set of data from a >> local data file e.g., Import[ToFileName[....]]. >> This data is also available via an HTTP web service that returns >> text/plain. >> When I try to use Import[http://thatservice], Mathematica returns >> Disallowed Key Characters. and I'm unable to find any reference to what >> If I 'wget' or 'curl' http://thatservice and then Import the saved file, >> the notebook processes the data just fine. >> The best I can figure Import w/ an http url probably wants real html and >> not plain text. >> Does anyone know of a way around this (other than the obvious of >> externally copying said data and importing locally)? >> -jbl > > === Subject: Re: Import[http://..] wackiness.... ? Looks like it was the servlet providing the service that is broken, not Import -- sorry for the intrusion. > Folk, > I've written a notebook that allows me to process a set of data from a > local data file e.g., Import[ToFileName[....]]. This data is also available via an HTTP web service that returns > text/plain. When I try to use Import[http://thatservice], Mathematica returns > Disallowed Key Characters. and I'm unable to find any reference to what If I 'wget' or 'curl' http://thatservice and then Import the saved file, > the notebook processes the data just fine. The best I can figure Import w/ an http url probably wants real html and > not plain text. Does anyone know of a way around this (other than the obvious of externally > copying said data and importing locally)? > -jbl > === Subject: Import[http://..] wackiness.... ? Folk, I've written a notebook that allows me to process a set of data from a local data file e.g., Import[ToFileName[....]]. This data is also available via an HTTP web service that returns text/plain. When I try to use Import[http://thatservice], Mathematica returns Disallowed Key Characters. and I'm unable to find any reference to what If I 'wget' or 'curl' http://thatservice and then Import the saved file, the notebook processes the data just fine. The best I can figure Import w/ an http url probably wants real html and not plain text. Does anyone know of a way around this (other than the obvious of externally copying said data and importing locally)? -jbl === Subject: Re: SetDelayed > Why does Mathematica reply with: ..Integrand [(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5 is not numerical at {y}={1.5708}, to the following: Clear[f] > f[x_]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]; > Plot[Evaluate[f[x],{x,0,2}] How should it be written? Clear[f] f[x_?NumericQ] := NIntegrate[(x - Cos[y])/(1 + x^2 - 2*x*Cos[y])^1.5, {y, 0, Pi}] Plot[f[x], {x, 0, 2}] function which evaluates only when the argument is a number? http://support.wolfram.com/mathematica/kernel/features/evalwhennumber.html === Subject: Re: SetDelayed Itzhak, Try replacing your function definition with this: Clear[f] f[x_?NumericQ] := NIntegrate[... Kevin > Why does Mathematica reply with: ..Integrand [(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5 is not numerical at {y}={1.5708}, to the following: Clear[f] > f[x_]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]; > Plot[Evaluate[f[x],{x,0,2}] How should it be written? === Subject: Re: SetDelayed > Why does Mathematica reply with: ...Integrand [(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5 is not numerical at {y}={1.5708}, to the following: Clear[f] > f[x_]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]; > Plot[Evaluate[f[x],{x,0,2}] > Because you used Evaluate, and x is a symbol. f[x_?NumericQ]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]; Plot[f[x],{x,0,2}] === Subject: Dynamic problem (possibly simple) Hi all, I have the following problem: I want to dynamically plot a function (tangential plane to a 3D Plot) One part is that I have to compute the gradient of the function. I could not manage this (dynamically). I have stripped of any unnessesary code to descripe the problem, so look at this: This makes a slider to select a point (works well, of course) {Slider2D[Dynamic[aufpunkt], {{-2, -2}, {2, 2}}], Dynamic[aufpunkt]} This should do a computation with aufpunkt (does not work) DynamicModule[{x, y, a, b}, x = Dynamic[aufpunkt[[1]]]; y = Dynamic[aufpunkt[[2]]]; y^2 ] The output is not evaluated, I get, for instance, (0.5)^2, instead of 0.25. How can I manage to get the formula (y^2 in this case) evaluatet? Mike === Subject: solving systems of transcendental equations I am writing to advertise my two demonstrations on the Wolfram demonstrations site: http://demonstrations.wolfram.com/SemenovsAlgorithmForSolvingSystemsOfNonlin earEquations/ and http://demonstrations.wolfram.com/SolvingSystemsOfTranscendentalEquations/ They both illustrate a method of numerically finding roots of systems of non-linear (possibly transcendental) equations in n-variables in a rectangular region in a rectangular domain in R^n. Questions concerning doing this sort of thing with Mathematica appear periodically in this forum. The method illustrated in these demonstrations is due to V.Yu. Semenov, whose paper was published last year in a Russian language journal. The only other account of the work in English that I am aware of is a review (by myself) in Mathematical Reviews. I think the demonstrations are a much better way of presenting the contents of the paper. Here is a brief explanation of the method. Suppose we are given a system of n-equations in n variables and a rectangular region in R^n where we want o find all solutions (with 100% certainty). The functions defining the equations have to be of class C^2 (twice differentiable with continuous second derivative). Let's at first assume that we know the equations have no multiple roots in the specified region. The algorithm works as follows. There are two tests (described precisely in the first of the above demonstrations). Each test can be performed on any rectangular region. If the first test is passed by the region we know for sure that the system has no roots in the region. If the second test is passed then we know for sure that there is at most a single root in the region. We start with our given region and perform Test 1 on it. If it is passed, there are no roots and we are done. If it fails we go to the second test. If it is passed, we know there is at most one root in the region and we apply the built-in Mathematica function FindRoot to find it. If the second test fails we subdivide the rectangular region into 4 smaller rectangles of equal size and apply Test 1 to each. All the rectangles that pass Test 1 are colored yellow in the demonstrations and are eliminated form further search. On the remaining rectangles we perform Test 2. Those that pass Test 2 (they contain at most one root) are colored orange and left for later. The ones that fail both tests are colored blue and subdivided again. Test 1 and Test 2 are then performed on the rectangles of the subdivision. One can prove that, if there are no repeated roots in the region, the process will end in a finite number of steps (in other words, there will be no blue rectangles left). At this stage all the roots have been isolated and we can find them using FindRoot (with initial point in the middle of the orange rectangles). If the system has multiple roots inside the specified rectangular area, the above process will never finish. There will always remain blue rectangles around the point where the multiple root is located, but their total area will become arbitrarily small. Thus we can always stop the process when the enclosing area becomes small enough. Like other numerical methods, Semenov's method cannot distinguish between a multiple root and a cluster of roots very close together. one too test the correctness of the method. For this reason, in the first demonstration the equations are all polynomials (cubics), in which case one can find all the roots using NSolve. The demonstration lets one specify the cubic and see the roots (computed by NSolve) and observe that they are correctly isolated by Semenov's method. In the second demonstration I tried some transcendental equations that the present version of Mathematica cannot solve. Three of these are given by an analytic equation in one complex variable (an analytic equation in one complex variable corresponds to two real analytic equations in two complex variables). These kind of equations will (probably) be solvable in the next version of Mathematica (I took them from a paper by Adam Strzebonski describing the forthcoming method of solving transcendental complex univariate equations). But the fourth example consists of two real equations not derived form a single complex analytic one, which is something that Mathematica will not be able to solve by means of built in functions for at least a couple of versions. I think it would be nice to make an Add On package for Mathematica based on Semenov's method, but I am not going to do this. Still, the demonstrations contain all the information needed for this purpose. Finally, one last remark. I have been reviewing papers for Math. been non computational and thus non-suitable for making demonstrations. However, in the last few years I got interested in computational mathematics and have been regularly reviewing papers in this area. I am very excited about using Mathematica Demonstrations as a modern form of review, for this type of papers. I think it is vastly more informative and more enjoyable (for both the author and a reader) than a traditional text based review. It shows how right WRI has been to develop the capabilities of Mathematica beyond mere computation contrary to what various modern Luddites (or one particular one) have been arguing on this forum. Andrzej Kozlowski === Subject: Re: Save as PDF with color > I made a notebook in a certain style and want to save it as pdf with all = font colors as in the notebook. When I save now all the font colors of the = original notebook are converted to black. > Any solution? When you choose File > Save As > PDF from the menu in Mathematica, the PDF file is created with the Printing style. Does your Stylesheet's Printing style use different (or no) colors? If you want it to appear exactly as it does on screen you can choose File > Printing Settings > Printing Environment. === Subject: Re: Corrupt graphics output If you are using Version 6 you don't need a lot of PlotPoints. You can control things better using MaxRecursion. The following gives a fairly decent representation: Plot3D[Abs[Gamma[x + I y]], {x, -5.5, 5}, {y, -2, 2}, PlotPoints -> {20, 5}, MaxRecursion -> 4, PlotRange -> {0, 10}, BoxRatios -> {10.5, 4, 8}, AxesLabel -> {Re[z], Im[z], Abs[Gamma[z]]}] Each of the poles should have infinite height but instead they have smaller height for the more negative poles. One method to supplement the graphic is to add a table of the residues obtained by integrating around each pole. poles = {0, -1, -2, -3, -4, -5}; Table[{z0, With[{[CapitalDelta] = .05}, NIntegrate[ Gamma[z], {z, z0 - [CapitalDelta] - I [CapitalDelta], z0 + [CapitalDelta] - I [CapitalDelta], z0 + [CapitalDelta] + I [CapitalDelta], z0 - [CapitalDelta] + I [CapitalDelta], z0 - [CapitalDelta] - I [CapitalDelta]}] // Abs]}, {z0, poles}] // TableForm 0 6.28319 -1 6.28319 -2 3.14159 -3 1.0472 -4 0.261799 -5 0.0523599 -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I was playing around with Mathematica the other day and was attempting > to graph the modulus of the complex-valued gamma function. When I use > a PlotPoints value of 120 the graph looks fine. However, the > following command yields a corrupt graph (PlotPoints value of 150). Plot3D[Abs[Gamma[x + I y]], {x, -5, 5}, {y, -5, 5}, > PlotPoints -> {150, 150}, PlotRange -> {0, 10}, > BoxRatios -> {1, 1, 0.8}, AxesLabel -> {x, I y, Abs[Gamma[z]]}] Anyone know the reason for this and possible solutions? Paul > === Subject: Re: Corrupt graphics output I'm not seeing any corruption at PlotPoints->{150,150} compared to PlotPoints->{120,120}. That's Mathematica 6.0.3 under Windows XP. I presume the main reason you want to set the value of PlotPoints is in order to see the poles with smaller real part. But you might try using MaxRecursion instead of PlotPoints. I was playing around with Mathematica the other day and was attempting > to graph the modulus of the complex-valued gamma function. When I use > a PlotPoints value of 120 the graph looks fine. However, the > following command yields a corrupt graph (PlotPoints value of 150). Plot3D[Abs[Gamma[x + I y]], {x, -5, 5}, {y, -5, 5}, > PlotPoints -> {150, 150}, PlotRange -> {0, 10}, > BoxRatios -> {1, 1, 0.8}, AxesLabel -> {x, I y, Abs[Gamma[z]]}] Anyone know the reason for this and possible solutions? Paul > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Collapsing cell groups [was: Mathematica > To be honest, you're the first person to suggest that this is a problem, and > it's not clear to me what simple user interface would allow you to pick the > group level when collapsing. So, there's no direct way to work around the > limitation. However, it is pretty easy to redo the cell grouping for your example so that > it's one flat group, and therefore can collapse around the Output cell. To do > so, select the cell group and do Cell->Grouping->Group Cells/Group Together. > This applies a manual cell group which overrides the automatic grouping on those > cells and flattens the cell cell group hierarchies. > John Fultz > jfu...@wolfram.com > User Interface Group > Wolfram Research, Inc. > That new-in-6 feature only seems to work with a cell at the topmost > level within a group. For example, I have a notebook with the following > structure: > Section > Input cell with a Plot expression > Output cell from that Plot > Text cell > Section > Yes, if I double-click the text cell, the rest of the entire Section > group collapses to that text cell. > However, suppose I want to collapse everything in that section except > the Plot output. I double-click the Plot output cell's bracket and the > Input/Output pair collapses to just the output cell. > But now how could I collapse the entire section so that just the plot > output cell shows? If I double-click the output cell bracket, nothing > happens; if I double-click the Plot Input/Output group bracket, then of > course it just reopens the Plot Input cell again. > Am I missing something here? >> ... There are >> several options for hiding the input cells, including the new ability >> in version >> 6 to collapse a cell group around a cell other than the topmost cell >> (double-click the cell bracket of the cell you wish to remain visible). John is right, most of the time the default Mathematica behaviour makes sense. After all, if you bother to create a Section heading, why would you want to hide it? Simply grouping the text cell together with the plot in/out cells, will allow you to control the hiding of the text cell when you double click the plot output cell. However if you really insist in hiding everything except the plot output, flattening the grouping, as John suggests, is the way to do it. === Subject: Re: What does FullForm[ ] actually do? > AES you certainly have a lot of time to split hair and write about > it :-) Good for you. Point taken, and well put (though I'm not sure whether the final three > words are to be taken seriously, or sarcastically). I've been making > serious resolutions in fact, to spend more of time splitting wood rather > than hair, or at least doing something else involving physical rather > than mental exercise. (My wife strongly agrees.) But two final points on this topic: 1) Consider Options[] in addition to FullForm[]. To my way of thinking, FullForm[] and Options[] are both _queries_ > -- you use them to get information, in preparation for (maybe) doing > something, but not to accomplish something. You invoke them to ask, what What will some expr do?, not to say Do > this and tell me what you did. This seems even more obvious for > Options[] than for FullForm[] -- yet Options evaluates also. And this seems even more relevant when the evaluation of said expr can > readily have other totally unrelated effects and impacts that don't show > up at all in the output of FullForm or Option[], and have nothing to do > with that output. Try some tests, for example, with expr's of the form > expr1;expr2;expr3 -- 1 and 2 seem to get evaluated along with 3, but > you only get information about 3. When I ask my banker, WhatsTheMeaningOf[Balance available for immediate > withdrawal], that does NOT mean Withdraw that balance and tell me what > it is. 2) Couldn't there be an alternative and more reasonable choice for the > operation of FullForm[expr] besides just evaluate expr or don't -- > like,Show me what the full form result would be _IF_ this expr were > evaluated -- but don't, for God's sake, evaluate it -- I'll do that > when I'm ready to. oh, no sarcasm at all! I wish I had the time, energy and perhaps efficiency to write all the memorable and less memorable things you write here and elsewhere. In general I would agree with your wife: totally disregarding physical activities, in favour of just intellectual ones, in the long run does not pay and could be lethal. The body is the container of the mind. If the container breaks down, the mind goes with it, regardless how smart one is. To my way of thinking FullForm is a visualization mode, like input- output forms and Standard-Traditional forms. So I think it should have its own menu entry like the other forms, in the Cell/ConvertTo submenu. Or, even better it should have its own little toggle button somewhere on the main Mathematica window: click...you see the FullForm (of the unevaluated expression) click...you see the StandardForm again Who would like that? I would. This can be programmed by the user of course (as most things in Mathematica 6.x), but if it were made by the Makers, it would be nicer. What do you think WRI ? will you take this little summer homework for your next 6.0x F1 racer ? Regarding your banking example: nowadays I think most people are just happy to see that their bank is still there! If they can even actually withdraw any money from it, it's just super :-) Options : normally you only give as arguments to Options just a symbol, like Plot or Graphics or your home-baked functions. So there very little to evaluate anyway. According to the doc center you can also feed it a complicated expression, but I cannot really come up with a meaningful example right now. So i do not see a real problem with Options expr1;expr2;expr3....oh no, not again please! I thought we split hair to molecular levels just recently :-) Let's look at it this way: every time you want to do something moderately complex with Mathematica, you probably will split it in several sub tasks (expressions), but you are only interested in printing the final result. So all you have to do in Mathematica is subtask1;subtask2;subtask3;lastcalculationsandresult If you really want to see some intermediate result (for debugging purposes for example) you can always insert a print statement as subtask-n. I think this is quite intuitive, don't you? And yes, the semicolon is actually the infix notation for CompoundExpression[] and bla bla bla....but for most people it is just a way to chain-yet-separate different expressions. And they still survive and prosper. Anything more about it risks entering into metaphysics. AES... don't you hear your wife calling? Don't we all hear them in this wonderful mid-summer Saturday afternoon? It's time for me to go split a 14.335 kg water-melon. I wish you and all mathgroupers a pleasant week-end === Subject: Problems with FindMinimum I'm having problems with the FindMinimum. I'm currently getting errors like this: FindMinimum::nrlnum: The function value {0.335521+43899.8 [ImaginaryI],0.376043+43899.8 [ImaginaryI],0.424669+43899.8 [ImaginaryI],<<6>>,0.311208+46311.9 [ImaginaryI],<<27>>} is not a list of real numbers with dimensions {37} at {x0,y0,x1,y1,hh0,hh1} = {0.00580647,-2.13969*10^20,-9.86301*10^-6,1.23875*10^20,-30574.3,19.6042}. I guess this happens because the function I'm trying to fit with experimantal data, gets imaginary values for some values of the parameters. How can I avoid this and get meaningful results ? Teodoro === Subject: RE: Problems with FindMinimum Merci Jean-Marc, unfortunately the exponential (Z0 in the following) is 3/2, not 2/3. When one is lucky ... because in the most general case the exponential is a real number (between 1 and 1.5). The function I'm trying to fit with the experimental data (that are supplied in Vgk[[i]] and Vak[[i]]) is is[Vgk_,Vak_,Z0_,G0_,G1_,G2_, G3_,mu0_,mu1_,mu2_,mu3_,H0_,H1_,H2_,H3_]:=(G0+G1 Vgk+G2 Vgk^2+G3 Vgk^3 ) (Vgk+Vak/(mu0+mu1 Vgk+mu2 Vgk^2+mu3 Vgk^3)+H0+H1 Vgk+H2 Vgk^2+H3 Vgk^3)^Z0 It has a lot of parameters, I know, but usually G0>>G1>>G2>>G3 and so on, so I could, in principle, attempt a perturbative approach. Unfortunately I get the same error even if I start from a enough good solution (enough near fit). Teodoro Marinucci -----Original Message----- === Subject: Re: Problems with FindMinimum > I'm having problems with the FindMinimum. > I'm currently getting errors like this: > FindMinimum::nrlnum: The function value {0.335521+43899.8 > [ImaginaryI],0.376043+43899.8 [ImaginaryI],0.424669+43899.8 > [ImaginaryI],<<6>>,0.311208+46311.9 [ImaginaryI],<<27>>} is not a > list of real numbers with dimensions {37} at {x0,y0,x1,y1,hh0,hh1} > {0.00580647,-2.13969*10^20,-9.86301*10^-6,1.23875*10^20,-30574.3,19.6042} . > I guess this happens because the function I'm trying to fit with > experimantal data, gets imaginary values for some values of the > parameters. > How can I avoid this and get meaningful results ? Hard to tell w/o more information about what your code actually is. It would have been very helpful for the group if you had posted an small self-contained fully-working example that reproduces the error and gives the gist of what you are doing. Anyway, the following tip might help you. Sometimes, it is a good idea to write a model in a slightly different way to force Mathematica to use real numbers only. For instance, evaluate and compare the following expressions that all deal with the same function (cubic root of a square) but written in different fashions. (The graphics have been deleted.) In[1]:= f = x^(2/3); Plot[f, {x, -1, 1}] FindMinimum[f, {x, 1}] During evaluation of In[1]:= FindMinimum::nrnum:The function value -0.381571+0.660901 I is not a real number at {x} = {-0.666667}. Out[3]= {1., {x -> 1.}} In[4]:= f = (x^2)^(1/3); Plot[f, {x, -1, 1}] FindMinimum[f, {x, 1}, WorkingPrecision -> 20] // Chop During evaluation of In[4]:= FindMinimum::lstol:The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than 20.` digits of working precision to meet these tolerances. Out[6]= {0, {x -> 0}} === Subject: Re: Problems with FindMinimum > I'm having problems with the FindMinimum. > I'm currently getting errors like this: > FindMinimum::nrlnum: The function value {0.335521+43899.8 > [ImaginaryI],0.376043+43899.8 [ImaginaryI],0.424669+43899.8 > [ImaginaryI],<<6>>,0.311208+46311.9 [ImaginaryI],<<27>>} is not a > list of real numbers with dimensions {37} at {x0,y0,x1,y1,hh0,hh1} = > {0.00580647,-2.13969*10^20,-9.86301*10^-6,1.23875*10^20,-30574.3,19.6042}. > I guess this happens because the function I'm trying to fit with > experimantal data, gets imaginary values for some values of the > parameters. > How can I avoid this and get meaningful results ? Hard to tell w/o more information about what your code actually is. It would have been very helpful for the group if you had posted an small self-contained fully-working example that reproduces the error and gives the gist of what you are doing. Anyway, the following tip might help you. Sometimes, it is a good idea to write a model in a slightly different way to force Mathematica to use real numbers only. For instance, evaluate and compare the following expressions that all deal with the same function (cubic root of a square) but written in different fashions. (The graphics have been deleted.) In[1]:= f = x^(2/3); Plot[f, {x, -1, 1}] FindMinimum[f, {x, 1}] During evaluation of In[1]:= FindMinimum::nrnum:The function value -0.381571+0.660901 I is not a real number at {x} = {-0.666667}. Out[3]= {1., {x -> 1.}} In[4]:= f = (x^2)^(1/3); Plot[f, {x, -1, 1}] FindMinimum[f, {x, 1}, WorkingPrecision -> 20] // Chop During evaluation of In[4]:= FindMinimum::lstol:The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than 20.` digits of working precision to meet these tolerances. Out[6]= {0, {x -> 0}} === Subject: Re: ListPlot, Inverse plotting I'll leave it to you to decide whether this is easy or not. Richard Trilling === Subject: Installing Personal Package Documentation not showing up Hello All: I have recently purchased Mathematica 6 and have installed two packages successfully, including their documentation. However, I tried to follow the same routine for another suite of Notebooks I would like to view via the Installed AddOns Link in the Documentation Centre, but no dice. Here is what I have done. (1) I created a directory: /usr/share/Mathematica/Applications/ MyPackage/Documentation/English/ (2) I installed the *.nb files in there. (3) Went to the Documentation Centre and Installed AddOns. Not there. What is weird is that I did the exact same thing for the files from the text Mathematica Navigator. It shows up in the Documentation no problem. As far as I can reckon, there must be a special tag or file that indicates that it should be found by the Installed Add-Ons. Any ideas? I keep finding links that suggest to rebuild the help index. Unfortunately, that seems to be a deprecated function from an earlier version of Mathematica. I have also notice a Browser Categories.m file in the documentation for the Time Series package that shows up. Perhaps that is what I need? Any ideas how to generate one of those? Any ideas or links that I've not found yet would be a huge help. t. === Subject: Re: Installing Personal Package Documentation not showing up For the documentation to appear in the Mathematica Help Browser (not the Documentation Center) you will need an appropriate BrowserCategories.m file. For the documentation to appear in the Documentation Center you will need an appropriate PacletInfo.m file in the appropriate place. To understand some of the details of the this issue come up frequently in this group. You can find a link to it here: http://www.scientificarts.com/worklife/notebooks/ and the notebook is called DocumentationCenterNotes.nb I hope that this helps... --David A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... Trial Version at: http://scientificarts.com/worklife/ > Hello All: I have recently purchased Mathematica 6 and have installed two > packages successfully, including their documentation. However, I tried > to follow the same routine for another suite of Notebooks I would like > to view via the Installed AddOns Link in the Documentation Centre, > but no dice. Here is what I have done. (1) I created a directory: /usr/share/Mathematica/Applications/ > MyPackage/Documentation/English/ (2) I installed the *.nb files in there. (3) Went to the Documentation Centre and Installed AddOns. Not there. What is weird is that I did the exact same thing for the files from > the text Mathematica Navigator. It shows up in the Documentation no > problem. As far as I can reckon, there must be a special tag or file > that indicates that it should be found by the Installed Add-Ons. Any ideas? I keep finding links that suggest to rebuild the help > index. Unfortunately, that seems to be a deprecated function from an > earlier version of Mathematica. I have also notice a Browser > Categories.m file in the documentation for the Time Series package > that shows up. Perhaps that is what I need? Any ideas how to generate > one of those? Any ideas or links that I've not found yet would be a huge help. > t. === Subject: Re: Installing Personal Package Documentation not showing up > Hello David, 6 and 5 and the new paradigm for viewing help files. I managed to find > Author Tools the other night as well. I guess that was a standard > palette option in previous releases and I was going bananas thinking I > was doing something wrong. > t. PS - Great site! --David === Subject: Re: Installing Personal Package Documentation not showing up Hello David, 6 and 5 and the new paradigm for viewing help files. I managed to find Author Tools the other night as well. I guess that was a standard palette option in previous releases and I was going bananas thinking I was doing something wrong. t. PS - Great site! === Subject: Re: Can you help me rewrite my matlab code to mathematica code? > use a function erf(x), while the x used by me is complex arguments, so > the matlab cannot give the results. i realized that the mathematica can > realize this. I'm a green hand in Mathematica, so I cannot rewrite my > matlab code to Mathematica. the matlab code written by me is attached > in http://www.mathworks.com/matlabcentral/newsreader/view_thread/172809. > is there anyone can help me rewrite the code using Mathematica. Hum, the code you posted on this forum is not in -- not even close to -- Mathematica syntax, so one may wonder if you even try to write anything by yourself... To help you started, the erf function is *Erf[z]* in Mathematica and it works over the complex field. In[1]:= Erf[1.5 - I] Out[1]= 1.0784+ 0.0279637 I Also, in addition to the introductory material available with any standard installation of Mathematica, you should read the following How are the different brackets, such as {}, [], and () used in Mathematica? http://support.wolfram.com/mathematica/kernel/features/brackets.html Why doesn't sin[x] work in Mathematica? http://support.wolfram.com/mathematica/kernel/features/casesensitive.html http://support.wolfram.com/mathematica/kernel/features/differentequals.html Why aren't my assignments and function definitions working? http://support.wolfram.com/mathematica/kernel/features/assignments.html === Subject: Re: Can you help me rewrite my matlab code to mathematica code? Try this: n=I * (x Cos[theta]+y Sin[theta]) m=(4*Cos[theta]^2+9*Sin[theta]^2)/4 + I*z ik=3/(2*Pi)* Sin[theta]^2*(1/(2*m)+ Sqrt[Pi]/4*n/(m)^(3/2)*Exp[n^2/4/m]*(1+Erf[n/(2*Sqrt[m])])) fik[x_,y_,z_]=FullSimplify[ik] absintIK[x_,y_,z_]:=Abs@NIntegrate[Evaluate[fik[x,y,z]],{theta,0,2 Pi}] absintIK[0,0,0] absintIK[4,5,6] === Subject: Re: What does FullForm[ ] actually do? >1) Consider Options[] in addition to FullForm[]. >To my way of thinking, FullForm[] and Options[] are both _queries_ >-- you use them to get information, in preparation for (maybe) doing >something, but not to accomplish something. Given all of the built-in queries (at least that I know about) end in Q, it is clear neither of these were intended as queries. >You invoke them to ask, what What will some expr do?, not to say >Do this and tell me what you did. Neither FullForm nor Options tell you what some expression will do nor what some expression did. FullForm tells you the form of the evaluated expression. Not what it did, nor what it will do. >This seems even more obvious for Options[] than for FullForm[] -- yet >Options evaluates also. I don't at all understand why this would be an issue. Options provides a list of the options set for a specific object. That is when you do Options[Integrate] you get a list of each of the options for Integrate and their current setting. Using Integrate as an example, the only way I can see evaluation being an issue is if you did something like Options[Integrate[x,x]] Why would anyone want to do this instead of Options[Integrate]? >2) Couldn't there be an alternative and more reasonable choice for >the operation of FullForm[expr] besides just evaluate expr or don't >-- like,Show me what the full form result would be _IF_ this expr >were evaluated -- but don't, for God's sake, evaluate it -- I'll do >that when I'm ready to. Think about what you are asking here. How is any Mathematica function to determine what the result would be if an expression were evaluated without evaluating that expression? Keep in mind an expression can be any compound expression which can include results of external programs. And even if an expression is limited to built-in functions, the result can be literally anything that can be put on your hard drive or displayed on the screen. === Subject: Re: Spreadsheet like input >Please, where can I learn about entering data into Mathematica's >front end by means of a spreadsheet looking grid (of course, >whithout further external software) ? The only things I know in Mathematica that look like a spreadsheet would be the creation of a table or matrix. You can get a template for either by using the menu item Insert->Table/Matr= You can add rows using cntrl-return or add columns using cntrl-, Note, these are Mac keyboard shortcuts. Shortcuts for Windows or another operating system are likely somewhat different. An alternative for using the menu item above would be to have the Basic Math Input palette open and click on the box showing a 2 x 2 matrix template. I like this alternative better since the result has the first element highlighted which accepts the next keystroke as an entry. In contrast, the first method has none of the cells highlighted, requiring you to select one before you can start inputting data. === Subject: Re: Spreadsheet like input > buenos d=EDas ! Please, where can I learn about entering > data into Mathematica's front end by means > of a spreadsheet looking grid (of course, > whithout further external software) ? > Ignacio De Villares > In addition to the other comments, it is worth noting that you can use Import to read an XLS or CSV files generated by XL directly into Mathematica. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Spreadsheet like input I should add that the method outlined below will certainly not give you the flexibility of a true spreadsheet for creating tables. Of course you can either process the resulting table afterward. Or you could take a completely different approach: create your table in a spreadsheet program and use Import to pull it into Mathematica. You can import either an original XLS or ODS format spreadsheet or, if you wish, first save the spreadsheet to CSV format and then import that. > Menu command Insert > Table/Matrix > New. Now specify your options in > the Create Table/Matrix dialog and press OK. Move the cursor to the placeholder -- the little empty square -- at the > upper left. Type your entry there. Use Tab to move to the next square, etc. Of course before using that menu command you probably want to begin by > entering data = or some such expression so that what you eventually > enter into the table or matrix will be assigned to a named object. > buenos d=EDas ! >> Please, where can I learn about entering >> data into Mathematica's front end by means >> of a spreadsheet looking grid (of course, >> whithout further external software) ? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Spreadsheet like input > Please, where can I learn about entering > data into Mathematica's front end by means > of a spreadsheet looking grid (of course, > whithout further external software) ? The closest thing to what you are looking for must be menu Insert -> Table/Matrix -> New... === Subject: Re: Spreadsheet like input Menu command Insert > Table/Matrix > New. Now specify your options in the Create Table/Matrix dialog and press OK. Move the cursor to the placeholder -- the little empty square -- at the upper left. Type your entry there. Use Tab to move to the next square, etc. Of course before using that menu command you probably want to begin by entering data = or some such expression so that what you eventually enter into the table or matrix will be assigned to a named object. > buenos d=EDas ! Please, where can I learn about entering > data into Mathematica's front end by means > of a spreadsheet looking grid (of course, > whithout further external software) ? > Ignacio De Villares > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Non linear system Hello! I am employed at the resolution of a system not linear equations with 23 equations and 23 variables. All the equations are of the form: X=k*y*x+k*z*x Where k are constant and x and z variables. I use for resolution the function Nsolve, but I do not obtain solution, have to abort the evaluation after near an hour(o'clock) without obtaining results. What function might I use? === Subject: 3D Graphics are too slow. origen = {0, 0, 0}; vi = {1, 0, 0}; vj = {0, 1, 0}; vk = {0, 0, 1}; tronco = Cylinder[{origen, vk}, 0.05]; (*tronco={Red,Line[{origen,vk}]};*) Manipulate[ transf = tronco; If[tr == False, k = 0, k = 0.5 ]; For[j = 1, j <= ite, j++, transf = {transf, Table[Rotate[ Translate[Rotate[Scale[{transf}, esc, {0, 0, 0}], phi, vi], vk], 2 Pi (i - k)/br, vk], {i, 0, br - 1}]}]; Graphics3D[{tronco, transf}], {{esc, 1, Escalamiento (0.1 a 1) }, 0.2, 1}, {{phi, Pi/2, Angulo}, 0, Pi}, {{br, 4, Brazos}, 2, 4, 1, RadioButton}, {{tr, False, Torcimiento}, {False, True}}, {{ite, 2, Iteraciones}, 1, 5, 1, RadioButton}] === Subject: Re: 3D Graphics are too slow. On Jul 21, 3:27 am, Nayeli Espinosa mming syntax. I can plot 3D Fractal Trees but when I increase the number of= iterations, my program gets to run really very slow. What can I do to opti= mize this code for a humanly reasonable running speed? origen = {0, 0, 0}; vi = {1, 0, 0}; vj = {0, 1, 0}; vk = {0, 0, 1= }; tronco = Cylinder[{origen, vk}, 0.05]; > (*tronco={Red,Line[{origen,vk}]};*) Manipulate[ > transf = tronco; > If[tr == False, k = 0, k = 0.5 ]; > For[j = 1, j <= ite, j++, > transf = {transf, > Table[Rotate[ > Translate[Rotate[Scale[{transf}, esc, {0, 0, 0}], phi, vi], > vk], 2 Pi (i - k)/br, vk], {i, 0, br - 1}]}]; Graphics3D[{tronco, transf}], {{esc, 1, Escalamiento (0.1 a 1) }, 0.2, > 1}, {{phi, Pi/2, Angulo}, 0, Pi}, > {{br, 4, Brazos}, 2, 4, 1, RadioButton}, > {{tr, False, Torcimiento}, {False, True}}, {{ite, 2, > Iteraciones}, 1, 5, 1, RadioButton}] In your case the transformations can be carried out 'symbolically': origen = {0, 0, 0}; vi = {1, 0, 0}; vj = {0, 1, 0}; vk = {0, 0, 1}; tronco = Cylinder[{origen, vk}, .05]; f[phi_, i_, br_, tr_, esc_, {{x1_, y1_, z1_}, {x2_, y2_, z2_}}] = ({{x1, y1, z1, 1}, {x2, y2, z2, 1}}. Transpose@ TransformationMatrix@ Composition[ RotationTransform[2 Pi (i - k)/br, vk], TranslationTransform[vk], RotationTransform[phi, vi], ScalingTransform[{esc, esc, esc}, {0, 0, 0}]] )[[All, {1, 2, 3}]] /. k -> Boole[tr]/2; Manipulate[ Graphics3D[{tronco, Flatten@ NestList[# /. Cylinder[L_, r_] :> Table[Cylinder[ f[phi, i, br, tr, esc, L], Abs[esc] r], {i, 0, br - 1}]&, tronco, ite]}, Boxed -> False], {{esc, 1, Escalamiento (0.1 a 1) }, 0.2, 1}, {{phi, Pi/2, Angulo}, 0, Pi}, {{br, 4, Brazos}, 2, 4, 1, RadioButton}, {{tr, False, Torcimiento}, {False, True}}, {{ite, 2, Iteraciones}, 1, 5, 1, RadioButton}] Maxim Rytin m.r@inbox.ru === Subject: a boolean algebra graph drawing question Hello I need to customize the graph in this link, which is for 5 dimensions with 6 levels (I consider each level as a one distance away from the origin or the level before it): http://www.cs.sunysb.edu/~skiena/combinatorica/animations/ham.html how can I make the function in /Combinatorica :/ ShowGraph[ a = BooleanAlgebra[2]] for 2D, or ShowGraph[ a = BooleanAlgebra[3]] for 3D work on more levels? An example of my understanding of a 2D and 3D tensors is provided here: http://www.cse.unsw.edu.au/~mhelal/2DDepNetwork.pdf http://www.cse.unsw.edu.au/~mhelal/3DDepNetwork.pdf Each node has k-children where k is the rank of the tensor. The nodes in a level have overlapping parents from a previous level. This keeps growing till the middle level, then the number of nodes will start to decay, till it becomes one at the last level. There are equations for the relationship between the tensor shape (upper bounds of each dimension, but I can assume they are all the same) and the total waves (levels in the graph), and the number of nodes in each level. Can I use these equations to customize the graph? I have done these graphics manually, but I need to do more analysis and draw more graphs for higher dimensions and more levels in the graph, and I am sure mathematica can help. There is an obvious symmetry in the dependency arrows between the nodes, and I am not sure whether there is an equation that can scale well with dimensionality, where I can parameterize it with the dimensionality, level in the graph, node order, and it can give me the node orders of its parents on the lower level, and its children on the higher level? It is a research question, and if someone is willing to collaborate, we can publish a paper together, because I come from computer science background, not really math. However, finding an answer for this question can significantly speed up my application. I appreciate your help a lot, Manal === Subject: memorize the attained minimum over time in ODE I have an ODE that solves at each time step n something like y'(n)=f(y(n-1),Min(y(n),y(n-1)) i.e., y' depends on the Minimum of y attained so far. How do I implement that usind NDSolve? I cannot use algebraic equations, because I used Method->StiffnessSwitching. joerg === Subject: Re: Problems with FindMinimum >errors like this: FindMinimum::nrlnum: The function value >{0.335521+43899.8 [ImaginaryI],0.376043+43899.8 >[ImaginaryI],0.424669+43899.8 [ImaginaryI],<<6>>,0.311208+46311.9 >[ImaginaryI],<<27>>} is not a list of real numbers with dimensions >{37} at {x0,y0,x1,y1,hh0,hh1} = >{0.00580647,-2.13969*10^20,-9.86301*10^-6,1.23875*10^20,-30574.3,19. >6042}. I guess this happens because the function I'm trying to fit >with experimantal data, gets imaginary values for some values of the >parameters. How can I avoid this and get meaningful results ? If you truly expect a response that is better than your guess you need to provide more details such as what is the function you are trying to fit? Meanwhile, there are a variety of things you could try such as: Specifying the method for FindMinimum to use rather than accepting the result Use NMinimize with appropriate constraints instead of FindMinimum Use FindFit instead of FindMinimum =46indFit is designed to fit a function to data. As a general rule, you will get better results with Mathematica when you use things more specific to your task than the more general things. === Subject: Re: 1/x? > Hey, I'm a new user to Mathematica, and was wondering if any of you > encountered this strange, yet incredibly basic problem - whey plotting > 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be > intersecting with the X axis... Has anyone encountered such an issue (or can plot 1/x without this > embarrassing side effect)? > Plot[1/x, {x, 0, 100}, AxesOrigin -> {0, 0}] Andrzej Kozlowski === Subject: Re: 1/x? Check out the origin chosen by default for the axes - it's not where you think it is. To override the default setting, use the option AxesOrigin as follows: Plot[1/x, {x, 0, 100}, AxesOrigin -> {0, 0}] Jason > Hey, I'm a new user to Mathematica, and was wondering if any of you > encountered this strange, yet incredibly basic problem - whey plotting > 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be > intersecting with the X axis... Has anyone encountered such an issue (or can plot 1/x without this > embarrassing side effect)? > -- Dr. J. McKenzie Alexander Department of Philosophy, Logic and Scientific Method London School of Economics and Political Science Houghton Street, London, WC2A 2AE Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm === Subject: Re: 1/x? Try Plot[1/x, {x, 0, 100}, AxesOrigin -> {0, 0}] Mathematica does not automatically choose (0,0) as the origin. Your graph was not crossing the x-axis but it was crossing the horizontal line drawn by Mathematica. Tim Brophy > Hey, I'm a new user to Mathematica, and was wondering if any of you > encountered this strange, yet incredibly basic problem - whey plotting > 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be > intersecting with the X axis... Has anyone encountered such an issue (or can plot 1/x without this > embarrassing side effect)? > === Subject: 1/x? Hey, I'm a new user to Mathematica, and was wondering if any of you encountered this strange, yet incredibly basic problem - whey plotting 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be intersecting with the X axis... Has anyone encountered such an issue (or can plot 1/x without this embarrassing side effect)? === Subject: Re: 1/x? you might want to lookup the Plot option AxesOrigin. Alois === Subject: Re: 1/x? > I'm a new user to Mathematica, and was wondering if any of you > encountered this strange, yet incredibly basic problem - whey plotting > 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be > intersecting with the X axis... no problem here, the axis happens to be drawn at y=+0.02 with the default settings. > Has anyone encountered such an issue (or can plot 1/x without this > embarrassing side effect)? Plot[1/x, {x, 0, 100}, AxesOrigin -> {0, 0}] hth, albert === Subject: Re: 1/x? no because it depends on the y-position where the x-axis is placed. The most people, that make plots have the ability to *read* what is written on the axis. The numbers that are usual placed there, are not a pure decoration. And one learn in school (in Germany in the 4 class) that one has to read the numbers first. And Plot[1/x, {x, 0, 100}, AxesOrigin -> {0, 0}] work fine. Jens > Hey, I'm a new user to Mathematica, and was wondering if any of you > encountered this strange, yet incredibly basic problem - whey plotting > 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be > intersecting with the X axis... Has anyone encountered such an issue (or can plot 1/x without this > embarrassing side effect)? > === Subject: Re: 1/x? > Hey, I'm a new user to Mathematica, and was wondering if any of you > encountered this strange, yet incredibly basic problem - whey plotting > 1/x (Plot[1/x, {x, 0, 100}]), the resulting graph seems to be > intersecting with the X axis... > Mathematica not always makes the axes cross at (0,0). In this example the axes cross at (0,0.2). You can set the origin with an option: Plot[1/x, {x, 0, 100}, AxesOrigin -> {0, 0}] Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: export eps There is a big difference between using SaveAs a .pdf file say, and Printing to the Adobe PDF printer with an up-to-date Adobe Acrobat! When I do Jens-Peer's first example: ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}] using the Print to Adobe PDF printer, with Adobe Acrobat 8, I obtain a file that is 49 KB in size. The Mathematica SaveAs .pdf command produces huge files of very poor quality. For example, for another test I did with a small notebook, the SaveAs command produced a pdf file of 1,762 KB (and very poor quality) compared to 85 KB for the Print to Adobe PDF command. I don't know why that is. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > hi I have a graph generated with ContourPlot3D. when I try to export it as eps, the eps file is 50MB size. I need to use the eps image in Latex. how to solve this problem > === Subject: Re: export eps > There is a big difference between using SaveAs a .pdf file say, and > Printing to the Adobe PDF printer with an up-to-date Adobe Acrobat! When > I do Jens-Peer's first example: > ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}] > using the Print to Adobe PDF printer, with Adobe Acrobat 8, I obtain a > file that is 49 KB in size. > The Mathematica SaveAs .pdf command produces huge files of very poor > quality. For example, for another test I did with a small notebook, the > SaveAs command produced a pdf file of 1,762 KB (and very poor quality) > compared to 85 KB for the Print to Adobe PDF command. > I don't know why that is. > -- > David Park try them soon. I hope this is something Wolfram will address soon. It is too > fundamental to ignore, IMO... John So far as I can tell, using Save Selection As and Print to... PDF file give file sizes which are the same (within several kB for a ~ 1.4 MB file). However, this is using Linux, and not the OS X's nifty print anything to a .pdf ability. Opening either file using Acrobat (or other .pdf readers) gives quite a pause as all of the constituent polygons are drawn and filled. Does anyone else using any Linux get the file sizes radically different? C.O. -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: export eps On 2008-07-22 17:32:14 +0930, David Park said: > There is a big difference between using SaveAs a .pdf file say, and Pri= nting > to the Adobe PDF printer with an up-to-date Adobe Acrobat! When I do > Jens-Peer's first example [...] using the Print to Adobe PDF printer, > with Adobe Acrobat 8, I obtain a file that is 49 KB in size. Interesting! This is good evidence that FixPolygon's technique could be improved and integrated directly into Mathematica's Export. Now the next questions are: (a) how to do this programatically (and in my student copy of the program, at least, the PDF needs post-processing to remove a Printed by Mathematica banner and crop the margins), and (b) if it's possible to use the same technique to get high quality EPS files too. Will === Subject: Re: export eps > There is a big difference between using SaveAs a .pdf file say, and Printing > to the Adobe PDF printer with an up-to-date Adobe Acrobat! When I do > Jens-Peer's first example: ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}] using the Print to Adobe PDF printer, with Adobe Acrobat 8, I obtain a file > that is 49 KB in size. The Mathematica SaveAs .pdf command produces huge files of very poor > quality. For example, for another test I did with a small notebook, the > SaveAs command produced a pdf file of 1,762 KB (and very poor quality) > compared to 85 KB for the Print to Adobe PDF command. I don't know why that is. -- > David Park try them soon. I hope this is something Wolfram will address soon. It is too fundamental to ignore, IMO... John === Subject: Re: export eps ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}] using the Print to Adobe PDF printer, with Adobe Acrobat 8, I obtain a file > that is 49 KB in size. The Mathematica SaveAs .pdf command produces huge files of very poor > quality. For example, for another test I did with a small notebook, the > SaveAs command produced a pdf file of 1,762 KB (and very poor quality) > compared to 85 KB for the Print to Adobe PDF command. I don't know why that is. -- > David Park David, could you give a bit more detail about the sequence of steps you're following here? In particular, are you starting with an existing PDF file already on your hard disk (which came from Mathematica originally somehow, and is bad); opening that PDF file in Acrobat; then Printing it to PDF, from Acrobat, into a _new_ (and good) PDF file? Or are you Printing to a PDF file _from Mathematica itself_ to get the good file? In my case, I'm on a Mac. On a Mac, you can print an open document to a PDF file from almost any Mac application (including Mathematica), using a print to PDF capability which I believe is part of the Mac OS, and is called or used by all these applications. But, this built-in Mac capability can not be used from Acrobat (Acrobat 7 in my case) -- it's disabled. Instead, Acrobat just tells me to use the Acrobat Foile >> Save menu command -- and I'm skeptical that just Saving a bad file that was Opened in Acrobat will convert it into a good file, or change it in any way. And I'm not finding any other Print to PDF command elsewhere in the version of Acrobat on my Mac . . . ? (There is a Reduce File Size command -- but I my impression is that it mostly strips out stuff having to do with earlier versions of PDF, or duplicate stuff, and is not sophisticated enough to dig within 3D graphics content and eliminate duplicate polygons.) === Subject: Re: export eps On 2008-07-23 19:49:17 +0930, AES said: > Or are you Printing to a PDF file _from Mathematica itself_ to get the > good file? In my case, I'm on a Mac. Me too. Print to Selection brings up a standard print dialog, from which you can save to PDF with the Apple distiller. The resulting PDF isn't quite as small as the Acrobat-generated one (seemingly -- I don't have it) but the quality is very good and the file size is definitely small enough. Will === Subject: Re: export eps > I have a graph generated with ContourPlot3D. when I try to export it as eps, the eps file is 50MB size. I need to use the eps image in Latex. how to solve this problem That all depends on what your plot actually is. Usually, when a graph is the options *PlotPoints* and *MaxRecursion* (see the online help for more details). Below are two examples of the influence of these options on the size of the resulting graphs. Module[{g}, Grid[Table[g = ContourPlot3D[Sin[3*x]*Sin[3*y]*Sin[3*z] == 1/2, {x, 0, 3}, {y, 0, 3}, {z, -1, 1}, Mesh -> None, BoxRatios -> Automatic, PlotPoints -> pp, MaxRecursion -> mr]; Export[g.eps, g]; Print[Points: , pp, , Recursions: , mr, , File Size (MB): , N[FileByteCount[g.eps]/2^20]]; g, {pp, {5, 10}}, {mr, {0, 2}}]]] Points: 5, Recursions: 0, File Size (MB): 0.0848265 Points: 5, Recursions: 2, File Size (MB): 5.90143 Points: 10, Recursions: 0, File Size (MB): 0.201566 Points: 10, Recursions: 2, File Size (MB): 22.4477 Module[{g}, Grid[Table[g = ContourPlot3D[x^4 + y^4 + z^4 - (x^2 + y^2 + z^2)^2 + 3*(x^2 + y^2 + z^2) == 3, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, ContourStyle -> Directive[Orange, Opacity[0.8], Specularity[White, 30]], PlotPoints -> pp, MaxRecursion -> mr]; Export[g.eps, g]; Print[Points: , pp, , Recursions: , mr, , File Size (MB): , N[FileByteCount[g.eps]/2^20]]; g, {pp, {20, 40}}, {mr, {0, 2}}]]] Points: 20, Recursions: 0, File Size (MB): 1.73392 Points: 20, Recursions: 2, File Size (MB): 4.47856 Points: 40, Recursions: 0, File Size (MB): 7.84393 Points: 40, Recursions: 2, File Size (MB): 19.5442 === Subject: Re: export eps I have used both functions MaxRecursion and PlotPoints to get the problem solved. The resulting file is 1.30MB (the original one without using funtions was 50MB). === Subject: Re: export eps > On Jul 20, 5:58 am, Jean-Marc Gulliet I have a graph generated with ContourPlot3D. > when I try to export it aseps, theepsfile is 50MB size. > I need to use theepsimage in Latex. > how to solve this problem > Usually, when a graph is > the options *PlotPoints* and *MaxRecursion* Yes, Jean-Marc, but what if one is not setting PlotPoints nor > MaxRecursion to an unusually high number? What to do then about these > large graphics files? IMO, this is a very dissatisfying unresolved feature of v6 over 5 > that I am very surprised (and disappointed) has not been resolved at > this late date. When I Save Selection As... either PDF or EPS of a simple Plot3D[Sin[x^2+y^2],{x,-2,2},{y,-2,2}] I get PDF's that are about 700K and EPS that are almost 4 mb. These > are huge file sizes---especially relative to how small these files > were in v5. Ugh. Indeed, the simple p3D=Plot3D[Sin[x^2+y^2],{x,-2,2},{y,-2,2}] Export[p3D.pdf,p3D] gives you an unusable .pdf: The exported file contains lots of spurious white polygons filling flat faces. The only work-around I've found is to export in bitmap (.png for instance) and then convert it to pdf or eps (?!) A. Verga === Subject: Re: export eps On Jul 20, 5:58 am, Jean-Marc Gulliet I have a graph generated with ContourPlot3D. > when I try to export it aseps, theepsfile is 50MB size. > I need to use theepsimage in Latex. > how to solve this problem Usually, when a graph is > the options *PlotPoints* and *MaxRecursion* Yes, Jean-Marc, but what if one is not setting PlotPoints nor MaxRecursion to an unusually high number? What to do then about these large graphics files? IMO, this is a very dissatisfying unresolved feature of v6 over 5 that I am very surprised (and disappointed) has not been resolved at this late date. When I Save Selection As... either PDF or EPS of a simple Plot3D[Sin[x^2+y^2],{x,-2,2},{y,-2,2}] I get PDF's that are about 700K and EPS that are almost 4 mb. These are huge file sizes---especially relative to how small these files were in v5. Ugh. === Subject: Re: export eps On 2008-07-21 17:58:36 +0930, J Davis said: > When I Save Selection As... either PDF or EPS of a simple Plot3D[Sin[x^2+y^2],{x,-2,2},{y,-2,2}] I get PDF's that are about 700K and EPS that are almost 4 mb. These > are huge file sizes---especially relative to how small these files > were in v5. Hi J, Check out the fixpolygons package: my co-author to fix this exact problem. Not only are the graphics huge, they display very poorly on-screen and when printed. The problem is that the Mathematica graphic contains every polygon used in the mesh to generate the plot, even if they are the same colour and next to each other. The package provides a function that literally just merges these adjacent polygons into one. It's not exactly lightning quick, however. Hope this helps, Will === Subject: Re: export eps since you don't give us an example I can only try to reduce the size with my own example plt = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}]; FileInformation[Export[i:/temp/ctest.eps, plt]] gives ByteCount -> 2688623} while plt1 = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}, MaxRecursion -> 0, PlotPoints -> 64, Method -> {Refinement -> {CellDecomposition -> Quad}}] FileInformation[Export[i:/temp/ctest1.eps, plt1]] gives ByteCount -> 679263} the last file is nearly 4 times smaller and plt2 = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}, MaxRecursion -> 0, PlotPoints -> 32, Method -> {Refinement -> {CellDecomposition -> Quad}}]; FileInformation[Export[i:/temp/ctest2.eps, plt2]] gives a nearly 9 times smaller *.eps file. So you have to play around a with the PlotPoints and MaxRecursions option. How ever since the refinement is adaptive, the size reduction depend on the function you try to plot. Hope that helps Jens > hi I have a graph generated with ContourPlot3D. when I try to export it as eps, the eps file is 50MB size. I need to use the eps image in Latex. how to solve this problem > === Subject: Re: export eps This may be a little off topic: I browsed through the documentation, but could not find which Methods are possible and what they mean. Can anyone give me a hint where all possible setting of Method are listed including a description of their meaning? since you don't give us an example I can only try to reduce the size > with my own example plt = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}]; > FileInformation[Export[i:/temp/ctest.eps, plt]] gives > ByteCount -> 2688623} while plt1 = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}, > MaxRecursion -> 0, PlotPoints -> 64, > Method -> {Refinement -> {CellDecomposition -> Quad}}] > FileInformation[Export[i:/temp/ctest1.eps, plt1]] > gives ByteCount -> 679263} the last file is nearly 4 times smaller and plt2 = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}, > MaxRecursion -> 0, PlotPoints -> 32, > Method -> {Refinement -> {CellDecomposition -> Quad}}]; > FileInformation[Export[i:/temp/ctest2.eps, plt2]] gives a nearly 9 times smaller *.eps file. So you have to play around a with the PlotPoints and MaxRecursions > option. How ever since the refinement is adaptive, the size reduction depend on > the function you try to plot. Hope that helps > Jens >> hi >> I have a graph generated with ContourPlot3D. >> when I try to export it as eps, the eps file is 50MB size. >> I need to use the eps image in Latex. >> how to solve this problem > Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Inheriting options - is there a way? Is there a way to define a function so that it will inherit all the options - or a spcified subset of the options - of some other function - either another user defined function or a built-in Mathematica function - without explicity having to define all the optoins that are inherited? Don === Subject: Re: Inheriting options - is there a way? > Is there a way to define a function so that it will inherit all the options - > or a spcified subset of the options - of some other function - either another user defined function or a built-in Mathematica function - without explicity having to define all the optoins that are inherited? The following will make f inherit all options of Plot and the default values that are set at the time this is executed: Options[f]=Options[Plot] Test: f[OptionsPattern[]]:=OptionValue[Ticks] f[Ticks->None] One could try to use SetDelayed (:=) so that the defaults for f's options reflect the current settings of Plot, but this works only until one does a SetOptions[f,...]. To make the behaviour more consistent in that case would require some extra work... hth, albert === Subject: Re: DatabaseLink and OpenOffice Base I've found the answer to my own question at http://marc.info/?l=hsqldb-user&m=119751397311432&w=2 If this is done then a .m file created along the lines of the examples (eg publisher.m)and saved in one of the DatabaseResources folders it works. Ian === Subject: Re: Non linear system >I am employed at the resolution of a system not linear equations >with 23 equations and 23 variables. >All the equations are of the form: >X=k*y*x+k*z*x Where k are constant and x and z variables. This isn't an equation in Mathematica syntax. This expression assigns the results of k*y*x+k*z*x to X. If this is the actual expression you gave NSolve to work with then you will need to use Equal (==) not Set (=). Also, your title indicates you are trying to solve a non-linear system yet your example is linear since X is not x. Perhaps you meant an equation (using Mathematica syntax) in the form of x == k*y*x+k*z*x rather than what you posted. But since this reduces to 1 == k*y+k*z which is still linear. Clearly, there is something else missing or wrong. >I use for resolution the function Nsolve, but I do not obtain >solution, Note there is no built-in function Nsolve. The built-in function is NSolve. >What function might I use? There really is no way to answer this without more detail. But based on what you posted, my guess is you have not used syntax consistent with what you intend or want. === Subject: Re: On default numerical precision http://reference.wolfram.com/mathematica/ref/$Pre.html http://reference.wolfram.com/mathematica/ref/$Post.html $Pre is a global variable whose value, if set, is applied to every input expression. $Post is a global variable whose value, if set, is applied to every output expression. Does this mean that one needs to set both variables to maintain precision throughout a computational sesion? $Pre = ( #1 /. a_Real :> SetPrecision[a, 32]) &; $Post = ( #1 /. a_Real :> SetPrecision[a, 32]) &; Sergio PS. I am trying this stuff on a computer having In[1]:= $Version > I am missing but here are the results of following > the sugested approach: In[1]:= $Post = ( # /. a_Real :> NumberForm[a, {32, 16}]) &; In[2]:= a=2. Out[2]//NumberForm= 2. In[3]:= b=3. Out[3]//NumberForm= 3. In[4]:= a*b Out[4]//NumberForm= 6. But the following form works the way I was looking > for: In[5]:= $Post =. In[6]:= $Post Out[6]= $Post In[7]:= $Post = ( # /. a_Real :> SetPrecision[a, 32]) &; In[8]:= a=2. Out[8]= 2.0000000000000000000000000000000 In[9]:= b=3. Out[9]= 3.0000000000000000000000000000000 In[10]:= a*b Out[10]= 6.0000000000000000000000000000000 > Sergio On Jul 19, 4:49 am, Jens-Peer Kuska $Post = ( # /. a_Real :> NumberForm[a, {32, 16}]) &; > Jens > Hello all, > I am wonderin on how to change the mathematica default printing > precision, so I don't have to type on any defined constant the > required precision, like `30 in: > In[1]:= a=2.3`30; b=2.1`30; > In[2]:= a*b > Out[2]= 4.83000000000000000000000000000 > I would like to be able to do: > a=2.3; b=2.1; and obtain > a*b = 4.83000000000000000000000000000 > Sergio > PS. Apparently the internal variable $Pre could be set to do that, but > the respective help page [ http://reference.wolfram.com/mathematica/ref/$Pre.html > ] is not clear about how to do that. === Subject: Re: On default numerical precision > PS. Apparently the internal variable $Pre could be set to do that well, with my limited mathematica-knowledge, I can do setprec[new_]:=NumberForm[new,{32,16}]; $Pre=setprec; Seems to work, though output is given as Out//NumperForm === Subject: Re: On default numerical precision I am missing but here are the results of following the sugested approach: In[1]:= $Post = ( # /. a_Real :> NumberForm[a, {32, 16}]) &; In[2]:= a=2. Out[2]//NumberForm= 2. In[3]:= b=3. Out[3]//NumberForm= 3. In[4]:= a*b Out[4]//NumberForm= 6. But the following form works the way I was looking for: In[5]:= $Post =. In[6]:= $Post Out[6]= $Post In[7]:= $Post = ( # /. a_Real :> SetPrecision[a, 32]) &; In[8]:= a=2. Out[8]= 2.0000000000000000000000000000000 In[9]:= b=3. Out[9]= 3.0000000000000000000000000000000 In[10]:= a*b Out[10]= 6.0000000000000000000000000000000 Sergio On Jul 19, 4:49 am, Jens-Peer Kuska $Post = ( # /. a_Real :> NumberForm[a, {32, 16}]) &; Jens > Hello all, > I am wonderin on how to change the mathematica default printing > precision, so I don't have to type on any defined constant the > required precision, like `30 in: > In[1]:= a=2.3`30; b=2.1`30; > In[2]:= a*b > Out[2]= 4.83000000000000000000000000000 > I would like to be able to do: > a=2.3; b=2.1; and obtain > a*b = 4.83000000000000000000000000000 > Sergio > PS. Apparently the internal variable $Pre could be set to do that, but > the respective help page [ http://reference.wolfram.com/mathematica/ref/$Pre.html > ] is not clear about how to do that. === Subject: Re: On default numerical precision > I am missing but here are the results of following > the sugested approach: In[1]:= $Post = ( # /. a_Real :> NumberForm[a, {32, 16}]) &; In[2]:= a=2. Out[2]//NumberForm= 2. In[3]:= b=3. Out[3]//NumberForm= 3. In[4]:= a*b Out[4]//NumberForm= 6. What version of Mathematica do you use? Jens-Peer's solution works fine on my system (64-bit Intel Core 2 Duo Mac OS X Leopard 1.5.4 Mathematica 6.0.3). In[1]:= $Post =. $Post = #1 /. a_Real :> NumberForm[a, {32, 30}] & ; a = 2. Precision[%] Precision[a] a = 0.3 b = 0.7 a*b Out[3]//NumberForm= 2.000000000000000000000000000000 Out[4]= MachinePrecision Out[5]= MachinePrecision Out[6]//NumberForm= 0.300000000000000000000000000000 Out[7]//NumberForm= 0.700000000000000000000000000000 Out[8]//NumberForm= 0.210000000000000000000000000000 > But the following form works the way I was looking > for: In[5]:= $Post =. In[6]:= $Post Out[6]= $Post In[7]:= $Post = ( # /. a_Real :> SetPrecision[a, 32]) &; In[8]:= a=2. Out[8]= 2.0000000000000000000000000000000 In[9]:= b=3. Out[9]= 3.0000000000000000000000000000000 In[10]:= a*b Out[10]= 6.0000000000000000000000000000000 Are you hundred percent sure that changing the precision of result is the thing to do if what you want is just more zeros to your display? What the above does is evaluating a numeric expression according to the rules and precision of hardware floating-point arithmetic (lowest precision but fastest computational model out of the three Mathematica implements), then Mathematica converts the result/output to higher precision according to the arbitrary-precision model. In other words, you upcast real numbers from lower to higher precision which might lead to some surprising result to say the least. (Be sure to test thoroughly your solution before using it for real work.) In[9]:= $Post =. $Post = #1 /. a_Real :> SetPrecision[a, 30] & ; a = 2. Precision[%] Precision[a] a = 0.3 b = 0.7 a*b Out[11]= 2.00000000000000000000000000000 Out[12]= 30.0000000000000000000000000000 Out[13]= MachinePrecision Out[14]= 0.299999999999999988897769753748 Out[15]= 0.699999999999999955591079014994 Out[16]= 0.209999999999999992228438827624 Sergio > On Jul 19, 4:49 am, Jens-Peer Kuska $Post = ( # /. a_Real :> NumberForm[a, {32, 16}]) &; >> Jens > Hello all, > I am wonderin on how to change the mathematica default printing > precision, so I don't have to type on any defined constant the > required precision, like `30 in: > In[1]:= a=2.3`30; b=2.1`30; > In[2]:= a*b > Out[2]= 4.83000000000000000000000000000 > I would like to be able to do: > a=2.3; b=2.1; and obtain > a*b = 4.83000000000000000000000000000 > Sergio > PS. Apparently the internal variable $Pre could be set to do that, but > the respective help page [ http://reference.wolfram.com/mathematica/ref/$Pre.html > ] is not clear about how to do that. === Subject: Threading over matrices How can I get evaluations to thread over matrices with conditional functions? Here's examples that show the behaviour that's really frustrating me. Create a couple of matrices: x = Table[Random[],{3},{4}]; y = Table[Random[],{3},{4}]; a=0.5; (These are example values I would like the following to apply to lists of any dimension.) When you add them they create a result with the same dimensions where each element corresponds to the input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y x > a I would have liked those to produce a matrix of corresponding True and False results, and then something like: If[x > y, 1/x, x - y] Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, Thread, Apply, Distribute, ...) and this archive, where there are similar enquiries but none that match. Perhaps I'm looking in the wrong place - I expect there's someone who can help. Robert === Subject: Re: Threading over matrices it seems MapThread and Listable are the key functions I need practice with. Robert > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: === Subject: Re: Threading over matrices Hi Robert, you can make your functions thread over arguments by setting the Listable attribute. In[1]:= SetAttributes[myGreater,Listable] In[2]:= myGreater[x_,y_] := x>y In[3]:= x = Table[Random[],{3},{4}]; In[4]:= y = Table[Random[],{3},{4}]; In[5]:= a=0.5 Out[5]= 0.5 In[6]:= myGreater[ x, a*y ] Out[6]= {{True, True, True, True}, {False, True, True, True}, > {True, False, False, True}} See for example Sin In[7]:= Attributes[Sin] Out[7]= {Listable, NumericFunction, Protected} Hope this helps, Oliver > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; > a=0.5; (These are example values I would like the following > to apply to lists of any dimension.) > When you add them they create a result with the same > dimensions where each element corresponds to the > input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or > more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, > Thread, Apply, Distribute, ...) and this archive, where there > are similar enquiries but none that match. Perhaps I'm looking > in the wrong place - I expect there's someone who can help. Robert === Subject: Re: Threading over matrices What should x > y mean when x and y are matrices (or just lists of numbers, or higher-dimensional tables)? I presume that, for your If[x > y,...] example, you would NOT, in fact, want x > y for matrices simply to act element by element, since you'd just get another matrix of True / False answers, and that would hardly be a suitable first argument for an If. Such an elementwise comparison, with result again a matrix, would be the natural analog of what happens with +, in other words, giving > the Attribute of being Listable. So I doubt that you really want what you seem to suggest! So perhaps you'd expect the result to be a single True or False -- True in case all the individual, elementwise comparisons give True. That's easy to make happen: And @@ Flatten[Thread /@ Thread[x > y]] But maybe you, or somebody else using such a computation, wants something else, namely whether all the elements of SOME row of x are greater than all the elements of the corresponding row of y. Or ditto for columns instead of rows. So it would seem that one reason for Mathematica NOT automatically threading > over lists and matrices is that there is no clear-cut semantics for the result. A deeper answer is that the overall language design of Mathematica does not facilitate such things. The trouble begins with the fact that matrices and higher-dimensional tables are just lists of lists, or lists of lists of lists, etc., rather than primitive types of objects. For easier, nearly automatic treatment of the sort of thing you are asking, you would really want a language where arbitrary dimension arrays are primitive kinds of objects; where functions have rank; and where you can change at will the rank upon which the functions operate. There are such languages (J is one). But I know of no such language that also has the symbolic capabilities of Mathematica. > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; [Some functions act element-by-element] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or > more usefully how to do what I would like them to do. -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Threading over matrices > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; > a=0.5; (These are example values I would like the following > to apply to lists of any dimension.) > When you add them they create a result with the same > dimensions where each element corresponds to the > input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't Because they don't have the attribute Flat. > or > more usefully how to do what I would like them to do. There are a variety of ways to do this, and I'm sure you'll see a lot of varying responses, personally I use MapThread in such situations: MapThread[>,{x,y},2] or MapThread[>,{x,a},2] Ssezi === Subject: Re: Threading over matrices x = Table[Random[], {3}, {4}]; y = Table[Random[], {3}, {4}]; a = 0.5; You need to get the Listable Attribute for your functions. Less is not Listable, so let's define our own Less that is. SetAttributes[MyLess, Listable] MyLess[p_, q_] := p < q x~MyLess~y And for the other two functions: SetAttributes[f1, Listable] f1[x_, y_] := If[x < y, 1/x, x - y] x~f1~y SetAttributes[f2, Listable] f2[x_, y_] := Piecewise[{{1, x == a}, {x^2, x > a}}, x y^2] x~f2~y -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; > a=0.5; (These are example values I would like the following > to apply to lists of any dimension.) > When you add them they create a result with the same > dimensions where each element corresponds to the > input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or > more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, > Thread, Apply, Distribute, ...) and this archive, where there > are similar enquiries but none that match. Perhaps I'm looking > in the wrong place - I expect there's someone who can help. Robert === Subject: Re: Threading over matrices You may try MapThread[] For example: Create the data x = RandomReal[{0, 1}, {3, 4}] y = RandomReal[{0, 1}, {3, 4}] {{0.0617457, 0.895605, 0.766934, 0.0769308}, {0.226479, 0.0894829, 0.563185, 0.789292}, {0.0419649, 0.823764, 0.597748, 0.513526}} {{0.610528, 0.955936, 0.999041, 0.0561156}, {0.59444, 0.375375, 0.659419, 0.205936}, {0.278044, 0.874925, 0.532864, 0.799205}} Define the desired function f, f = If[#1 > #2, 1/#1, #1 - #2] & Use MapThread to apply f to each pair {x(i,j),y(i,j)} of numvers: MapThread[f, {x, y}, 2] You get the matrix: {{-0.548783, -0.0603309, -0.232108, 12.9987}, {-0.367961, -0.285892, -0.0962331, 1.26696}, {-0.236079, -0.0511604, 1.67295, -0.285678}} Alberto Verga > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; > a=0.5; (These are example values I would like the following > to apply to lists of any dimension.) > When you add them they create a result with the same > dimensions where each element corresponds to the > input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or > more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, > Thread, Apply, Distribute, ...) and this archive, where there > are similar enquiries but none that match. Perhaps I'm looking > in the wrong place - I expect there's someone who can help. Robert === Subject: Re: Threading over matrices The reason that Cos, Sin etc work is because they have Attribute Listable. (You can see this by typing Attributes[Cos], etc.) Your own custom functions, by default, do not. (Nor does Greater (>) which explains why x>y etc do not work). There are at least two relatively easy ways to create a function with Attribute Listable. (1) Clear[f]; SetAttributes[f,Listable]; f[x_,y_]:=If[x>y,1/x,x-y] (2) Use a pure function. Function[{x,y},If[x>y,1/x,x-y],{Listable}][x,y] or when you don't know how many arguments will be passed Function[Null, Greater[##],{Listable}][x,y] or if you need to reuse the function you can do f= Function[Null, Greater[##],{Listable}]; f[x,y] (The trick of using Null as the first argument in Function in order to use # (or #2 or ## as required) in the definition, followed by the list of Attributes is not documented anywhere that I could find, but is a very useful trick.) Derek === Subject: Re: Threading over matrices One (possibly unsafe, because of side-effects of changing built-in functions) is to change the Attributes of Greater to Listable. More experienced people on this list will no doubt give you safer answers, but this works for now: In[1]:= x = Table[Random[], {3}, {4}]; y = Table[Random[], {3}, {4}]; a = 0.5; In[6]:= x > y Out[6]= {{0.01432836995516749, 0.09515407173910441, 0.48841843475140667, 0.3395359448842172}, {0.3986715877183224, 0.5711689325446518, 0.8271242358431401, 0.024686794108350518}, {0.04448891091931848, 0.883241018061436, 0.18041741376355377, 0.5897676139414311}} > {{0.11203174432553262, 0.4876408786826164, 0.6582974159811842, 0.2449933028313157}, {0.49076245925119527, 0.6832411898014257, 0.11689814214195506, 0.9360252255085725}, {0.3472609604891661, 0.9945840449839825, 0.3323321824476469, 0.6419687904506073}} In[7]:= Unprotect[Greater] SetAttributes[Greater, Listable] Out[7]= {Greater} In[9]:= x > y Out[9]= {{False, False, False, True}, {False, False, True, False}, {False, False, False, False}} Of course, such modifications would have to be done to other boolean operators if you wanted to use them, such as Equal and GreaterEqual, etc. C.O. On Tuesday 22 July 2008 01:57:45 Robert > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; > a=0.5; (These are example values I would like the following > to apply to lists of any dimension.) > When you add them they create a result with the same > dimensions where each element corresponds to the > input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or > more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, > Thread, Apply, Distribute, ...) and this archive, where there > are similar enquiries but none that match. Perhaps I'm looking > in the wrong place - I expect there's someone who can help. Robert -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Threading over matrices x = Table[Random[], {3}, {4}]; y = Table[Random[], {3}, {4}]; a = 0.5; a) If[x > y, 1/x, x - y] with MapThread[If[#1 > #2, 1/#1, #1 - #2] &, {x, y}, 2] b) MapThread[ Piecewise[{{1, #1 == a}, {#1^2, #1 > a}}, #1 #2^2] &, {x, y}, 2] Jens > How can I get evaluations to thread over matrices with > conditional functions? > Here's examples that show the behaviour that's really > frustrating me. > Create a couple of matrices: x = Table[Random[],{3},{4}]; > y = Table[Random[],{3},{4}]; > a=0.5; (These are example values I would like the following > to apply to lists of any dimension.) > When you add them they create a result with the same > dimensions where each element corresponds to the > input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y > x > a I would have liked those to produce a matrix of corresponding > True and False results, and then something like: If[x > y, 1/x, x - y] > Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or > more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, > Thread, Apply, Distribute, ...) and this archive, where there > are similar enquiries but none that match. Perhaps I'm looking > in the wrong place - I expect there's someone who can help. Robert === Subject: Curved edges for GraphPlot? Hi all, Is there a way to ask GraphPlot to generate network graphs with curved edges instead of straight ones, either user-defined curves or just some random curves? Can I put something in EdgeRenderingFunction to Sam === Subject: Re: how to read such kind of list? Although there are probably better ways, I would use Import rather than ReadList Something like the following ... list = Import[/Users/..../test.txt, Table] Out[45] = {{The, stat, results, of, Quantum, Dots, of, file, :, D:ProGramqd, 2.1.21.TXT}, {}, {totally, 110, QDs, were, segmented}, {}, {QD, number, per, cm^2:, 4.36659*10^10, per, cm^2}, {mean, height:, 5.29252, nm}, {mean, diameter:, 28.8015, nm}, {mean, distance:, 33.3098, nm}, {area, coverage:, 0.291367}, {volume, density:, 0.545079, nm^3, per, nm^2}, {mean, orientation:, 1.2718, degree, with, x-axis}, {mean, MajorAxisLength:, 28.3723, nm}, {mean, MinorAxisLength:, 20.4584, nm}, {}, {Diameter, Height, Area, MajorAxisLength, MinorAxisLength, Orientation, CentroidX, CentroidY, Volume, Distance}, {30.6543, 5.68231, 738.026, 31.1171, 23.1063, -1.62224, 15.3199, 215.548, 1593.05, 48.7416}, {26.0824, 5.76352, 534.3, 25.9359, 20.2485, -27.2306, 10.9906, 349.057, 1109.33, 30.6338}, {16.9929, 2.05731, 226.789, 15.9034, 11.4045, -80.5826, 5.92925, 419.607, 104.23, 32.4718}, {33.1842, 5.23201, 864.874, 33.2583, 23.8731, 2.54486, 33.0374, 170.141, 1416.6, 40.4787}, {34.6983, 6.37284, 945.596, 35.0717, 25.0663, 0.415529, 35.6798, 386.624, 1878.84, 27.9015}, {32.2872, 6.18688, 818.748, 31.8627, 23.3669, -8.17129, 36.0545, 67.1377, 1757.76, 51.3242}} I can then manipulate the above list. For example, list[[-7 ;; -1]] Grid[%] Or, if I just want data (no headings) Grid@list[[-6 ;; -1]] I use Mathematica 6. Tom Dowling > lines) _ > The stat results of Quantum Dots of file : D:ProGramqd 2.1.21.TXT totally 110 QDs were segmented QD number per cm^2: 4.36659e+010 per cm^2 > mean height: 5.292516 nm > mean diameter: 28.801531 nm > mean distance: 33.309811 nm > area coverage: 0.291367 > volume density: 0.545079 nm^3 per nm^2 > mean orientation: 1.271796 degree with x-axis > mean MajorAxisLength: 28.372259 nm > mean MinorAxisLength: 20.458377 nm Diameter Height Area MajorAxisLength MinorAxisLength Orientation > CentroidX CentroidY Volume Distance > 30.654263 5.682305 738.025950 31.117139 23.106343 > -1.622242 15.319892 > 215.548346 1593.049175 48.741649 > 26.082407 5.763518 534.300037 25.935928 20.248467 > -27.230550 10.990649 > 349.057494 1109.325936 30.633786 > 16.992852 2.057310 226.789224 15.903377 11.404470 > -80.582608 5.929246 > 419.606587 104.229902 32.471795 > 33.184213 5.232010 864.874160 33.258266 23.873106 > 2.544861 33.037368 > 170.140864 1416.598341 40.478731 > 34.698269 6.372842 945.595748 35.071694 25.066265 > 0.415529 35.679808 > 386.624306 1878.842938 27.901502 > 32.287176 6.186880 818.747538 31.862749 23.366885 > -8.171290 36.054502 > 67.137732 1757.760754 51.324165 _ ___ I have dozens of such kind of lists and actually what i'm interested > is the data not these letters.However i can't figure out by > Read[**.txt,Number,RecordList->True] > How to sovle this problem? > === Subject: Re: how to read such kind of list? I tried: ReadList[**.txt,Word] and Partition to get sublists. Obviously, yours is the best way. Pity there is no such command Grid in V.5.0 I use, but i can figure it out On 7=D4=C222=C8=D5, =CF=C2=CE=E76=CA=B139=B7=D6, Thomas Dowling ReadList Something like the following ... list = Import[/Users/..../test.txt, Table] Out[45] = {{The, stat, results, of, Quantum, Dots, of, > file, > :, D:ProGramqd, 2.1.21.TXT}, {}, {totally, 110, QDs, > were, segmented}, {}, {QD, number, per, cm^2:, > 4.36659*10^10, per, cm^2}, {mean, height:, 5.29252, > nm}, {mean, diameter:, 28.8015, nm}, {mean, distance:, > 33.3098, nm}, {area, coverage:, 0.291367}, {volume, > density:, 0.545079, nm^3, per, nm^2}, {mean, > orientation:, 1.2718, degree, with, x-axis}, {mean, > MajorAxisLength:, 28.3723, nm}, {mean, MinorAxisLength:, > 20.4584, nm}, {}, {Diameter, Height, Area, > MajorAxisLength, MinorAxisLength, Orientation, CentroidX, > CentroidY, Volume, Distance}, {30.6543, 5.68231, 738.026, > 31.1171, 23.1063, -1.62224, 15.3199, 215.548, 1593.05, > 48.7416}, {26.0824, 5.76352, 534.3, 25.9359, 20.2485, -27.2306, > 10.9906, 349.057, 1109.33, 30.6338}, {16.9929, 2.05731, 226.789, > 15.9034, 11.4045, -80.5826, 5.92925, 419.607, 104.23, > 32.4718}, {33.1842, 5.23201, 864.874, 33.2583, 23.8731, 2.54486, > 33.0374, 170.141, 1416.6, 40.4787}, {34.6983, 6.37284, 945.596, > 35.0717, 25.0663, 0.415529, 35.6798, 386.624, 1878.84, > 27.9015}, {32.2872, 6.18688, 818.748, 31.8627, 23.3669, -8.17129, > 36.0545, 67.1377, 1757.76, 51.3242}} I can then manipulate the above list. For example, list[[-7 ;; -1]] Grid[%] Or, if I just want data (no headings) Grid@list[[-6 ;; -1]] I use Mathematica 6. Tom Dowling === Subject: how to read such kind of list? lines) _ The stat results of Quantum Dots of file : D:ProGramqd 2.1.21.TXT totally 110 QDs were segmented QD number per cm^2: 4.36659e+010 per cm^2 mean height: 5.292516 nm mean diameter: 28.801531 nm mean distance: 33.309811 nm area coverage: 0.291367 volume density: 0.545079 nm^3 per nm^2 mean orientation: 1.271796 degree with x-axis mean MajorAxisLength: 28.372259 nm mean MinorAxisLength: 20.458377 nm Diameter Height Area MajorAxisLength MinorAxisLength Orientation CentroidX CentroidY Volume Distance 30.654263 5.682305 738.025950 31.117139 23.106343 -1.622242 15.319892 215.548346 1593.049175 48.741649 26.082407 5.763518 534.300037 25.935928 20.248467 -27.230550 10.990649 349.057494 1109.325936 30.633786 16.992852 2.057310 226.789224 15.903377 11.404470 -80.582608 5.929246 419.606587 104.229902 32.471795 33.184213 5.232010 864.874160 33.258266 23.873106 2.544861 33.037368 170.140864 1416.598341 40.478731 34.698269 6.372842 945.595748 35.071694 25.066265 0.415529 35.679808 386.624306 1878.842938 27.901502 32.287176 6.186880 818.747538 31.862749 23.366885 -8.171290 36.054502 67.137732 1757.760754 51.324165 I have dozens of such kind of lists and actually what i'm interested is the data not these letters.However i can't figure out by Read[**.txt,Number,RecordList->True] How to sovle this problem? === Subject: Re: how to read such kind of list? > lines) > _ > The stat results of Quantum Dots of file : D:ProGramqd 2.1.21.TXT totally 110 QDs were segmented QD number per cm^2: 4.36659e+010 per cm^2 > mean height: 5.292516 nm > mean diameter: 28.801531 nm > mean distance: 33.309811 nm > area coverage: 0.291367 > volume density: 0.545079 nm^3 per nm^2 > mean orientation: 1.271796 degree with x-axis > mean MajorAxisLength: 28.372259 nm > mean MinorAxisLength: 20.458377 nm Diameter Height Area MajorAxisLength MinorAxisLength Orientation > CentroidX CentroidY Volume Distance > 30.654263 5.682305 738.025950 31.117139 23.106343 -1.622242 15.319892 > 215.548346 1593.049175 48.741649 > 26.082407 5.763518 534.300037 25.935928 20.248467 -27.230550 10.990649 > 349.057494 1109.325936 30.633786 > 16.992852 2.057310 226.789224 15.903377 11.404470 -80.582608 5.929246 > 419.606587 104.229902 32.471795 > 33.184213 5.232010 864.874160 33.258266 23.873106 2.544861 33.037368 > 170.140864 1416.598341 40.478731 > 34.698269 6.372842 945.595748 35.071694 25.066265 0.415529 35.679808 > 386.624306 1878.842938 27.901502 > 32.287176 6.186880 818.747538 31.862749 23.366885 -8.171290 36.054502 > 67.137732 1757.760754 51.324165 > _ ___ I have dozens of such kind of lists and actually what i'm interested > is the data not these letters.However i can't figure out by > Read[**.txt,Number,RecordList->True] > How to sovle this problem? > I would tackle this by reading in the data as a list of strings: ReadList[file,String] The first few items of the resultant list could be handled individually to extract the numerical values - say by using a string pattern to extract just the number and the using ToExpression to convert the string to a number. You could then use Drop to strip off the front of the list and leave only the array of numbers (I am assuming that the lines do not alternate in length as they appear to do, but that they are uniform lines of data. This data could be converted thus: Map[ImportString[#,List]&,remaininglist] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Threading over matrices Use MapThread MapThread[#1 > #2 &, {x, y}, 2] MapThread[If[#1 > #2, 1/#1, #1 - #2] &, {x, y}, 2] MapThread[Piecewise[ {{1, #1 == a}, {#1^2, #1 > a}}, #1* #2^2] &, {x, y}, 2] How can I get evaluations to thread over matrices with conditional functions? Here's examples that show the behaviour that's really frustrating me. Create a couple of matrices: x = Table[Random[],{3},{4}]; y = Table[Random[],{3},{4}]; a=0.5; (These are example values I would like the following to apply to lists of any dimension.) When you add them they create a result with the same dimensions where each element corresponds to the input elements x + a y And some functions do similar Cos[x] + Sin[a y] But some don't, e.g. x > y x > a I would have liked those to produce a matrix of corresponding True and False results, and then something like: If[x > y, 1/x, x - y] Piecewise[{{1,x==a},{x^2,x>a}},x y^2] to produce a matrix of results corresponding to each element. They don't - I haven't managed to find out why they don't or more usefully how to do what I would like them to do. I have searched Help on all the likely commands (I think: Map, Thread, Apply, Distribute, ...) and this archive, where there are similar enquiries but none that match. Perhaps I'm looking in the wrong place - I expect there's someone who can help. Robert === Subject: NDSolve[] with error dsfun: Hello Mathematica Friends, When I used NDSolve[] to a set of equations (one equation used an interpolating function), I got an error message saying, NDSolve::dsfun: {InterpolatingFunction[{{0.,1.}},<<3>>,{Automatic}][t]} cannot be used as a function. >> Error message details show that somehow function is replaced by string or number. But by replacing with a number still means a meaningful ODE (constant term), and expect it to solve with no problem. But with string, yes there is a problem. But I really don't know why a well defined interpolating function has such a problem. The below given code (for Mathematica version 6) takes only less than 30 seconds to run. So please try it. Gopinath University of Oklahoma Below is the code: (* Starts here *) mperl = 2303; ag = 9.81; bs = 3.757; ht = 2.1; moi = (bs ht^3)/12; emod = 2.87*10^9; spload = 508329.675; waload = 127082.41875; load = spload + waload; Print[The total load is , load]; tmass = load/ag; spmass = spload/ag; wamass = waload/ag; Print[The sprung load of vehicle (Chassis) is , spload, and sprung mass is , spmass]; Print[The unsprung load of vehicle (Wheel/Axle) is , waload, and unsprung mass is , wamass]; Print[The total load of vehicle is , load, and the total mass is , tmass]; logdampdecbeam = 0.5; len = 25; vel = 30; (* default is 4.778 *) Tfact = len/vel; [Beta] = 1/(2 [Pi]) logdampdecbeam; deflmid = (2 load len^3)/([Pi]^4 emod moi); Print[The midspan deflection of SS beam loaded by P = , load, is , deflmid]; brK = load/deflmid; Print[Total bridge stiffness is given by , brK]; [Omega][j_] := (j^2 [Pi]^2)/len^2 Sqrt[(emod moi)/mperl]; [CapitalOmega][k_] := (k [Pi])/Tfact; vfreq = ([Pi] vel)/len; w = ([Pi] vel)/len; (* Remove this parameter later *) Print[The natural frequency of the beam is , [Omega][1]]; sK = (0.5 [Omega][ 1])^2 spmass; (* sK is equivalent to parameter C of Fryba's and change 0.5 to some value to effect a change in srf, srf [Congruent] 0.5 *) wK = (7.071 [Omega][ 1])^2 wamass; (* wK is equivalent to parameter Subscript[K, 1] of Fryba's and change 7.071 to effect a change in wrf, wrf [Congruent] 7.071 *) fsm = 1/(2 [Pi]) Sqrt[sK/ spmass]; (* The reason fsm is defined like this instead of fsm = 0.5 [Omega][1]/(2 [Pi]) or fsm = srf [Omega][1]/(2 [Pi]) is to have flexibility to change sK later, srf [Congruent] 0.5 *) fwm = 1/(2 [Pi]) Sqrt[wK/wamass]; Print[The frequency of sprung (chassis) mass is , fsm]; Print[The frequency of unsprung (wheel-axle) mass is , fwm]; dsK = 2 0.5 spmass fsm; (* Here 0.5 stands for the value of logarithmic decrement of vehicle spring damping, dwraw [Congruent] 0.5 *) Print[The spring constant of suspension system between chassis and wheel-axle system is , sK]; Print[The viscous damping coefficient !(*SubscriptBox[C, b]) of suspension system between chassis and wheel-axle system is , dsK]; Print[The spring constant for the tire is , wK]; [Kappa] = load/(ag mperl len); Print[The mass ratio of vehicle to beam (Fryba [Chi]) is , [Kappa]]; [Kappa]1 = waload/spload; Print[The wheel-axle to chassis mass ratio (Fryba's !(*SubscriptBox[[Chi], 0])) is , [Kappa]1]; [Alpha] = vfreq/[Omega][1]; Print[The speed parameter is , [Alpha]]; srf = (2 [Pi] fsm)/[Omega][ 1]; (* srf is equivalent to Subscript[[Gamma], 2] of Fryba's and if you want to change srf, change 0.5 in sK definition *) gammasd = (sK deflmid)/load; (* gammasd is equivalent to ! *SubsuperscriptBox[([Gamma]), (2), (')] of Fryba's which can be alternatively used for defining sprung frequency parameter *) gammaud = (wK deflmid)/load; (* gammaud is equivalent to ! *SubsuperscriptBox[([Gamma]), (1), (')] of Fryba's which can be used for defining unsprung frequency parameter *) wrf = (2 [Pi] fwm)/[Omega][ 1]; (* wrf is equivalent to Subscript[[Gamma], 1] of Fryba's and if you want to change wrf, change 7.071 in wK definition *) Print[Check factor , wrf^2, should be equal to , ((1 + [Kappa]1)/( 2 [Kappa] [Kappa]1)) gammaud]; Print[Check factor , srf^2, should be equal to , ((1 + [Kappa]1)/(2 [Kappa])) gammasd]; dwraw = dsK/(2 spmass fsm); Print[srf equals , srf]; Print[wrf equals , wrf]; Print[The logarithmic decrement of vehicle spring damping is , dwraw]; Subscript[[Omega], b] = [Beta] [Omega][1]; [Omega]jd[j_] := Sqrt[([Omega][j])^2 - Subscript[[Omega], b]^2]; step = 0; nmx = 3; compareMatrices[A_?MatrixQ, B_?MatrixQ] := If[Dimensions[A] == Dimensions[B], And @@ MapThread[Greater, Flatten /@ {A, B}], Print[the matrices are not of the same dimension]]; bdefm = Table[v[im][t], {im, 1, nmx}]; bdefm1t = D[bdefm, t]; bdefm2t = D[bdefm, {t, 2}]; icsp1 = Table[bdefm[[im]] /. t -> 0, {im, 1, nmx}]; icsp2 = Table[1/Tfact bdefm1t[[im]] /. t -> 0, {im, 1, nmx}]; spld[im_, t_] := Sin[im [Pi] t]; modset = Table[[Pi]^2 [Alpha]^2 bdefm2t[[im]] + 2 [Pi]^3 [Alpha] [Beta] bdefm1t[[im]] + im^4 [Pi]^4 bdefm[[im]] - 96 spld[im, t], {im, 1, nmx}]; sol1 = Table[ NDSolve[{modset[[im]] == 0, icsp1[[im]] == 0, icsp2[[im]] == 0}, bdefm[[im]], {t, 0, 1}], {im, 1, nmx}]; bdefmsol1 = Table[Chop[bdefm[[im]] /. sol1[[im]]], {im, 1, nmx}]; Plot[bdefmsol1[[1]], {t, 0, 1}] bdefspld[x_] := !( *UnderoverscriptBox[([Sum]), (im = 1), (nmx)]((bdefmsol1[([)(im)(])] Sin[ im [Pi] x]))); (* this is the beam displacement solution we use to substitute later for iterating the vehicle beam interaction *) p1 = Plot[bdefspld[0.5], {t, 0, 1}] bdefspld[x] bdefspld[0.5] bdeftot[x_] := Flatten[Table[bdefspld[x], {t, 0, 1, 0.05}]]; bdeftot[0.5] time = Table[t, {t, 0, 1, 0.05}]; xlis = Table[xs, {xs, 0, 1, 0.1}]; gridxt = {xlis, time}; bdeftotintp = Table[Chop[bdeftot[x]], {x, 0, 1, 0.1}]; funcSPL[x_, y_] := ListInterpolation[bdeftotintp, gridxt, InterpolationOrder -> 3][x, y]; funcSPL[0.5, 0.5] bdefspld[0.5] /. t -> 0.5 definstxt = Table[Chop[funcSPL[t, t]], {t, 0, 1, 0.05}]; Print[The deflection of beam at the point of action of load is ]; definstxt // MatrixForm definstxtitr = definstxt; funcSPLitr[x_, y_] = funcSPL[x, y]; wdefitr[t_] = v1[t]; sdefitr[t_] = v3[t]; (* No v2[t] is defined in this code, just to be consistent with the sprung mass definition with 2 axle load problem in which sprung mass is denoted by v3[t] *) oldeflBeam = Table[0, {i, 0, 1, 0.1}, {j, 0, 1, 0.05}]; errdeflBeam = Table[1, {i, 0, 1, 0.1}, {j, 0, 1, 0.05}]; mxsize = Dimensions[oldeflBeam][[1]]; mtsize = Dimensions[oldeflBeam][[2]]; (* Start While/Do Loop from here *) While[compareMatrices[ Drop[Abs[errdeflBeam], {1, mxsize, mxsize - 1}, {1}], Drop[Abs[0.05 oldeflBeam], {1, mxsize, mxsize - 1}, {1}]], Print[The value of step is , step]; bdefmitr = Table[vi[im][t], {im, 1, nmx}]; bdefmitr1t = D[bdefmitr, t]; bdefmitr2t = D[bdefmitr, {t, 2}]; icon1 = Table[bdefmitr[[im]] /. t -> 0, {im, 1, nmx}]; icon2 = Table[1/Tfact bdefmitr1t[[im]] /. t -> 0, {im, 1, nmx}]; wdeficon1 = v1[t] /. t -> 0; wdeficon2 = D[v1[t], t] /. t -> 0; sdeficon1 = v3[t] /. t -> 0; sdeficon2 = D[v3[t], t] /. t -> 0; reactP[t] = (2 [Kappa] [Kappa]1 wrf^2)/( 1 + [Kappa]1) (Chop[wdefitr[t]] - Chop[funcSPLitr[t, t]]); If[step != 0, Print[After solution and before setting reaction is , reactP[t] // MatrixForm]; (* reactP[t]=Evaluate[reactP[t]]/.x_?Negative-> 0; *) reactP[t] = If[Evaluate[reactP[t]] < 0, 0]; Print[Positive/modified reaction force at loadpoint is , reactP[t] // MatrixForm]]; v3eq = v3''[t] + ([Pi]^2 srf^2)/[Alpha]^2 (v3[t] - v1[t]) + ( dwraw srf)/[Alpha] (v3'[t] - v1'[t]); v1eq = v1''[ t] - [Pi]^2/[Alpha]^2 ((1 + [Kappa]1)/( 2 [Kappa] [Kappa]1)) (1 - reactP[t]) + ([Pi]^2 srf^2)/([Alpha]^2 [Kappa]1) (v1[t] - v3[t]) + (dwraw srf)/([Kappa]1 [Alpha]) (v1'[t] - v3'[t]); modsetitr = Table[[Pi]^2 [Alpha]^2 bdefmitr2t[[im]] + 2 [Pi]^3 [Alpha] [Beta] bdefmitr1t[[im]] + im^4 [Pi]^4 bdefmitr[[im]] - Evaluate[96 reactP[t] Sin[im [Pi] t]], {im, 1, nmx}]; Print[Before block]; solitr1 = Table[NDSolve[{v3eq == 0, v1eq == 0, modsetitr[[im]] == 0, icon1[[im]] == 0, icon2[[im]] == 0, wdeficon1 == wdeficon2 == 0, sdeficon1 == sdeficon2 == 0}, {bdefmitr[[im]], wdefitr[t], sdefitr[t]}, {t, 0, 1}], {im, 1, nmx}]; bdefmitrsol1 = Table[Chop[bdefmitr[[im]] /. solitr1[[im]]], {im, 1, nmx}]; bdefsplditr[x_] := !( *UnderoverscriptBox[([Sum]), (k = 1), (nmx)]((bdefmitrsol1[([)(k)(])] Sin[ k [Pi] x]))); bdeftotitr[x_] := Flatten[Table[bdefsplditr[x], {t, 0, 1, 0.05}]]; Print[First mode contribution is given by the following plot]; Print[Plot[bdefmitrsol1[[1]], {t, 0, 1}]]; Print[Second mode contribution is given by the following plot]; Print[Plot[bdefmitrsol1[[2]], {t, 0, 1}]]; Print[Third mode contribution is given by the following plot]; Print[Plot[bdefmitrsol1[[3]], {t, 0, 1}]]; Print[Combined/effective midspan displacement is given by the following plot]; Print[p1 = Plot[bdefsplditr[0.5], {t, 0, 1}]]; Print[After block]; bdeftotintpitr = Table[Chop[bdeftotitr[x]], {x, 0, 1, 0.1}]; Print[bdeftotintpitr is , bdeftotintpitr // MatrixForm]; funcSPLitr[x_, y_] = ListInterpolation[bdeftotintpitr, gridxt, InterpolationOrder -> 3][ x, y]; definstxtitr = Table[Chop[funcSPLitr[t, t]], {t, 0, 1, 0.05}]; wdefitr[t_] = v1[t] /. solitr1[[1]]; sdefitr[t_] = v3[t] /. solitr1[[1]]; Print[Plot[wdefitr[t], {t, 0, 1}]]; Print[Plot[sdefitr[t], {t, 0, 1}]]; errdeflBeam = bdeftotintpitr - oldeflBeam; oldeflBeam = bdeftotintpitr; step = step + 1]; Print[Solution converged and errdeflBeam is not greater than 0.05 times oldeflBeam]; Table[solitr1[[im, All]], {im, 1, nmx}] // MatrixForm Print[Analysis of Solution]; (* Ends Here *) === Subject: several plots in manipulate I would like to manipulate a plot created from three different parametric plots. I display the plot with Show[plot1,plot2,plot3] (see code below). If I try this in Manipulate, the plots are displayed next to each other. I need them in a single plot. I cannot combine them in a single ParameterPlot because the options are different. Any help is very much appreciated. Cristina ---------------------------------------------------------------------------= -------------- In the plot r2=2/3. In Manipulate r2 should be between r1 and 1. r1 := 1/4 r2 := 2/3 u := Pi/3 plot1 := ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, 0, r1^4*r2^4 - 10^(-6)}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[.5, t, r]], PlotPoints -> 25, Mesh -> False] plot2 := ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, r1^4*r2^4 - 10^(-6), r1^4*r2^4 + 10^(-2)}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[1, t, r]], PlotPoints -> 45, Mesh -> False] plot3 := ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4 *r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, r1^4*r2^4 + 10^(-2), 1}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[.1, t, r]], PlotPoints -> 25, Mesh -> False] === Subject: Re: several plots in manipulate On Jul 23, 12:20 pm, Cristina Ballantine plots. I display the plot with Show[plot1,plot2,plot3] (see code below). > If I try this in Manipulate, the plots are displayed next to each other. = I > need them in a single plot. I cannot combine them in a single ParameterPl= ot > because the options are different. On my system, the following works as expected: the three plots are drawn on the same graph, though it takes few seconds for the complete rendering to be completed. (Note that I have written the expressions for the plots as function of three parameters and added the option MaxRecursion->0 to speed up computations.) With[{r1 = 1/4, u = Pi/3}, Manipulate[ Show[plot1[r1, r2, u], plot2[r1, r2, u], plot3[r1, r2, u]], {{r2, 2/3}, r1, 1}]] HTH, - Jean-Marc $Version 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) plot1[r1_, r2_, u_] := ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, 0, r1^4*r2^4 - 10^(-6)}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[.5, t, r]], PlotPoints -> 25, MaxRecursion -> 0, Mesh -> False] plot2[r1_, r2_, u_] := ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, r1^4*r2^4 - 10^(-6), r1^4*r2^4 + 10^(-2)}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[1, t, r]], PlotPoints -> 45, MaxRecursion -> 0, Mesh -> False] plot3[r1_, r2_, u_] := ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, r1^4*r2^4 + 10^(-2), 1}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[.1, t, r]], PlotPoints -> 25, MaxRecursion -> 0, Mesh -> False] With[{r1 = 1/4, u = Pi/3}, Manipulate[ Show[plot1[r1, r2, u], plot2[r1, r2, u], plot3[r1, r2, u]], {{r2, 2/3}, r1, 1} ] ] -------------- End of Code === Subject: Running programs from the command line in Mathematica Basically, I would like to run the following command from Mathematica: idl /users/burkart/idlpro/autoexportdata.bat If I type this command into a terminal (I'm running Mac OSX Leopard), it works perfectly well. However, if I try the same thing using Mathematica's Run[] command, it does not execute and I get the following result: In[9]:= Run[idl /users/burkart/idlpro/autoexportdata.bat] Out[9]= 32512 The error code Run[] produces is the same every time and I don't know what it means (might be OS-specific). The command, when executed from the terminal, is designed to self-quit after finishing. Is there some way to do what I'm trying to do? Josh Burkart === Subject: Re: Running programs from the command line in Mathematica It seems Run[] does not capture any output from the program run. It is important to realize that Run never =93captures=94 any of the output from an external command. As a result, where this output goes is purely determined by your operating system. Similarly, Run does not supply input to external commands. This means that the commands can get input through any mechanism provided by your operating system. Sometimes external commands may be able to access the same input and output streams that are used by Mathematica itself. In some cases, this may be what you want. But particularly if you are using Mathematica with a front end, this can cause considerable trouble. === Subject: Re: Running programs from the command line in Mathematica I've posted to this effect before, but normally you can capture the output from terminal commands with ReadList or Import which provide various possibilities for parsing it. Try Import[!dir, Text] (on Windows) ReadList[!dir, Record] (on Windows) Import[!ls, Lines ] (on Unix-like) ReadList[!ls, Record] (on Unix-like) The exclamation mark is essential to distinguish the command from a file name. John Jowett > It seems Run[] does not capture any output from the program run. It is important to realize that Run never =93captures=94 any of the o= utput > from an external command. As a result, where this output goes is > purely determined by your operating system. Similarly, Run does not > supply input to external commands. This means that the commands can > get input through any mechanism provided by your operating system. > Sometimes external commands may be able to access the same input and > output streams that are used by Mathematica itself. In some cases, > this may be what you want. But particularly if you are using > Mathematica with a front end, this can cause considerable trouble. === Subject: Re: Running programs from the command line in Mathematica Josh, If you do not mind me asking. What is idl? Also, can you try this: Run[/usr/bin/date] Run[idl,/users/burkart/idlpro/autoexportdata.bat] Run[/some/path/idl,/users/burkart/idlpro/autoexportdata.bat] Steven Siew Basically, I would like to run the following command from Mathematica: idl /users/burkart/idlpro/autoexportdata.bat If I type this command into a terminal (I'm running Mac OSX Leopard), it = works perfectly well. However, if I try the same thing using Mathematica's = Run[] command, it does not execute and I get the following result: In[9]:= Run[idl /users/burkart/idlpro/autoexportdata.bat] Out[9]= 32512 The error code Run[] produces is the same every time and I don't know wha= t it means (might be OS-specific). The command, when executed from the term= inal, is designed to self-quit after finishing. Is there some way to do wha= t I'm trying to do? Josh Burkart === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: First clue: funifcase2[t] If[0 <= t < 1/3, val1 + val1 xv yv^2 wdef1[t] Sin[t], If[sep/len <= t <= (2 sep)/len, val1 + val2 + val1 xv yv^2 wdef1[t] Sin[t] + val2 yv xv^2 wdef2[t] Sin[t - sep/len], If[(2 sep)/len < t <= 1, val2 + val2 yv xv^2 wdef2[t] Sin[t - sep/len]]]] involves val1 and val2 (symbolic) even though they have values. That's because: Attributes@If {HoldRest, Protected} Next clue: solifcase2=NDSolve[{y''[t]+y'[t]+y[t]-funifcase2[t]==0,y[0]==0,y'[0]==1},y,{ t,0,1}] NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >> Although it says at t == 0., NDSolve has actually done a symbolic calculation. We know that because funifcase2[0] 50 ... definitely numerical. But as we saw above, it's quite possible to get a value for funifcase2 that involves val1 and val2. To prevent this, redefine funifcase2: Clear@funifcase2 funifcase2[t_?NumericQ]=If[0<=t> NDSolve[{-funifcase2[t]+y[t]+(y^[Prime])[t]+(y^[Prime][Prime])[t]==0,y [0]==0,(y^[Prime])[0]==1},y,{t,0,1}] That's the usual cure for a lot of NDSolve problems, but as you can see, it didn't work! Why? Because Mathematica doesn't know how to differentiate If. (Surprising, isn't it?) The obvious answer is to use Piecewise and have done with it. If you'd rather teach Mathematica to differentiate If... well, good luck with that. Bobby > Hello Mathematica Friends, I am stuck with this problem, where I use NDSolve[] to solve a nested > If[] statement. The use of Piecewise[] solves with no problem, but > wanted to know if I can solve the If[] part as well. The sample code (just for demo) is shown below, which is similar to my > case. The third section is similar to my case, while the first and > second case, I kept it here, to show that NDSolve[] solves the nested > If[] with no problem. So you can directly go to the third section, > please see the comments to go to the correct section. The reason I am > posting it here, is even the Piecewise[] is not solving in my (original > problem) case. you. Gopinath > University of Oklahoma (* code starts here *) (* First section: Showing simple sine function inside NDSolve[] *) > funReg[t_] := Sin[t]; > solReg = NDSolve[{y''[t] + y'[t] + y[t] - funReg[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solReg], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}} ] > (* Here no particular time value is required for the > function,i.e.Sin[t] is valid for any time t *) > (* Second Section: Nested If[] inside NDSolve[] *) > funifcase1[t_] := > If[0 <= t < 1/3, Sin[t], > If[1/3 <= t <= 2/3, -1, If[2/3 < t <= 1, Cos[t]]]]; > Print[funifcase1 is given by , funifcase1[t]]; > solifcase1 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase1[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase1], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] > (* In the above also, the function is undetermined (I mean, dependent > on time t, which is not supplied until the NDSolve[] increments from > initial conditions step by step by some direct integration scheme, I > guess *) > (* Third case: I expect this case also to solve because it is very > similar to the above cases *) > sep = 1; > len = 3; > wdef1[t_] := y[t]; > wdef2[t_] := y[t]; > val1 = 50; > val2 = 20; > xv = 1/2; > yv = 1/5; > funifcase2[t_] := > If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > If[sep/len <= t <= (2 sep)/len, > val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > If[(2 sep)/len < t <= 1, > val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]; > funifcase3[t_] := > Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > 0 <= t < sep/len}, {val1 + val2 + > val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > sep/len <= t <= (2 sep)/len}, {val2 + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= > 1}}]; > Chop[Table[funifcase2[t], {t, 0, 1, 0.1}]] > Print[compare values, just to check the correctness of equation > above]; > Chop[Table[funifcase3[t], {t, 0, 1, 0.1}]] > Print[The definition funifcase2[t] is , funifcase2[t]]; > Print[The definition funifcase3[t] is , funifcase3[t]]; solifcase2 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase2[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > (* Plot[Evaluate[{y[t],y'[t],y''[t]}/.solifcase2],{t,0,1},PlotStyle- Automatic] *) > Print[Proceeding to solve the above equation with Piecewise > definition]; > solifcase3 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase3[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase3], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] > (* However the nested If[] does not solve, but the Piecewise[] does. > But both are same definitions and same set of equations inside of > NDSolve[]. And I expect similar behavior from NDSolve[] for these > cases *) (* code ends here *) -- DrMajorBob@longhorns.com === Subject: NDSolve[] with nested If[] and Piecewise[] usage: Hello Mathematica Friends, I am stuck with this problem, where I use NDSolve[] to solve a nested If[] statement. The use of Piecewise[] solves with no problem, but wanted to know if I can solve the If[] part as well. The sample code (just for demo) is shown below, which is similar to my case. The third section is similar to my case, while the first and second case, I kept it here, to show that NDSolve[] solves the nested If[] with no problem. So you can directly go to the third section, please see the comments to go to the correct section. The reason I am posting it here, is even the Piecewise[] is not solving in my (original problem) case. Gopinath University of Oklahoma (* code starts here *) (* First section: Showing simple sine function inside NDSolve[] *) funReg[t_] := Sin[t]; solReg = NDSolve[{y''[t] + y'[t] + y[t] - funReg[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; Plot[Evaluate[{y[t], y'[t]} /. solReg], {t, 0, 1}, PlotStyle -> {Black, {Red, Dashed}} ] (* Here no particular time value is required for the function,i.e.Sin[t] is valid for any time t *) (* Second Section: Nested If[] inside NDSolve[] *) funifcase1[t_] := If[0 <= t < 1/3, Sin[t], If[1/3 <= t <= 2/3, -1, If[2/3 < t <= 1, Cos[t]]]]; Print[funifcase1 is given by , funifcase1[t]]; solifcase1 = NDSolve[{y''[t] + y'[t] + y[t] - funifcase1[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; Plot[Evaluate[{y[t], y'[t]} /. solifcase1], {t, 0, 1}, PlotStyle -> {Black, {Red, Dashed}}] (* In the above also, the function is undetermined (I mean, dependent on time t, which is not supplied until the NDSolve[] increments from initial conditions step by step by some direct integration scheme, I guess *) (* Third case: I expect this case also to solve because it is very similar to the above cases *) sep = 1; len = 3; wdef1[t_] := y[t]; wdef2[t_] := y[t]; val1 = 50; val2 = 20; xv = 1/2; yv = 1/5; funifcase2[t_] := If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], If[sep/len <= t <= (2 sep)/len, val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], If[(2 sep)/len < t <= 1, val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]; funifcase3[t_] := Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], 0 <= t < sep/len}, {val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], sep/len <= t <= (2 sep)/len}, {val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= 1}}]; Chop[Table[funifcase2[t], {t, 0, 1, 0.1}]] Print[compare values, just to check the correctness of equation above]; Chop[Table[funifcase3[t], {t, 0, 1, 0.1}]] Print[The definition funifcase2[t] is , funifcase2[t]]; Print[The definition funifcase3[t] is , funifcase3[t]]; solifcase2 = NDSolve[{y''[t] + y'[t] + y[t] - funifcase2[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; (* Plot[Evaluate[{y[t],y'[t],y''[t]}/.solifcase2],{t,0,1},PlotStyle-> Automatic] *) Print[Proceeding to solve the above equation with Piecewise definition]; solifcase3 = NDSolve[{y''[t] + y'[t] + y[t] - funifcase3[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; Plot[Evaluate[{y[t], y'[t]} /. solifcase3], {t, 0, 1}, PlotStyle -> {Black, {Red, Dashed}}] (* However the nested If[] does not solve, but the Piecewise[] does. But both are same definitions and same set of equations inside of NDSolve[]. And I expect similar behavior from NDSolve[] for these cases *) (* code ends here *) === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: Hi Gopinath, here are some suggestions: funifcase2[t_] := If[0 <= t < sep/len, val1 + val1 xv yv^2 (y[t]) Sin[t], If[sep/len <= t <= (2 sep)/len, val1 + val2 + val1 xv yv^2 (y[t]) Sin[t] + val2 yv xv^2 (y[t]) Sin[t - sep/len], If[(2 sep)/len < t <= 1, val2 + val2 yv xv^2 (y[t]) Sin[t - sep/len]]]]; in this case I have replaced the internal function call to wdef1[t] and wdef2[t] with y[t]. If you look at ?funifcase2 you will find quite a lot of stuff that is still unevaluated. So, here is a second version. In this case I a generate a function which has evaluated as much as is possible. createFun = Function[ t, Evaluate[ Which[ Evaluate[ 0 <= t < sep/len], Evaluate[ val1 + val1 xv yv^2 (wdef1[t]) Sin[t] ], Evaluate[ sep/len <= t <= (2 sep)/len ], Evaluate[ val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len] ], Evaluate[ (2 sep)/len < t <= 1 ], Evaluate[ val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len] ] ] ] ] ?createFun Function[t, Which[0 <= t < 1/3, 50 + Sin[t] y[t], 1/3 <= t <= 2/3, 70 - Sin[1/3 - t] y[t] + Sin[t] y[t], 2/3 < t <= 1, 20 - Sin[1/3 - t] y[t]]] Also, I used Which, which I find a little more readable. solifcase2 = NDSolve[{y''[t] + y'[t] + y[t] - createFun[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1} ] Plot[Evaluate[{y[t], y'[t]} /. solifcase2], {t, 0, 1}, PlotStyle -> {Black, {Red, Dashed}}] Hope this helps, Oliver > Hello Mathematica Friends, I am stuck with this problem, where I use NDSolve[] to solve a nested If[] statement. The use of Piecewise[] solves with no problem, but wanted to know if I can solve the If[] part as well. The sample code (just for demo) is shown below, which is similar to my case. The third section is similar to my case, while the first and second case, I kept it here, to show that NDSolve[] solves the nested If[] with no problem. So you can directly go to the third section, please see the comments to go to the correct section. The reason I am posting it here, is even the Piecewise[] is not solving in my (original problem) case. > Gopinath > University of Oklahoma (* code starts here *) (* First section: Showing simple sine function inside NDSolve[] *) > funReg[t_] := Sin[t]; > solReg = NDSolve[{y''[t] + y'[t] + y[t] - funReg[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solReg], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}} ] > (* Here no particular time value is required for the > function,i.e.Sin[t] is valid for any time t *) > (* Second Section: Nested If[] inside NDSolve[] *) > funifcase1[t_] := > If[0 <= t < 1/3, Sin[t], > If[1/3 <= t <= 2/3, -1, If[2/3 < t <= 1, Cos[t]]]]; > Print[funifcase1 is given by , funifcase1[t]]; > solifcase1 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase1[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase1], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] > (* In the above also, the function is undetermined (I mean, dependent > on time t, which is not supplied until the NDSolve[] increments from > initial conditions step by step by some direct integration scheme, I > guess *) > (* Third case: I expect this case also to solve because it is very > similar to the above cases *) > sep = 1; > len = 3; > wdef1[t_] := y[t]; > wdef2[t_] := y[t]; > val1 = 50; > val2 = 20; > xv = 1/2; > yv = 1/5; > funifcase2[t_] := > If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > If[sep/len <= t <= (2 sep)/len, > val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > If[(2 sep)/len < t <= 1, > val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]; > funifcase3[t_] := > Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > 0 <= t < sep/len}, {val1 + val2 + > val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > sep/len <= t <= (2 sep)/len}, {val2 + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= > 1}}]; > Chop[Table[funifcase2[t], {t, 0, 1, 0.1}]] > Print[compare values, just to check the correctness of equation > above]; > Chop[Table[funifcase3[t], {t, 0, 1, 0.1}]] > Print[The definition funifcase2[t] is , funifcase2[t]]; > Print[The definition funifcase3[t] is , funifcase3[t]]; solifcase2 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase2[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > (* Plot[Evaluate[{y[t],y'[t],y''[t]}/.solifcase2],{t,0,1},PlotStyle- Automatic] *) > Print[Proceeding to solve the above equation with Piecewise > definition]; > solifcase3 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase3[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase3], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] > (* However the nested If[] does not solve, but the Piecewise[] does. > But both are same definitions and same set of equations inside of > NDSolve[]. And I expect similar behavior from NDSolve[] for these > cases *) (* code ends here *) > === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: Clear[funifcase1] funifcase1[t_?NumericQ] := If[0 <= t < 1/3, Sin[t], If[1/3 <= t <= 2/3, -1, If[2/3 < t <= 1, Cos[t]]]]; Print[funifcase1 is given by , funifcase1[t]]; solifcase1 = NDSolve[{y''[t] + y'[t] + y[t] - funifcase1[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; Plot[Evaluate[{y[t], y'[t]} /. solifcase1], {t, 0, 1}, PlotStyle -> {Black, {Red, Dashed}}] work fine, what is your problem ? Jens > Hello Mathematica Friends, I am stuck with this problem, where I use NDSolve[] to solve a nested If[] statement. The use of Piecewise[] solves with no problem, but wanted to know if I can solve the If[] part as well. The sample code (just for demo) is shown below, which is similar to my case. The third section is similar to my case, while the first and second case, I kept it here, to show that NDSolve[] solves the nested If[] with no problem. So you can directly go to the third section, please see the comments to go to the correct section. The reason I am posting it here, is even the Piecewise[] is not solving in my (original problem) case. > Gopinath > University of Oklahoma (* code starts here *) (* First section: Showing simple sine function inside NDSolve[] *) > funReg[t_] := Sin[t]; > solReg = NDSolve[{y''[t] + y'[t] + y[t] - funReg[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solReg], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}} ] > (* Here no particular time value is required for the > function,i.e.Sin[t] is valid for any time t *) > (* Second Section: Nested If[] inside NDSolve[] *) > funifcase1[t_] := > If[0 <= t < 1/3, Sin[t], > If[1/3 <= t <= 2/3, -1, If[2/3 < t <= 1, Cos[t]]]]; > Print[funifcase1 is given by , funifcase1[t]]; > solifcase1 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase1[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase1], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] > (* In the above also, the function is undetermined (I mean, dependent > on time t, which is not supplied until the NDSolve[] increments from > initial conditions step by step by some direct integration scheme, I > guess *) > (* Third case: I expect this case also to solve because it is very > similar to the above cases *) > sep = 1; > len = 3; > wdef1[t_] := y[t]; > wdef2[t_] := y[t]; > val1 = 50; > val2 = 20; > xv = 1/2; > yv = 1/5; > funifcase2[t_] := > If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > If[sep/len <= t <= (2 sep)/len, > val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > If[(2 sep)/len < t <= 1, > val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]; > funifcase3[t_] := > Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > 0 <= t < sep/len}, {val1 + val2 + > val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > sep/len <= t <= (2 sep)/len}, {val2 + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= > 1}}]; > Chop[Table[funifcase2[t], {t, 0, 1, 0.1}]] > Print[compare values, just to check the correctness of equation > above]; > Chop[Table[funifcase3[t], {t, 0, 1, 0.1}]] > Print[The definition funifcase2[t] is , funifcase2[t]]; > Print[The definition funifcase3[t] is , funifcase3[t]]; solifcase2 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase2[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > (* Plot[Evaluate[{y[t],y'[t],y''[t]}/.solifcase2],{t,0,1},PlotStyle- Automatic] *) > Print[Proceeding to solve the above equation with Piecewise > definition]; > solifcase3 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase3[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase3], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] > (* However the nested If[] does not solve, but the Piecewise[] does. > But both are same definitions and same set of equations inside of > NDSolve[]. And I expect similar behavior from NDSolve[] for these > cases *) (* code ends here *) > === Subject: Mathematica Special Interest Group (Washington DC Area) The Washington D.C. area Mathematica Special Interest Group will meet Friday, 25 July, 7:30 to 9:30 a.m. at the SAIC Enterprise Center building in Tysons Corner (see directions below). Early risers meet before 7:00 in the morning for admission at the front desk, then we have a Dutch treat breakfast downstairs. By about 7:30 we have moved to one of the classrooms. Meetings consist of prepared talks, informal discussion about Mathematica programming and applications, general questions, and new business. Dan Martinez will present two talks: Dynamic Variable Isolation and A Basic Example of Statics of Rigid Bodies. Bruce Colletti will present MathGroup Corner, a summary of the month's highlighted traffic in MathGroup, a forum for Mathematica users. To inquire about attending, e-mail Dan Martinez (dmartinez@sprintmail.com) or Bruce Colletti (bcolletti@compuserve.com). In your e-mail subject line, please include 'Mathematica SIG.' The SIG-site is http://web.mac.com/hrbishop.pmsi/DCSIG.m/DCSIG.html A SIG representative will meet you in the lobby. Please arrive no later than ten minutes to seven if you wish to join us for breakfast, and no later than twenty after seven to attend the meeting only. The desk officer will ask for a driver's license before issuing a visitor's badge. === Subject: Text search within a documentation page? There's no text search or Find capability _within_ an onscreen documentation page? === Subject: Re: Text search within a documentation page? > There's no text search or Find capability _within_ an onscreen > documentation page? > Just use the normal Find command Ctrl+F Robert === Subject: Re: Text search within a documentation page? > No, AES is right in some cases for the Documentation Center pages. > Some Documentation Center pages are peculiar in some ways in terms of > using Mathematica's search capabilities. > For example. Go to the main Documentation Center page. Once there= , > click on the page to be sure that you are in it. Now bring up the > find and replace dialog and, for example, type in Overview (without > the quotes) in the Find field and click on the Next button. Nothing > happens (and a warning beep is generated) even though the word > Overview does appear on the page. You can use the Web version of the Documentation Center and it does not have this problem. > This sort of thing does not happen for all pages by any means, but > there are some peculiarities to be found. Perhaps it has something t= o > do with the style sheets that is used, or perhaps it is a gremlin... > Another peculiarity is that in the Search Result pages (which > sometimes -- often? -- open when you enter a term or select a symbol > name in a Mathematica notebook and click on Help), there are cases where > a search within that Search Result page for, e.g. Plot (with Ignore > Case checked) will cycle through all the occurrences of plot or Plot in > the tiny-type text of the links on the page -- but never touch the Plot > string in the titles of the links on the page, e.g. Plot3D. > Online version doesn't have this problem either. But maybe neither does the local version I just discovered. It seems that if you use the Previous | Next links to go to another page of the found items, the Find window's Next button appears not to work, but if you click on the Previous button, the strings are found in reverse. So it would appear that when you use the Previous | Next feature, the position of the start of the search is at the bottom of the page, and even though the Wrap around checkbox is checked it doesn't wrap around. Sure looks like a bug to me?? > The real question, it seems to me, is, what good _at all_ are these > online Search Pages? If you search on a term, you frequently get Searc= h > Result pages that contain 100s to 1000s of links, extending over many > 10s of further screenfuls or pages. How can one proceed further at that point? Is there any way to drill > down further into these very long Search Result lists _efficiently_? I= f > they were structured as one immensely long page, one could at least both > rapidly page down using the Page Down key, to scan all the entries, or > more efficiently jump down to relevant entries using the Find command -- > but I don't find any way to do either of these. Notes to WRI's documentation people (if there are any . . .jab, jab): 1) Safari has a beautiful search function where, if you've opened an > immensely long web page, you type a search term into the search field at > the top and it immediately shows you the total number of hits in the > entire document, with little forward and back arrowheads on each side of > the number. Clicking either of these instantly jumps you to the next o= r > previous occurrence of the search string in the document (centered in > the document window, of course, which is where any online search of this > type ought to take you). Gorgeous technique to use; best one I'm aware of. I agree 100% with this, and on top of that Safari highlights all the occurrences of the searched string on the page so they are very easy to visually pick out. Also if you use the web version of the Documentation Center, this is completely doable right now. 2) As someone who does a fair amount of searching in documentation, I > make every effort to capture on my own HD PDF files of the full manuals > or books about software I use (or other technologies or subjects I'm > studying; and then often find that the most efficient way to search for > information on some topic is just to open one of these documents and do > a pure linear full text search in Acrobat. This is very often much better than going to the index of the document. = > Indexes can be helpful on paper, much less helpful on screen: too much > awkward jumping back and forth between index and main text. And even > with good intentions, doing a good job of indexing is hard. With the > linear text search you may have to divert your attention to something > else for a few moments, while Acrobat grinds its way through a 500-page > manual -- but when you get a hit, you're very often there (at the > info you want), or have seredipitously learned something useful related > to your search. Sometimes I think that I would love to have a PDF version of the Documentation Center available -- would think is this something that Wolfram could generate?, but know it would be immense, so maybe this is not practical. But the ability to insert my own comments and put in my own bookmarks, and all the other things that you do with PDF files in Acrobat would make this something I would like to have available to find out. === Subject: Re: Text search within a documentation page? Except that it lacks an index -- and this is no insignificant matter! -- doesn't the belatedly added Virtual Book address many of the needs for tutorial (what you call user) documentation? Just the sort of thing that constituted the beginning of The Book before. I don't know what kind of blindness it is within WRI that has led to the > current documentation disaster for Mathematica (and that's truly what it > is). The currently available documentation is not particularly bad as > _reference_ documentation; but it is very badly done and badly > structured as _user_ documentation, and could be made vastly more > friendly and helpful with very little work. Great companies are > supposedly made great by paying close attention to their customers. > I've yet to see any real recognition of that in Mathematica -- at least > not for the kind of customers I'm associated with. -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Text search within a documentation page? > No, AES is right in some cases for the Documentation Center pages. > Some Documentation Center pages are peculiar in some ways in terms of > using Mathematica's search capabilities. You can use the Web version of the Documentation Center and it does > not have this problem. Great idea! > Another peculiarity is that in the Search Result pages (which > sometimes -- often? -- open when you enter a term or select a symbol > name in a Mathematica notebook and click on Help), there are cases where > a search within that Search Result page for, e.g. Plot (with Ignore > Case checked) will cycle through all the occurrences of plot or Plot in > the tiny-type text of the links on the page -- but never touch the Plot > string in the titles of the links on the page, e.g. Plot3D. Online version doesn't have this problem either. But maybe neither > does the local version I just discovered. It seems that if you use the > Previous | Next links to go to another page of the found items, the > Find window's Next button appears not to work, but if you click on > the Previous button, the strings are found in reverse. So it would > appear that when you use the Previous | Next feature, the position > of the start of the search is at the bottom of the page, and even > though the Wrap around checkbox is checked it doesn't wrap around. > Sure looks like a bug to me?? Don't know if it's a bug or just the way it works, but this is consistent with what I've seen. > 1) Safari has a beautiful search function where, if you've opened an > Gorgeous technique to use; best one I'm aware of. I agree 100% with this, and on top of that Safari highlights all the > occurrences of the searched string on the page so they are very easy > to visually pick out. Also if you use the web version of the > Documentation Center, this is completely doable right now. That's great also! I'll try it immediately. WRI, take note -- you've now got two of us telling you this. > Sometimes I think that I would love to have a PDF version of the > Documentation Center available -- would think is this something that > Wolfram could generate?, but know it would be immense, so maybe this > is not practical. But the ability to insert my own comments and put in > my own bookmarks, and all the other things that you do with PDF files > in Acrobat would make this something I would like to have available to > find out. Doing this would seem to me to be not only practicable but in fact a trivially _easy_ task for WRI. All the data for the built-in non-web version is already on users' hard disks as part of the Mathematica installation -- is that not so? Printing it to a PDF version would be a trivially automated task for the WRI people who know the system and the material, and it's hard to believe that the size as a PDF would greatly exceed what's already there. Either WRI or those of us with Acrobat could then index our own copy using Acrobat's excellent document indexing tools (all the unhelpful Mathematica Search Pages would become unnecessary). Reading and printing the PDF pages in Adobe's own interface (Acrobat or just Reader) would become immensely easily easier than in the Mathematica interface. And, we could do all the personalized modifications that you suggest. I don't know what kind of blindness it is within WRI that has led to the current documentation disaster for Mathematica (and that's truly what it is). The currently available documentation is not particularly bad as _reference_ documentation; but it is very badly done and badly structured as _user_ documentation, and could be made vastly more friendly and helpful with very little work. Great companies are supposedly made great by paying close attention to their customers. I've yet to see any real recognition of that in Mathematica -- at least not for the kind of customers I'm associated with. Over and out as radio operators supposedly say -- I think I've done all the debating on this issue that I'm willing to do, especially given the deafness with which it seems to be received. === Subject: Re: Text search within a documentation page? No, AES is right in some cases for the Documentation Center pages. Some Documentation Center pages are peculiar in some ways in terms of using Mathematica's search capabilities. For example. Go to the main Documentation Center page. Once there, click on the page to be sure that you are in it. Now bring up the find and replace dialog and, for example, type in Overview (without the quotes) in the Find field and click on the Next button. Nothing happens (and a warning beep is generated) even though the word Overview does appear on the page. This sort of thing does not happen for all pages by any means, but there are some peculiarities to be found. Perhaps it has something to do with the style sheets that is used, or perhaps it is a gremlin... --David On Jul 24, 4:54 am, Robert <@frank-exchange-of-views.oucs.ox.ac.uk, > There's no text search or Find capability _within_ an onscreen > documentation page? Just use the normal Find command Ctrl+F Robert === Subject: Re: Text search within a documentation page? This is the same sort of issue one faces with, say, a Google search -- except that in Google one can use has additional parameters to narrow down the domain, time, etc. I was going to say that Google also allows AND, OR, and NOT whereas the Mathematica Documentation Center Search does not. But I discovered to my surprise that these connectives work in the latter, too! For example: plot AND NOT Sin does NOT list the reference page for Plot (at least among the first 150 items in the result that I examined). And plot OR EllipticF returns pages for both plot and EllipticF. So perhaps some drilling down can be accomplished by adding some AND or AND NOT phrase to the end of the item in the search bar after you get too long a list of results. Does Mathematica do a full-text search already? If not, the search does seem often to pick up quite a few instances of a supplied phrase within the body of pages whose links are returned. ... The real question, it seems to me, is, what good _at all_ are these > online Search Pages? If you search on a term, you frequently get Search > Result pages that contain 100s to 1000s of links, extending over many > 10s of further screenfuls or pages. How can one proceed further at that point? Is there any way to drill > down further into these very long Search Result lists _efficiently_? If > they were structured as one immensely long page, one could at least both > rapidly page down using the Page Down key, to scan all the entries, or > more efficiently jump down to relevant entries using the Find command -- > but I don't find any way to do either of these. Notes to WRI's documentation people...: 2) As someone who does a fair amount of searching in documentation, I > make every effort to capture on my own HD PDF files of the full manuals > or books about software I use (or other technologies or subjects I'm > studying; and then often find that the most efficient way to search for > information on some topic is just to open one of these documents and do > a pure linear full text search in Acrobat. This is very often much better than going to the index of the document. > Indexes can be helpful on paper, much less helpful on screen: too much > awkward jumping back and forth between index and main text. And even > with good intentions, doing a good job of indexing is hard. With the > linear text search you may have to divert your attention to something > else for a few moments, while Acrobat grinds its way through a 500-page > manual -- but when you get a hit, you're very often there (at the > info you want), or have seredipitously learned something useful related > to your search. > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Text search within a documentation page? > No, AES is right in some cases for the Documentation Center pages. > Some Documentation Center pages are peculiar in some ways in terms of > using Mathematica's search capabilities. For example. Go to the main Documentation Center page. Once there, > click on the page to be sure that you are in it. Now bring up the > find and replace dialog and, for example, type in Overview (without > the quotes) in the Find field and click on the Next button. Nothing > happens (and a warning beep is generated) even though the word > Overview does appear on the page. This sort of thing does not happen for all pages by any means, but > there are some peculiarities to be found. Perhaps it has something to > do with the style sheets that is used, or perhaps it is a gremlin... Another peculiarity is that in the Search Result pages (which sometimes -- often? -- open when you enter a term or select a symbol name in a Mathematica notebook and click on Help), there are cases where a search within that Search Result page for, e.g. Plot (with Ignore Case checked) will cycle through all the occurrences of plot or Plot in the tiny-type text of the links on the page -- but never touch the Plot string in the titles of the links on the page, e.g. Plot3D. The real question, it seems to me, is, what good _at all_ are these online Search Pages? If you search on a term, you frequently get Search Result pages that contain 100s to 1000s of links, extending over many 10s of further screenfuls or pages. How can one proceed further at that point? Is there any way to drill down further into these very long Search Result lists _efficiently_? If they were structured as one immensely long page, one could at least both rapidly page down using the Page Down key, to scan all the entries, or more efficiently jump down to relevant entries using the Find command -- but I don't find any way to do either of these. Notes to WRI's documentation people (if there are any . . .jab, jab): 1) Safari has a beautiful search function where, if you've opened an immensely long web page, you type a search term into the search field at the top and it immediately shows you the total number of hits in the entire document, with little forward and back arrowheads on each side of the number. Clicking either of these instantly jumps you to the next or previous occurrence of the search string in the document (centered in the document window, of course, which is where any online search of this type ought to take you). Gorgeous technique to use; best one I'm aware of. 2) As someone who does a fair amount of searching in documentation, I make every effort to capture on my own HD PDF files of the full manuals or books about software I use (or other technologies or subjects I'm studying; and then often find that the most efficient way to search for information on some topic is just to open one of these documents and do a pure linear full text search in Acrobat. This is very often much better than going to the index of the document. Indexes can be helpful on paper, much less helpful on screen: too much awkward jumping back and forth between index and main text. And even with good intentions, doing a good job of indexing is hard. With the linear text search you may have to divert your attention to something else for a few moments, while Acrobat grinds its way through a 500-page manual -- but when you get a hit, you're very often there (at the info you want), or have seredipitously learned something useful related to your search. === Subject: Re: Text search within a documentation page? Agreed - this is a problem! You are right that the documentation centre needs a re-working - somehow there has been too much attention to glitz, and not enough to core functionality and content. Also, accessing the help system seems slower than accessing GOOGLE - at least on my machine! David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: Oliver, I have to say that I tried using Evaluate[] (couple of them for each of the If[] inside. But I did not try putting Evaluate[] for the expressions inside each of the If[]s, which made all the difference. Yes, Which[] also made the difference. Now I am in the process of inserting Evaluate[] in my code. Gopinath === Subject: How to call or run a NB file in another NB file? Hi guys, I met a problem, in ABC.nb , I need to run XYZ.nb, is there any function to execute the XYZ.nb in ABC.nb? cheers, leo === Subject: Re: How to call or run a NB file in another NB file? > Hi guys, I met a problem, in ABC.nb , I need to run XYZ.nb, is there any > function to execute the XYZ.nb in ABC.nb? cheers, leo Leo, Here the command that you need to execute from ABC.nb: nb=NotebookOpen[path_to_file_XYZXYZ.nb,Visible->True]; FrontEndExecute[{FrontEndToken[nb,EvaluateNotebook]}]; GS === Subject: Re: How to call or run a NB file in another NB file? GS, yes, the previous replies can solve my problem, I need XYZ.nb run from ABC.nb, and XYZ outputs in XYZ.nb. cheers, leo 2008/7/27 Bob F : >> Hi guys, >> I met a problem, in ABC.nb , I need to run XYZ.nb, is there any >> function to execute the XYZ.nb in ABC.nb? >> cheers, >> leo >> Leo, >> Here the command that you need to execute from ABC.nb: >> nb=NotebookOpen[path_to_file_XYZXYZ.nb,Visible->True]; >> FrontEndExecute[{FrontEndToken[nb,EvaluateNotebook]}]; >> GS This opens the notebook and runs it, but shows the output in it's > notebook, not the notebook that the command ran in. The impression I > got from Leo's question was that he wanted the output to show in the > first notebook, not the second. So, Leo, where did you want to see the output appear? -Bob === Subject: Re: How to call or run a NB file in another NB file? > Hi guys, > I met a problem, in ABC.nb , I need to run XYZ.nb, is there any > function to execute the XYZ.nb in ABC.nb? > cheers, > leo Leo, Here the command that you need to execute from ABC.nb: nb=NotebookOpen[path_to_file_XYZXYZ.nb,Visible->True]; > FrontEndExecute[{FrontEndToken[nb,EvaluateNotebook]}]; GS This opens the notebook and runs it, but shows the output in it's notebook, not the notebook that the command ran in. The impression I got from Leo's question was that he wanted the output to show in the first notebook, not the second. So, Leo, where did you want to see the output appear? -Bob === Subject: Re: How to call or run a NB file in another NB file? this is total useless, write a package with the code of XYZ.nb and load the package in ABC.nb Jens > Hi guys, > I met a problem, in ABC.nb , I need to run XYZ.nb, is there any > function to execute the XYZ.nb in ABC.nb? cheers, leo > === Subject: Re: How to call or run a NB file in another NB file? > I met a problem, in ABC.nb , I need to run XYZ.nb, is there any > function to execute the XYZ.nb in ABC.nb? Make the vital lines in XYZ.nb Initialization cells then save it to create XYZ.m this can now be run with the Get or Needs function as a Package <})[[1]]] Robert === Subject: User defined options shared by more than one function - potential Are there any compelling reasons for placing the statement Options[functionName] -> {opt1->, opt2->} in the public or private section of a user defined Mathematica package? If there is more than one function that has the same option name then, to get rid of the option name showing up in red letters (because the option has been defined in multiple contexts when the functions are in different packages) then having the options defined in the private section of a package gets rid of this problem (i.e. the problem of having the option name, when used while calling a function, show up in red letters). Would it still be possible to have a usage statement for an option (to document its meaning) in the public section of a package, even though it is defined with the Option statement above in the private section? Don === Subject: Re: User defined options shared by more than one function - potential nobody put the Options[] into the public section. You should only put usage messages in the public part. Jens > Are there any compelling reasons for placing the > statement Options[functionName] -> {opt1->, opt2->} in the public or private section of > a user defined Mathematica package? If there is more than one function that has the same > option name then, to get rid of the option name > showing up in red letters (because the option has been defined > in multiple contexts when the functions are in different packages) then having the options defined in the private > section of a package gets rid of this problem (i.e. the problem of having the option name, when used while calling a function, show up in red letters). > > Would it still be possible to have a usage statement for an option (to document its meaning) in the public section of a package, even though it is defined with the Option statement above in the private section? > Don > === Subject: Re: User defined options shared by more than one function - potential Write usage messages in the public section of the package for opt1 and opt2. Use different option names in different packages. That is, make the option name specific to the function, or at least to the package. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Are there any compelling reasons for placing the > statement Options[functionName] -> {opt1->, opt2->} in the public or private section of > a user defined Mathematica package? If there is more than one function that has the same > option name then, to get rid of the option name > showing up in red letters (because the option has been defined > in multiple contexts when the functions are in different packages) then > having the options defined in the private > section of a package gets rid of this problem (i.e. the problem of having > the option name, when used while calling a function, show up in red > letters). Would it still be possible to have a usage statement for an option (to > document its meaning) in the public section of a package, even though it > is defined with the Option statement above in the private section? > Don > === Subject: Sending Objects from Java - Mathematica i have written a Java-code, where i want to send some objects to Mathematica. To call a function(written in Mathematica) with four parameters under Java, i need to send objects to Mathematica. This is my Java-code: public void sendListOfEdgesToMathematica(List edg) throws MathLinkException { try { ml = MathLinkFactory.createKernelLink(argv); } catch (MathLinkException e) { System.out.println(Fatal error opening link: + e.getMessage()); return; } try { ml.enableObjectReferences(); ml.discardAnswer(); ml.evaluate(< Mathematica. To call a function(written in Mathematica) with four > parameters under Java, i need to send objects to Mathematica. This is my Java-code: > public void sendListOfEdgesToMathematica(List edg) throws > MathLinkException { > try { ml = MathLinkFactory.createKernelLink(argv); > } catch (MathLinkException e) { > System.out.println(Fatal error opening link: + > e.getMessage()); > return; > } > > try { > ml.enableObjectReferences(); > ml.discardAnswer(); > ml.evaluate(< ml.discardAnswer(); > ml.putFunction(EvaluatePacket, 1); > ml.putFunction(doGetEdges, 1); > ml.put(edg); > ml.endPacket();.............. edg( a list) contains the element e11 and i have written a Function > under Mathematica for receiving the object from Java: > doGetEdges[edg_] := > JavaBlock[Module[{outStream}, outStream = edg@getOutputStream[]; > outStream@print[Edges]; > edgesG6 = edg > ] > ] The problem is, Mathematica does not receive the correct value(e11). > I tried to test my implementation with a PacketListener, but without > success. After sending four objects to Mathematica, i want to call the > Mathematica-function under Java: objectGraph[edgesG6, verticesG6, sourcesG6, targetsG6] Any help would be fantastic. Unless you really need to work at such a low level, it is much easier to call StdLink.getLink().evaluateToInputForm(str,0); Where str is a string representation of the Mathematica function call you want to make. As for your code, I would need to be able to debug it to be sure, but I think the problem is that you need to explicitly generate the list using: ml.putFunction(List, 1); (followed by the 1 element of your list) David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] Out[2]= 6.72288 I know the exact result: In[3]:= (1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])]))//N Out[3]= 6.72288 but I would like to prove it. V.Astanoff === Subject: Try it again, Mathematica! Was: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) I played around a little bit and found the following interesting behaviour: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] Out[1]:= !( *SubsuperscriptBox[([Integral]), (0), ([Pi])]( SqrtBox[(5 - 4 Cos[t] + Cos[2 t])] [DifferentialD]t)) In[2]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] Out[2]:= 1/5 Sqrt[ 2 + 4 I] (-5 I EllipticE[-(3/5) - (4 I)/5] + (2 + I) Sqrt[5] EllipticE[-(3/5) + (4 I)/5] - (12 - 4 I) EllipticK[-(3/5) - ( 4 I)/5] + (6 - 2 I) Sqrt[5] EllipticK[8/5 - (4 I)/5] + 4 I Sqrt[5] EllipticPi[ 1/5 + (2 I)/5, -(3/5) + (4 I)/5] + (8 + 4 I) EllipticPi[ 1 - 2 I, -(3/5) - (4 I)/5]) So it seems, it helps to ask Mathematica twice. Best wishes, Alois === Subject: Re: Try it again, Mathematica! Was: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) > I played around a little bit and found the following interesting > behaviour: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]:= !( > *SubsuperscriptBox[([Integral]), (0), ([Pi])]( > SqrtBox[(5 - 4 Cos[t] + Cos[2 t])] [DifferentialD]t)) In[2]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]:= 1/5 Sqrt[ > 2 + 4 I] (-5 I EllipticE[-(3/5) - (4 I)/5] + (2 + I) Sqrt[5] > EllipticE[-(3/5) + (4 I)/5] - (12 - 4 I) EllipticK[-(3/5) - ( > 4 I)/5] + (6 - 2 I) Sqrt[5] EllipticK[8/5 - (4 I)/5] + > 4 I Sqrt[5] > EllipticPi[ > 1/5 + (2 I)/5, -(3/5) + (4 I)/5] + (8 + 4 I) EllipticPi[ > 1 - 2 I, -(3/5) - (4 I)/5]) So it seems, it helps to ask Mathematica twice. On my system, one must ask Mathematica _three_ times. (The third time's the charm.) The reason Mathematica eventually succeeded is that it remembered work from its previous attempts. If we had done ClearSystemCache[] between attempts, Mathematica would presumably never have succeeded. Is there a parameter which we can change so that Mathematica succeeds on the first try? David === Subject: Re: Try it again, Mathematica! Was: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) Here is the response I got from Mathematica support: *** my email *** I have enclosed a nb with a strange integration problem that Alois Steindl and I have been looking at. As you will see, the first time I execute the integral, it returns the input after a long time, i.e. no answer. The second time I evaluate the same integral it again takes a long time, but then returns an answer. The third time it returns the same answer as the second, but it is nearly instantaneous. What's going on? *** response *** Information is being cached and there are time limits on internal functions like Simplify which prevent getting an answer on the first try, giving an answer on the second try and almost nothing happening on the third try. Here are the timings of these on my Windows: In[1]:= Timing[Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}]] Out[1]= {62.187, Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}]} In[2]:= Timing[Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}]] Out[2]= {9.610000000000003, (1/5)*Sqrt[2 + 4*I]* (-5*I*EllipticE[-(3/5) - (4*I)/5] + (2 + I)*Sqrt[5]* EllipticE[-(3/5) + (4*I)/5] - (12 - 4*I)* EllipticK[-(3/5) - (4*I)/5] + (6 - 2*I)*Sqrt[5]* EllipticK[8/5 - (4*I)/5] + 4*I*Sqrt[5]*EllipticPi[1/5 + (2*I)/5, -(3/5) + (4*I)/5] + (8 + 4*I)*EllipticPi[1 - 2*I, -(3/5) - (4*I)/5])} In[3]:= Timing[Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}]] Out[3]= {0.5460000000000036, (1/5)*Sqrt[2 + 4*I]* (-5*I*EllipticE[-(3/5) - (4*I)/5] + (2 + I)*Sqrt[5]* EllipticE[-(3/5) + (4*I)/5] - (12 - 4*I)* EllipticK[-(3/5) - (4*I)/5] + (6 - 2*I)*Sqrt[5]* EllipticK[8/5 - (4*I)/5] + 4*I*Sqrt[5]*EllipticPi[1/5 + (2*I)/5, -(3/5) + (4*I)/5] + (8 + 4*I)*EllipticPi[1 - 2*I, -(3/5) - (4*I)/5])} After working on this issue, I thought that it would be nicer if we had a warning message generated after the first trial. I have forwarded your examples to our development group and I filed a suggestion report about having such a message. We apologize for any inconvenience caused by this issue. Zubeyir Cinkir Technical Support Wolfram Research, Inc. > I played around a little bit and found the following interesting > behaviour: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]:= !( > *SubsuperscriptBox[([Integral]), (0), ([Pi])]( > SqrtBox[(5 - 4 Cos[t] + Cos[2 t])] [DifferentialD]t)) In[2]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]:= 1/5 Sqrt[ > 2 + 4 I] (-5 I EllipticE[-(3/5) - (4 I)/5] + (2 + I) Sqrt[5] > EllipticE[-(3/5) + (4 I)/5] - (12 - 4 I) EllipticK[-(3/5) - ( > 4 I)/5] + (6 - 2 I) Sqrt[5] EllipticK[8/5 - (4 I)/5] + > 4 I Sqrt[5] > EllipticPi[ > 1/5 + (2 I)/5, -(3/5) + (4 I)/5] + (8 + 4 I) EllipticPi[ > 1 - 2 I, -(3/5) - (4 I)/5]) So it seems, it helps to ask Mathematica twice. Best wishes, > Alois > === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) expr = 5 - 4*Cos[t] + Cos[2*t] // TrigExpand Integrate[Sqrt[expr], {t, 0, Pi}] ?? Jens > Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]= 6.72288 I know the exact result: In[3]:= (1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - > 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* > EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])]))//N > Out[3]= 6.72288 but I would like to prove it. V.Astanoff > === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) > Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]= 6.72288 I know the exact result: In[3]:= (1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - > 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* > EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])])= )//N > Out[3]= 6.72288 but I would like to prove it. > V.Astanoff You can use the TrigExpand[] function for the Cos[2t] to get the equivalent Cos[t]^2 - Sin[t]^2, and if you do this Mathematica 6.0.3 on a Mac comes up with 1/5 Sqrt[2 + 4 I] (-5 I EllipticE[-(3/5) - (4 I)/5] + (2 + I) Sqrt[5] EllipticE[-(3/5) + (4 I)/5] - (12 - 4 I) EllipticK[-(3/5) - (4 I)/5] + (6 - 2 I) Sqrt[5] EllipticK[8/5 - (4 I)/5] + 4 I Sqrt[5] EllipticPi[1/5 + (2 I)/5, -(3/5) + (4 I)/5] + (8 + 4 I) EllipticPi[1 - 2 I, -(3/5) - (4 I)/5]) The equivalence to your expression is left up to you...but this does evaluate numerically to the same as what you had. -Bob === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) > Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]= 6.72288 I know the exact result: In[3]:= =9A(1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - > =9A =9A =9A =9A 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* > =9A =9A =9A =9A EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])])= )//N > Out[3]= 6.72288 but I would like to prove it. > V.Astanoff Hello. You can try to take indefinite integral: eq=Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], t] Here Mathematica gives you an answer: ((2/5 + (4*I)/5)*Cos[t/2]^4*((2 + I)*Sqrt[1 - 2*I]* EllipticE[I*ArcSinh[Sqrt[1 - 2*I]*Tan[t/2]], -3/5 + (4*I)/5]* Sec[t/2]^2*Sqrt[1 + (1 - 2*I)*Tan[t/2]^2]* Sqrt[1 + (1 + 2*I)*Tan[t/2]^2] - I*((6 - 2*I)*Sqrt[1 - 2*I]*EllipticF[ I*ArcSinh[Sqrt[1 - 2*I]*Tan[t/2]], -3/5 + (4*I)/5]*Sec[t/2]^2* Sqrt[1 + (1 - 2*I)*Tan[t/2]^2]*Sqrt[1 + (1 + 2*I)*Tan[t/2]^2] - 4*Sqrt[1 - 2*I]*EllipticPi[1/5 + (2*I)/5, I*ArcSinh[Sqrt[1 - 2*I]*Tan[t/2]], -3/5 + (4*I)/5]*Sec[t/2]^2* Sqrt[1 + (1 - 2*I)*Tan[t/2]^2]*Sqrt[1 + (1 + 2*I)*Tan[t/2]^2] + (2 + I)*(Tan[t/2] + 2*Tan[t/2]^3 + 5*Tan[t/2]^5))))/ Sqrt[5 - 4*Cos[t] + Cos[2*t]] Then find Limits: Limit[eq, t ->0] gives 0, Limit[eq, t -> Pi] gives (2/5 + I/5)*Sqrt[2/5 + (4*I)/5]* ((1 + 2*I)*Sqrt[5]*EllipticE[-3/5 - (4*I)/5] - 5*EllipticE[-3/5 + (4*I)/5] + (4 - 4*I)*Sqrt[5]* EllipticK[-3/5 - (4*I)/5] - (10 - 10*I)*EllipticK[8/5 - (4*I)/5] - (4 + 8*I)*EllipticPi[1/5 + (2*I)/5, -3/5 + (4*I)/5] - 4*Sqrt[5]*EllipticPi[1 - 2*I, -3/5 - (4*I)/5]) so, the result is N@% -6.72287972344033 - 9.947771772989*^-15*I The problem only with the sign of result. === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) > Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] Actually, we can use Mathematica 6 to integrate that. In[9]:= indef = Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], t] Out[9]= ((2/5 + (4*I)/5)*Sqrt[5 - 4*Cos[t] + Cos[2*t]]*((2 + I)*Sqrt[1 - 2*I]* EllipticE[I*ArcSinh[Sqrt[1 - 2*I]*Tan[t/2]], -(3/5) + (4*I)/5]*(1 + Tan[t/2]^2)*Sqrt[1 + (1 - 2*I)*Tan[t/2]^2]*Sqrt[1 + (1 + 2*I)*Tan[t/2]^2] - I*((6 - 2*I)*Sqrt[1 - 2*I]*EllipticF[I*ArcSinh[Sqrt[1 - 2*I]*Tan[t/2]], -(3/5) + (4*I)/5]*(1 + Tan[t/2]^2)*Sqrt[1 + (1 - 2*I)*Tan[t/2]^2]*Sqrt[1 + (1 + 2*I)*Tan[t/2]^2] - 4*Sqrt[1 - 2*I]*EllipticPi[1/5 + (2*I)/5, I*ArcSinh[Sqrt[1 - 2*I]*Tan[t/2]], -(3/5) + (4*I)/5]*(1 + Tan[t/2]^2)*Sqrt[1 + (1 - 2*I)*Tan[t/2]^2]*Sqrt[1 + (1 + 2*I)*Tan[t/2]^2] + (2 + I)*(Tan[t/2] + 2*Tan[t/2]^3 + 5*Tan[t/2]^5))))/((1 + Cos[t])*Sqrt[(5 - 4*Cos[t] + Cos[2*t])/(1 + Cos[t])^2]*(1 + Tan[t/2]^2)*Sqrt[2 + 4*Tan[t/2]^2 + 10*Tan[t/2]^4]) In[10]:= FullSimplify[ Limit[indef, t -> Pi, Direction -> 1] - (indef /. t -> 0)] Out[10]= (1/5)*Sqrt[2 + 4*I]*(-5*I*EllipticE[-(3/5) - (4*I)/5] + (2 + I)*Sqrt[5]*EllipticE[-(3/5) + (4*I)/5] - (12 - 4*I)*EllipticK[-(3/5) - (4*I)/5] + (6 - 2*I)*Sqrt[5]*EllipticK[8/5 - (4*I)/5] + 4*I*Sqrt[5]*EllipticPi[1/5 + (2*I)/5, -(3/5) + (4*I)/5] + (8 + 4*I)*EllipticPi[1 - 2*I, -(3/5) - (4*I)/5]) In[11]:= N[%] Out[11]= 6.722879723440325 + 1.0534455252564358*^-14*I Of course I readily agree that Out[10] is not as nice in appearance as your In[3] below. (Nobody who works much with Mathematica and elliptic integrals would be surprised by that.) Nonetheless, Out[10] is a correct answer. David W. Cantrell > In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]= 6.72288 I know the exact result: In[3]:= (1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - > 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* > EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])]))//N > Out[3]= 6.72288 but I would like to prove it. > V.Astanoff === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) [...] Good day, for your advice and suggestions. Though I still wonder why (1/5)*Sqrt[2+4*I]*(-5*I*EllipticE[-(3/5)-(4*I)/5]+ (2+I)*Sqrt[5]*EllipticE[-(3/5)+(4*I)/5]- (12-4*I)*EllipticK[-(3/5)-(4*I)/5]+ (6-2*I)*Sqrt[5]*EllipticK[8/5-(4*I)/5]+ 4*I*Sqrt[5]*EllipticPi[1/5+(2*I)/5,-(3/5)+(4*I)/5]+ (8+4*I)*EllipticPi[1-2*I,-(3/5)-(4*I)/5]) doesn't fullsimplifies to (1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5-Sqrt[5])]- 10*EllipticK[(1/10)*(5-Sqrt[5])]+(5+3*Sqrt[5])* EllipticPi[(1/10)*(5-3*Sqrt[5]),(1/10)*(5-Sqrt[5])])) (I have to say I'm not very familiar with the Elliptics!) Valeri === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) I actually get: 1/5 Sqrt[2+4 I] (-5 I EllipticE[-(3/5)-(4 I)/5]+(2+I) Sqrt[5] EllipticE[-(3/5)+(4 I)/5]-(12-4 I) EllipticK[-(3/5)-(4 I)/5]+(6-2 I) Sqrt[5] EllipticK[8/5-(4 I)/5]+4 I Sqrt[5] EllipticPi[1/5+(2 I)/5,-(3/5)+(4 I)/5]+(8+4 I) EllipticPi[1-2 I,-(3/5)-(4 I)/5]) which evaluates to your numerical answer below, > Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]= 6.72288 I know the exact result: In[3]:= (1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - > 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* > EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])]))//N > Out[3]= 6.72288 but I would like to prove it. V.Astanoff > === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) > Good day, Neither Mathematica 6 nor anyone here can integrate this: In[1]:= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[1]= Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] In[2]:= NIntegrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi}] > Out[2]= 6.72288 I know the exact result: In[3]:= =9A(1/5^(3/4))*(Sqrt[2]*(10*EllipticE[(1/10)*(5 - Sqrt[5])] - > =9A =9A =9A =9A 10*EllipticK[(1/10)*(5 - Sqrt[5])] + (5 + 3*Sqrt[5])* > =9A =9A =9A =9A EllipticPi[(1/10)*(5 - 3*Sqrt[5]), (1/10)*(5 - Sqrt[5])])= )//N > Out[3]= 6.72288 but I would like to prove it. > V.Astanoff Or even beter eq = Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, 0, Pi/2}] + Integrate[Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t, Pi/2, Pi}]; FullSimplify[eq] Out: (Sqrt[2 + 4*I]*((-5*I)*EllipticE[-3/5 - (4*I)/5] + (2 + I)*Sqrt[5]*EllipticE[-3/5 + (4*I)/5] - (12 - 4*I)*EllipticK[-3/5 - (4*I)/5] + (6 - 2*I)*Sqrt[5]* EllipticK[8/5 - (4*I)/5] + (4*I)*Sqrt[5]*EllipticPi[1/5 + (2*I)/ 5, -3/5 + (4*I)/5] + (8 + 4*I)*EllipticPi[1 - 2*I, -3/5 - (4*I)/ 5]))/ 5 In[]=N@% Out: 6.72288+ 1.05693*10^-14* I Moreover, you can replace Cos[2t]->Cos[t]^2-Sin[t]^2 so Integrate[ Sqrt[5 - 4*Cos[t] + Cos[2*t]] /. Cos[2 t] -> Cos[t]^2 - Sin[t]^2, {t, 0, Pi}]; gives result as above 6.72288+ 8.76799*10^-15 I And the last solution is may be the best one: Integrate[ TrigExpand/@Sqrt[5 - 4*Cos[t] + Cos[2*t]], {t,0, Pi}]; === Subject: Re: Can't integrate sqrt(a+b*cos(t)+c*cos(2t)) If I ask Mathematica 6.0.2.1 to Integrate[Simplify[Sqrt[5 - 4*Cos[t] + Cos[2*t]]], {t, 0, Pi}] it gives me 1/5 Sqrt[ 2 + 4 I] (-5 I EllipticE[-(3/5) - (4 I)/5] + (2 + I) Sqrt[5] EllipticE[-(3/5) + (4 I)/5] - (12 - 4 I) EllipticK[-(3/5) - ( 4 I)/5] + (6 - 2 I) Sqrt[5] EllipticK[8/5 - (4 I)/5] + 4 I Sqrt[5] EllipticPi[ 1/5 + (2 I)/5, -(3/5) + (4 I)/5] + (8 + 4 I) EllipticPi[ 1 - 2 I, -(3/5) - (4 I)/5]) Taking N[%] gives 6.72288+ 6.52169*10^-15 I I am wondering, why the Simplify helps, because Simplify[Sqrt[5 - 4*Cos[t] + Cos[2*t]]] just returns Sqrt[5 - 4 Cos[t] + Cos[2 t]]. Best wishes Alois -- Alois Steindl, Tel.: +43 (1) 58801 / 32558 Inst. for Mechanics and Mechatronics Fax.: +43 (1) 58801 / 32598 Vienna University of Technology, A-1040 Wiedner Hauptstr. 8-10 === Subject: Re: Text search within a documentation page? The menu item Edit / Find / Find... or keyboard equivalent works on my Mac. There's no text search or Find capability _within_ an onscreen documentation page? === Subject: Solving 3d degree polynomial I have a function f(q)=2n(n+1)q^3-(1+t)(2n+1)q^2+2(t-(n+1)A)q+(1+t)A in which n>1, -1 I have a function > f(q)=2n(n+1)q^3-(1+t)(2n+1)q^2+2(t-(n+1)A)q+(1+t)A > in which n>1, -1 Solve[Y==0,q] it gives me 3 real roots. > If instead I ask for a symbolic solution before filling in the same values of the parameters, Mathematica gives almost the same roots, but now there is an imaginary part to the solution. It is of the order 10^(-16). Why are the roots complex if I find a solution before filling in parameters, but real if I fill in parameters before finding the solution? The tiny -- negligible -- spurious imaginary (or real) parts are due to rounding error when parameters are replaced by numerical values into the large symbolic expressions returned by Solve[]. Use *Chop[]* to discard tiny floating-point values or *ComplexExpand[]* to simplify symbolically. In[1]:= expr = 2*n*(n + 1)*q^3 - (1 + t)*(2*n + 1)*q^2 + 2*(t - (n +1)*A)*q + (1 + t)*A; sols = Solve[expr == 0, q]; sols /. {n -> 2, A -> 0, t -> 1/2} N[%] Chop[%] ComplexExpand /@ (sols /. {n -> 2, A -> 0, t -> 1/2}) N[%] Chop[%] Out[3]= 5 1 1 135 1/3 {{q -> -- + -- (- (--- + 54 I Sqrt[11])) + 24 36 2 4 9 -------------------------------}, 2/3 135 1/3 8 2 (--- + 54 I Sqrt[11]) 4 5 1 1 135 1/3 {q -> -- - -- (1 - I Sqrt[3]) (- (--- + 54 I Sqrt[11])) - 24 72 2 4 9 (1 + I Sqrt[3]) --------------------------------}, 2/3 135 1/3 16 2 (--- + 54 I Sqrt[11]) 4 5 1 1 135 1/3 {q -> -- - -- (1 + I Sqrt[3]) (- (--- + 54 I Sqrt[11])) - 24 72 2 4 9 (1 - I Sqrt[3]) --------------------------------}} 2/3 135 1/3 16 2 (--- + 54 I Sqrt[11]) 4 Out[4]= -17 {{q -> 0.432178 - 2.77556 10 I}, -17 -17 {q -> -2.77556 10 - 4.16334 10 I}, -17 {q -> 0.192822 + 9.71445 10 I}} Out[5]= {{q -> 0.432178}, {q -> 0}, {q -> 0.192822}} Out[6]= 5 1 1 8 Sqrt[11] {{q -> -- + - Cos[- ArcTan[----------]]}, 24 4 3 5 5 1 1 8 Sqrt[11] {q -> -- - - Cos[- ArcTan[----------]] - 24 8 3 5 1 1 8 Sqrt[11] - Sqrt[3] Sin[- ArcTan[----------]]}, 8 3 5 5 1 1 8 Sqrt[11] {q -> -- - - Cos[- ArcTan[----------]] + 24 8 3 5 1 1 8 Sqrt[11] - Sqrt[3] Sin[- ArcTan[----------]]}} 8 3 5 Out[7]= -17 {{q -> 0.432178}, {q -> 2.77556 10 }, {q -> 0.192822}} Out[8]= {{q -> 0.432178}, {q -> 0}, {q -> 0.192822}} === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: Jens, The problem is with the unevaluated expressions inside If[] and as Oliver pointed out (his post is missing, I will wait for another day to see if his post appears here or I will post his comments as a quote) the use of Evaluate[] to evaluate them before NDSolve[] solves my problem. And also the funifcase1 works fine even before, but funifcase2 did not work without the use of Evaluate[] inside the If[]. I posted this question because both the funifcase1 and funifcase2 are similar and we expect NDSolve[] to behave the same way. Gopinath === Subject: Function Programming Problems A colleague and myself are working on some Mathematica labs for Calculus using Mathematica 6.0 and I can't seem to find any information or examples that explain defining functions and using functions as arguments. I want to define a LinearApproximation command that preferably would take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have LinearApproximation[Sin[x],0] give x as the output. So far I have: LinearApproximation[function_, a_, x_] := function[a] + function'[a]*(x - a) which works mostly nicely, except it only works with LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or even x^2, etc)? Getting rid of the third argument x would be nice, but not necessary. David Taylor Roanoke College === Subject: Re: Function Programming Problems Two comments: The use of a function name instead of a functional expression works just as nicely for a user-defined function as for a built-in function. For example: f[x_] := x^3 Exp[-x] LinearApproximation[f,0][x] Second, since the original poster is writing the LinearApproximation function for use in a calculus class, presumably this comes well before the notion of series expansion or Taylor polynomials are are ever discussed. So it would be unfair to the students at this point to spoil things by prematurely introducing Series. Let them deal with the special case of best local linear approximation, probably very early in Calculus I, and some time later with best local quadratic approximation. Then they'll have something upon which to build the generalization to best n-th degree polynomial local approximation. >> ...I want to define a LinearApproximation command that preferably would >> take two arguments and return the linear approximation. Ideally, >> LinearApproximation[function_,a_] would have >> LinearApproximation[Sin[x],0] give x as the output. ...for BUILT IN functions [EMPH ADDED] of a single argument the expression LinearApproximation[Sin, a, x] is also allowed as shorthand. Finally, Mathematica already has a function for series expansion > called Series which you may want to look at. -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Function Programming Problems > Two comments: The use of a function name instead of a functional expression works just > as nicely for a user-defined function as for a built-in function. For > example: f[x_] := x^3 Exp[-x] > LinearApproximation[f,0][x] Second, since the original poster is writing the LinearApproximation > function for use in a calculus class, presumably this comes well before > the notion of series expansion or Taylor polynomials are are ever > discussed. So it would be unfair to the students at this point to > spoil things by prematurely introducing Series. Let them deal with > the special case of best local linear approximation, probably very early > in Calculus I, and some time later with best local quadratic > approximation. Then they'll have something upon which to build the > generalization to best n-th degree polynomial local approximation. Then why not let them find the linear and quadratic approximations for themselves, instead of providing a function to do it? My students would do the following. f[x_] = x^2 Cos[x] a = [Pi] p1[x_] = f[a] + f'[a] (x - a) p2[x_] = f[a] + f'[a] (x - a) + f''[a]/2 (x - a)^2 Plot[{f[x], p1[x]}, {x, 0, 2 [Pi]}] Plot[{f[x], p2[x]}, {x, 0, 2 [Pi]}] -- Helen Read University of Vermont === Subject: Re: Function Programming Problems David, 1. In[8]:= LinearApproximation[f_, x0_, x_] := (f /. {x -> x0}) + (D[f, x] /. {x -> x0})*(x - x0); LinearApproximation[Sin[x], Pi/4, x] Out[9]= 1/Sqrt[2] + (-(Pi/4) + x)/Sqrt[2] 2. In[10]:= LinearApproximation1[f_, x0_, x_] := Normal[Series[f, {x, x0, 1}]]; LinearApproximation1[Sin[x], Pi/4, x] Out[11]= 1/Sqrt[2] + (-(Pi/4) + x)/Sqrt[2] 3. In[14]:= LinearApproximation2[f_, x0_, x_, n_] := Normal[Series[f, {x, x0, n}]]; LinearApproximation2[Sin[x], Pi/4, x, 5] Out[15]= 1/Sqrt[2] + (-(Pi/4) + x)/Sqrt[2] - (-(Pi/4) + x)^2/(2*Sqrt[2]) - (-(Pi/4) + x)^3/(6*Sqrt[2]) + (-(Pi/4) + x)^4/(24*Sqrt[2]) + (-(Pi/4) + x)^5/(120*Sqrt[2]) Adriano Pascoletti 2008/7/24 : A colleague and myself are working on some Mathematica labs for > Calculus using Mathematica 6.0 and I can't seem to find any > information or examples that explain defining functions and using > functions as arguments. I want to define a LinearApproximation command that preferably would > take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have > LinearApproximation[Sin[x],0] give x as the output. So far I have: > LinearApproximation[function_, a_, x_] := function[a] + > function'[a]*(x - a) which works mostly nicely, except it only works with > LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or > even x^2, etc)? Getting rid of the third argument x would be nice, > but not necessary. > David Taylor > Roanoke College === Subject: Re: Function Programming Problems > A colleague and myself are working on some Mathematica labs for > Calculus using Mathematica 6.0 and I can't seem to find any > information or examples that explain defining functions and using > functions as arguments. I want to define a LinearApproximation command that preferably would > take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have > LinearApproximation[Sin[x],0] give x as the output. So far I have: > LinearApproximation[function_, a_, x_] := function[a] + > function'[a]*(x - a) which works mostly nicely, except it only works with > LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or > even x^2, etc)? Getting rid of the third argument x would be nice, > but not necessary. One possible way is as follow. First, we prevent the evaluation of the first argument of our function so it is written/replaced in the body as it is. Both definitions have an optional third argument that holds the name of the independent variable, assuming that the default name is x (so the function also works when called with only two arguments). The first definition handles the case when the function is provided in the form f[x]. The second definition handles the case when the function is provided just as f (without the independent variable). In[1]:= SetAttributes[linApp, HoldFirst] linApp[fun_, a_, var_: x] := (fun /. var -> a) + (D[fun, var] /. var -> a)*(var - a) linApp[fun_Symbol, a_, var_: x] := (fun[var] /. var -> a) + (D[fun[var], var] /. var -> a)*(var - a) linApp[Sin[x], a] linApp[Sin[x], 0] linApp[x^2, a] linApp[x^2, 0] linApp[Sin, a] linApp[Sin, 0] linApp[Sin[y], a, y] linApp[Sin, a, z] linApp[t^2, b, t] Out[4]= (-a + x)*Cos[a] + Sin[a] Out[5]= x Out[6]= a^2 + 2*a*(-a + x) Out[7]= 0 Out[8]= (-a + x)*Cos[a] + Sin[a] Out[9]= x Out[10]= (-a + y)*Cos[a] + Sin[a] Out[11]= (-a + z)*Cos[a] + Sin[a] Out[12]= b^2 + 2*b*(-b + t) === Subject: Re: Function Programming Problems First, do you REALLY want your students to think of a function as an expression in x -- technically, a functional relation in variable x -- such as sin x (Mathematica: Sin[x]). Or wouldn't you rather want then to think of a function as an object in its own right, or as an object sine (Mathematica: Sin) in its own right, such as sine (Mathematica: Sin)? Mathematically, surely the former is preferable. If so, then it seems to me a more natural way to set this up would be: LocalLinearApproximation[f_,a_][x_] := f[a] + f'[a](x-a) For example: LocalLinearApproximation[Sin,0][x] x That makes evident that the local linear approximation depends upon the function and the point a and, in essence, gives you a function that can then, in turn, be evaluated at any input x. Of course you could make this more explicit by the following variant: Clear[LocalLinearApproximation] LocalLinearApproximation[f_, a_] := f[a] + f'[a] (# - a) & (* or: LocalLinearApproximation[f_,a_] := Function[x, f[a]+f'[a] (x-a)] *) But if you insist upon the unfortunate, traditional calculus textbook approach of confusing a function with a functional relation in a variable x, then I'm not sure how you would want to get rid of that third argument entirely: how else would Mathematica know what is the variable? A colleague and myself are working on some Mathematica labs for > Calculus using Mathematica 6.0 and I can't seem to find any > information or examples that explain defining functions and using > functions as arguments. I want to define a LinearApproximation command that preferably would > take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have > LinearApproximation[Sin[x],0] give x as the output. So far I have: > LinearApproximation[function_, a_, x_] := function[a] + > function'[a]*(x - a) which works mostly nicely, except it only works with > LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or > even x^2, etc)? Getting rid of the third argument x would be nice, > but not necessary. > David Taylor > Roanoke College > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Function Programming Problems A colleague and myself are working on some Mathematica labs for > Calculus using Mathematica 6.0 and I can't seem to find any > information or examples that explain defining functions and using > functions as arguments. I want to define a LinearApproximation command that preferably would > take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have > LinearApproximation[Sin[x],0] give x as the output. So far I have: > LinearApproximation[function_, a_, x_] := function[a] + > function'[a]*(x - a) which works mostly nicely, except it only works with > LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or > even x^2, etc)? Getting rid of the third argument x would be nice, > but not necessary. Sin[x] is not a function in Mathematica, Sin[#]& or Function[{x},Sin [x]] are functions, you can pass them as arguments, so LinearApproximation[Sin[#]&,a,x] works, as does LinearApproximation[#^2&,a,x] Two other notes; first Mathematica will simplify the resulting polynomials so you may not get the exact results you expected, secondly for built in functions of a single argument the expression LinearApproximation[Sin, a, x] is also allowed as shorthand. Finally, Mathematica already has a function for series expansion called Series which you may want to look at. Ssezi === Subject: Re: Function Programming Problems if you say: LinearApproximation[function_, a_, x_] := function[a] + function'[a]*(x - a) you have to give a pure function and LinearApproximation[#^2 &, 0, x] will work For a general expression you have to give a symbol where the expression depend on, i.e. add a rule: LinearApproximation[foo_,y_,at_,x_]:=LinearApproximation[Function[{y},foo],a t,x] Jens A colleague and myself are working on some Mathematica labs for > Calculus using Mathematica 6.0 and I can't seem to find any > information or examples that explain defining functions and using > functions as arguments. I want to define a LinearApproximation command that preferably would > take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have > LinearApproximation[Sin[x],0] give x as the output. So far I have: > LinearApproximation[function_, a_, x_] := function[a] + > function'[a]*(x - a) which works mostly nicely, except it only works with > LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or > even x^2, etc)? Getting rid of the third argument x would be nice, > but not necessary. > David Taylor > Roanoke College > === Subject: Re: Interval arithmetic bug > In[1]:= Limit[Sin[x], x -> Infinity] Out[1]= Interval[{-1, 1}] > In[2]:= Limit[Sin[x + Pi/4], x -> Infinity] Out[2]= Interval[{-Sqrt[2], Sqrt[2]}] > In[3]:= TrigExpand[Sin[x + Pi/4]] Out[3]= Cos[x]/Sqrt[2] + Sin[x]/Sqrt[2] > In[4]:= (Limit[#1, x -> Infinity] & ) /@ {Cos[x]/Sqrt[2], > Sin[x]/Sqrt[2]} Out[4]= {Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}], > Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}]} > In[5]:= Plus @@ % Out[5]= Interval[{-Sqrt[2], Sqrt[2]}] > In[6]:= $Version Out[6]= 6.0 for Microsoft Windows (32-bit) (May 21, 2008) > oh my god.. > What do you mean by a interval arithemtic bug?. Interval arithmetic behaves exactly as it should, and it is perfectly correct that: Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}] + Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}] Interval[{-Sqrt[2], Sqrt[2]}] It is also quite correct that: Sin[# + Pi/4] &@Interval[{-Infinity, Infinity}] Interval[{-1, 1}] and also this: Cos[#]/Sqrt[2] + Sin[#]/Sqrt[2] &@Interval[{-Infinity, Infinity}] Interval[{-Sqrt[2], Sqrt[2]}] The reason is that interval arithmetic is *supposed to* only return upper bounds, that is unions of intervals that contain the correct answer. They will in general be larger than the optimal interval and will be different for different expressions even when they are mathematically equivalent. All of these are well known and normal properties of interval arithmetic and there is nothing buggy about the. The reason for this is that the purpose of interval arithmetic is estimation of errors and proofs of convergence. What one normally uses interval arithmetic to do is showing that the error in some computation is less than some specified number. For this reason it is enough to obtain any interval that of length smaller than the one that is required, and the fact that this interval may be much larger than the minimal one, is less important then the computational efficiency of the procedure. In fact the only issue involved here it is not an interval arithmetic bug but of imprecise documentation of Limit. Te problem is that interval arithmetic only tries to find an upper bound for the range of the function whose limit is being computed but the documentation for Limit says Limit returns Interval objects to represent ranges of possible values, for example at essential singularities. The word represent suggests that the interval object returned by Limit[f[x],x->a] consists of all the limit points of the function f for all sequences x_n->a, but actually what is returned is an interval object that contains all such points but which also contains points that are not themselves limits of the given function. I think this ought to be made more clear, that's all. Andrzej Kozlowski === Subject: Interval arithmetic bug In[1]:= Limit[Sin[x], x -> Infinity] Out[1]= Interval[{-1, 1}] In[2]:= Limit[Sin[x + Pi/4], x -> Infinity] Out[2]= Interval[{-Sqrt[2], Sqrt[2]}] In[3]:= TrigExpand[Sin[x + Pi/4]] Out[3]= Cos[x]/Sqrt[2] + Sin[x]/Sqrt[2] In[4]:= (Limit[#1, x -> Infinity] & ) /@ {Cos[x]/Sqrt[2], Sin[x]/Sqrt[2]} Out[4]= {Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}], Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}]} In[5]:= Plus @@ % Out[5]= Interval[{-Sqrt[2], Sqrt[2]}] In[6]:= $Version Out[6]= 6.0 for Microsoft Windows (32-bit) (May 21, 2008) oh my god.. === Subject: Re: Interval arithmetic bug > In[1]:= Limit[Sin[x], x -> Infinity] Out[1]= Interval[{-1, 1}] In[2]:= Limit[Sin[x + Pi/4], x -> Infinity] Out[2]= Interval[{-Sqrt[2], Sqrt[2]}] In[3]:= TrigExpand[Sin[x + Pi/4]] Out[3]= Cos[x]/Sqrt[2] + Sin[x]/Sqrt[2] In[4]:= (Limit[#1, x -> Infinity] & ) /@ {Cos[x]/Sqrt[2], > Sin[x]/Sqrt[2]} Out[4]= {Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}], > Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}]} In[5]:= Plus @@ % Out[5]= Interval[{-Sqrt[2], Sqrt[2]}] In[6]:= $Version Out[6]= 6.0 for Microsoft Windows (32-bit) (May 21, 2008) oh my god.. I might have missed the point, but as far as I can tell, the interval arithmetic is correct. What you may have expected is to get the interval [-1, 1], which is included in the interval [-sqrt(2), sqrt(2)]; however, when computing limits, they is no guarantee whatsoever that Mathematica will return systematically the smallest interval that encompasses all possible values since an *Interval[]* object has no knowledge of the function that generated it in first instance (so the standard rules of interval arithmetic applied). For instance, the following example is perfeclty correct in terms of interval arithmetic, though one may have wished to get one for the last expression: In[1]:= Limit[Cos[x]^2 + Sin[x]^2, x -> Infinity] Limit[Cos[x]^2, x -> Infinity] Limit[Sin[x]^2, x -> Infinity] Limit[Cos[x]^2, x -> Infinity] + Limit[Sin[x]^2, x -> Infinity] Out[1]= 1 Out[2]= Interval[{0, 1}] Out[3]= Interval[{0, 1}] Out[4]= Interval[{0, 2}] === Subject: Re: Interval arithmetic bug > In[1]:= Limit[Sin[x], x -> Infinity] Out[1]= Interval[{-1, 1}] In[2]:= Limit[Sin[x + Pi/4], x -> Infinity] Out[2]= Interval[{-Sqrt[2], Sqrt[2]}] Of course, we would like Out[2] to be the same as Out[1]. But I'm not sure this behavior, shown in Out[2], should be called a bug. It's not new to version 6, and I suppose that WR has long been aware of it. Note that Out[2] contains Out[1] as a subinterval. Thus, containment has not been violated. David > In[3]:= TrigExpand[Sin[x + Pi/4]] Out[3]= Cos[x]/Sqrt[2] + Sin[x]/Sqrt[2] In[4]:= (Limit[#1, x -> Infinity] & ) /@ {Cos[x]/Sqrt[2], > Sin[x]/Sqrt[2]} Out[4]= {Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}], > Interval[{-(1/Sqrt[2]), 1/Sqrt[2]}]} In[5]:= Plus @@ % Out[5]= Interval[{-Sqrt[2], Sqrt[2]}] In[6]:= $Version Out[6]= 6.0 for Microsoft Windows (32-bit) (May 21, 2008) oh my god.. === Subject: Given function of single parameter function, to find function and By what Mathematica procedures is it possible to solve for function f and the parameter/argument linking relation UV [u,v] = 0 from a given relation f[v]= 4 f[u]^3 - 3 f[u] ? Known answer for this case is function f = cos, argument link relation v =3 u respectively. For another simpler case f(u)^2 + f(v)^2 =1, one solution is u + v = (2 k-1) pi/2, for f = cos or sin. Narasimham === Subject: A suggestion fo web-hosting of 3-D images It would be nice if Mathematica web-hosts a site wherein images of 3D objects previously defined in Mathematica (Plot 3D,ParametricPlot3D, Show,Animations) can be securely submitted for visitors viewing Realtime3D using mouse. Narasimham === Subject: Suggestions for selling a copy of Mathematica V6 wanted I have an extra copy of Mathematica V6 for Windows that I am not using and that still has over 6 months of Premier Service support left that will allow unlimited phone and e-mail support and free upgrades (only for US and Canada customers) and all the other benefits of support. Does anyone have any suggestions where I might try to sell it (other than eBay) or know of someone who might be in the market? Since this is a professional license (aka Standard), and not a student or academic version, there is no problem in selling and transferring the license to someone else. This is a US and Canada only version, so cant export it or sell it anywhere else. Wolfram's only stipulations are that I just have to give all the copies of the software and other elements I have to the buyer and write a letter certifying I have deleted the licensed copy I had installed and the buyer has to agree to accept all the terms and conditions of the license agreement. This would be a good buy for someone who would like to save a lot off the list price of a new copy, so if you know of someone in the market, please let them know and pass this along to them. I hope this doesn't cause a bru-ha-ha, so if this topic offends [Normally, I do not permit attempted sales of Mathematica copies in this group, but I realized that there has never an attempt to point people to places to correctly sell copies they might have. Therefore, once Bob's question is answered, I will have information I can pass on to others who post similar questions. -- moderator] -Bob === Subject: Re: Suggestions for selling a copy of Mathematica V6 wanted > I have an extra copy of Mathematica V6 for Windows that I am not using > and that still has over 6 months of Premier Service support left that > will allow unlimited phone and e-mail support and free upgrades (only > for US and Canada customers) and all the other benefits of support. > Does anyone have any suggestions where I might try to sell it (other > than eBay) or know of someone who might be in the market? Since this > is a professional license (aka Standard), and not a student or > academic version, there is no problem in selling and transferring the > license to someone else. This is a US and Canada only version, so cant > export it or sell it anywhere else. Wolfram's only stipulations are that I just have to give all the > copies of the software and other elements I have to the buyer and > write a letter certifying I have deleted the licensed copy I had > installed and the buyer has to agree to accept all the terms and > conditions of the license agreement. This would be a good buy for someone who would like to save a lot off > the list price of a new copy, so if you know of someone in the market, > please let them know and pass this along to them. I hope this doesn't cause a bru-ha-ha, so if this topic offends [Normally, I do not permit attempted sales of Mathematica copies > in this group, but I realized that there has never an attempt > to point people to places to correctly sell copies they might > have. Therefore, once Bob's question is answered, I will have > information I can pass on to others who post similar questions. -- modera= tor] -Bob Sorry, but this sold about a week ago, so it is no longer available from me. I got only one inquiry a couple of days after I posted this question looking for suggestions, and he ended up buying this after he verified it was a legit license. Then got two more in the last couple of days, so thought I would put something here, so everyone knew that it was no longer available. I never did hear one comment from anyone about any suggestions as to where something like this could be sold, so that question never did get resolved. The Professional version of Mathematica is indeed transferable (but am not sure about the student or academic) -- just read paragraph d of the Mathematica License Agreement's Permitted Uses section about how to transfer a license, and verify with Wolfram that the license is the proper Use Class, and follow the steps. I suppose the difficult part is being able to verify that the license in question is a legit copy, and we were able to do it by having the buyer call the Wolfram sales person I bought it from and they verified it, so the buyer was satisfied and I didn't need to give out the license number before I received payment. mechanism for people to ask for suggestions on what to do with a no- longer-used copy of Mathematica. -Bob === Subject: Exact NullSpace computations I need to compute the (exact) NullSpace of an mxn complex exact rational matrix M where m>>n (looking at 1766x1425 now). Moreover, M is pretty sparse and I know the dimensions of the nullspace because I am able to do a fast rank computation on M with MatrixRank[M, Modulus->largeprime]. When I simply apply the NullSpace[M] function, the computations take one whole month to finish. I am sure there should be a faster way but I don't have a clue yet. Any suggestions ? Hope you guys can help me ! Brey from The Netherlands === Subject: Re: HypergeometricPFQ - simplification I could only now return to the problem, but I appreciate very much your solution. However, I keep saying, that a symbol manipulation system is the least appropriate to manipulate symbols :) Or, these kinds of problems are much more complicated than to solve a system of nonlinear PDEs. Janos > Could anyone show using Mathematica that the expression > -2/27 + (253*HypergeometricPFQ[{-1/2, -1/6, 1/6}, {4/3, 5/3}, -1/729])/ > 108 - (911*HypergeometricPFQ[{1/2, 5/6, 7/6}, {7/3, 8/3}, -1/729])/ > 6298560 + > (73*HypergeometricPFQ[{3/2, 11/6, 13/6}, {10/3, 11/3}, -1/729])/ > 9795520512 > is equal to > (-2*(-1 + 10*Sqrt[10]))/27? (Using, say, TraceInternal, to see what is > going on.) > Janos > A way to prove this in Mathematica takes couple of lines of code: In[1]:= $Version Out[1]= 6.0 for Microsoft Windows (32-bit) (March 13, 2008) (* your expression *) > In[2]:= expr = -(2/27) + > 253/108 HypergeometricPFQ[{-(1/2), -(1/6), 1/6}, {4/3, 5/3}, -(1/ > 729)] - ( > 911 HypergeometricPFQ[{1/2, 5/6, 7/6}, {7/3, 8/3}, -(1/729)])/ > 6298560 + ( > 73 HypergeometricPFQ[{3/2, 11/6, 13/6}, {10/3, 11/3}, -(1/729)])/ > 9795520512; Now define In[3]:= e1 = ({D[ > HypergeometricPFQ[{-(1/2), -(1/6), 1/6 + a} - 1, {4/3, 5/3} - > 1, -z^3], z], > D[HypergeometricPFQ[{-(1/2), -(1/6), 1/6 + a} - 1, {4/3, 5/3} - > 1, -z^3], z, z], > D[HypergeometricPFQ[{-(1/2), -(1/6), 1/6 + a} - 1, {4/3, 5/3} - > 1, -z^3], z, z, z]} /. {a -> 0, z -> 1/9} // Expand) Out[3]= {(35/144)* > HypergeometricPFQ[{-(1/2), -(1/6), 1/6}, {4/3, 5/3}, -(1/729)], > (35/8)* > HypergeometricPFQ[{-(1/2), -(1/6), 1/6}, {4/3, > 5/3}, -(1/729)] - (7* > HypergeometricPFQ[{1/2, 5/6, 7/6}, {7/3, 8/3}, -(1/729)])/ > 124416, (315/8)* > HypergeometricPFQ[{-(1/2), -(1/6), 1/6}, {4/3, 5/3}, -(1/729)] - > (7*HypergeometricPFQ[{1/2, 5/6, 7/6}, {7/3, 8/3}, -(1/729)])/ > 2304 + > (35*HypergeometricPFQ[{3/2, 11/6, 13/6}, {10/3, > 11/3}, -(1/729)])/214990848} Now repeat the same with variable a set to 0 from the outset: In[4]:= e2 = > FullSimplify[ > With[{a = 0}, {D[ > HypergeometricPFQ[{-(1/2), -(1/6), 1/6 + a} - 1, {4/3, 5/3} - > 1, -z^3], z], > D[HypergeometricPFQ[{-(1/2), -(1/6), 1/6 + a} - 1, {4/3, 5/3} - > 1, -z^3], z, z], > D[HypergeometricPFQ[{-(1/2), -(1/6), 1/6 + a} - 1, {4/3, 5/3} - > 1, -z^3], z, z, z]}] /. z -> 1/9] Out[4]= {Sqrt[ > 11236809 + 778034 Sqrt[73] - > 2000 Sqrt[12368090 + 7780340 Sqrt[73]]]/1458, > 7/324 Sqrt[ > 21873 + 10658 Sqrt[73] - 200 Sqrt[-781270 + 106580 Sqrt[73]]], > 35/36 Sqrt[73/2 (15 + Sqrt[73]) + 10 Sqrt[5 (595 + 73 Sqrt[73])]]} Now solve for hypergeometric functions: In[7]:= ru = > Thread[Union[Cases[e1, _HypergeometricPFQ, Infinity]] -> {h1, h2, > h3}]; and substitute back into your original expression: In[8]:= FullSimplify[ > expr /. (Solve[((e1 - e2) /. ru) == 0, {h1, h2, h3}] /. (Reverse /@ > ru))] Out[8]= {2/27 (-1 + 10 Sqrt[10])} Hope this helps, > Oleksandr Pavlyk > Wolfram Research === Subject: Export into Excel Worksheets I've got a list of data that I'd like to Export into Excel. The twist is, I'd like to export each element of the list into a separate worksheet within the same Excel Workbook. Can this be done in Mathematica v6? Mark === Subject: Re: Export into Excel Worksheets > I've got a list of data that I'd like to Export into Excel. The twist > is, I'd like to export each element of the list into a separate > worksheet within the same Excel Workbook. Can this be done in Mathematica v6? Assuming that you mean that you have a list of lists of lists, Mathematica 6.0 will automatically save each list of lists in a separate sheet within the same worksheet. For instance, try the following data = RandomReal[{0, 1}, {3, 4, 2}]; Export[test.xls, data] === Subject: Re: Solving 3d degree polynomial When you fill in those specific values of the parameters, are you supplying exact rationals or other exact numbers, with square-roots, e.g., or are you supplying decimals? > I have a function > f(q)=2n(n+1)q^3-(1+t)(2n+1)q^2+2(t-(n+1)A)q+(1+t)A > in which n>1, -1 Solve[Y==0,q] it gives me 3 real roots. > If instead I ask for a symbolic solution before filling in the same values of the parameters, Mathematica gives almost the same roots, but now there is an imaginary part to the solution. It is of the order 10^(-16). Why are the roots complex if I find a solution before filling in parameters, but real if I fill in parameters before finding the solution? > Floris > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Solving 3d degree polynomial f[q] = 2 n (n + 1) q^3 - (1 + t) (2 n + 1) q^2 + 2 (t - (n + 1) A) q + (1 + t) A; sub = {n -> 3, A -> 1/4, t -> 1/2}; soln1 = Solve[f[q] == 0, q] // Simplify; soln2 = Solve[f[q] == 0 /. sub, q] // Simplify; (soln1 /. sub) == soln2 // Simplify True soln1 /. sub // N {{q -> 0.4533892260432264 + 0.*I}, {q -> -0.19375575274301296 + 1.2335811384723961*^-17*I}, {q -> 0.17786652669978656 - 4.9343245538895844*^-17*I}} soln2 // N {{q -> 0.45338922604322646 - 5.551115123125783*^-17*I}, {q -> -0.19375575274301293 - 6.476300976980079*^-17*I}, {q -> 0.17786652669978645 + 1.1102230246251565*^-16*I}} Both have small Imaginary parts due to numerical errors when using machine size numbers in the calculation. Use Chop {%, %%} // Chop {{{q -> 0.45338922604322646}, {q -> -0.19375575274301293}, {q -> 0.17786652669978645}}, {{q -> 0.4533892260432264}, {q -> -0.19375575274301296}, {q -> 0.17786652669978656}}} I have a function f(q)=2n(n+1)q^3-(1+t)(2n+1)q^2+2(t-(n+1)A)q+(1+t)A in which n>1, -1 The following code calculates the elements of matrises (x6). But in the result there are some characters like #1,& vs. > And I couldn't success to express the result without these characters. Is there anyway to express more clear result? Please help!!!!!!!!! A = {{0, -R, 0, 0, 0, 0}, {(-Gamma^2*R^3*k)/Dnn, 0, -1,(R*(1 + Gamma^2))/Dnn, 0, 0}, {0, 1, 0, 0, (R*(1+ Gamma^2))/Dtt, (-R^2*Gamma^2)/Dtt}, {0, 0, 0, 0, -1, R}, {0, 0, 0, 1, 0, 0}, {k*R, 0, 0, 0, 0, 0}} expmat = MatrixExp[t*A] > expmat // MatrixForm > FullSimplify[expmat[[1, 1]]] The characters (#!, &, and the likes) you are referring to are parts of larger expressions called *Root[]*. Each Root[] object is an exact concise symbolic representation of a root. See http://reference.wolfram.com/mathematica/ref/Root.html If you want to get rid of them, you can use *ToRadicals[]*. See http://reference.wolfram.com/mathematica/ref/ToRadicals.html Note that, arguably, transforming Root[] objects into radicals might not be such a good idea since the complexity of the resulting matrix (measured in terms of binary tree size and depth) is dramatically increased. For instance, A = {{0, -R, 0, 0, 0, 0}, {(-Gamma^2*R^3*k)/Dnn, 0, -1, (R*(1 + Gamma^2))/Dnn, 0, 0}, {0, 1, 0, 0, (R*(1 + Gamma^2))/Dtt, (-R^2*Gamma^2)/Dtt}, {0, 0, 0, 0, -1, R}, {0, 0, 0, 1, 0, 0}, {k*R, 0, 0, 0, 0, 0}}; expmat = MatrixExp[t*A]; LeafCount[expmat[[1, 1]]] (* 7972 *) LeafCount[ToRadicals[expmat[[1, 1]]]] (* 74516 *) LeafCount[expmat] (* 232132 *) LeafCount[ToRadicals[expmat]] (* 2063994 *) === Subject: Is this a bug? I tried to solve the following equation with mathematica 6.03 Solve[{Abs[X+Y I]==5,X==3},{X,Y}] and got the answer {{X -> 3, Y -> -2 I}, {X -> 3, Y -> 8 I}} Am I suppose to get {{X -> 3, Y -> 4 I}, {X -> 3, Y -> -4 I}} ? === Subject: Re: Is this a bug? > I tried to solve the following equation with mathematica 6.03 Solve[{Abs[X+Y I]==5,X==3},{X,Y}] and got the answer {{X -> 3, Y -> -2 I}, {X -> 3, Y -> 8 I}} It's easy to verify that both of those solutions are correct. > Am I suppose to get {{X -> 3, Y -> 4 I}, {X -> 3, Y -> -4 I}} ? No. Rather, I think that you were wanting Y itself to be real, and so you should have been hoping for {{X -> 3, Y -> 4}, {X -> 3, Y -> -4}} instead. In any event, it seems that you were wanting Mathematica to find the possible imaginary parts of complex numbers having real part 3 and modulus 5. The way I'd do that is In[1]:= Reduce[Abs[3 + Im[z]*I] == 5, z] Out[1]= Im[z] == -4 || Im[z] == 4 Finally, in your title, you asked if there were a bug. Well, as I had said, the two solutions which your Solve gave are correct. But I think that Mathematica is perhaps at fault for not having warned you that Solve was not necessarily giving you all possible solutions. David === Subject: Re: Is this a bug? > I tried to solve the following equation with mathematica 6.03 Solve[{Abs[X+Y I]==5,X==3},{X,Y}] and got the answer {{X -> 3, Y -> -2 I}, {X -> 3, Y -> 8 I}} Am I suppose to get {{X -> 3, Y -> 4 I}, {X -> 3, Y -> -4 I}} ? Looks correct to me: {X -> 3, Y -> -2 I}: Abs[X + Y I] == Abs[3 + (-2 I) I] == Abs[3 + 2] == Abs[5] = 5 {X -> 3, Y -> 8 I}: Abs[X + Y I] == Abs[3 + (8 I) I] == Abs[3 - 8] == Abs[-5] = 5 -- Andy === Subject: Re: Is this a bug? > I tried to solve the following equation with mathematica 6.03 Solve[{Abs[X+Y I]==5,X==3},{X,Y}] and got the answer {{X -> 3, Y -> -2 I}, {X -> 3, Y -> 8 I}} Am I suppose to get {{X -> 3, Y -> 4 I}, {X -> 3, Y -> -4 I}} ? No. Mathematica is correct. Also, from the online help, Solve gives generic solutions only. It discards solutions that are valid only when the parameters satisfy special conditions. Reduce gives the complete set of solutions. For instance, In[1]:= eqns = {Abs[x + y*I] == 5, x == 3}; sols = Solve[eqns] eqns /. sols eqns /. {{x -> 3, y -> 4 I}, {x -> 3, y -> -4 I}} Reduce[eqns] Out[2]= {{x -> 3, y -> -2 I}, {x -> 3, y -> 8 I}} Out[3]= {{True, True}, {True, True}} Out[4]= {{False, True}, {False, True}} Out[5]= 2 -2 <= Im[y] <= 8 && (Re[y] == -Sqrt[16 + 6 Im[y] - Im[y] ] || 2 Re[y] == Sqrt[16 + 6 Im[y] - Im[y] ]) && x == 3 See http://reference.wolfram.com/mathematica/ref/Solve.html http://reference.wolfram.com/mathematica/ref/Reduce.html === Subject: Re: Is this a bug? > I tried to solve the following equation with mathematica 6.03 Solve[{Abs[X+Y I]==5,X==3},{X,Y}] and got the answer {{X -> 3, Y -> -2 I}, {X -> 3, Y -> 8 I}} Am I suppose to get {{X -> 3, Y -> 4 I}, {X -> 3, Y -> -4 I}} ? No, you suppose to get {{X->3, Y->4},{X->3, Y->-4}} (without I), that's what I would expect too. The solutions Mathematica gives are correct -- just plug in. But you are right, they are not what one would expect. This will give you the expected result: Solve[{ComplexExpand[Abs[x+I y]]==5,x==3},{x,y}] Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Listplot with colours I cannot find this in the help at all, although I am sure it is straightforward. I have a list of coordinates of points points={{x1,y1},{x2,y2}...} and two lists of attributes att1={a1,a2,..} and att2={b1,b2,...} I want to do something like ListPlot[points,PlotStyle->{Hue[att1],PointSize[att2]}] So I get dots at each point in colour att1 and size given by att2. I'm sure it's easy but I can't do it. I am using version 5.1 Peter === Subject: Re: Listplot with colours > I cannot find this in the help at all, although I am sure it is > straightforward. I have a list of coordinates of points points={{x1,y1},{x2,y2}...} > and two lists of attributes att1={a1,a2,..} and att2={b1,b2,...} I want to do something like > ListPlot[points,PlotStyle->{Hue[att1],PointSize[att2]}] > So I get dots at each point in colour att1 and size given by att2. I'm > sure it's easy but I can't do it. I am using version 5.1 The code below should work with version prior to 6.0, though you may have to add some Evaluate[] for the handling of arguments may have change between version 5.x and 6.x. points = {{0, 3}, {4, 1}, {5, 3}, {8, 1}, {2, 3}}; att1 = {0.878824, 0.313478, 0.264895, 0.535987, 0.619636}; att2 = {0.05, 0.1, 0.15, 0.2, 0.25}; ListPlot[List /@ points, PlotStyle -> MapThread[{Hue[#1], PointSize[#2]} & , {att1, att2}]] === Subject: Unprotect[Pi] How does one unprotect symbol Pi and the Greek lower case letter pi (π)? Unprotect[Pi] doesn't seem to do the job. Pi // N 3.14159 Unprotect[Pi] {Pi} Pi π Pi // N 3.14159 Unprotect[π] π//N 3.14159 === Subject: Re: Unprotect[Pi] In[1]:= Unprotect[Pi] Out[1]= {Pi} In[2]:= N[Pi,10] Out[2]= 3.141592654 In[3]:= Pi = 3 Out[3]= 3 In[4]:= N[Pi,10] Out[4]= 3.000000000 Cool! Now Pi is 3 just like the bible said. And he [Hiram] made a molten sea, ten cubits from the one rim to the other it was round all about, and...a line of thirty cubits did compass it round about....And it was an hand breadth thick.... =97 First Kings, chapter 7, verses 23 and 26 > How does one unprotect symbol Pi and the Greek lower case letter pi > (π)? =A0Unprotect[Pi] doesn't seem to do the job. Pi // N > 3.14159 > Unprotect[Pi] > {Pi} > Pi > π > Pi // N > 3.14159 > Unprotect[π] > π//N > 3.14159 === Subject: Re: Unprotect[Pi] > How does one unprotect symbol Pi and the Greek lower case letter pi > (π)? Unprotect[Pi] doesn't seem to do the job. Pi // N > 3.14159 > Unprotect[Pi] > {Pi} > Pi > π > Pi // N > 3.14159 > Unprotect[π] > π//N > 3.14159 I am not sure to have grasped what your try to achieve, but Unprotect[] works fine on my system. The following redefines the value of Pi to the nonsensical complex number 3 - I In[1]:= Unprotect[Pi]; Pi = 3 - I; Protect[Pi]; Pi Out[4]= 3 - I === Subject: Re: Writing to an External file, ie .txt For[w = 1, w < (time), mkw[[w, 2]] = v[w] /. solution; w++]; > For[w = 1, w < (time), mkw[[w, 1]] = w; w++]; mkw; > Export[saveFilesAB[[i]], mkw, Table]; In the export file the data looks like this: 1 {-79.84700975294606} > 2 {-79.69051240690148} > 3 {-79.53102986953975} > 4 {-79.36900699034439} > 5 {-79.20482318524301} > 6 {-79.03880245505214} > 7 {-78.87122188515096} > 8 {-78.70231884148791} > 9 {-78.53229705609004} > 10 {-78.36133171685125} > 11 {-78.18957405806462} > 12 {-78.01715486892012} > 13 {-77.84418733157375} > 14 {-77.6707702358632} > 15 {-77.49698984909358} > 16 {-77.32292183143544} > 17 {-77.148632902709} > 18 {-76.97418220274439} > 19 {-76.7996223969284} > 20 {-76.62500065712533} I have tried different export style but it can't get rid of it. Is this something to do with using .solution? My data analysis requires this format but can't handle the {} so I am stuck with out passing it though a java script that will remove them. [... Crossposted to MathGroup ...] A quick fix would be: mkw[[All, 2]] = Flatten[mkw[[All, 2]]] For instance, [...] In[12]:= mkw = Table[0, {time - 1}, {2}]; For[w = 1, w < (time), mkw[[w, 2]] = v[w] /. solution; w++]; For[w = 1, w < (time), mkw[[w, 1]] = w; w++]; mkw[[All, 2]] = Flatten[mkw[[All, 2]]]; Export[ie2.txt, mkw, Table]; Import[ie2.txt, Table] Out[17]= {{1, v[1]}, {2, v[2]}, {3, v[3]}, {4, v[4]}, {5, v[5]}, {6, v[6]}, {7, v[7]}, {8, v[8]}, {9, v[9]}} === Subject: Multidimensional FITS files I am trying to import a 4 dimensional data FITS file: 1024 x 1024 x 272 x 1. This file is a bona fide FITS file, created by the Canadian Astronomy Data Centre (more precisely it is one file extracted from the Canadian Galactic Plane Survey: http://www1.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/cgps/query.html). After the command, nebula=Import[CGPS_MB2_HI_line_image.fits.gz,{GZIP,FITS}]; here is the error message I obtain: Import::errstruct: Malformed data structure. !(Missing required keyword BITPIX). Using another software, I have checked that the required keyword exists... My question: is Mathematica able to handle FITS files having more than 2 dimensions (data cubes, etc.)? Yves Grosdidier === Subject: Re: Multidimensional FITS files I have forgotten to let you know my config: 6.0.2.0, WinXP SP2 Yves === Subject: Re: Multidimensional FITS files > I have forgotten to let you know my config: 6.0.2.0, WinXP SP2 Yves, You should submit a bug report -- if you have not already done so -- to support@wolfram.com about the specific error you got. (It appears that the errors we get respectively might not be related) I myself submitted a bug report about the error on my system (64-bit Intel Mac OS X Leopard 1.5.4 Mathematica 6.0.3). Here is an extract of last email I got from WRI: I was able to reproduce both errors; the first error I believe is due to a corrupted download. If I attempt to download the file by clicking on the floppy disk icon under the Download NOW table heading, I cannot unzip the archive, no matter what archive utility I use on either Mac or Linux. However, by selecting the checkbox next to the file and clicking Request Marked Datasets I am then able to download an uncorrupted version of the file. Then I am able to reproduce the second error that you receive; in this case, I believe the problem is occurring because of the size of the file that you are trying to import; a FITS file that is ~600 MB will take up about 4 times as much memory space when imported into Mathematica, and Mathematica will have a lot of problems when attempting to deal with a file that requires that kind of space. I am able to import smaller FITS files with no difficulty. === Subject: Possible bug in Fits.exe on Mac OSX Mathematica 6.0.3 > I am trying to import a 4 dimensional data FITS file: 1024 x 1024 x > 272 x 1. This file is a bona fide FITS file, created by the Canadian Astronomy > Data Centre (more precisely it is one file extracted from the Canadian > Galactic Plane Survey: http://www1.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/cgps/query.html). After the command, nebula=Import[CGPS_MB2_HI_line_image.fits.gz,{GZIP,FITS}]; here is the error message I obtain: Import::errstruct: Malformed data structure. !(Missing required > keyword BITPIX). Using another software, I have checked that the required keyword > exists... My question: is Mathematica able to handle FITS files having more than > 2 dimensions (data cubes, etc.)? FYIW, I downloaded a FITS file (about 445 MB) from the website you mentioned. Then I tried to import the compress as well as the uncompress file without success but with a different message/problem from yours: the import helper program Fits.exe quits unexpectedly. (The downloaded file is good since MicroObservatory Image 2.0 [1] has no problem to read and manipulate it.) Mathematica 6.0.3 In[1]:= Timing[ image = Import[CGPS_MH1_HI_line_image.fits.gz, {GZIP, FITS}]] During evaluation of In[1]:= LinkObject::linkd:Unable to communicate with closed link LinkObject[/Applications/Mathematica.app/SystemFiles/Converters/ Binaries/MacOSX-x86-64/FITS.exe,9,9]. >> Out[1]= {3.98607, $Failed} In[2]:= Timing[image = Import[CGPS_MH1_HI_line_image.fits]] During evaluation of In[2]:= LinkObject::linkd:Unable to communicate with closed link LinkObject[/Applications/Mathematica.app/SystemFiles/Converters/ Binaries/MacOSX-x86-64/FITS.exe,10,9]. >> Out[2]= {3.70389, $Failed} In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) - Jean-Marc [1] MicroObservatory Image 2.0, http://mo-www.harvard.edu/MicroObservatoryImage/ === Subject: Re: Possible bug in Fits.exe on Mac OSX Mathematica 6.0.3 > I am trying to import a 4 dimensional data FITS file: 1024 x 1024 x >> 272 x 1. >> This file is a bona fide FITS file, created by the Canadian Astronomy >> Data Centre (more precisely it is one file extracted from the Canadian >> Galactic Plane Survey: http://www1.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/cgps/query.html). >> After the command, >> nebula=Import[CGPS_MB2_HI_line_image.fits.gz,{GZIP,FITS}]; >> here is the error message I obtain: >> Import::errstruct: Malformed data structure. !(Missing required >> keyword BITPIX). >> Using another software, I have checked that the required keyword >> exists... >> My question: is Mathematica able to handle FITS files having more than >> 2 dimensions (data cubes, etc.)? FYIW, I downloaded a FITS file (about 445 MB) from the website you mentioned. > Then I tried to import the compress as well as the uncompress file > without success but with a different message/problem from yours: the > import helper program Fits.exe quits unexpectedly. (The downloaded file > is good since MicroObservatory Image 2.0 [1] has no problem to read and > manipulate it.) Mathematica 6.0.3 In[1]:= Timing[ > image = Import[CGPS_MH1_HI_line_image.fits.gz, {GZIP, FITS}]] During evaluation of In[1]:= LinkObject::linkd:Unable to communicate > with closed link > LinkObject[/Applications/Mathematica.app/SystemFiles/Converters/ > Binaries/MacOSX-x86-64/FITS.exe,9,9]. Out[1]= {3.98607, $Failed} In[2]:= Timing[image = Import[CGPS_MH1_HI_line_image.fits]] During evaluation of In[2]:= LinkObject::linkd:Unable to communicate > with closed link > LinkObject[/Applications/Mathematica.app/SystemFiles/Converters/ > Binaries/MacOSX-x86-64/FITS.exe,10,9]. Out[2]= {3.70389, $Failed} In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) > - Jean-Marc [1] MicroObservatory Image 2.0, > http://mo-www.harvard.edu/MicroObservatoryImage/ > I submitted a bug report [TS 25343] about the error on my system (64-bit Intel Mac OS X Leopard 1.5.4 Mathematica 6.0.3). It seems the error on my system is due to the size of the file I downloaded because the import program/Mathematica needs 4 times the file's size in memory to convert the file. Here is an extract of last email I got from WRI: Then I am able to reproduce the second error that you receive; in this case, I believe the problem is occurring because of the size of the file that you are trying to import; a FITS file that is ~600 MB will take up about 4 times as much memory space when imported into Mathematica, and Mathematica will have a lot of problems when attempting to deal with a file that requires that kind of space. I am able to import smaller FITS files with no difficulty. === Subject: Re: Multidimensional FITS files I confirm the problem (6.0.3, WinXP): I downloaded this file to try it as well (geeze, couldn't you have chosen a smaller example??). In> fitsElementsNames=Import[CGPS_MB2_HI_line_image. fits.gz,{GZIP,FITS, Elements}] Out> {Airmass,Author,BitDepth,ColorSpace,Comments,Data,DataType, Declination,Device,Equinox,ExposureTime,Graphics,History,HourAngle, Plaintext,Range,RawData,Reference,RightAscension,SiderealTime, TableData,TableHeaders,TableUnits,Telescope} In> fitsElements=Import[CGPS_MB2_HI_line_image. fits.gz,{GZIP,FITS, fitsElementsNames}] Out> Import::errstruct: Malformed data structure. Missing required keyword BITPIX. >> $Failed In> bitdepth=Import[CGPS_MB2_HI_line_image. fits.gz,{GZIP,FITS, {BitDepth}}] Out> Import::errstruct: Malformed data structure. Missing required keyword BITPIX. >> $Failed This happens for various permutations of above, e.g., {GZIP,FITS, {BitDepth}} {GZIP,FITS, BitDepth} {GZIP,FITS, BitDepth} DataType, et cet. I also viewed the file using fv.exe (NASA FITS viewer, http://heasarc.gsfc.nasa.gov/ftools/fv) and confirmed that BITPIX=16. Here's a header dump: SIMPLE = T / file does conform to FITS standard BITPIX = 16 / number of bits per data pixel NAXIS = 4 / number of data axes NAXIS1 = 1024 / length of data axis 1 NAXIS2 = 1024 / length of data axis 2 NAXIS3 = 272 / length of data axis 3 NAXIS4 = 1 / length of data axis 4 EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format defined in Astronomy and COMMENT Astrophysics Supplement Series v44/p363, v44/p371, v73/p359, v73/p365. COMMENT Contact the NASA Science Office of Standards and Technology for the COMMENT FITS Definition document #100 and other FITS information. BLANK = -32767 / UNDEFINED PIXEL VALUE (FITS DATA) DATE-FTS= '2000-11-20' / DATE OF FITS FILE CREATION ADC_ARCH= 'CGPS ' / DATA CENTRE ARCHIVE ADC_TYPE= 'MOSAIC ' / TYPE OF IMAGE: FIELD/MOSAIC ADC_AREA= 'MB2 ' / IMAGE AREA CODE IMAG_DES= 'HI line cube' / IMAGE DESCRIPTION ADC_BAND= 'HI ' / SPECTRAL BAND ADC_UNIT= 'line ' / BAND UNITS, OR DESCRIPTOR ADC_POLR= ' ' / STOKES CODE, BLANK = VARIOUS ADC_QUAL= 'image ' / IMAGE-TYPE QUALIFIER ORIGIN = 'CGPS Consortium' / FITS WRITING INSTITUTION INSTRUME= 'DRAO ST ' / DATA ACQUISITION INSTRUMENT DATE-OBS= '1999-01-01' / MEAN DATE OF OBSERVATION DATE-GPS= '2000-11-20' / DATE OF RELEASE TO CGPS CONSORTIUM PUB_RELD= '2000-11-20' / PUBLIC RELEASE DATE BUNIT = 'K (Tb) ' / BRIGHTNESS UNITS OBSFREQ = 1.420406000000E+09 / OBSERVING FREQUENCY (HZ) CTYPE1 = 'GLON-CAR' / X COORDINATE TYPE CRVAL1 = 1.247500000000E+02 / REF. X COORD. VALUE (DEG) CRPIX1 = 513.00 / REF. X PIXEL CDELT1 = -4.9999990E-03 / DELTA X (DEG) CROTA1 = 0.00 / X ROTATION ANGLE (DEG) CTYPE2 = 'GLAT-CAR' / Y COORDINATE TYPE CRVAL2 = 3.000000000000E+00 / REF. Y COORD. VALUE (DEG) CRPIX2 = 513.00 / REF. Y PIXEL CDELT2 = 4.9999990E-03 / DELTA Y (DEG) CROTA2 = 0.00 / Y ROTATION ANGLE (DEG) CTYPE3 = 'VELO-LSR' / Z COORDINATE TYPE CRVAL3 = -6.000000000000E+04 / Z REF. LSR VELOCITY (M/S) CRPIX3 = 145.00 / REF. Z PIXEL CDELT3 = -8.2446002E+02 / DELTA Z (M/S) CROTA3 = 0.00 / Z ROTATION ANGLE (DEG) CTYPE4 = 'STOKES ' / 4TH COORDINATE TYPE CRVAL4 = 1.000000000000E+00 / REF. COORD. 1-4=I,Q,U,V CRPIX4 = 1.00 / REF. PIXEL CDELT4 = 1.0000000E+00 / DELTA COORD. CROTA4 = 0.00 / ROTATION ANGLE (DEG) BZERO = -2.654173583984E+02 / DATA=FITS*BSCALE+BZERO BSCALE = 1.628218207000E-02 / DATA=FITS*BSCALE+BZERO MINCOL = 793 / COLUMN POSITION OF MIN VALUE MAXCOL = 423 / COLUMN POSITION OF MAX VALUE MINROW = 1014 / ROW POSITION OF MIN VALUE MAXROW = 758 / ROW POSITION OF MAX VALUE MINFIL = 83 / IMAGE (IN FITS FILE) OF MIN VALUE MAXFIL = 272 / IMAGE (IN FITS FILE) OF MAX VALUE HISTORY > HISTORY ********************************************************************* HISTORY The data in this FITS file have been produced by the Canadian Galactic HISTORY Plane Survey (CGPS) Consortium. The CGPS is supported by the National HISTORY Research Council Canada and the Natural Sciences and Engineering HISTORY Research Council of Canada. These data are released to the public for HISTORY scientific research and educational purposes. The CGPS Consortium has HISTORY made very reasonable efforts to produce accurate data, but no warranty HISTORY is expressed or implied as to the suitability of the data for any HISTORY particular purpose. Users are requested to include the following HISTORY acknowledgement in publications making use of CGPS data: HISTORY > HISTORY The Canadian Galactic Plane Survey (CGPS) is a Canadian project with HISTORY international partners. The Dominion Radio Astrophysical Observatory HISTORY is operated as a national facility by the National Research Council HISTORY Canada. The CGPS is supported by a grant from the Natural Sciences HISTORY and Engineering Research Council of Canada. HISTORY > HISTORY General information on the CGPS may be obtained from the CGPS public HISTORY web site http://www.ras.ucalgary.ca/CGPS and queries regarding the HISTORY CGPS or its data may be addressed to cgps@ras.ucalgary.ca . HISTORY > HISTORY More detailed comments regarding the data in this FITS file may be HISTORY found in a readme file which accompanies this data release. HISTORY ********************************************************************* HISTORY > HISTORY The file definition included the comment: HISTORY MB2 HISTORY > HISTORY > HISTORY Channels 1-18 and 272 are contaminated by mosaicing HISTORY artifacts and/or are blank channels. CHECKSUM= 'ZSA9fR26ZR96fR96' / encoded HDU checksum updated on 20/11/00 DATASUM = '3004591013' / data unit checksum updated on 20/11/00 END === Subject: Mathematica in Education and Research Please click on this link: http://www.ijournals.net/ and you get the message: Unfortunately Mathematica in Education and Research folded in 2008. be available for download from the Wolfram information Center. What is to be done? Robert Scheyder === Subject: Re: Mathematica in Education and Research > Please click on this link: http://www.ijournals.net/ and you get the message: Unfortunately Mathematica in Education and Research folded in 2008. > be available for download from the Wolfram information Center. What is to be done? Weep in one's beer, I'd imagine. Businesses are ephemeral and, sadly, this one didn't make it. for all who wish to read a copy: http://scientificarts.com/worklife/notebooks/ David Robert Scheyder === Subject: Re: Function Programming Problems >A colleague and myself are working on some Mathematica labs for >Calculus using Mathematica 6.0 and I can't seem to find any >information or examples that explain defining functions and using >functions as arguments. >I want to define a LinearApproximation command that preferably would >take two arguments and return the linear approximation. Ideally, >LinearApproximation[function_,a_] would have >LinearApproximation[Sin[x],0] give x as the output. >So far I have: LinearApproximation[function_, a_, x_] := function[a] >+ function'[a]*(x - a) >which works mostly nicely, except it only works with >LinearApproximation[Sin,0,x]. >Does anyone know how I would fix this to allow Sin[x] as input (or >even x^2, etc)? Getting rid of the third argument x would be >nice, but not necessary. Your version will work with x^2 provided you supply this as a pure function. That is, LinearApproximation[#^2 &, a, x] a^2+2 (x-a) a However, I would define this using the built-in function Series. And to get rid of the third argument I would do LinearApproximation[func_, a_] := Block[{x}, Normal@Series[func[x], {x, a, 1}]] Like your code, to use this with x^2 you need to supply this as a pure function. === Subject: Re: Solving 3d degree polynomial >I have a function f(q)=2n(n+1)q^3-(1+t)(2n+1)q^2+2(t-(n+1)A)q+(1+t)A >in which n>1, -1appropriate values for the parameters before: Solve[Y==0,q] it gives >me 3 real roots. If instead I ask for a symbolic solution before >filling in the same values of the parameters, Mathematica gives >almost the same roots, but now there is an imaginary part to the >solution. It is of the order 10^(-16). Why are the roots complex if >I find a solution before filling in parameters, but real if I fill >in parameters before finding the solution? I suspect in both cases you are using machine precision numbers. If so, this is the reason. By default, Mathematica does not simplify expressions before evaluating them with your substituted values. The symbolic solution you get by using Solve before substituting values will have a different structure and have different numerical properties even though it will be mathematically equivalent to the alternative approach. You should be able to get exactly the same result if you use exact numbers for the parameter values in both cases. Also, if you want a machine precision number the better choice would be to substitute the values for the parameters and use NSolve rather than Solve. === Subject: Cos[a x - b] displayed as Cos[b - a x] I have an expression which I wish to put it in the form of Cos[a x - b]. However when I input it to Mathematica, it automatically converted to Cos[b - a x]. Similarly, for Sin[a x - b] it would become -Sin[b - ax]. I understand that both are equivalent, but I just wish to have the form of Cos[a x - b]. Is there any way to do this? Ho === Subject: Re: Cos[a x - b] displayed as Cos[b - a x] > I have an expression which I wish to put it in the form of Cos[a x - b]. > However when I input it to Mathematica, it automatically converted to > Cos[b - a x]. Similarly, for Sin[a x - b] it would become -Sin[b - ax]. I understand that both are equivalent, but I just wish to have the form > of Cos[a x - b]. Is there any way to do this? You could use *HoldForm[]* to keep the expression as you typed it. For instance, In[1]:= Cos[a x - b] // HoldForm Out[1]= Cos[a x - b] In[2]:= Sin[a x - b] // HoldForm Out[2]= Sin[a x - b] See, http://reference.wolfram.com/mathematica/ref/HoldForm.html === Subject: Re: Cos[a x - b] displayed as Cos[b - a x] I have an expression which I wish to put it in the form of Cos[a x - b]. > However when I input it to Mathematica, it automatically converted to > Cos[b - a x]. Similarly, for Sin[a x - b] it would become -Sin[b - ax]. I understand that both are equivalent, but I just wish to have the form > of Cos[a x - b]. Is there any way to do this? > Ho > Mathematica automatically performs certain simplifications on expressions, which includes resolving certain superficial differences between expressions. The only real way to prevent these happening is to wrap the expression in Hold or HoldForm (or something equivalent), but that stops many manipulations taking place. It might help if you described exactly what you are trying to achieve. In your example, Mathematica is using two pieces of mathematical information - the fact that sums of terms can be rearranged (which is very hard to suppress), and the symmetry properties of the trig functions. Sometimes it is helpful to use your own version of a function - say cos - and then switch to the normal notation when you need it: In[3]:= test=cos[a x-b] Out[3]= cos[-b+a x] In[4]:= test/.cos->Cos Out[4]= Cos[b-a x] Mathematica 'knows' nothing about the function 'cos' so it can't assume symmetry about 0. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Function Programming Problems Clear[linearApproximation]; linearApproximation[expr_, a_, x_Symbol: x] := Module[{var}, (expr + D[expr, x]*(var - a)) /. {x -> a, var -> x}]; linearApproximation[Sin[a*x], 0] == Series[Sin[a*x], {x, 0, 1}] // Normal True linearApproximation[Exp[-a*x], 0] == Series[Exp[-a*x], {x, 0, 1}] // Normal True linearApproximation[f[y], a, y] == Series[f[y], {y, a, 1}] // Normal True A colleague and myself are working on some Mathematica labs for Calculus using Mathematica 6.0 and I can't seem to find any information or examples that explain defining functions and using functions as arguments. I want to define a LinearApproximation command that preferably would take two arguments and return the linear approximation. Ideally, LinearApproximation[function_,a_] would have LinearApproximation[Sin[x],0] give x as the output. So far I have: LinearApproximation[function_, a_, x_] := function[a] + function'[a]*(x - a) which works mostly nicely, except it only works with LinearApproximation[Sin,0,x]. Does anyone know how I would fix this to allow Sin[x] as input (or even x^2, etc)? Getting rid of the third argument x would be nice, but not necessary. David Taylor Roanoke College === Subject: Re: Can't Simplify logical expression > Simplify[(a && (! b)) || (b && (! a))] I get this: > a && ! b || b && ! a But I want this: > Xor[a,b] > Any suggestions? > What you are asking for is the inverse of: LogicalExpand[Xor[a, b]] (a && ! b) || (b && ! a) but Mathematica has no built in functions for doing this. It is possible to implement a function that would do this by using the equivalence between Boolean algebras and Boolean rings and the Groebner Basis algorithm modulo 2, as I described a 2006 post on this forum: http://forums.wolfram.com/mathgroup/archive/2006/Sep/msg00266.html The idea is to work in a ring (with 1) with two generators a and b, and relations 2a = 0, 2 b = 0, a^2=a,b^2=b. The element a of the ring corresponds to the logical statment a, the element b to the logical statement b, the element 1-a to !a, 1-b to !b. The product * corresponds to And and the sum + to Xor. Logical Or[a,b] corresponds to a*b+a+b hence your statement (a && ! b) || (b && ! a) corresponds to: a*(1 - b) + (1 - a)*a*b*(1 - b) + (1 - a)*b Now we can use GroebnerBasis and PolynomialReduce to simplify this, using the relations ^2=a,b^2=b: Last[PolynomialReduce[p, {a^2 - a, b^2 - b}, {a, b}, Modulus -> 2]] a + b This corresponds to Xor[a,b], so we got what we wanted. It should not be too not too hard to write a package to do all this automatically. Andrzej Kozlowski === Subject: Re: Can't Simplify logical expression >> Simplify[(a && (! b)) || (b && (! a))] >> I get this: >> a && ! b || b && ! a >> But I want this: >> Xor[a,b] >> Any suggestions? > What you are asking for is the inverse of: LogicalExpand[Xor[a, b]] > (a && ! b) || (b && ! a) but Mathematica has no built in functions for doing this. It is > possible to implement a function that would do this by using the > equivalence between Boolean algebras and Boolean rings and the > Groebner Basis algorithm modulo 2, as I described a 2006 post on > this forum: http://forums.wolfram.com/mathgroup/archive/2006/Sep/msg00266.html The idea is to work in a ring (with 1) with two generators a and b, > and relations 2a = 0, 2 b = 0, a^2=a,b^2=b. The element a of the > ring corresponds to the logical statment a, the element b to the > logical statement b, the element 1-a to !a, 1-b to !b. The product * > corresponds to And and the sum + to Xor. Logical Or[a,b] > corresponds to a*b+a+b hence your statement (a && ! b) || (b && ! > a) corresponds to: a*(1 - b) + (1 - a)*a*b*(1 - b) + (1 - a)*b Now we can use GroebnerBasis and PolynomialReduce to simplify this, > using the relations ^2=a,b^2=b: Last[PolynomialReduce[p, {a^2 - a, b^2 - b}, {a, b}, Modulus -> 2]] > a + b where, of course, p = a*(1 - b) + (1 - a)*a*b*(1 - b) + (1 - a)*b Andrzej Kozlowski > This corresponds to Xor[a,b], so we got what we wanted. It should not be too not too hard to write a package to do all this > automatically. Andrzej Kozlowski === Subject: Can't Simplify logical expression Simplify[(a && (! b)) || (b && (! a))] I get this: a && ! b || b && ! a But I want this: Xor[a,b] Any suggestions? === Subject: Re: Can't Simplify logical expression > Simplify[(a && (! b)) || (b && (! a))] I get this: > a && ! b || b && ! a But I want this: > Xor[a,b] > Any suggestions? First, a couple of general remarks. Functions such as FullSimplify[] and LogicalExpand[] are more appropriate than Simplify[] when dealing with logical expressions. Also, it is better to use Implies[] rather than Equal[]. For instance, FullSimplify[(a && (! b)) || (b && (! a)) == Xor[a, b]] (a && ! b) || (b && ! a) == (a [Xor] b) Implies[(a && (! b)) || (b && (! a)), Xor[a, b]] // FullSimplify True LogicalExpand[(a && (! b)) || (b && (! a))] == LogicalExpand[ Xor[a, b]] True Back to your original query, though Mathematica can easily go from Xor[] to its expanded form LogicalExpand[ Xor[a, b]] (a && ! b) || (b && ! a) the reverse operation might be much more challenging for a variety of reasons. The thread titled, ((a&&b)||c)==((a||c)&&(b||c)), (started on Wednesday, 9 Nov 2005), is a must read on this subject. If you do not want to read all the posts, at least be sure to read Lichtblau's reply about And, Or, and Not vs Xor at === Subject: Compression (zip) in 5.2? I'm using Mathematica 5.2 (haven't yet upgraded to 6). Does anyone know if there's a library/mathematica package that allows Mathematica to import/export to a zip-compressed format? I know this functionality exists in 6.0, but am looking for a 5.2 solution. === Subject: Re: Comments on online documentation >> --But no: GridBox takes you to its MS age, but GridLine takes you >> to an >> MSR page. And Plot takes you to an MS -- but plot takes you to >> an MSR. > Because there is no built in command GridLine, so Mathematica can't take you to its MS page, for the very good reason that there isn't one (because GridLine is not a Mathematica built in function). GridLines takes you to its MS page. For exactly the same reason plot can't take you to an MS page because one does not exist. There is one for Plot, Plot3D, ListPlot etc. They are built-in functions. One has to use a little logic even when it is only Mathematica's documentation one is dealing with. Mathematica itself needs more than that. Andrzej Kozlowski === Subject: Comments on online documentation The following are neither questions nor gripes/criticisms, just observations on some of the idiosyncrasies, inconsistencies, and generally odd behavior one encounters in dealing with the online documentation: 1) Open an ordinary notebook: up/down arrows are immediately functional; Find command is immediately functional; Page Up/Down keys are immediately functional; you can start typing immediately -- no mouse clicking needed for any of these. 2) Open a typical documentation window, for example by positioning the cursor just after a M function name, symbol name, or an ordinary word and hitting Help key or typing cmd-shift-F: --One or another kind of M-appearing window opens, e.g. a M Function Definition (FD), a M Symbol (MS), or a M Search Results (MSR). --Up/down arrows are NOT immediately functional -- you can't immediate start scrolling down through the window using the arrow key (would be nice if you could) --For some windows, Find command is immediately functional, but for others (notably SR windows), it's NOT. --On windows where it's not immediately functional, you can (sometimes, anyway) click or double-click in the window, and the Find command, and also up/down arrow keys will start functioning (but it sometimes seems as if the conditions under which one or the other function will work are not the same). --This is especially true for MSR (search result) windows: depends on how you click. Find will start working if you select a single text word, for example -- but will only find text words, not the same string in highlighted symbol names. Sometimes repeated clicks in the Find dialog box (or cmd-G, or Return) will wrap around through all the text on the page; sometimes not. --M Search Result pages (MSRs) are often 100s to 1000s of items long, extending over literally 100s of screens or pages -- which means they are essentially worthless and useless for any practical purpose, unless you can _search_ down into them for more specific information -- right? But, so far as I can tell, you can't -- nor (so far I've found, anyway) can you rapidly page down through subsequent pages with the arrow or Page Up/Down keys. --Try going back and forth between a notebook and an M documentation window, by clicking in the window, or clicking on something in the window, or by clicking on the menu bar, and so on, then doing things in the doc window. Behavior can be sufficiently complex and variable that I won't try to describe it. 3) Various other oddities: Apply the position insertion point after a word in a notebook and activate Help technique to various terms, e.g.: --Grid takes you to a MSR page; but GridBox takes you to an MS page. --Hmmm -- maybe that means more generic terms like Grid (which is a component of longer names as well) will take you to an MSR but specific terms like GridBox take you directly to the relevant MS page. --But no: GridBox takes you to its MS age, but GridLine takes you to an MSR page. And Plot takes you to an MS -- but plot takes you to an MSR. --and so on. --------- All in all: Dealing with M's online document is fun; frustrating; and much less helpful than it ought to be. === Subject: Re: Listplot with colours points = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; att1 = {1, .3, .5, .7}; att2 = {.05, .1, .05, .075}; Show[Graphics[Transpose[ {Hue /@ att1, PointSize /@ att2, Point /@ points}]], Axes -> True] ListPlot[List /@ points, PlotStyle -> Transpose[{Hue /@ att1, PointSize /@ att2}], PlotRange -> {{-0.1, 1.1}, {-0.1, 1.1}}, AspectRatio -> 1] In version 6: Graphics[Transpose[ {Hue /@ att1, PointSize /@ att2, Point /@ points}], Axes -> True] I cannot find this in the help at all, although I am sure it is straightforward. I have a list of coordinates of points points={{x1,y1},{x2,y2}...} and two lists of attributes att1={a1,a2,..} and att2={b1,b2,...} I want to do something like ListPlot[points,PlotStyle->{Hue[att1],PointSize[att2]}] So I get dots at each point in colour att1 and size given by att2. I'm sure it's easy but I can't do it. I am using version 5.1 Peter === Subject: question about sorting lists I have the following numerical list: {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. I need to sort the list so that the eigenvalues are arranged in the order of decreasing the absolute value of the difference between any of the two eigenvalues. (and that the eigenvectors still correspond to the original eigenvalues). What would be the correct syntax for this operation in Mathematica 5.2? Tatyana === Subject: Re: question about sorting lists lst = {{4, -3, 8}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}}; Transpose[Sort[Transpose[lst], Abs[#1[[1]]] < Abs[#2[[1]]] &]] Jens I have the following numerical list: {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, > x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. I need to sort the list so that the eigenvalues are arranged in the > order of decreasing the absolute value of the difference between any > of the two eigenvalues. (and that the eigenvectors still correspond to > the original eigenvalues). What would be the correct syntax for this operation in Mathematica 5.2? Tatyana > === Subject: Re: question about sorting lists > I have the following numerical list: {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, > x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. I need to sort the list so that the eigenvalues are arranged in the > order of decreasing the absolute value of the difference between any > of the two eigenvalues. (and that the eigenvectors still correspond to > the original eigenvalues). What would be the correct syntax for this operation in Mathematica 5.2? First the easy part of your question. Say we want to sort the eigenvalues in increasing order and keep their respective eigenvector in order. One possible way of doing that is as follows: eigsys = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]] {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, {-1.28335, -0.141675, 1.}, {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, {1., -2., 1.}, {0.283349, 0.641675, 1.}}} (Note that functions such as Sort, Ordering, etc., all have a second or third optional argument that specifies the sort function -- relation -- to use.) Although I might have missed the obvious when reading your specifications, your criterion is not strong enough to define an order relation (among other things, it is not antisymmetric). For instance, say we have the eigenvalues {-1, 0, 1}. How would you ordered them? You might say (-1, 1, 0) for the distances among adjacent pairs are 2 (Abs[(-1) - 1]) and 1 (Abs[1 - 0]). Now the triple (1, -1, 0) also matches the same order. So which one to choose? === Subject: Re: Is this a bug? >I tried to solve the following equation with mathematica 6.03 >Solve[{Abs[X+Y I]==5,X==3},{X,Y}] >and got the answer >{{X -> 3, Y -> -2 I}, {X -> 3, Y -> 8 I}} This is correct since 3 + (-2 I) I = 3 + 2 = 5 and 3 + (8 I) I = 3 - 8 = -5 >Am I suppose to get {{X -> 3, Y -> 4 I}, {X -> 3, Y -> -4 I}} This would be incorrect. I suspect you wanted real values for x and y such as obtained from In[14]:= Solve[{Sqrt[x^2 + y^2] == 5, x == 3}, {x, y}] Out[14]= {{y->-4,x->3},{y->4,x->3}} === Subject: How do I set PlotRegion value permantly? Hello All: My apologies if this is a newbie question, but I cannot seem to find anything that helps me out. First off, yes, it is Friday night and I'm playing around with Options in Mathematica. Ouch. Okay, but I can deal with that. What I am struggling with, however, is this simple question: How do I set a default for PlotRegion->{{0.1,0.9}, {0.1,0.9}}? For all of my 2D plots/*listplots. I just want to add a small margin as i like to keep Frame->True. Now, here is what I have tried to no avail. (1) Edit with the Option Inspector. Seems like I can click on the value to edit it, but as soon as I click away, it returns to the default. (2) Editing $UserBaseDirectory/FrontEnd/init.m I've tried adding either SetOption[Graphics,PlotRegion->{{0.1,0.9},{0.1,0.9}}] or Graphics[PlotRegion->{{0.15,0.85},{0.15,0.85}}] Both of which were bad ideas, or so I gathered from the error message windows. Yikes! (3) Editing $UserBaseDirectory/Kernel/init.m with the same values above, no error windows now, but also no effect it seems. For what it's worth I have Mathematica 6.0 on Kubuntu 8.04 (Linux).... Any ideas? t. === Subject: Re: How do I set PlotRegion value permantly? and you are sure, that you don't mean PlotRangePadding ? Jens > Hello All: My apologies if this is a newbie question, but I cannot seem to find > anything that helps me out. First off, yes, it is Friday night and I'm > playing around with Options in Mathematica. Ouch. Okay, but I can deal > with that. What I am struggling with, however, is this simple > question: How do I set a default for PlotRegion->{{0.1,0.9}, > {0.1,0.9}}? For all of my 2D plots/*listplots. I just want to add a small margin > as i like to keep Frame->True. Now, here is what I have tried to no avail. (1) Edit with the Option Inspector. Seems like I can click on the > value to edit it, but as soon as I click away, it returns to the > default. (2) Editing $UserBaseDirectory/FrontEnd/init.m I've tried adding either SetOption[Graphics,PlotRegion->{{0.1,0.9},{0.1,0.9}}] or Graphics[PlotRegion->{{0.15,0.85},{0.15,0.85}}] Both of which were bad ideas, or so I gathered from the error message > windows. Yikes! (3) Editing $UserBaseDirectory/Kernel/init.m with the same values > above, no error windows now, but also no effect it seems. For what it's worth I have Mathematica 6.0 on Kubuntu 8.04 (Linux).... Any ideas? > t. > === Subject: Re: How do I set PlotRegion value permantly? > (2) Editing $UserBaseDirectory/FrontEnd/init.m > I've tried adding either > SetOption[Graphics,PlotRegion->{{0.1,0.9},{0.1,0.9}}] This should work. Of course, you need SetOptions, rather than SetOption. Notice, however that setting the options of Graphics will not affect the options of Plot. Probably your best option is to set the options of the individual Plot commands that you want to use. Alternatively, you could set $Post: PlotRegion -> {{0.1, 0.9}, {0.1, 0.9}}], #] &; I don't really recommend this, though. Mark McClure === Subject: Re: How do I set PlotRegion value permantly? D'Oh! SetOptions <-- The s was missing.... t. === Subject: Reading Directive Values > I would like to be able to define graphics objects whose color >> scheme, lighting, etc. might be changed by graphics directives in >> an informed way. In order to do this, I need to be able to read >> the current state of graphics directives. What I need is a >> function like OptionValue, but I can't find one after substantial >> perusal of official and unofficial documentation. >> For example, I'd like to be able to define something along these >> lines: >> pg = {If[DirectiveValue[Hue][[3]] <= 0.3, Brown, Sequence[], >> Yellow], Polygon[{{1, 0, 0}, {1, 1, 1}, {0, 0, 1}}]} ; >> so that >> Graphics3D[pg] >> Graphics3D[{Red, pg}] >> Graphics3D[{Black, pg}] >> would produce yellow, red, and brown polygons. >> Any suggestions? A graphic is an expression as is everything in Mathematica. > Therefore, one can use functions such as *Cases[]* to extract > specific information from a graphic object. Below, the inner Cases[] seeks out expressions with head > Directive and returns a list of such expressions. The outer cases > looks for expressions with heads matching the second argument of > the function, this within the list previously returned by the inner > Cases[]. > In[1]:= DirectiveValue[g_, d_Symbol] := > Cases[Cases[g, r_Directive, Infinity], > d[a__] -> a, Infinity] g = Plot3D[Im[ArcSin[(x + I y)^4]], {x, -2, 2}, {y, -2, > 2}, > Mesh -> None, PlotStyle -> Directive[Yellow, > Specularity[White, 20], Opacity[0.8]], > ExclusionsStyle-> {None, Red}] DirectiveValue[g, Opacity][[1]] DirectiveValue[g, Specularity][[2]] Out[2]= <... graphic deleted ... > Out[3]= 0.8 Out[4]= 20 HTH, > assigned to a symbol, but in common use they aren't, as in my examples such as Graphics3D[{Red, pg}]. Mathematica or rather Graphics (3D) tucks their values away somewhere, similar to Sow[], and then applies that to each subsequent graphic, as if with Reap[]. -- Andy === Subject: Reading Directive Values I would like to be able to define graphics objects whose color scheme, lighting, etc. might be changed by graphics directives in an informed way. In order to do this, I need to be able to read the current state of graphics directives. What I need is a function like OptionValue, but I can't find one after substantial perusal of official and unofficial documentation. For example, I'd like to be able to define something along these lines: pg = {If[DirectiveValue[Hue][[3]] <= 0.3, Brown, Sequence[], Yellow], Polygon[{{1, 0, 0}, {1, 1, 1}, {0, 0, 1}}]} ; so that Graphics3D[pg] Graphics3D[{Red, pg}] Graphics3D[{Black, pg}] would produce yellow, red, and brown polygons. Any suggestions? -- Andy === Subject: Re: Reading Directive Values > I would like to be able to define graphics objects whose color > scheme, lighting, etc. might be changed by graphics directives in an > informed way. In order to do this, I need to be able to read the > current state of graphics directives. What I need is a function like > OptionValue, but I can't find one after substantial perusal of > official and unofficial documentation. For example, I'd like to be able to define something along these lines: pg = {If[DirectiveValue[Hue][[3]] <= 0.3, Brown, Sequence[], > Yellow], Polygon[{{1, 0, 0}, {1, 1, 1}, {0, 0, 1}}]} ; so that Graphics3D[pg] > Graphics3D[{Red, pg}] > Graphics3D[{Black, pg}] would produce yellow, red, and brown polygons. Any suggestions? A graphic is an expression as is everything in Mathematica. Therefore, one can use functions such as *Cases[]* to extract specific information from a graphic object. Below, the inner Cases[] seeks out expressions with head Directive and returns a list of such expressions. The outer cases looks for expressions with heads matching the second argument of the function, this within the list previously returned by the inner Cases[]. In[1]:= DirectiveValue[g_, d_Symbol] := Cases[Cases[g, r_Directive, Infinity], d[a__] -> a, Infinity] g = Plot3D[Im[ArcSin[(x + I y)^4]], {x, -2, 2}, {y, -2, 2}, Mesh -> None, PlotStyle -> Directive[Yellow, Specularity[White, 20], Opacity[0.8]], ExclusionsStyle-> {None, Red}] DirectiveValue[g, Opacity][[1]] DirectiveValue[g, Specularity][[2]] Out[2]= <... graphic deleted ...> Out[3]= 0.8 Out[4]= 20 HTH, === Subject: Re: Cos[a x - b] displayed as Cos[b - a x] It may be worthwhile checking out HoldForm. exp = HoldForm[Cos[a x - b]] Out[19] = Cos[a x - b] Evaluate[exp] // ReleaseHold Out[20] = Cos[b - a x] I have an expression which I wish to put it in the form of Cos[a x - b]. > However when I input it to Mathematica, it automatically converted to > Cos[b - a x]. Similarly, for Sin[a x - b] it would become -Sin[b - ax]. I understand that both are equivalent, but I just wish to have the form > of Cos[a x - b]. Is there any way to do this? > Ho === Subject: Re: Cos[a x - b] displayed as Cos[b - a x] y = HoldForm[Cos[a x - b]] cos(a x-b) {y == Cos[a x - b], y == Cos[a x - b] // ReleaseHold} {cos(a x-b) == cos(b-a x), True} I have an expression which I wish to put it in the form of Cos[a x - b]. However when I input it to Mathematica, it automatically converted to Cos[b - a x]. Similarly, for Sin[a x - b] it would become -Sin[b - ax]. I understand that both are equivalent, but I just wish to have the form of Cos[a x - b]. Is there any way to do this? Ho === Subject: Re: Export into Excel Worksheets > I've got a list of data that I'd like to Export into Excel. The twist > is, I'd like to export each element of the list into a separate > worksheet within the same Excel Workbook. Can this be done in > Mathematica v6? v6 docs say Import and Export by default use the Data element., and Data ... [is a] list of full arrays, representing all sheets. So the answer is yes, confirmed by my testing. Specifically, a tensor with dimension S x R x C will be saved into S sheets with R rows and C columns. For example, In:= a = Table[Random[], {4}, {3}, {2}] Out= { {{0.196065, 0.0107993}, {0.0621981, 0.149353}, {0.489958, 0.740329}}, {{0.236605, 0.662268}, {0.64053, 0.553502}, {0.915333, 0.741054}}, {{0.856358, 0.347337}, {0.831542, 0.126143}, {0.253758, 0.206718}}, {{0.693209, 0.839594}, {0.331732, 0.39102}, {0.416769, 0.630923}} } In:= Export[test.xls, a] will produce the file test.xls with four sheets, each containing one of the lines above in a 3 x 2 cell range. -- Andy === Subject: Re: Export into Excel Worksheets >I've got a list of data that I'd like to Export into Excel. The >twist is, I'd like to export each element of the list into a >separate worksheet within the same Excel Workbook. Can this be done >in Mathematica v6? Yes. For example, Export[test.xls,RandomReal[1, {3, 3, 3}],XLS] will create a workbook file with three spreadsheets. === Subject: ParametricPlot precision problem With the code below, plot1 gives a line from -a to 0 (in the complex plane). plot2 should give the the symmetric of plot1 with respect to the unit circle, i.e., a line from -1/Conjugate[a] to infinity (same slope as line from -a to 0). I cannot get plot2 to give the correct line. Any help is very much appreciated. Cristina --------------------------------- r := 1/3 alpha := Pi/3 a := r*Exp[I*alpha] n := 3 B[z_] := z^n*((Conjugate[a]/a)*(a^2 - z^2)/(1 - (Conjugate[a])^2*z^2))^n b := 1/(r*Sqrt[2])*Sqrt[3 - r^4 - Sqrt[(3 - r^4)^2 - 4*r^4]]* Exp[I*alpha] s := -Abs[B[b]] z1[t_] := -(t/27) - ((1 + I Sqrt[3]) (27 - 27 (-1)^(1/3) - t^2))/( 27 2^(2/3) (19602 t - 19602 (-1)^(1/3) t + 2 t^3 + Sqrt[ 4 (27 - 27 (-1)^(1/3) - t^2)^3 + (19602 t - 19602 (-1)^(1/3) t + 2 t^3)^2])^( 1/3)) + ((1 - I Sqrt[3]) (19602 t - 19602 (-1)^(1/3) t + 2 t^3 + Sqrt[4 (27 - 27 (-1)^(1/3) - t^2)^3 + (19602 t - 19602 (-1)^(1/3) t + 2 t^3)^2])^(1/3))/(54 2^(1/3)) plot1:=ParametricPlot[{Re[z1[t]], Im[z1[t]]}, {t, s, 0}, PlotStyle -> {Orange, Thick}, PlotPoints -> 100, MaxRecursion -> 5, PlotRange -> 1, WorkingPrecision -> 100] plot2 := ParametricPlot[{Re[1/Conjugate[z1[t]]], Im[1/Conjugate[z1[t]]]}, {t, s, 0}, PlotStyle -> {Orange, Thick}, PlotPoints -> 2000, MaxRecursion -> 15, PlotRange -> All, WorkingPrecision -> 100] === Subject: Re: ParametricPlot precision problem On Jul 27, 1:43 am, Cristina Ballantine With the code below, plot1 gives a line from -a to 0 (in the complex > plane). plot2 should give the the symmetric of plot1 with respect to the > unit circle, i.e., a line from -1/Conjugate[a] to infinity (same slope as > line from -a to 0). I cannot get plot2 to give the correct line. Any help > is very much appreciated. Cristina --------------------------------- r := 1/3 > alpha := Pi/3 > a := r*Exp[I*alpha] > n := 3 B[z_] := z^n*((Conjugate[a]/a)*(a^2 - z^2)/(1 - (Conjugate[a])^2*z^2))^= n b := 1/(r*Sqrt[2])*Sqrt[3 - r^4 - Sqrt[(3 - r^4)^2 - 4*r^4]]* > Exp[I*alpha] s := -Abs[B[b]] z1[t_] := -(t/27) - ((1 + I Sqrt[3]) (27 - 27 (-1)^(1/3) - t^2))/( > 27 2^(2/3) (19602 t - 19602 (-1)^(1/3) t + 2 t^3 + Sqrt[ > 4 (27 - 27 (-1)^(1/3) - t^2)^3 + (19602 t - 19602 (-1)^(1/3) t= + > 2 t^3)^2])^( > 1/3)) + ((1 - I Sqrt[3]) (19602 t - 19602 (-1)^(1/3) t + 2 t^3 + > Sqrt[4 (27 - 27 (-1)^(1/3) - t^2)^3 + (19602 t - > 19602 (-1)^(1/3) t + 2 t^3)^2])^(1/3))/(54 2^(1/3)) plot1:=ParametricPlot[{Re[z1[t]], Im[z1[t]]}, {t, s, 0}, > PlotStyle -> {Orange, Thick}, PlotPoints -> 100, MaxRecursion -> 5, > PlotRange -> 1, WorkingPrecision -> 100] plot2 := > ParametricPlot[{Re[1/Conjugate[z1[t]]], Im[1/Conjugate[z1[t]]]}, {t, > s, 0}, PlotStyle -> {Orange, Thick}, PlotPoints -> 2000, > MaxRecursion -> 15, PlotRange -> All, WorkingPrecision -> 100] There isn't a straight line going through the origin, what you're seeing in the first plot is several points very close to z1[s] and an outlier at {0, 0}. This is similar to Sqrt[-1 - I t^2] for real t near 0: both limits are equal to -I but the value at t=0 is +I. So basically z1[t] has a removable singularity at 0. You can make a nice demonstration out of your example: (*z1 as defined above*) Module[{c2p, f, closest, gr, t}, c2p = {Re@#, Im@#} &; f[p_, t_] := c2p@If[Norm[p] < 1, z1[t], z1[t]/Norm@z1[t]^2]; closest[p_] := Quiet[f[p, t] /. Last@FindMinimum[Norm[f[p, t] - p], {t, .01, -1, 1}, PrecisionGoal -> 2]]; gr = ParametricPlot[ c2p /@ {z1[t], z1[t]/Norm@z1[t]^2} // Evaluate, {t, -1, 1}, PlotStyle -> {Directive[Orange, Thick], Directive[Magenta, Thick]}]; DynamicModule[{p = c2p@z1[.01]}, LocatorPane[Dynamic[p, (p = closest[#]) &], Show[gr, Graphics[ {Circle[], Dashed, Line@Dynamic@Sort[{{0, 0}, p, p/Norm@p^2}, Norm@# < Norm@#2 &], Locator[Dynamic[p/Norm@p^2, None], Appearance -> Small], Locator[Dynamic[p, None], Appearance -> Small]}], PlotRange -> All], Appearance -> None] ]] Maxim Rytin m.r@inbox.ru === Subject: Method Option A lot of build-in functions in Mathematica have the option Method. Usually this is mentioned in the More Information section of the reference page. Most of the time there is the statement Method->Automatic. Take for example ContourPlot: Method Automatic the method to use for refining contours OK, but what other methods do I have then? Going to the Options-section, I would expect to find method and a list of the possible methods besides Automatic including an explanation what they do. But for most functions the Method option isn't listed in the Options section of the ref page. Is there a way to find out which methods are available for a particular function? Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Method Option if you are lucky, than you know the methods, if you are less lucky than you have to look into the so called Documentation and may be you find a documentation for the methods. The most excellent example is the advanced documentation for NDSolve[]. If this is not the case you can try to send some nonsense as Method and hope you will get an error message that tell you about the allowed options. If that all not works than you can ask the WRI Support or the mathgroup. Jens > A lot of build-in functions in Mathematica have the option Method. Usually > this is mentioned in the More Information section of the reference > page. Most of the time there is the statement Method->Automatic. Take for example ContourPlot: > Method Automatic the method to use for refining contours OK, but what other methods do I have then? > Going to the Options-section, I would expect to find method and a list > of the possible methods besides Automatic including an explanation what > they do. But for most functions the Method option isn't listed in the > Options section of the ref page. Is there a way to find out which methods are available for a particular > function? > Gruss Peter === Subject: Re: Method Option The Method->Bogus ruse obviously works, but the situation seems to cry out for a better way. Having to go to the function's reference page to see the list of methods in the MOREa built-in function to determine the possible values of Method when Method is a legitimate option. Perhaps a new function Methods (too easily confused with Method, though)... Methods[NIntegrate] ... or an extension of Options: Options[NIntegrate, Method] >> A lot of build-in functions in Mathematica have the option Method. Usually >> this is mentioned in the More Information section of the reference page. >> Most of the time there is the statement Method->Automatic. >> Take for example ContourPlot: >> Method Automatic the method to use for refining contours >> OK, but what other methods do I have then? Even though Method -> Automatic appears in the list > generated by Options[ContourPlot], the option appears > to be ignored. Otherwise, > ContourPlot[x^2 + y^2, {x, -2, 2}, {y, -2, 2}, > Method -> Bogus] > would generate error messages. Actually, this is a > good technique find possible options. Here's an > example with NIntegrate: ----------------------------- > Mathematica 6.0 for Mac OS X x86 (32-bit) > Copyright 1988-2008 Wolfram Research, Inc. In[1]:= NIntegrate[x^2, {x,-2,2}, Method -> Bogus] NIntegrate::bdmtd: > The Method option should be one of Automatic, > CartesianRule, ClenshawCurtisRule, > GaussBerntsenEspelidRule, GaussKronrodRule, > LobattoKronrodRule, LobattoPeanoRule, MultiPanelRule, > NewtonCotesRule, TrapezoidalRule, AdaptiveMonteCarlo, > AdaptiveQuasiMonteCarlo, DoubleExponential, > DuffyCoordinates, ExtrapolatingOscillatory, MonteCarlo, > QuasiMonteCarlo, Trapezoidal, EvenOddSubdivision, > SymbolicPiecewiseSubdivision, OscillatorySelection, > UnitCubeRescaling, or a user-implemented integration > strategy or rule. NIntegrate::nsr: > Bogus is not a valid specification of an integration > strategy or rule. 2 > Out[1]= NIntegrate[x , {x, -2, 2}, Method -> Bogus] > ------------------------------- You can find information on the method types by searching > the documentation. I don't believe there is standard way > to do this, though. I'd like to know a general technique > to detect which method is selected when Method is set to > Automatic. Mark McClure > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Method Option > A lot of build-in functions in Mathematica have the option Method. Usually > this is mentioned in the More Information section of the reference page. > Most of the time there is the statement Method->Automatic. > Take for example ContourPlot: > Method Automatic the method to use for refining contours > OK, but what other methods do I have then? Even though Method -> Automatic appears in the list generated by Options[ContourPlot], the option appears to be ignored. Otherwise, ContourPlot[x^2 + y^2, {x, -2, 2}, {y, -2, 2}, Method -> Bogus] would generate error messages. Actually, this is a good technique find possible options. Here's an example with NIntegrate: ----------------------------- Mathematica 6.0 for Mac OS X x86 (32-bit) Copyright 1988-2008 Wolfram Research, Inc. In[1]:= NIntegrate[x^2, {x,-2,2}, Method -> Bogus] NIntegrate::bdmtd: The Method option should be one of Automatic, CartesianRule, ClenshawCurtisRule, GaussBerntsenEspelidRule, GaussKronrodRule, LobattoKronrodRule, LobattoPeanoRule, MultiPanelRule, NewtonCotesRule, TrapezoidalRule, AdaptiveMonteCarlo, AdaptiveQuasiMonteCarlo, DoubleExponential, DuffyCoordinates, ExtrapolatingOscillatory, MonteCarlo, QuasiMonteCarlo, Trapezoidal, EvenOddSubdivision, SymbolicPiecewiseSubdivision, OscillatorySelection, UnitCubeRescaling, or a user-implemented integration strategy or rule. NIntegrate::nsr: Bogus is not a valid specification of an integration strategy or rule. 2 Out[1]= NIntegrate[x , {x, -2, 2}, Method -> Bogus] ------------------------------- You can find information on the method types by searching the documentation. I don't believe there is standard way to do this, though. I'd like to know a general technique to detect which method is selected when Method is set to Automatic. Mark McClure === Subject: Re: Method Option > this is a good first try to find the possible methods, but not > exhausting. > I posted this message to get more insight when reading a post from > Jens Peer Kuska who put a method option to ContourPlot like this: > plt1 = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}, > MaxRecursion -> 0, PlotPoints -> 64, > Method -> {Refinement -> {CellDecomposition -> Quad}}] So I believe, Methods to be defined as strings are even harder to find. Interesting. On the other hand: In[1]:= Eigenvalues[RandomReal[{0,1},{20,20}], 1, Method -> Bogus] Eigenvalues::emeth: The method specified by Method -> Bogus should be either Automatic or Arnoldi. Note, however, that Arnoldi is not a built in object; Method- >Arnoldi is the appropriate way to call it. Furthermore, there area quite a few other possible Method options for Eigenvalues, as documented in the linear algebra documentation. The trick I mentioned, incidentally, comes from one of Michael Trott's books. So, I'm beginning to wonder if the internal handling of Bogus options has been relaxed. Mark McClure === Subject: Re: Method Option Hi Mark, this is a good first try to find the possible methods, but not exhausting. I posted this message to get more insight when reading a post from Jens Peer Kuska who put a method option to ContourPlot like this: plt1 = ContourPlot[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}, MaxRecursion -> 0, PlotPoints -> 64, Method -> {Refinement -> {CellDecomposition -> Quad}}] I tried what I could imagine to get information about Refinement, CellDecomposition and Quad. So I believe, Methods to be defined as strings are even harder to find. >> A lot of build-in functions in Mathematica have the option Method. Usually >> this is mentioned in the More Information section of the reference page. >> Most of the time there is the statement Method->Automatic. >> Take for example ContourPlot: >> Method Automatic the method to use for refining contours >> OK, but what other methods do I have then? Even though Method -> Automatic appears in the list > generated by Options[ContourPlot], the option appears > to be ignored. Otherwise, > ContourPlot[x^2 + y^2, {x, -2, 2}, {y, -2, 2}, > Method -> Bogus] > would generate error messages. Actually, this is a > good technique find possible options. Here's an > example with NIntegrate: ----------------------------- > Mathematica 6.0 for Mac OS X x86 (32-bit) > Copyright 1988-2008 Wolfram Research, Inc. In[1]:= NIntegrate[x^2, {x,-2,2}, Method -> Bogus] NIntegrate::bdmtd: > The Method option should be one of Automatic, > CartesianRule, ClenshawCurtisRule, > GaussBerntsenEspelidRule, GaussKronrodRule, > LobattoKronrodRule, LobattoPeanoRule, MultiPanelRule, > NewtonCotesRule, TrapezoidalRule, AdaptiveMonteCarlo, > AdaptiveQuasiMonteCarlo, DoubleExponential, > DuffyCoordinates, ExtrapolatingOscillatory, MonteCarlo, > QuasiMonteCarlo, Trapezoidal, EvenOddSubdivision, > SymbolicPiecewiseSubdivision, OscillatorySelection, > UnitCubeRescaling, or a user-implemented integration > strategy or rule. NIntegrate::nsr: > Bogus is not a valid specification of an integration > strategy or rule. 2 > Out[1]= NIntegrate[x , {x, -2, 2}, Method -> Bogus] > ------------------------------- You can find information on the method types by searching > the documentation. I don't believe there is standard way > to do this, though. I'd like to know a general technique > to detect which method is selected when Method is set to > Automatic. Mark McClure > Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: several plots in manipulate The enclosed message solved the problem I posted on the discussion group. On Jul 23, 12:20= pm, Cristina Ballantine plots. I display the plot with Show[plot1,plot2,plot3] (see code below). > If I try this in Manipulate, the plots are displayed next to each other. I > need them in a single plot. I cannot combine them in a single ParameterPlot > because the options are different. On my system, the following works as expected: the three plots are drawn on the same graph, though it takes few seconds for the complete rendering to be completed. (Note that I have written the expressions for the plots as function of three parameters and added the option MaxRecursion->0 to speed up computations.) With[{r1 == 1/4, u == Pi/3}, Manipulate[ Show[plot1[r1, r2, u], plot2[r1, r2, u], plot3[r1, r2, u]], {{r2, 2/3}, r1, 1}]] HTH, - Jean-Marc $Version 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) plot1[r1_, r2_, u_] :== ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, 0, r1^4*r2^4 - 10^(-6)}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[.5, t, r]], PlotPoints -> 25, MaxRecursion -> 0, Mesh -> False] plot2[r1_, r2_, u_] :== ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, r1^4*r2^4 - 10^(-6), r1^4*r2^4 + 10^(-2)}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[1, t, r]], PlotPoints -> 45, MaxRecursion -> 0, Mesh -> False] plot3[r1_, r2_, u_] :== ParametricPlot[{{Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ 1*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[1*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[ I*Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[I*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-1)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-1)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) + Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}, {Re[(-I)* Exp[I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/4)], Im[(-I)*Exp[ I*u]*(((r1^4 + r2^4)*(1 - r*Exp[I*t]) - Sqrt[(r1^4 + r2^4)^2*(1 - r*Exp[I*t])^2 - 4*(1 - r1^4*r2^4*r*Exp[I*t])*(r1^4*r2^4 - r*Exp[I*t])])/(2*(1 - r1^4*r2^4*r*Exp[I*t])))^(1/ 4)]}}, {t, 10^(-10), 2*Pi - 10^(-10)}, {r, r1^4*r2^4 + 10^(-2), 1}, PlotRange -> All, ColorFunction -> Function[{x, y, t, r}, Hue[.1, t, r]], PlotPoints -> 25, MaxRecursion -> 0, Mesh -> False] With[{r1 == 1/4, u == Pi/3}, Manipulate[ Show[plot1[r1, r2, u], plot2[r1, r2, u], plot3[r1, r2, u]], {{r2, 2/3}, r1, 1} ] ] === Subject: Re: question about sorting lists Jean-Marc, thank you very much for the tip. Indeed, I forgot to specify that the eigenvalues have to also be arranged in order of increasing or decreasing their values depending on what the distance is between the adjacent two. Say, the eigenvalues list is {-2, 1, -3}. The way this list needs to be ordered is {-3, -2, 1}. If the list is {1, 2, -3} then it needs to be ordered as {2, 1, -3}. So that the middle element in the list has an intermediate absolute value, and the distance between the second and the third elements in the list is the largest. The way I used to do the ordering before is in two steps: first, the regular Sort operation to arrange the eigenvalues in order. Then, reassign the order if necessary according to the distance criterion. Something like: CS={1,2,-3} Eigensort = Sort[Eigenvalues[CS]]; If[Abs[Eigensort[[1]] - Eigensort[[2]]] > Abs[Eigensort[[3]] - Eigensort[[2]]], Vxx = Eigensort[[3]]; Vyy = Eigensort[[2]]; Vzz = Eigensort[[1]], Vxx = Eigensort[[1]]; Vyy = Eigensort[[2]]; Vzz = Eigensort[[3]]]; But then the problem arises when I need to pull out the corresponding eigenvectors, in some instances the Vxx, Vyy, and Vzz are not recognized by Mathematica as identical numbers to the original values stored in the list. Is this a precision problem? But in any event, I thought it may be a more concise way to do the sorting using a one-line expression, like you suggested. Tatyana ----- Original Message ----- === Subject: Re: question about sorting lists > I have the following numerical list: {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, > x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. I need to sort the list so that the eigenvalues are arranged in the > order of decreasing the absolute value of the difference between any > of the two eigenvalues. (and that the eigenvectors still correspond to > the original eigenvalues). What would be the correct syntax for this operation in Mathematica 5.2? First the easy part of your question. Say we want to sort the eigenvalues in increasing order and keep their respective eigenvector in order. One possible way of doing that is as follows: eigsys = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]] {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, {-1.28335, -0.141675, 1.}, {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, {1., -2., 1.}, {0.283349, 0.641675, 1.}}} (Note that functions such as Sort, Ordering, etc., all have a second or third optional argument that specifies the sort function -- relation -- to use.) Although I might have missed the obvious when reading your specifications, your criterion is not strong enough to define an order relation (among other things, it is not antisymmetric). For instance, say we have the eigenvalues {-1, 0, 1}. How would you ordered them? You might say (-1, 1, 0) for the distances among adjacent pairs are 2 (Abs[(-1) - 1]) and 1 (Abs[1 - 0]). Now the triple (1, -1, 0) also matches the same order. So which one to choose? === Subject: Re: question about sorting lists First of all, this is contradictory: > If > the list is {1, 2, -3} then it needs to be ordered as {2, 1, -3}. So > that the middle element in the list has an intermediate absolute value, > and the distance between the second and the third elements in the list > is the largest. 1 does NOT have intermediate absolute value in the list {1,2,-3}. 2 is intermediate, and I use that interpretation in the code below (as did others, I believe): Clear[eigenOrdering, eigenSort] eigenOrdering[{a_?NumericQ, b_?NumericQ, c_?NumericQ}] := Module[{a1, b1, c1, a2, b2, c2}, {a1, b1, c1} = Ordering@Abs@{a, b, c}; {a2, b2, c2} = {a, b, c}[[{a1, b1, c1}]]; If[Abs[a2 - b2] > Abs[b2 - c2], {c1, b1, a1}, {a1, b1, c1}]] eigenSort[{a_?NumericQ, b_?NumericQ, c_?NumericQ}] := {a, b, c}[[eigenOrdering@{a, b, c}]] eigenSort[{val_List, vec_List}] := Transpose[Transpose[{val, vec}][[eigenOrdering@val]]] First your two examples: evs = {-2, 1, -3} eigenSort@evs {-2, 1, -3} {-3, -2, 1} evs = {1, 2, -3} eigenSort@evs {1, 2, -3} {1, 2, -3} An arbitrarily chosen matrix: eigenSort@Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] {{0, 1/2 (15 - 3 Sqrt[33]), 1/2 (15 + 3 Sqrt[33])}, {{1, -2, 1}, {-(13/11) + 1/22 (15 - 3 Sqrt[33]), -(1/11) + 1/44 (15 - 3 Sqrt[33]), 1}, {-(13/11) + 1/22 (15 + 3 Sqrt[33]), -(1/11) + 1/44 (15 + 3 Sqrt[33]), 1}}} Random examples: evs = RandomInteger[100, 3] eigenSort@evs {43, 14, 60} {60, 43, 14} or evs = RandomComplex[10 + 5 I, 3] eigenSort@evs {0.334128+ 4.85947 I, 8.38226+ 4.66865 I, 5.33541+ 4.67186 I} {8.38226+ 4.66865 I, 5.33541+ 4.67186 I, 0.334128+ 4.85947 I} The code is NOT a one liner; it compartmentalizes the logic, in case you need to understand or modify it someday. The first definition of eigenSort (for eigenvalues, not systems) is handy for testing... against your examples, for instance. Bobby > Jean-Marc, > thank you very much for the tip. Indeed, I forgot to specify that the eigenvalues have to also be > arranged in order of increasing or decreasing their values depending on > what the distance is between the adjacent two. Say, the eigenvalues list > is {-2, 1, -3}. The way this list needs to be ordered is {-3, -2, 1}. If > the list is {1, 2, -3} then it needs to be ordered as {2, 1, -3}. So > that the middle element in the list has an intermediate absolute value, > and the distance between the second and the third elements in the list > is the largest. The way I used to do the ordering before is in two steps: > first, the regular Sort operation to arrange the eigenvalues in order. > Then, reassign the order if necessary according to the distance > criterion. Something like: CS={1,2,-3} > Eigensort = Sort[Eigenvalues[CS]]; > If[Abs[Eigensort[[1]] - Eigensort[[2]]] > Abs[Eigensort[[3]] - > Eigensort[[2]]], Vxx = Eigensort[[3]]; Vyy = Eigensort[[2]]; Vzz = > Eigensort[[1]], Vxx = Eigensort[[1]]; Vyy = Eigensort[[2]]; Vzz = > Eigensort[[3]]]; But then the problem arises when I need to pull out the corresponding > eigenvectors, in some instances the Vxx, Vyy, and Vzz are not recognized > by Mathematica as identical numbers to the original values stored in the > list. Is this a precision problem? But in any event, I thought it may be a more concise way to do the > sorting using a one-line expression, like you suggested. Tatyana > ----- Original Message ----- > mathgroup@smc.vnet.net === > Subject: Re: question about sorting lists >> I have the following numerical list: >> {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} >> where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, >> x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. >> I need to sort the list so that the eigenvalues are arranged in the >> order of decreasing the absolute value of the difference between any >> of the two eigenvalues. (and that the eigenvectors still correspond to >> the original eigenvalues). >> What would be the correct syntax for this operation in Mathematica 5.2? First the easy part of your question. Say we want to sort the > eigenvalues in increasing order and keep their respective eigenvector in > order. One possible way of doing that is as follows: eigsys = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N > {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]] > {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, > {-1.28335, -0.141675, 1.}, > {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, > {1., -2., 1.}, > {0.283349, 0.641675, 1.}}} > (Note that functions such as Sort, Ordering, etc., all have a second or > third optional argument that specifies the sort function -- relation -- > to use.) Although I might have missed the obvious when reading your > specifications, your criterion is not strong enough to define an order > relation (among other things, it is not antisymmetric). For instance, say we have the eigenvalues {-1, 0, 1}. How would you > ordered them? You might say (-1, 1, 0) for the distances among adjacent > pairs are 2 (Abs[(-1) - 1]) and 1 (Abs[1 - 0]). Now the triple (1, -1, > 0) also matches the same order. So which one to choose? > -- DrMajorBob@longhorns.com === Subject: Re: question about sorting lists On Jul 26, 11:43 pm, Tatyana Polenova be arranged in order of increasing or decreasing their values > depending on what the distance is between the adjacent two. > Say, the eigenvalues list is {-2, 1, -3}. The way this list > needs to be ordered is {-3, -2, 1}. If the list is {1, 2, -3} > then it needs to be ordered as {2, 1, -3}. So that the middle > element in the list has an intermediate absolute value, and > the distance between the second and the third elements in the > list is the largest. With the typo corrected: Transpose @ If[#[[2,1]]<.5(#[[1,1]]+#[[3,1]]),#,Reverse@#]& @ Sort @ Transpose @ Eigensystem @ yourmatrix === Subject: Re: question about sorting lists On Jul 26, 11:43 pm, Tatyana Polenova be arranged in order of increasing or decreasing their values > depending on what the distance is between the adjacent two. > Say, the eigenvalues list is {-2, 1, -3}. The way this list > needs to be ordered is {-3, -2, 1}. If the list is {1, 2, -3} > then it needs to be ordered as {2, 1, -3}. So that the middle > element in the list has an intermediate absolute value, and > the distance between the second and the third elements in the > list is the largest. Transpose @ If[#[[2,1]]<.5(#[[1,1]]+#[[3,1]]),@,Reverse@#]& @ Sort @ Transpose @ Eigensystem @ yourmatrix === Subject: Re: question about sorting lists > Jean-Marc, > thank you very much for the tip. Indeed, I forgot to specify that the eigenvalues have to also be arranged in order of increasing or decreasing their values depending on what the distance is between the adjacent two. Say, the eigenvalues list is {-2, 1, -3}. The way this list needs to be ordered is {-3, -2, 1}. If the list is {1, 2, -3} then it needs to be ordered as {2, 1, -3}. So that the middle element in the list has an intermediate absolute value, and the distance between the second and the third elements in the list is the largest. The way I used to do the ordering before is in two steps: > first, the regular Sort operation to arrange the eigenvalues in order. Then, reassign the order if necessary according to the distance criterion. Something like: CS={1,2,-3} > Eigensort = Sort[Eigenvalues[CS]]; > If[Abs[Eigensort[[1]] - Eigensort[[2]]] > Abs[Eigensort[[3]] - Eigensort[[2]]], Vxx = Eigensort[[3]]; Vyy = Eigensort[[2]]; Vzz = Eigensort[[1]], Vxx = Eigensort[[1]]; Vyy = Eigensort[[2]]; Vzz = Eigensort[[3]]]; But then the problem arises when I need to pull out the corresponding eigenvectors, in some instances the Vxx, Vyy, and Vzz are not recognized by Mathematica as identical numbers to the original values stored in the list. Is this a precision problem? But in any event, I thought it may be a more concise way to do the sorting using a one-line expression, like you suggested. Tatyana Hi Tatyana, I believe the following function is doing what you wish in an elegant and concise way (of course, elegance is in the eye of the beholder :). First, we sort the eigenvalues and their corresponding eigenvectors according to increasing values of the eigenvalues. Second, we swap the third and first columns of the eigenvalue and eigenvector arrays if and only if the distance between the first and second eigenvalues is greater than the distance between the second and third eigenvalues. Note that the second column of each array always stay in place since it is already at the right place after the initial sort. mySort[eigsys_] := Module[{es = eigsys}, es = {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]]; If[Abs[es[[1, 1]] - es[[1, 2]]] > Abs[es[[1, 3]] - es[[1, 2]]], {es[[1, 1]], es[[1, 3]]} = {es[[1, 3]], es[[1, 1]]}; {es[[2, 1]], es[[2, 3]]} = {es[[2, 3]], es[[2, 1]]}]; es] eigs = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N mySort[eigs] {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, {-1.28335, -0.141675, 1.}, {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, {1., -2., 1.}, {0.283349, 0.641675, 1.}}} eigs = Eigensystem[N[{{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}]] mySort[eigs] {{29.9428, 1.83935, 0.217884}, {{-0.119842, -0.329513, -0.936514}, {-0.716252, -0.656311, 0.237146}, {-0.848423, 0.515028, -0.122164}}} {{0.217884, 1.83935, 29.9428}, {{-0.848423, 0.515028, -0.122164}, {-0.716252, -0.656311, 0.237146}, {-0.119842, -0.329513, -0.936514}}} mySort[{{30, 1, 5}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{1, 5, 30}, {{1, 4, 9}, {1, 8, 27}, {1, 2, 3}}} *) mySort[{{-2, 1, -3}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{-3, -2, 1}, {{1, 8, 27}, {1, 2, 3}, {1, 4, 9}}} *) mySort[{{1, 2, -3}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{2, 1, -3}, {{1, 4, 9}, {1, 2, 3}, {1, 8, 27}}} *) mySort[{{1, -1, 0}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{-1, 0, 1}, {{1, 4, 9}, {1, 8, 27}, {1, 2, 3}}} *) - Jean-Marc > ----- Original Message ----- === > Subject: Re: question about sorting lists >> I have the following numerical list: >> {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} >> where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, >> x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. >> I need to sort the list so that the eigenvalues are arranged in the >> order of decreasing the absolute value of the difference between any >> of the two eigenvalues. (and that the eigenvectors still correspond to >> the original eigenvalues). >> What would be the correct syntax for this operation in Mathematica 5.2? First the easy part of your question. Say we want to sort the > eigenvalues in increasing order and keep their respective eigenvector in > order. One possible way of doing that is as follows: eigsys = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N > {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]] > {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, > {-1.28335, -0.141675, 1.}, > {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, > {1., -2., 1.}, > {0.283349, 0.641675, 1.}}} > (Note that functions such as Sort, Ordering, etc., all have a second or > third optional argument that specifies the sort function -- relation -- > to use.) Although I might have missed the obvious when reading your > specifications, your criterion is not strong enough to define an order > relation (among other things, it is not antisymmetric). For instance, say we have the eigenvalues {-1, 0, 1}. How would you > ordered them? You might say (-1, 1, 0) for the distances among adjacent > pairs are 2 (Abs[(-1) - 1]) and 1 (Abs[1 - 0]). Now the triple (1, -1, > 0) also matches the same order. So which one to choose? === Subject: Manipulate with specified step size I wanted to revisit the issue in this thread: I have the following: conv[f_, g_, t_] = !( *SubsuperscriptBox[([Integral]), (0), (t)](f[s] g[t - s] [DifferentialD]s)); x[t_] = UnitStep[t - 2] - UnitStep[t - 3]; y[t_] = UnitStep[t - 2] - UnitStep[t - 3]; Manipulate[ Show[ Plot[{Tooltip[x[s], f(s)], Tooltip[y[t - s], g(t-s)]}, {s, 0, 8}, PlotRange -> {{-.01, 8}, {-.4, 2}}, PlotStyle -> {{GrayLevel[.85]}, {GrayLevel[.85]}}, Exclusions -> None], Plot[Tooltip[x[s] y[t - s], f(s)g(t-s)], {s, t, 8.1}, PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, Exclusions -> None], Plot[Evaluate[x[s] y[t - s]], {s, -.01, t}, Filling -> Axis, PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, Exclusions -> None], Plot[Evaluate[Tooltip[conv[x, y, z], (f*g)(t)]], {z, -.01, t}, PlotRange -> {{-.01, 8}, {0, 16}}, PlotStyle -> Blue, Exclusions -> None], Graphics[{Dashed, Line[{{t, -6}, {t, conv[x, y, t]}}]}], Graphics[ Text[Style[t, Italic, Bold, Blue, 14], {t - .1, -6 + .2}]] ] , {t, 0, 8, 1} When I move the slider the dynamics are slow to evaluate. I would be content to simply play the animation at the discrete values t=0 to t=8 in increments of 1. However, I have been unable to obtain that result. Suggestions? John PS I am also surprised that these computations are slow since these are rather simple functions involved in the convolution. === Subject: Re: Manipulate with specified step size on your t-slider is on the left side a little minus, you may call the slider with Manipulate[ ___, {t, 0, 8, 1, Appearance -> Open} ] and than you see the animation control. And DynamicModule[{convolved}, convolved[z_] = conv[x, y, z] // PiecewiseExpand; Manipulate[ Show[ Plot[{Tooltip[x[s], f(s)], Tooltip[y[t - s], g(t-s)]}, {s, 0, 8}, PlotRange -> {{-.01, 8}, {-.4, 2}}, PlotStyle -> {{GrayLevel[.85]}, {GrayLevel[.85]}}, Exclusions -> None], Plot[Tooltip[x[s] y[t - s], f(s)g(t-s)], {s, t, 8.1}, PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, Exclusions -> None], Plot[Evaluate[x[s] y[t - s]], {s, -.01, t}, Filling -> Axis, PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, Exclusions -> None], Plot[Evaluate[Tooltip[convolved[ z], (f*g)(t)]], {z, -.01, t}, PlotRange -> {{-.01, 8}, {0, 16}}, PlotStyle -> Blue, Exclusions -> None], Graphics[{Dashed, Line[{{t, -6}, {t, convolved[t]}}]}], Graphics[ Text[Style[t, Italic, Bold, Blue, 14], {t - .1, -6 + .2}]] ] , {t, 0, 8, 1, Appearance -> Open}] ] should be faster. Jens > I wanted to revisit the issue in this thread: > I have the following: conv[f_, g_, t_] = !( > *SubsuperscriptBox[([Integral]), (0), (t)](f[s] > g[t - s] [DifferentialD]s)); x[t_] = UnitStep[t - 2] - UnitStep[t - 3]; > y[t_] = UnitStep[t - 2] - UnitStep[t - 3]; > Manipulate[ > Show[ > Plot[{Tooltip[x[s], f(s)], Tooltip[y[t - s], g(t-s)]}, {s, 0, > 8}, PlotRange -> {{-.01, 8}, {-.4, 2}}, > PlotStyle -> {{GrayLevel[.85]}, {GrayLevel[.85]}}, > Exclusions -> None], > Plot[Tooltip[x[s] y[t - s], f(s)g(t-s)], {s, t, 8.1}, > PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, > Exclusions -> None], > Plot[Evaluate[x[s] y[t - s]], {s, -.01, t}, Filling -> Axis, > PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, > Exclusions -> None], > Plot[Evaluate[Tooltip[conv[x, y, z], (f*g)(t)]], {z, -.01, t}, > PlotRange -> {{-.01, 8}, {0, 16}}, PlotStyle -> Blue, > Exclusions -> None], > Graphics[{Dashed, Line[{{t, -6}, {t, conv[x, y, t]}}]}], > Graphics[ > Text[Style[t, Italic, Bold, Blue, 14], {t - .1, -6 + .2}]] > ] > , {t, 0, 8, 1} When I move the slider the dynamics are slow to evaluate. I would be > content to simply play the animation at the discrete values t=0 to > t=8 in increments of 1. However, I have been unable to obtain that > result. Suggestions? John PS I am also surprised that these computations are slow since these > are rather simple functions involved in the convolution. > === Subject: Re: Manipulate with specified step size The key is to precompute and simplify the conv[x,y,z] function. c[z_] = conv[x, y, z] // Simplify [Piecewise] { {6 - z, 5 < z <= 6}, {-4 + z, 4 < z <= 5} } Substitute that into your Manipulate statement and everything will work smoothly. Also, you don't have to move in steps of 1. Here is a Presentations package version of it: Needs[Presentations`Master`] conv[f_, g_, t_] = !( *SubsuperscriptBox[([Integral]), (0), (t)](f[s] g[t - s] [DifferentialD]s)); x[t_] = UnitStep[t - 2] - UnitStep[t - 3]; y[t_] = UnitStep[t - 2] - UnitStep[t - 3]; c[z_] = conv[x, y, z] // Simplify Manipulate[ Draw2D[ {Draw[{x[s], y[t - s]}, {s, 0, 8}, PlotRange -> {{-.01, 8}, {-.4, 2}}, PlotStyle -> {{GrayLevel[.85]}, {GrayLevel[.85]}}, Exclusions -> None], Draw[x[s] y[t - s], {s, t, 8.1}, PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, Exclusions -> None], Draw[Evaluate[x[s] y[t - s]], {s, -.01, t}, Filling -> Axis, PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, Exclusions -> None], Draw[c[z], {z, -.01, t}, PlotRange -> {{-.01, 8}, {0, 16}}, PlotStyle -> Blue, Exclusions -> None], {Dashed, Line[{{t, -6}, {t, c[t]}}]}, Text[Style[t, Italic, Bold, Blue, 14], {t - .1, -1.5 + .2}]}, Frame -> False, PlotRange -> {{-.5, 8.5}, {-1.5, 2}} ], Style[Convolution Demonstration, 16], Delimiter, {t, 0, 8, Appearance -> Labeled} ] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >I wanted to revisit the issue in this thread: > I have the following: conv[f_, g_, t_] = !( > *SubsuperscriptBox[([Integral]), (0), (t)](f[s] > g[t - s] [DifferentialD]s)); x[t_] = UnitStep[t - 2] - UnitStep[t - 3]; > y[t_] = UnitStep[t - 2] - UnitStep[t - 3]; > Manipulate[ > Show[ > Plot[{Tooltip[x[s], f(s)], Tooltip[y[t - s], g(t-s)]}, {s, 0, > 8}, PlotRange -> {{-.01, 8}, {-.4, 2}}, > PlotStyle -> {{GrayLevel[.85]}, {GrayLevel[.85]}}, > Exclusions -> None], > Plot[Tooltip[x[s] y[t - s], f(s)g(t-s)], {s, t, 8.1}, > PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, > Exclusions -> None], > Plot[Evaluate[x[s] y[t - s]], {s, -.01, t}, Filling -> Axis, > PlotRange -> {{0, 8.1}, {0, 16}}, PlotStyle -> Black, > Exclusions -> None], > Plot[Evaluate[Tooltip[conv[x, y, z], (f*g)(t)]], {z, -.01, t}, > PlotRange -> {{-.01, 8}, {0, 16}}, PlotStyle -> Blue, > Exclusions -> None], > Graphics[{Dashed, Line[{{t, -6}, {t, conv[x, y, t]}}]}], > Graphics[ > Text[Style[t, Italic, Bold, Blue, 14], {t - .1, -6 + .2}]] > ] > , {t, 0, 8, 1} When I move the slider the dynamics are slow to evaluate. I would be > content to simply play the animation at the discrete values t=0 to > t=8 in increments of 1. However, I have been unable to obtain that > result. Suggestions? John PS I am also surprised that these computations are slow since these > are rather simple functions involved in the convolution. > === Subject: Re: Export into Excel Worksheets Yes, the following code works in exporting data from Mathematica to Excel file data = RandomReal[{0, 1}, {3, 4, 2}]; Export[test.xls, data]; However, in importing the same file test.xls back to Mathematica, the following code does not work. WHY? data1 = Import[D:test.xls, {Data, 1}] data2 = Import[D:test.xls, {Data, 2}] data3 = Import[D:test.xls, {Data, 3}] Tugrul -----Original Message----- === Subject: Re: Export into Excel Worksheets >I've got a list of data that I'd like to Export into Excel. The >twist is, I'd like to export each element of the list into a >separate worksheet within the same Excel Workbook. Can this be done >in Mathematica v6? Yes. For example, Export[test.xls,RandomReal[1, {3, 3, 3}],XLS] will create a workbook file with three spreadsheets. === Subject: Re: Export into Excel Worksheets > Yes, the following code works in exporting data from Mathematica to Excel > file data = RandomReal[{0, 1}, {3, 4, 2}]; > Export[test.xls, data]; However, in importing the same file test.xls back to Mathematica, the > following code does not work. WHY? data1 = Import[D:test.xls, {Data, 1}] > data2 = Import[D:test.xls, {Data, 2}] > data3 = Import[D:test.xls, {Data, 3}] It is very likely that you are not reading the file you have just created: the exported file test.xls is located in $HomeDirectory whereas D:test.xls is located on the root level of the second drive/partition. In[1]:= data = RandomReal[{0, 1}, {3, 4, 2}] Export[test.xls, data] 0.880122}, {0.713961, 0.625327}}, {{0.157472, 0.849435}, {0.947472, 0.976526}, {0.834299, 0.528255}, {0.994454, 0.807406}}, {{0.61929, 0.253483}, {0.695069, 0.76067}, {0.635693, 0.0609954}, {0.761752, 0.608448}}} Out[2]= test.xls In[3]:= data1 = Import[test.xls, {Data, 1}] data2 = Import[test.xls, {Data, 2}] data3 = Import[test.xls, {Data, 3}] 0.880122}, {0.713961, 0.625327}} Out[4]= {{0.157472, 0.849435}, {0.947472, 0.976526}, {0.834299, 0.528255}, {0.994454, 0.807406}} Out[5]= {{0.61929, 0.253483}, {0.695069, 0.76067}, {0.635693, 0.0609954}, {0.761752, 0.608448}} === Subject: Cube root of -1 and 1 Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? -Bob === Subject: Re: Cube root of -1 and 1 because (-1)^(1/3) is not -1, it is 1/2 + (I/2)*Sqrt[3] Jens > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob > === Subject: Re: Cube root of -1 and 1 Mathematica just does a straight forward calculation and does not try to find multiple roots. (Sqrt[36] - 7)^(1/3) // Trace {{{Sqrt[36],6},6-7,-1},{{1/3,1/3},1/3,1/3},(-1)^(1/3)} (Sqrt[36]-5)^(1/3)//Trace {{{Sqrt[36],6},6-5,1},{{1/3,1/3},1/3,1/3},1^(1/3),1} (Notice that 1^x gives 1.) If you want all the roots use Solve: Solve[w^3 == (Sqrt[36] - 7)] {{w->-1},{w->(-1)^(1/3)},{w->-(-1)^(2/3)}} Solve[w^3 == (Sqrt[36] - 5)] {{w->1},{w->-(-1)^(1/3)},{w->(-1)^(2/3)}} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob > === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob After seeing responses of others, try to see rotating effect in cube roots of 'another' unity: ( (1 + I )/Sqrt[2] ) ^ (1/3) Narasimham === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob I subscribe to the question. I also do not understand this behavour: In[12]:= (-1)^(1/3)//ComplexExpand Out[12]= 1/2+(I Sqrt[3])/2 In[13]:= FullSimplify[(-1)^(1/3) == 1/2 + (I Sqrt[3])/2] Out[13]= True But: In[14]:= FullSimplify[(-1)^(1/3)==-1] Out[14]= False In[17]:= (-1)^3 Out[17]= -1 In[20]:= FullSimplify[(-1)^3 == -1] Out[20]= True It is contradiction, is not it? === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob > The function z->z^n is a complex multivalued function, and, of course, there are three values that could serve as (-1)^(1/3). The most convenient choice is the so called principal value, which in case is not -1. To see this clearly, note that Mathematica uses the following definition of Power: Power[x,y] = Exp[y Log[x]] So the choice of the principal value of Power[-1,1/3] amounts to the choice principal value of Log[-1]. What should be that? Well, we would like the following relationship between Log and Arg to hold: Log[z] = log[Abs[z]]+I Arg[z] hence Log[-1]= I Arg[-1] Since clearly one would not want Arg to be anything else but: Arg[-1] Pi we have to choose Log[-1] as Pi I and hence Power[-1,1/3] as Exp[Pi I/ 3]. Any other choice would make many formulas and computations more complicated. Andrzej Kozlowski === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob > Mathematica treats every number as a complex one. So it returns always the principal value, the value with the smallest Arg. Your first example is (-1)^(1/3) which is multivalued with the possible values {Exp[I 60¡], -1=Exp[I 180¡], Exp[I 300¡]}. The smalles Arg is 60¡, so this one is given. In the second example (1)^(1/3) the set is {1=Exp[I 0¡], Exp[I 120¡], Exp[I 240¡]}, so 0¡ is the smallest and you get -1. Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? > Try this Table[(Sqrt[36]-n)^(1/3),{n,0,7}] (1)^(1/3) (0)^(1/3) The short answer is : One to the power of anything is one Zero to the power of anything (non-zero) is zero. Zero to the power of zero is Indeterminate. Steven Siew > In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? > Try this Table[(Sqrt[36]-n)^(1/3),{n,0,7}] (1)^(1/3) (0)^(1/3) The short answer is : One to the power of anything is one Zero to the power of anything (non-zero) is zero. No. Rather, zero to any _positive_ power is zero. In[5]:= Assuming[x > 0, Simplify[0^x]] Out[5]= 0 David > Zero to the power of zero is Indeterminate. Steven Siew > In[53]:= > (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) > Out[53]= (-1)^(1/3) > Out[54]= 1 > In other words why isn't (-1)^1/3 expressed as -1 ?? > > -Bob === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob Because In[1]:= Solve[x^3 == -1, x] Out[1]= {{x -> -1}, {x -> (-1)^(1/3)}, {x -> -(-1)^(2/3)}} A.V. === Subject: Re: Cube root of -1 and 1 Because of the following? Arg[-1] Pi Arg[1] 0 According to the reference page for Power, For complex numbers x and y, Power gives the principal value of e^(y log (x)). And an example there shows the result (-1)^(1/3) for (-1)^(1/3) and says, The principal root is always used. If you want an actual expansion for (-1)^(1/3) into real and complex parts, then use ComplexExpand: ComplexExpand[(-1)^(1/3)] // InputForm 1/2 + (I/2)*Sqrt[3] > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? > -Bob > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Cube root of -1 and 1 > Could someone explain why Mathematica evaluates these so differently? In[53]:= (Sqrt[36] - 7)^(1/3) > (Sqrt[36] - 5)^(1/3) Out[53]= (-1)^(1/3) Out[54]= 1 In other words why isn't (-1)^1/3 expressed as -1 ?? Branch cut and principal root are the key words here. See, How do I get x^(1/3) (where x is a negative number) to evaluate to a real number? http://support.wolfram.com/mathematica/mathematics/algebra/realpower.html === Subject: Re: NDSolve[] with error dsfun: Vgn === Subject: Re: question about sorting lists Jean-Marc, Tatyana ----- Original Message ----- === Subject: Re: question about sorting lists > Jean-Marc, > thank you very much for the tip. Indeed, I forgot to specify that the eigenvalues have to also be arranged in order of increasing or decreasing their values depending on what the distance is between the adjacent two. Say, the eigenvalues list is {-2, 1, -3}. The way this list needs to be ordered is {-3, -2, 1}. If the list is {1, 2, -3} then it needs to be ordered as {2, 1, -3}. So that the middle element in the list has an intermediate absolute value, and the distance between the second and the third elements in the list is the largest. The way I used to do the ordering before is in two steps: > first, the regular Sort operation to arrange the eigenvalues in order. Then, reassign the order if necessary according to the distance criterion. Something like: CS={1,2,-3} > Eigensort = Sort[Eigenvalues[CS]]; > If[Abs[Eigensort[[1]] - Eigensort[[2]]] > Abs[Eigensort[[3]] - Eigensort[[2]]], Vxx = Eigensort[[3]]; Vyy = Eigensort[[2]]; Vzz = Eigensort[[1]], Vxx = Eigensort[[1]]; Vyy = Eigensort[[2]]; Vzz = Eigensort[[3]]]; But then the problem arises when I need to pull out the corresponding eigenvectors, in some instances the Vxx, Vyy, and Vzz are not recognized by Mathematica as identical numbers to the original values stored in the list. Is this a precision problem? But in any event, I thought it may be a more concise way to do the sorting using a one-line expression, like you suggested. Tatyana Hi Tatyana, I believe the following function is doing what you wish in an elegant and concise way (of course, elegance is in the eye of the beholder :). First, we sort the eigenvalues and their corresponding eigenvectors according to increasing values of the eigenvalues. Second, we swap the third and first columns of the eigenvalue and eigenvector arrays if and only if the distance between the first and second eigenvalues is greater than the distance between the second and third eigenvalues. Note that the second column of each array always stay in place since it is already at the right place after the initial sort. mySort[eigsys_] := Module[{es = eigsys}, es = {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]]; If[Abs[es[[1, 1]] - es[[1, 2]]] > Abs[es[[1, 3]] - es[[1, 2]]], {es[[1, 1]], es[[1, 3]]} = {es[[1, 3]], es[[1, 1]]}; {es[[2, 1]], es[[2, 3]]} = {es[[2, 3]], es[[2, 1]]}]; es] eigs = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N mySort[eigs] {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, {-1.28335, -0.141675, 1.}, {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, {1., -2., 1.}, {0.283349, 0.641675, 1.}}} eigs = Eigensystem[N[{{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}]] mySort[eigs] {{29.9428, 1.83935, 0.217884}, {{-0.119842, -0.329513, -0.936514}, {-0.716252, -0.656311, 0.237146}, {-0.848423, 0.515028, -0.122164}}} {{0.217884, 1.83935, 29.9428}, {{-0.848423, 0.515028, -0.122164}, {-0.716252, -0.656311, 0.237146}, {-0.119842, -0.329513, -0.936514}}} mySort[{{30, 1, 5}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{1, 5, 30}, {{1, 4, 9}, {1, 8, 27}, {1, 2, 3}}} *) mySort[{{-2, 1, -3}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{-3, -2, 1}, {{1, 8, 27}, {1, 2, 3}, {1, 4, 9}}} *) mySort[{{1, 2, -3}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{2, 1, -3}, {{1, 4, 9}, {1, 2, 3}, {1, 8, 27}}} *) mySort[{{1, -1, 0}, {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}}}] (* {{-1, 0, 1}, {{1, 4, 9}, {1, 8, 27}, {1, 2, 3}}} *) - Jean-Marc > ----- Original Message ----- === > Subject: Re: question about sorting lists >> I have the following numerical list: >> {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}} >> where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21, >> x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors. >> I need to sort the list so that the eigenvalues are arranged in the >> order of decreasing the absolute value of the difference between any >> of the two eigenvalues. (and that the eigenvectors still correspond to >> the original eigenvalues). >> What would be the correct syntax for this operation in Mathematica 5.2? First the easy part of your question. Say we want to sort the > eigenvalues in increasing order and keep their respective eigenvector in > order. One possible way of doing that is as follows: eigsys = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N > {eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[[1]]]] > {{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.}, > {-1.28335, -0.141675, 1.}, > {1., -2., 1.}}} {{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.}, > {1., -2., 1.}, > {0.283349, 0.641675, 1.}}} > (Note that functions such as Sort, Ordering, etc., all have a second or > third optional argument that specifies the sort function -- relation -- > to use.) Although I might have missed the obvious when reading your > specifications, your criterion is not strong enough to define an order > relation (among other things, it is not antisymmetric). For instance, say we have the eigenvalues {-1, 0, 1}. How would you > ordered them? You might say (-1, 1, 0) for the distances among adjacent > pairs are 2 (Abs[(-1) - 1]) and 1 (Abs[1 - 0]). Now the triple (1, -1, > 0) also matches the same order. So which one to choose? === Subject: evaluations in Plot in Manipulate? I must be overlooking something simple in the way Mathematica handles the arguments of Manipulate. Could someone expound on the contrast in behavior between the last example below and the previous two? Clear[a, b, c, h]; a = 1; c = 1; h[t_] = InverseLaplaceTransform[1/(a s^2 + b s + c), s, t] Manipulate[ Plot[Evaluate[ InverseLaplaceTransform[1/(a s^2 + b s + c), s, t]], {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* works fine *) Manipulate[ Plot[-((E^((-(b/(2 a)) - Sqrt[b^2 - 4 a c]/(2 a)) t) - E^((-(b/(2 a)) + Sqrt[b^2 - 4 a c]/(2 a)) t))/Sqrt[ b^2 - 4 a c]), {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* works fine... I just copied and pasted the output of h[t] into the Plot[...] *) Manipulate[ Plot[Evaluate[h[t]], {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* nothing... what am I missing? *) Doesn't Evaluate[h[t]] hold the evaluated form of h[t] (so that it is computed just once) and then Plot simply substitutes a sequence of numerical values into that evaluated form? If so, why is there no output? John === Subject: Re: evaluations in Plot in Manipulate? you miss, that Manipulate[] by default localize the variables and in expr=Exp[a] Manipulate[ Exp[a],{a,1,5}] a in expr is not the same as a in Manipulate[]. You can see this when you type Manipulate[HoldForm[a], {a, 1, 5}] The option LocalizeVariables control the generation of local variables. Jens > I must be overlooking something simple in the way Mathematica handles > the arguments of Manipulate. Could someone expound on the contrast in behavior between the last > example below and the previous two? Clear[a, b, c, h]; > a = 1; > c = 1; > h[t_] = InverseLaplaceTransform[1/(a s^2 + b s + c), s, t] > Manipulate[ > Plot[Evaluate[ > InverseLaplaceTransform[1/(a s^2 + b s + c), s, t]], {t, 0, 10}, > PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* works fine *) > Manipulate[ > Plot[-((E^((-(b/(2 a)) - Sqrt[b^2 - 4 a c]/(2 a)) t) - > E^((-(b/(2 a)) + Sqrt[b^2 - 4 a c]/(2 a)) t))/Sqrt[ > b^2 - 4 a c]), {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, > 5}] (* works fine... I just copied and pasted the output of h[t] into the > Plot[...] *) > Manipulate[ > Plot[Evaluate[h[t]], {t, 0, 10}, > PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* nothing... what am I missing? *) Doesn't Evaluate[h[t]] hold the evaluated form of h[t] (so that it is > computed just once) and then Plot simply substitutes a sequence of > numerical values into that evaluated form? If so, why is there no > output? John > === Subject: Re: evaluations in Plot in Manipulate? > I must be overlooking something simple in the way Mathematica handles > the arguments of Manipulate. Could someone expound on the contrast in behavior between the last > example below and the previous two? Clear[a, b, c, h]; > a = 1; > c = 1; > h[t_] = InverseLaplaceTransform[1/(a s^2 + b s + c), s, t] > Manipulate[ > Plot[Evaluate[ > InverseLaplaceTransform[1/(a s^2 + b s + c), s, t]], {t, 0, 10}, > PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* works fine *) > Manipulate[ > Plot[-((E^((-(b/(2 a)) - Sqrt[b^2 - 4 a c]/(2 a)) t) - > E^((-(b/(2 a)) + Sqrt[b^2 - 4 a c]/(2 a)) t))/Sqrt[ > b^2 - 4 a c]), {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, > 5}] (* works fine... I just copied and pasted the output of h[t] into the > Plot[...] *) > Manipulate[ > Plot[Evaluate[h[t]], {t, 0, 10}, > PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] (* nothing... what am I missing? *) Doesn't Evaluate[h[t]] hold the evaluated form of h[t] (so that it is > computed just once) and then Plot simply substitutes a sequence of > numerical values into that evaluated form? If so, why is there no > output? Evaluate does nothing here since the function h[t] is defined with immediate assignment (= or *Set[]*), i.e. h[t] has already been evaluated when you defined it. (That's why you got an output when you evaluated the function. Contrast this behavior with the same definition but using delayed assignment := or *SetDelayed[]*). Manipulate must see all the variables it manipulates in its first argument. Therefore, when one uses a function, the function must explicitly depends on all the variables that are going to be controlled by Manipulate[]. One possible way is as follows: Clear[a, b, c, h]; a = 1; c = 1; h[b_][t_] = InverseLaplaceTransform[1/(a s^2 + b s + c), s, t]; Manipulate[ Plot[h[b][t], {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] === Subject: Interpretation should accept SelectWithContents In Mathematica 6 InterpretationBox accepts a new, undocumented and very useful Boolean option named SelectWithContents (False by default). However, the new function Interpretation (which is a high level interface to InterpretationBox) does not accept SelectWithContents. I«m sure this is an oversight. Carlos C.8esar de Ara.9cjo Gregos & Troianos Educacional http://www.gregosetroianos.mat.br Belo Horizonte, MG, Brasil (31) 3283-1122 === Subject: bug? f'[x]' G'day, Out[]= True Can anyone explain this? -Ben === Subject: Re: bug? f'[x]' As I'd said before, f[x]' is pretty much meaningless (without more definition than you've given). In Mathematica, f' is a function if f is a differentiable function, but is f[x] a function? No, or not usually. For instance, evaluate Clear[f] f[x_] = x; f[x][y] x[y] and so, naturally, f[x]'[y] (x^[Prime])[y] (Judge for yourself how useful that can possibly be.) f[x]' DOES make sense in a case like this: Clear[f] f[x_][y_] := Sin[x y]; f[x][y] Sin[x y] and then f[x]'[y] x Cos[x y] but f'[x] (f^[Prime])[x] That's unevaluatable because f isn't a function of one variable. But this works perfectly: f[x]' x Cos[x #1] & since f[x] IS a function of one variable. Bobby > Mathematica does distinguish between f'[x] (evaluating the derivative) > and f[x]' (derivative of the evaluation), so it seems unreasonable > that this behaviour should change when f is written in terms of its > antiderivative (i.e., f->g'). In other words, what is the justification for Derivative[i] > [ (Derivative[j][g][x]) ][y] ever evaluating to Derivative[i+j][g][x] > [y]? Even this behaviour is not consistent. Mathematica reverts to > mathematically correct behaviour again if g was explicitly specified. > For example, consider the function that takes an argument and returns > the operator for multiplication by the cube of that argument > (g=Function[x,Function[y,y*x^3]]). The derivative of its evaluation is > obviously (an operator that returns) a constant (namely the cube of > that argument, or zero for higher derivatives). By contrast, the > evaluation of the derivative is not a constant (it is the partial with > respect to the argument, an operator for multiplication by thrice the > squared argument; zero is not produced until the fourth derivative). Even Derivative[j]//Derivative[i] evaluates further, nonsensically > (garbage input ought only echo), as though a rule constraint had been > overlooked. I wondered if there could be scoping error, as internal > conversions involving #& are documented for Derivative. Also, this is > not the only case of odd behaviour involving the distinction between > numbers and operators: Ben > Since, however, it is not documented >> (and illogical) it is certianly cannot be regarded as any kind of bug. -- DrMajorBob@longhorns.com === Subject: Re: bug? f'[x]' Well, if I had to speculate about this, it would probably go like this. A long, long time ago, in the very early days of Mathematica, someone was writing code for Derivative and at some point decided to sacrifice a little of mathematical sense for a bit of notational convenience (for himself). He realized that it was quite likely that users would use expressions like f[1], f[2] etc, to denote functions, hence it would be a very bad idea to convert f[1]' to f'[1], etc. However, he thought it very unlikely that f'[1],f''[1], etc... would ever be used for anything but the values of the first, second etc. derivatives of f art 1. Hence, he though, it would do no harm, and could be quite convenient if Mathematica automatically interpreted f'[1]' as f''[1], etc. So he implemented this but being worried that math professors and other pedants would rise hell over this violation of mathematical sense he decided not to tell anyone about it (i.e. did not document it). That is of course what I would do if I had to speculate about this, but since I don't have to I won't. Andrzej Kozlowski > Mathematica does distinguish between f'[x] (evaluating the derivative) > and f[x]' (derivative of the evaluation), so it seems unreasonable > that this behaviour should change when f is written in terms of its > antiderivative (i.e., f->g'). In other words, what is the justification for Derivative[i] > [ (Derivative[j][g][x]) ][y] ever evaluating to Derivative[i+j][g][x] > [y]? Even this behaviour is not consistent. Mathematica reverts to > mathematically correct behaviour again if g was explicitly specified. > For example, consider the function that takes an argument and returns > the operator for multiplication by the cube of that argument > (g=Function[x,Function[y,y*x^3]]). The derivative of its evaluation is > obviously (an operator that returns) a constant (namely the cube of > that argument, or zero for higher derivatives). By contrast, the > evaluation of the derivative is not a constant (it is the partial with > respect to the argument, an operator for multiplication by thrice the > squared argument; zero is not produced until the fourth derivative). Even Derivative[j]//Derivative[i] evaluates further, nonsensically > (garbage input ought only echo), as though a rule constraint had been > overlooked. I wondered if there could be scoping error, as internal > conversions involving #& are documented for Derivative. Also, this is > not the only case of odd behaviour involving the distinction between > numbers and operators: Ben > Since, however, it is not documented >> (and illogical) it is certianly cannot be regarded as any kind of >> bug. > === Subject: Re: bug? f'[x]' Perhaps the actual trouble is that notations like f[x]' are in effect used all the time in traditional math notation. For example: (3x^2 + 5x - 8)' = 6x + 5, (sin x)' = cos x, (e^x)' = e^x Go look in just about any beginning calculus book. No wonder students don't understand calculus and functions when such clap-trap is taught. > The right side of both equations is meaningless in Mathematica, so of > course they are not True. For a version of the second one, we do have D[f'[x], x] == f''[x] True Bobby >> G'day, >> Out[]= True >> Can anyone explain this? >> -Ben > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: bug? f'[x]' Mathematica does distinguish between f'[x] (evaluating the derivative) and f[x]' (derivative of the evaluation), so it seems unreasonable that this behaviour should change when f is written in terms of its antiderivative (i.e., f->g'). In other words, what is the justification for Derivative[i] [ (Derivative[j][g][x]) ][y] ever evaluating to Derivative[i+j][g][x] [y]? Even this behaviour is not consistent. Mathematica reverts to mathematically correct behaviour again if g was explicitly specified. For example, consider the function that takes an argument and returns the operator for multiplication by the cube of that argument (g=Function[x,Function[y,y*x^3]]). The derivative of its evaluation is obviously (an operator that returns) a constant (namely the cube of that argument, or zero for higher derivatives). By contrast, the evaluation of the derivative is not a constant (it is the partial with respect to the argument, an operator for multiplication by thrice the squared argument; zero is not produced until the fourth derivative). Even Derivative[j]//Derivative[i] evaluates further, nonsensically (garbage input ought only echo), as though a rule constraint had been overlooked. I wondered if there could be scoping error, as internal conversions involving #& are documented for Derivative. Also, this is not the only case of odd behaviour involving the distinction between numbers and operators: Ben > Since, however, it is not documented > (and illogical) it is certianly cannot be regarded as any kind of bug. === Subject: Re: bug? f'[x]' The right side of both equations is meaningless in Mathematica, so of course they are not True. For a version of the second one, we do have D[f'[x], x] == f''[x] True Bobby > G'day, Out[]= True Can anyone explain this? -Ben -- DrMajorBob@longhorns.com === Subject: Re: bug? f'[x]' > G'day, Out[]= True Can anyone explain this? -Ben > Maybe not exactly explain... but this is a consequence of the following somewhat strange phenomenon: FullForm[Derivative[n][Derivative[m][f][x]]] FullForm[Derivative[m + n][f][x]] but not for m=0: FullForm[Derivative[n][Derivative[0][f][x]]] FullForm= FullForm[Derivative[n][f[x]]] Note that the first output is actually the (m+n)-th derivative of f at x, but the second output means (if anything) something completely different (n-th derivative of the functon f[x]). Although the first result may be part of some design, it is mathematically just as meaningless as the second. So I would guess the explanation of the phenomenon you have observed is of the garbage in -> garbage out kind. Andrzej Kozlowski === Subject: Re: bug? f'[x]' Perhaps I should have added that this: Derivative[n][Derivative[m][f]] Derivative[m + n][f] is mathematically perfectly sound, while this: Derivative[n][Derivative[m][f][x]] Derivative[m + n][f][x] cerainly is not. But this does not mean this is necesarily a bug. The syntax of second input illogical and not documented as anything meaningful in Mathematica but it returns a meaningful answer but perhaps might do so intentinally. Since, however, it is not documented (and illogical) it is certianly cannot be regarded as any kind of bug. Andrzej Kozlowski >> G'day, >> Out[]= True >> Can anyone explain this? >> -Ben > > Maybe not exactly explain... but this is a consequence of the following somewhat strange phenomenon: FullForm[Derivative[n][Derivative[m][f][x]]] > FullForm[Derivative[m + n][f][x]] but not for m=0: FullForm[Derivative[n][Derivative[0][f][x]]] > FullForm= FullForm[Derivative[n][f[x]]] Note that the first output is actually the (m+n)-th derivative of f > at x, but the second output means (if anything) something completely > different (n-th derivative of the functon f[x]). Although the first result may be part of some design, it is > mathematically just as meaningless as the second. So I would guess > the explanation of the phenomenon you have observed is of the > garbage in -> garbage out kind. Andrzej Kozlowski > === Subject: Re: bug? f'[x]' FullForm /@ {f'[x], f[x]'} {Derivative[1][f][x], Derivative[1][f[x]]} FullForm /@ {f''[x], f'[x]'} {Derivative[2][f][x], Derivative[2][f][x]} > G'day, Out[]= True Can anyone explain this? -Ben > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: bug? f'[x]' > Out[]= True Can anyone explain this? First, keep in mind that Mathematica does *pattern* matching. Second, SameQ requires exact correspondence between expressions when those expressions are expressed in *FullForm* (FullForm being the internal representation used by Mathematica regardless of the type of input). In your case, the fullform of f'[x] is Derivative[1][f][x] whereas the fullform of f[x]' is Derivative[1][f[x]], both expressions are *syntactically* not the same. OTOH, the fullform of f''[x] is Derivative[2][f][x] whereas the fullform of f'[x]' is Derivative[2][f][x], both expressions are *syntactically* the same. (Note that the fullform of f[x]'' is Derivative[2][f[x]].) Out[1]= True In[2]:= f'[x] =!= f[x]' Out[2]= True Out[3]= True In[4]:= f'[x] // FullForm Out[4]//FullForm= Derivative[1][f][x] In[5]:= f[x]' // FullForm Out[5]//FullForm= Derivative[1][f[x]] In[6]:= f''[x] // FullForm Out[6]//FullForm= Derivative[2][f][x] In[7]:= f'[x]' // FullForm Out[7]//FullForm= Derivative[2][f][x] === Subject: Warning for use of 3D Graphics manipulation with notebook computers After installing Mathematica 6 and programming some group-mechanical 3D-manipulations the nvidia go graphics chip of my Samsung laptop stopped working at the performance of a complex 3d-manipulation. Its internal digital lcd-part gave up with a crack noise. The external analog VGA is still working. On the internet, some hints can be found saying that certain laptop computers are in danger to burn their graphics chips because of insufficent cooling under high permanent load. -- Roland Franzius === Subject: Re: Warning for use of 3D Graphics manipulation with notebook computers that is not a problem of Mathematica, this is a problem of the nVidia chips for laptops. Any complex 3d scene may burn the chip. You don't need Mathematica for that, Crisis or Half Life will burn the graphics chip better and faster than Mathematica *and* for a more affordable prize ! *AND* if your VGA signal on an external monitor is still right, you graphics chip is ok, but you lcd-display may be broken and this has *nothing* to do with the overheating of the GeForce mobile chips. Jens > After installing Mathematica 6 and programming some group-mechanical > 3D-manipulations the nvidia go graphics chip of my Samsung laptop > stopped working at the performance of a complex 3d-manipulation. Its > internal digital lcd-part gave up with a crack noise. The external > analog VGA is still working. On the internet, some hints can be found saying that certain laptop > computers are in danger to burn their graphics chips because of > insufficent cooling under high permanent load. > === Subject: Re: Warning for use of 3D Graphics manipulation with notebook This, of course, is not a warning about a problem with Mathematica. > After installing Mathematica 6 and programming some group-mechanical > 3D-manipulations the nvidia go graphics chip of my Samsung laptop > stopped working at the performance of a complex 3d-manipulation. Its > internal digital lcd-part gave up with a crack noise. The external > analog VGA is still working. On the internet, some hints can be found saying that certain laptop > computers are in danger to burn their graphics chips because of > insufficent cooling under high permanent load. -- Roland Franzius === Subject: Re: ParametricPlot precision problem Maxim, solves my dilemma. Now I have to figure out the mathematical implications to the problem I am working on. Also thank you for the nice animation. Best wishes, Cristina On Jul 27, 1:43 am, Cristina Ballantine With the code below, plot1 gives a line from -a to 0 (in the complex > plane). plot2 should give the the symmetric of plot1 with respect to the > unit circle, i.e., a line from -1/Conjugate[a] to infinity (same slope = as > line from -a to 0). I cannot get plot2 to give the correct line. Any = help > is very much appreciated. Cristina --------------------------------- r := 1/3 > alpha := Pi/3 > a := r*Exp[I*alpha] > n := 3 B[z_] := z^n*((Conjugate[a]/a)*(a^2 - z^2)/(1 - (Conjugate[a])^2*z^2))^= n b := 1/(r*Sqrt[2])*Sqrt[3 - r^4 - Sqrt[(3 - r^4)^2 - 4*r^4]]* > Exp[I*alpha] s := -Abs[B[b]] z1[t_] := -(t/27) - ((1 + I Sqrt[3]) (27 - 27 (-1)^(1/3) - t^2))/( > 27 2^(2/3) (19602 t - 19602 (-1)^(1/3) t + 2 t^3 + Sqrt[ > 4 (27 - 27 (-1)^(1/3) - t^2)^3 + (19602 t - 19602 (-1)^(1/3) t + > 2 t^3)^2])^( > 1/3)) + ((1 - I Sqrt[3]) (19602 t - 19602 (-1)^(1/3) t + 2 t^3 + > Sqrt[4 (27 - 27 (-1)^(1/3) - t^2)^3 + (19602 t - > 19602 (-1)^(1/3) t + 2 t^3)^2])^(1/3))/(54 2^(1/3)) plot1:=ParametricPlot[{Re[z1[t]], Im[z1[t]]}, {t, s, 0}, > PlotStyle -> {Orange, Thick}, PlotPoints -> 100, MaxRecursion -> 5, > PlotRange -> 1, WorkingPrecision -> 100] plot2 := > ParametricPlot[{Re[1/Conjugate[z1[t]]], Im[1/Conjugate[z1[t]]]}, {t, > s, 0}, PlotStyle -> {Orange, Thick}, PlotPoints -> 2000, > MaxRecursion -> 15, PlotRange -> All, WorkingPrecision -> 100] There isn't a straight line going through the origin, what you're seeing in the first plot is several points very close to z1[s] and an outlier at {0, 0}. This is similar to Sqrt[-1 - I t^2] for real t near 0: both limits are equal to -I but the value at t=0 is +I. So basically z1[t] has a removable singularity at 0. You can make a nice demonstration out of your example: (*z1 as defined above*) Module[{c2p, f, closest, gr, t}, c2p = {Re@#, Im@#} &; f[p_, t_] := c2p@If[Norm[p] < 1, z1[t], z1[t]/Norm@z1[t]^2]; closest[p_] := Quiet[f[p, t] /. Last@FindMinimum[Norm[f[p, t] - p], {t, .01, -1, 1}, PrecisionGoal -> 2]]; gr = ParametricPlot[ c2p /@ {z1[t], z1[t]/Norm@z1[t]^2} // Evaluate, {t, -1, 1}, PlotStyle -> {Directive[Orange, Thick], Directive[Magenta, Thick]}]; DynamicModule[{p = c2p@z1[.01]}, LocatorPane[Dynamic[p, (p = closest[#]) &], Show[gr, Graphics[ {Circle[], Dashed, Line@Dynamic@Sort[{{0, 0}, p, p/Norm@p^2}, Norm@# < Norm@#2 &], Locator[Dynamic[p/Norm@p^2, None], Appearance -> Small], Locator[Dynamic[p, None], Appearance -> Small]}], PlotRange -> All], Appearance -> None] ]] Maxim Rytin m.r@inbox.ru === Subject: Problem with BinCounts I'm trying to do an autocorrelation analysis on an artificially generated neuronal spike train, but BinCounts is behaving strangely. I first generate a list of spike times for an oscillator with a mean frequency of 1 Hz, plus some gaussian jitter: st = NestList[(1 + RandomReal[NormalDistribution[0, 0.1]] + # &), 0,1000]; Then I do the autocorrelation like this: BinCounts[st, {# - 2.00, # + 2.00, 0.01}] & /@ st; ac = Last[Accumulate[%]]/Length[%]; The output of BinCounts ought to be a list of length st, with each list element having a fixed length of 400. And yet I get error messages like so: Thread::tdlen: Objects of unequal length in {13,11,15,9,12,13,14,13,9,6,<<390>>}+{0,1,0,0,0,0,0,0,0,0,<<389>>} cannot be combined. >> And sure enough, if I run Dimensions/@ the output of the BinCounts line, I get one or two elements with a length of 399. This happens completely at random, and I don't understand why. It seems to me that BinCounts ought to give me a fixed output length, regardless of what the results of the operation actually were. These shorter elements do not occur near the beginning or end, either, so it's not an edge effect. Furthermore, the values of st corresponding to the shorter elements of ac don't have any unusual properties like being whole numbers or anything. I will add that sometimes the code works correctly, and it's not obvious why. Has anyone else encountered such behavior before? What did you do about it? Mark -- Mark A. Teagarden, Ph.D. Institute for Neurosciences University of Texas - San Antonio San Antonio, TX 78249 Office: BSE 2.306 Phone: 210.458.4746 === Subject: Re: Problem with BinCounts > >> I'm trying to do an autocorrelation analysis on an artificially generated >> neuronal spike train, but BinCounts is behaving strangely. >> I first generate a list of spike times for an oscillator with a mean >> frequency of 1 Hz, plus some gaussian jitter: >> st = NestList[(1 + RandomReal[NormalDistribution[0, 0.1]] + # &), 0,100= >> > 0]; > >> Then I do the autocorrelation like this: >> BinCounts[st, {# - 2.00, # + 2.00, 0.01}] & /@ st; >> ac = Last[Accumulate[%]]/Length[%]; >> The output of BinCounts ought to be a list of length st, with each list >> element having a fixed length of 400. And yet I get error messages lik= >> > e so: > >> Thread::tdlen: Objects of unequal length in >> {13,11,15,9,12,13,14,13,9,6,<<390>>}+{0,1,0,0,0,0,0,0,0,0,<<389>>} >> cannot be combined. >> And sure enough, if I run Dimensions/@ the output of the BinCounts line, = >> > I > >> get one or two elements with a length of 399. This happens completely = >> > at > >> random, and I don't understand why. It seems to me that BinCounts ough= >> > t to > >> give me a fixed output length, regardless of what the results of the >> operation actually were. These shorter elements do not occur near the >> beginning or end, either, so it's not an edge effect. Furthermore, the >> values of st corresponding to the shorter elements of ac don't have any >> unusual properties like being whole numbers or anything. I will add th= >> > at > >> sometimes the code works correctly, and it's not obvious why. >> Has anyone else encountered such behavior before? What did you do abou= >> > t it? > Good day, All I can say is that if you rationalize 'st' > and all parameters then it doesn't occur : st=NestList[(1+RandomReal[NormalDistribution[0,0.1]]+#&), > 0,1000]//Rationalize[#,10^-6]&; BinCounts[st, {# - 2, # + 2, 1/100}] & /@ st; > V.Astanoff It's clear that this is a consequence of inexact arithmetic, but not yet clear if it is avoidable in general. Basically, a small amount of numerical error is enough to cause a bin to not be included (effectively something like a step going slightly beyond the end point in the inexact representation, though not with exact numbers) for some starting values. A way around this is to shift the data being binned rather than the bins themselves, as we see here in 100 trials In[1]:= Table[st = NestList[(1 + RandomReal[NormalDistribution[0, 0.1]] + # &), 0, 1000]; bc2 = BinCounts[st - #, {-2.00, 2.00, 0.01}] & /@ st; Map[Length, bc2] // Union, {100}] // Union Out[1]= {{400}} and better still to do this and use an exact binning spec to avoid any numerical error in the bins. In[2]:= Table[st = NestList[(1 + RandomReal[NormalDistribution[0, 0.1]] + # &), 0, 1000]; bc2 = BinCounts[st - #, {-2, 2, 1/100}] & /@ st; Map[Length, bc2] // Union, {100}] // Union Out[2]= {{400}} Darren Glosemeyer Wolfram Research === Subject: Re: Problem with BinCounts I'm trying to do an autocorrelation analysis on an artificially generated > neuronal spike train, but BinCounts is behaving strangely. I first generate a list of spike times for an oscillator with a mean > frequency of 1 Hz, plus some gaussian jitter: st = NestList[(1 + RandomReal[NormalDistribution[0, 0.1]] + # &), 0,100= 0]; Then I do the autocorrelation like this: BinCounts[st, {# - 2.00, # + 2.00, 0.01}] & /@ st; ac = Last[Accumulate[%]]/Length[%]; The output of BinCounts ought to be a list of length st, with each list > element having a fixed length of 400. And yet I get error messages lik= e so: Thread::tdlen: Objects of unequal length in {13,11,15,9,12,13,14,13,9,6,<<390>>}+{0,1,0,0,0,0,0,0,0,0,<<389>>} cannot be combined. > > And sure enough, if I run Dimensions/@ the output of the BinCounts line, = I > get one or two elements with a length of 399. This happens completely = at > random, and I don't understand why. It seems to me that BinCounts ough= t to > give me a fixed output length, regardless of what the results of the > operation actually were. These shorter elements do not occur near the > beginning or end, either, so it's not an edge effect. Furthermore, the > values of st corresponding to the shorter elements of ac don't have any > unusual properties like being whole numbers or anything. I will add th= at > sometimes the code works correctly, and it's not obvious why. Has anyone else encountered such behavior before? What did you do abou= t it? > Good day, All I can say is that if you rationalize 'st' and all parameters then it doesn't occur : st=NestList[(1+RandomReal[NormalDistribution[0,0.1]]+#&), 0,1000]//Rationalize[#,10^-6]&; BinCounts[st, {# - 2, # + 2, 1/100}] & /@ st; V.Astanoff === Subject: How to produce variable substitution list? Is there a straight-forward way to write a function that takes a list of symbols that are bound in the calling environment and produce a list such as is produced by Solve, like {var1->val1, var2->val2,...}? Currently, I'm using an expression (not a function) like {Hold[var1]- >var1, Hold[var2]->var2}, which produces the right result, but it looks bad to duplicate the symbols. I want something that looks clean, like bindings[var1, var2,...]. I know this isn't lisp, and there's no binding environment as such, but it would expect this to be doable. TIA for any suggestions. - Stoney === Subject: Re: How to produce variable substitution list? > Is there a straight-forward way to write a function that takes a list > of symbols that are bound in the calling environment and produce a > list such as is produced by Solve, like {var1->val1, var2->val2,...}? Currently, I'm using an expression (not a function) like {Hold[var1]->var= 1, Hold[var2]->var2}, which produces the right result, but it looks bad to duplicate the symbols. I want something that looks clean, > like bindings[var1, var2,...]. I know this isn't lisp, and there's no binding environment as such, > but it would expect this to be doable. TIA for any suggestions. =A0- Stoney Good day, This is a solution inspired from Roman Maeder's Programming in Mathematica: In[1]:=3D SetAttributes[myRules,HoldAll]; myRules[vars_List]:=3D With[{vv=3DMap[Hold,MapAt[Hold,Hold[vars],{1,0}],{2}][[1]]}, List@@(# -> ReleaseHold[#]& /@ vv) ]; In[2]:=3D var1=3D3; var2=3D5; myRules[{var1,var2}] Out[4]=3D {Hold[var1]->3,Hold[var2]->5} V.Astanoff === Subject: Re: How to produce variable substitution list? On 2008-07-29 06:11:06 -0400, Valeri Astanoff said: >> Is there a straight-forward way to write a function that takes a list >> of symbols that are bound in the calling environment and produce a >> list such as is produced by Solve, like {var1->val1, var2->val2,...}? >> Currently, I'm using an expression (not a function) like {Hold[var1]-> var= > 1, Hold[var2]->var2}, which produces the right result, but it >> looks bad to duplicate the symbols. I want something that looks clean, >> like bindings[var1, var2,...]. >> I know this isn't lisp, and there's no binding environment as such, >> but it would expect this to be doable. >> TIA for any suggestions. >> - Stoney Good day, This is a solution inspired from Roman Maeder's > Programming in Mathematica: In[1]:= SetAttributes[myRules,HoldAll]; > myRules[vars_List]:= > With[{vv=Map[Hold,MapAt[Hold,Hold[vars],{1,0}],{2}][[1]]}, > List@@(# -> ReleaseHold[#]& /@ vv) > ]; In[2]:= var1=3; var2=5; > myRules[{var1,var2}] Out[4]= {Hold[var1]->3,Hold[var2]->5} > V.Astanoff It's too bad the quoted-printable conversion made your code difficult to read in the newsgroup. Once I realized that With ignored Hold, your solution worked fine. While investigating it, I came up with this simplified form, which seems to produce the same result: myRules[vars_List] := Thread[Rule[Map[Hold, Hold[vars], {2}][[1]], vars]] - Stoney === Subject: Re: Calculating RMSE from 2D Data Use Interpolation to get a representation of your data. With the interpolated function you can then produce a list of regular synthetic data. Peter > I'm using Mathematica 6 to analyze some 2D laboratory data obtained at > irregular points. My data is in the form (x,y,z), where x and y are > spatial coordinates and z is my variable of interest. I'm able to plot > the data using ListContourPlot for qualitative analysis. However, I'm running into some difficulty trying to quantitatively > measure the variance of my data. I'd like to obtain a table of values > at regular spacings in my data set and calculate the RMSE (root mean > square error) or coefficient of variance (std. dev. / mean). Is there > a way I can get Mathematica to extract values from my contour plot or > otherwise do a 2D interpolation of my data? > === Subject: Calculating RMSE from 2D Data I'm using Mathematica 6 to analyze some 2D laboratory data obtained at irregular points. My data is in the form (x,y,z), where x and y are spatial coordinates and z is my variable of interest. I'm able to plot the data using ListContourPlot for qualitative analysis. However, I'm running into some difficulty trying to quantitatively measure the variance of my data. I'd like to obtain a table of values at regular spacings in my data set and calculate the RMSE (root mean square error) or coefficient of variance (std. dev. / mean). Is there a way I can get Mathematica to extract values from my contour plot or otherwise do a 2D interpolation of my data? === Subject: Adding assumptions to SOLVE Newbie question. SOLVE documentation indicates I have to include assumptions to solve this (I thought) simple problem: r[t] = {x[t] - L*Sin[q[t]], L*Cos[q[t]]}; r'[t] = D[r[t], t]; r''[t] = D[r'[t], t]; Eq1 = Mc*x''[t] - u + N Eq2 = Mp*({1, 0}.r''[t]) - N Eq3 = Mp*({0, 1}.r''[t]) - P + Mp*g Eq4 = J*q''[t] - P*L*Sin[q[t]] - N*L*Cos[q[t]] Solve[{Eq1 == 0, Eq2 == 0, Eq3 == 0, Eq4 == 0}, {x''[t], q''[t]}] My assumptions are: - N > 0 - P > 0 - g > 0 - L > 0 - Mc > 0 - Mp > 0 Yet, I can't figure out how to get Solve to return the sybolic equations for x''[t] and q''[t]. What am I missing? Joe === Subject: Re: Adding assumptions to SOLVE > Newbie question. SOLVE documentation indicates I have to include assumptions to solve this (I > thought) simple problem: r'[t] = D[r[t], t]; > r''[t] = D[r'[t], t]; Eq1 = Mc*x''[t] - u + N > Eq2 = Mp*({1, 0}.r''[t]) - N > Eq3 = Mp*({0, 1}.r''[t]) - P + Mp*g > Eq4 = J*q''[t] - P*L*Sin[q[t]] - N*L*Cos[q[t]] Solve[{Eq1 == 0, Eq2 == 0, Eq3 == 0, Eq4 == 0}, {x''[t], q''[t]}] > My assumptions are: - N > 0 > - P > 0 > - g > 0 > - L > 0 > - Mc > 0 > - Mp > 0 Yet, I can't figure out how to get Solve to return the sybolic equations for > x''[t] and q''[t]. What am I missing? Solve[] mostly solve linear and polynomial equations and *cannot* handle inequalities. Reduce[] does handle inequalities as well as a larger range of functions than Solve[]. Neither Solve[] nor Reduce[] will solve differential equations. However, *DSolve[]* is designed to solve differential equations. Therefore, you should use DSolve[] to solve for x and q of t, then you can get their second derivative w.r.t t. HTH, === Subject: Objectica: New third-party Mathematica application for object orientation Objectica, a new object-oriented programming application package for Mathematica, is now available. Objectica uses a simple, easy-to-learn syntax to extend full-scale object orientation to Mathematica, including abstract data types, inheritance, encapsulation, and polymorphism. In addition, its many consistency checks and automatisms help support development, particularly in a commercial environment. Objectica is developed and supported by Stephan Leibbrandt, Mathematica consultant and co-owner of Symbols and Numbers. Objectica requires Mathematica 6, and is available for Windows, Mac OS X, and Linux. For more information about Objectica, visit: http://www.wolfram.com/applications/objectica === Subject: Re: remove higher orders terms from mathemtica's result > Given this: K = (1+vy) (zx+wx) + vx (zy+wy); > Expand[K^2] Is it possible to remove automatically the 3rd and 4th orders from the > result of 'Expand[K^2]' ? By 3rd order I mean terms like: 2 wy zy vx^2 etc. (all terms with sum > of the degrees of derivatives of u,v,w is = 3) > By 4th order: wy^2 vx^2 etc. (sum of degrees of u,v,w = 4) Actually, there are many ways, but no single function that would do this. Here are a couple of short programs, which get rid of terms od degree >= 2 K = (1 + v y) (z x + w x) + v x (z y + w y); Block[{vars = Variables[K], t}, Normal[(K /. Thread[vars -> t vars]) + O[t]^3] /. t -> 1] w x + z x Block[{vars = Variables[K], m}, m = Take[CoefficientArrays[K, vars] // Normal, 3]; m[[1]] + m[[2]].vars + m[[3]].vars.vars] w x + z x Andrzej Kozlowski === Subject: remove higher orders terms from mathemtica's result Given this: K = (1+vy) (zx+wx) + vx (zy+wy); Expand[K^2] Is it possible to remove automatically the 3rd and 4th orders from the result of 'Expand[K^2]' ? By 3rd order I mean terms like: 2 wy zy vx^2 etc. (all terms with sum of the degrees of derivatives of u,v,w is = 3) By 4th order: wy^2 vx^2 etc. (sum of degrees of u,v,w = 4) === Subject: Re: remove higher orders terms from mathemtica's result > Given this: K = (1+vy) (zx+wx) + vx (zy+wy); > Expand[K^2] Is it possible to remove automatically the 3rd and 4th orders from the > result of 'Expand[K^2]' ? By 3rd order I mean terms like: 2 wy zy vx^2 etc. (all terms with sum > of the degrees of derivatives of u,v,w is = 3) > By 4th order: wy^2 vx^2 etc. (sum of degrees of u,v,w = 4) The following expression will do it: Plus @@ Pick[List @@ expr, Total@Exponent[#, Variables[expr]] & /@ List @@ expr, 0 | 1 | 2] Here a step by step, visual, explanation of how it works: In[1]:= K = (1 + vy) (zx + wx) + vx (zy + wy); In[2]:= expr = Expand[K^2] Out[2]= wx^2 + 2 vy wx^2 + vy^2 wx^2 + 2 vx wx wy + 2 vx vy wx wy + vx^2 wy^2 + 2 wx zx + 4 vy wx zx + 2 vy^2 wx zx + 2 vx wy zx + 2 vx vy wy zx + zx^2 + 2 vy zx^2 + vy^2 zx^2 + 2 vx wx zy + 2 vx vy wx zy + 2 vx^2 wy zy + 2 vx zx zy + 2 vx vy zx zy + vx^2 zy^2 In[3]:= Variables[expr] Out[3]= {wx, vy, vx, wy, zx, zy} In[4]:= List @@ expr Out[4]= {wx^2, 2 vy wx^2, vy^2 wx^2, 2 vx wx wy, 2 vx vy wx wy, vx^2 wy^2, 2 wx zx, 4 vy wx zx, 2 vy^2 wx zx, 2 vx wy zx, 2 vx vy wy zx, zx^2, 2 vy zx^2, vy^2 zx^2, 2 vx wx zy, 2 vx vy wx zy, 2 vx^2 wy zy, 2 vx zx zy, 2 vx vy zx zy, vx^2 zy^2} In[5]:= Exponent[#, Variables[expr]] & /@ List @@ expr Out[5]= {{2, 0, 0, 0, 0, 0}, {2, 1, 0, 0, 0, 0}, {2, 2, 0, 0, 0, 0}, {1, 0, 1, 1, 0, 0}, {1, 1, 1, 1, 0, 0}, {0, 0, 2, 2, 0, 0}, {1, 0, 0, 0, 1, 0}, {1, 1, 0, 0, 1, 0}, {1, 2, 0, 0, 1, 0}, {0, 0, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 2, 0}, {0, 1, 0, 0, 2, 0}, {0, 2, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1}, {1, 1, 1, 0, 0, 1}, {0, 0, 2, 1, 0, 1}, {0, 0, 1, 0, 1, 1}, {0, 1, 1, 0, 1, 1}, {0, 0, 2, 0, 0, 2}} In[6]:= Total@Exponent[#, Variables[expr]] & /@ List @@ expr Out[6]= {2, 3, 4, 3, 4, 4, 2, 3, 4, 3, 4, 2, 3, 4, 3, 4, 4, 3, 4, 4} In[7]:= Pick[List @@ expr, Total@Exponent[#, Variables[expr]] & /@ List @@ expr, 0 | 1 | 2] Out[7]= {wx^2, 2 wx zx, zx^2} In[8]:= Plus @@ Pick[List @@ expr, Total@Exponent[#, Variables[expr]] & /@ List @@ expr, 0 | 1 | 2] Out[8]= wx^2 + 2 wx zx + zx^2 === Subject: Re: remove higher orders terms from mathemtica's result > Given this: K = (1+vy) (zx+wx) + vx (zy+wy); > Expand[K^2] Is it possible to remove automatically the 3rd and 4th orders from the > result of 'Expand[K^2]' ? By 3rd order I mean terms like: 2 wy zy vx^2 etc. (all terms with sum > of the degrees of derivatives of u,v,w is = 3) > By 4th order: wy^2 vx^2 etc. (sum of degrees of u,v,w = 4) isn't 2 wy zy vx^2 a 4th order term? (I admit, that I don't understand your quatities sufficiently well. What is zy?) You could multiply all variables with a weighting factor epsilon, calculate a Series in epsilon, Normalize, and set epsilon=1. This also helps, if you need other weighting factors (eg. consider w itself as 2nd order). Good luck Alois === Subject: BEST Viewpoints: New third-party Mathematica application for data analysis BEST Viewpoints is a new third-party application package, the first that can run entirely on Mathematica Player Pro. This data analysis software is designed to combine the best data manipulation and analysis capabilities found in spreadsheets and database languages. Key characteristics: * Offers a highly intuitive interface that requires no programming skills * Has no software limits on dataset size * Provides powerful number crunching * Analyzes datasets of numbers, strings, graphics, and symbols (text mining capabilities) * Utilizes highly efficient categorical data analysis * Imports data and merges many datasets by combining any of the following: databases, xls, csv, txt * Exports output to csv, xls, gif, Metafile Developed and supported by Pronto Analytics Inc., BEST Viewpoints requires Mathematica 6 or Mathematica Player Pro and is available for Windows, Mac OS X, and Linux. For more information about BEST Viewpoints, visit: http://www.wolfram.com/applications/bestviewpoints === Subject: Plot Magic Voodoo ??? Consider the following: z := {L == x y, y == x, x == y} Solve[z, {L}] ---> {{L->y^2}} no surprises. now, Plot[L /. Solve[z, {L}][[1]], {y, 1, 10}] Works exactly as one would expect, BUT, this also works Plot[L /. Solve[z, {L}][[1]], {x, 1, 10}] BUT, the first argument of Plot is L /. Solve[z, {L}][[1]], which is y^2, so my brain said that Plot[L /. Solve[z, {L}][[1]], {x, 1, 10}] ---> Plot[y^2, {x, 1, 10}] which, of course, cannot work. Btw, Plot[L /. Solve[z, {L}][[1]], {q, 1, 10}] does not work, so SOMEHOW, Plot is magically peeking at the innards of the Solve expression, and is NOT evaluating it, and noticing that x is a free variable in the set of equations, z, and ... my brain is melting would someone be so kind as to shed some light on this voodoo, please === Subject: Re: Plot Magic Voodoo ??? > Consider the following: z := {L == x y, y == x, x == y} Solve[z, {L}] ---> {{L->y^2}} no surprises. now, Plot[L /. Solve[z, {L}][[1]], {y, 1, 10}] Works exactly as one would expect, BUT, this also works Plot[L /. Solve[z, {L}][[1]], {x, 1, 10}] BUT, the first argument of Plot is L /. Solve[z, {L}][[1]], which is > y^2, so my brain said that Plot[L /. Solve[z, {L}][[1]], {x, 1, 10}] ---> Plot[y^2, {x, 1, 10}] which, of course, cannot work. Btw, Plot[L /. Solve[z, {L}][[1]], {q, 1, 10}] does not work, so SOMEHOW, Plot is magically peeking at the innards of > the Solve expression, and is NOT evaluating it, and noticing that x is > a free variable in the set of equations, z, and ... my brain is > melting Trace[] is to the Mathematica user what the crystal ball is to the magician :) Below, you can see that first a value is assigned to y, x, or q by Plot, only then Solve[] is called. z := {L == x y, y == x, x == y} Plot[L /. Solve[z, {L}][[1]], {y, 1, 10}] // Trace {Plot[L/.Solve[z,{L}][[1]],{y,1,10}],{y=.,Null},{y=.,Null}, {{y}=.,{y=.},{y=.,Null},{Null}},{{{{z,{L==x y,y==x,x==y}, {{{y,1.00018},x 1.00018,1.00018 x},L==1.00018}, {{y,1.00018},1.00018==x},{{y,1.00018},x==1.00018}, {L==1.00018 x,1.00018==x,x==1.00018}}, Solve[{L==1.00018 x,1.00018==x,x==1.00018},{L}],{{L->1.00037}}}, {{L->1.00037}}[[1]],{L->1.00037}},L/.{L->1.00037},1.00037}, {y=.,Null},{y=.,Null},{y=.,Null},{y=.,Null}, [...] Plot[L /. Solve[z, {L}][[1]], {x, 1, 10}] // Trace {Plot[L/.Solve[z,{L}][[1]],{x,1,10}],{x=.,Null},{x=.,Null}, {{x}=.,{x=.},{x=.,Null},{Null}},{{{{z,{L==x y,y==x,x==y}, {{{x,1.00018},1.00018 y},L==1.00018 y}, {{x,1.00018},y==1.00018},{{x,1.00018},1.00018==y}, {L==1.00018 y,y==1.00018,1.00018==y}}, Solve[{L==1.00018 y,y==1.00018,1.00018==y},{L}], {{L->1.00037}}},{{L->1.00037}}[[1]],{L->1.00037}}, L/.{L->1.00037},1.00037},{x=.,Null},{x=.,Null},{x=.,Null}, [...] Plot[L /. Solve[z, {L}][[1]], {q, 1, 10}] // Trace {Plot[L/.Solve[z,{L}][[1]],{q,1,10}],{q=.,Null},{q=.,Null}, {{q}=.,{q=.},{q=.,Null},{Null}},{{{{z,{L==x y,y==x,x==y}}, Solve[{L==x y,y==x,x==y},{L}],{{L->y^2}}},{{L->y^2}}[[1]], {L->y^2}},L/.{L->y^2},y^2},{{q}=.,{q=.},{q=.,Null},{Null}}, {{q}=.,{q=.},{q=.,Null},{Null}},{{q}=.,{q=.},{q=.,Null},{Null}}, {{q}=.,{q=.},{q=.,Null},{Null}},{{q}=.,{q=.},{q=.,Null}, [...] === Subject: Re: How to produce variable substitution list? >Is there a straight-forward way to write a function that takes a >list of symbols that are bound in the calling environment and >produce a list such as is produced by Solve, like {var1->val1, >var2->val2,...}? This is easily done using Thread. For example, In[8]:= vars = {a, b, c}; values = RandomInteger[100, {3}]; Thread[vars -> values] Out[10]= {a->13,b->71,c->13} === Subject: SEM: New third-party Mathematica application for supercomputing SEM (Supercomputing Engine for Mathematica), a new application package for gridMathematica and Mathematica Personal Grid Edition, is now available. Key Features * Supports MPI specification * Runs Mathematica symbolic manipulation across a cluster, as cluster computing handles more than numerics * Drastically reduces execution time for Mathematica algorithms (up to 8 times faster on a single 8-CPU mode and up to 32 times faster on a cluster of four 8-CPU nodes) * Maximizes resource utilization in multi-CPU machines * Performs symbolic manipulations across a cluster entire cluster to run memory-consuming applications Developed by Advanced Cluster Systems, LLC, and Dauger Research, Inc., SEM requires gridMathematica 2.2 or Mathematica Personal Grid Edition 6 and is available for Mac OS X 10.4.11 and up. For more information, visit: http://www.wolfram.com/applications/sem === Subject: MetaMathematica I«m in need of a neutral sign for indicating that two Mathematica expressions are equivalent (in the sense that they have the same value). For this purpose, I recently started using Equilibrium. For example: expr[[n1,n2]][Equilibrium]Part[expr,n1,n2] Part[expr,n1,n2][Equilibrium]Part[Part[expr,n1],n2] Would anyone like to offer a suggestion for such a sign? Carlos C.8esar de Ara.9cjo Gregos & Troianos Educacional http://www.gregosetroianos.mat.br MSN: cca_gregosetroianos@hotmail.com Belo Horizonte, MG, Brasil (31) 3283-1122 === Subject: Re: MetaMathematica Hi Cca, I=B4m in need of a neutral sign for indicating that two Mathematica exp= ressions are equivalent (in the sense that they have the same value). For t= his purpose, I recently started using Equilibrium. For example: expr[[n1,n2]][Equilibrium]Part[expr,n1,n2] Part[expr,n1,n2][Equilibrium]Part[Part[expr,n1],n2] Would anyone like to offer a suggestion for such a sign? > How about this? SetAttributes[equinox, HoldAll] equinox[expr[[n1, n2] ], Part[expr, n1, n2]] equinox[expr[[n1, n2] ], Part[expr, n1, n3]] Hth, Oliver === Subject: Re: MetaMathematica > I'm in need of a neutral sign for indicating that two Mathematica expressions are equivalent (in the sense that they have the same value). For this purpose, I recently started using Equilibrium. For example: expr[[n1,n2]][Equilibrium]Part[expr,n1,n2] Part[expr,n1,n2][Equilibrium]Part[Part[expr,n1],n2] Would anyone like to offer a suggestion for such a sign? What about <=> or <==>, that is [DoubleLeftRightArrow] (esc<=>esc) or [DoubleLongLeftRightArrow] (esc<==>esc): DoubleLeftRightArrow[a, b] DoubleLongLeftRightArrow[a, b] === Subject: NMaximize Questions 1. Is there any limit to the number of variables in NMaximise. Is it possible/sensible to run a model with about 1,300 variables? 2. What is the meaning of the following error? Error is: NMaximize::nnum: The function value 0 is not a number at {c[1],c[2],c[3],cem[1],cem[2],cem[3],cpc[1],cpc[2],cpc[3],e[1],<<53>>} = {0.,2.57857*10^-17,-4.69557*10^-17,0.,<<24>>,<<23>>,<<23>>,3.6165* 10^-21,-6.20768*10^-21,4.81393*10^-13,<<53>>}. The error using FindMaximum is: FindMaximum::nrgnum: The gradient is not a vector of real numbers at {c[1],c[2],c[3],cem[1],cem[2],cem[3],cpc[1],cpc[2],cpc[3],e[1],<<46>>} = {1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,<<46>>}. -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects. === Subject: Re: Re: NMaximize Questions Jean-Marc, had found quite cryptic! I am wondering if NMaximize can be made faster for a large system of equations by doing some directed acyclic graph (DAC) / topological sorting to find the leaves or independent variables first. I am wondering whether, instead of submitting a large system of equations and variables, it might be faster to only submit the leaves as variables and use a function to topologically process the objective function. I have looked at Reduce, but it seems to take as long or longer than NMaximize. Also, NMaximize already seems to use a function like FindInstance to locate true in the identities. I would be interested in your opinion on whether DAC preprocessing is likely to be of any value or if NMaximize internally uses equivalent techniques anyway? Stuart -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects. === Subject: Re: NMaximize Questions > 1. Is there any limit to the number of variables in NMaximise. Is it > possible/sensible to run a model with about 1,300 variables? > 2. What is the meaning of the following error? > Error is: > NMaximize::nnum: The function value 0 is not a number at > {c[1],c[2],c[3],cem[1],cem[2],cem[3],cpc[1],cpc[2],cpc[3],e[1],<<53>>} > = {0.,2.57857*10^-17,-4.69557*10^-17,0.,<<24>>,<<23>>,<<23>>,3.6165* > 10^-21,-6.20768*10^-21,4.81393*10^-13,<<53>>}. The error using FindMaximum is: > FindMaximum::nrgnum: The gradient is not a vector of real numbers at > {c[1],c[2],c[3],cem[1],cem[2],cem[3],cpc[1],cpc[2],cpc[3],e[1],<<46>>} > = {1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,<<46>>}. The expressions such as c[1],c[2],c[3],cem[1], or cem[2], do not hold any values (and especially no numeric values); therefore they evaluate to themselves (as symbolic expressions). NMaximize an FinMaximum use numeric algorithms to find numeric solutions, thus they required -- and can handle only -- numeric values. Therefore, you must provide numeric values to *all* the parameters such as c[1], c[2], c[3], cem[1], ... For instance, say we want to maximize the function -x^4 - c[1] x^2 + x. Below, the coefficient c[1] does not hold any value but itself. In[1]:= NMaximize[-x^4 - c[1] x^2 + x, x] During evaluation of In[1]:= NMaximize::nnum: The function value -0.296289+0.0929857 c[1] is not a number at {x} = {0.304936}. Out[1]= NMaximize[x - x^4 - x^2 c[1], x] Now we assign the value 3 to c[1]. In[2]:= c[1] = 3; NMaximize[-x^4 - c[1] x^2 + x, x] Out[3]= {0.0825888, {x -> 0.16374}} Note that *Maximize* has no problem dealing with symbolic coefficients. In[4]:= c[1] =. (* Clear c[1] *) Maximize[-x^4 - c[1] x^2 + x, x] Out[5]= {-Root[ 27 + 4 c[1]^3 + (144 c[1] + 16 c[1]^4) #1 + 128 c[1]^2 #1^2 + 256 #1^3 &, 1], {x -> Root[-Root[ 27 + 4 c[1]^3 + (144 c[1] + 16 c[1]^4) #1 + 128 c[1]^2 #1^2 + 256 #1^3 &, 1] - #1 + c[1] #1^2 + #1^4 &, 1]}} If we replace c[1] by 3 in the above symbolic solution, we get the same answer as the one found by numerical algorithm. In[6]:= % /. c[1] -> 3 // N Out[6]= {0.0825888, {x -> 0.16374}} === Subject: Figure Title Hi I have an array of figures made using Show[ GraphicsArray[ {{..., ...}, {...}}, ....]] now i want to add the labels (a), (b), (c) ... to each of the subfigures. Next I want a title for each of them. === Subject: Re: Figure Title plts = MapThread[ Plot[#1[x], {x, 0, 2 Pi}, FrameLabel -> {xn <> #2, None, #1[x], None}, Frame -> True] & , {{Sin, Cos, Tan, Cot}, {a), b), c), d)}}]; GraphicsGrid[Partition[plts, 2]] ?? Jens > Hi I have an array of figures made using > Show[ GraphicsArray[ {{..., ...}, {...}}, ....]] > now i want to add the labels (a), (b), (c) ... to each of the > subfigures. > Next I want a title for each of them. === Subject: Re: Figure Title > Hi I have an array of figures made using > Show[ GraphicsArray[ {{..., ...}, {...}}, ....]] > now i want to add the labels (a), (b), (c) ... to each of the > subfigures. > Next I want a title for each of them. The plot option *PlotLabel* and the command *Labeled* should fulfill your needs. For instance, g1 = Plot[Sin[x], {x, 0, 2 Pi}, PlotLabel -> Sin[x]]; g2 = Plot[Cos[x], {x, 0, 2 Pi}, PlotLabel -> Cos[x]]; GraphicsArray[{Labeled[g1, {a}], Labeled[g2, {b}]}] === Subject: Problem with evaluating Graphics3D output Here is a problem I discovered right now. First, evaluate Graphics3D[{FaceForm[{GrayLevel[0]}, {GrayLevel[0]}], Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] Now, evaluate the output. My problem: FaceForm is not preserved. Why? Confirming: %[[1]] How can I preserve FaceForm upon reevaluation? This does not happen with Graphics3D[{GrayLevel[0], Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] Carlos C.8esar de Ara.9cjo Gregos & Troianos Educacional http://www.gregosetroianos.mat.br Belo Horizonte, MG, Brasil (31) 3283-1122 === Subject: Re: Problem with evaluating Graphics3D output what do you mean with FaceForm is not preserved ?? Mathematica 5.2 as well as 6.0.3 gives {FaceForm[{GrayLevel[0]}, {GrayLevel[0]}], Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]} Jens > Here is a problem I discovered right now. First, evaluate Graphics3D[{FaceForm[{GrayLevel[0]}, {GrayLevel[0]}], > Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] Now, evaluate the output. My problem: FaceForm is not preserved. Why? C= onfirming: %[[1]] How can I preserve FaceForm upon reevaluation? This does not happen with Graphics3D[{GrayLevel[0], > Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] Carlos C=E9sar de Ara=FAjo > Gregos & Troianos Educacional > http://www.gregosetroianos.mat.br > Belo Horizonte, MG, Brasil > (31) 3283-1122 === Subject: Re: Problem with evaluating Graphics3D output >Here is a problem I discovered right now. First, evaluate Graphics3D[{FaceForm[{GrayLevel[0]}, {GrayLevel[0]}], > Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] Now, evaluate the output. My problem: FaceForm is not preserved. Why? This is a bug in FaceForm that is specific to GrayLevel[0]. If you want your graphics to have this structure you could use GrayLevel[0.0] or RGBColor[0,0,0] in place of GrayLevel[0] as a workaround. I've made a fix to our internal development version which will appear apologize for the inconvenience. Chris Hill Wolfram Research === Subject: Re: Problem with evaluating Graphics3D output > Here is a problem I discovered right now. First, evaluate Graphics3D[{FaceForm[{GrayLevel[0]}, {GrayLevel[0]}], > Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] Now, evaluate the output. My problem: FaceForm is not preserved. Why? Confirming: %[[1]] How can I preserve FaceForm upon reevaluation? This does not happen with Graphics3D[{GrayLevel[0], > Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] You may have found a bug. I could reproduce the issue on my Mac OS X 6.0.3 system. Apparently the problem appears with GrayLevel only. I tried several variations of your expression (color scheme and geometric object) and FaceForm was preserved upon evaluation of the output cell. For instance, Graphics3D[{FaceForm[Yellow, Blue], Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]}] [ Evaluate the output cell with shift + enter] %[[1]] {FaceForm[RGBColor[1, 1, 0], RGBColor[0, 0, 1]], Cylinder[{{-0.5, 0, 0}, {0.5, 0, 0}}, 0.05]} === Subject: rotate axes labels with Plot3D? For a Plot3D when the value of one of the labels in AxesLabel is a string of some length, each label is nonetheless printed upright. And this this makes the body of the graph itself smaller just to squeeze in the long label. Is there some way to change the label orientations so that the labels flow in the same direction as the axes themselves -- other than to construct a Text[...] or Inset[...]? And without merely breaking the label's text with n (I should think that with scientific 3D plots, especially, this would be a common situation.) -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: FW: Sending Objects from Java - Mathematica i still hope for some help about the conversion-problems to Mathematica. J.A. > -----Urspr.9fngliche Nachricht----- > Von: Jochen Adamek An: mathgroup@smc.vnet.net > Betreff: Sending Objects from Java - Mathematica i have written a Java-code, where i want to send some objects to > Mathematica. To call a function(written in Mathematica) with four > parameters under Java, i need to send objects to Mathematica. This is my Java-code: > public void sendListOfEdgesToMathematica(List edg) throws > MathLinkException { > try { ml = MathLinkFactory.createKernelLink(argv); > } catch (MathLinkException e) { > System.out.println(Fatal error opening link: + > e.getMessage()); > return; > } > > try { > ml.enableObjectReferences(); > ml.discardAnswer(); > ml.evaluate(< ml.discardAnswer(); > ml.putFunction(EvaluatePacket, 1); > ml.putFunction(doGetEdges, 1); > ml.put(edg); > ml.endPacket();.............. edg( a list) contains the element e11 and i have written a Function > under Mathematica for receiving the object from Java: > doGetEdges[edg_] := > JavaBlock[Module[{outStream}, outStream = edg@getOutputStream[]; > outStream@print[Edges]; > edgesG6 = edg > ] > ] The problem is, Mathematica does not receive the correct value(e11). > I tried to test my implementation with a PacketListener, but without > success. After sending four objects to Mathematica, i want to call the > Mathematica-function under Java: objectGraph[edgesG6, verticesG6, sourcesG6, targetsG6] Any help would be fantastic. > === Subject: Performance of Array Addition Let there be, for example, an array of reals with dimensions {d1,d2,3}. I have noticed that the command array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]]; is much faster than Map[Total, array, {2}]; even though they return the same answer. The advantage of Map[Total, array, {2}] is that it allows arrays of dimension {d1,d2,d3}, with d3 arbitrary. Is there a way to get closer to the speed advantages of hand-coding the addition of the final dimension, while allowing the number of elements in the final dimension to be arbitrary? === Subject: Re: Performance of Array Addition >Let there be, for example, an array of reals with dimensions >{d1,d2,3}. I have noticed that the command array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]]; is much faster than Map[Total, array, {2}]; even though they return the same answer. The advantage of Map[Total, array, {2}] is that it allows arrays of >dimension {d1,d2,d3}, with d3 arbitrary. Is there a way to get closer to the speed advantages of hand-coding >the addition of the final dimension, while >allowing the number of elements in the final dimension to be >arbitrary? > Why not Total[array, {3}] ? Carl Woll Wolfram Research === Subject: Re: Performance of Array Addition Here are timings of your methods and a couple of my own. First with integers, then with reals. Clear[integers] integers[d1_, d2_] := RandomInteger[10, {d1, d2, 3}] array = integers[3000, 4000]; Timing[one = array[[All, All, 1]] + array[[All, All, 2]] + array[[All, All, 3]];] Timing[two = Map[Total, array, {2}];] Timing[three = Plus @@ Transpose[array, {2, 3, 1}];] Timing[four = Total@Transpose[array, {2, 3, 1}];] one == two == three == four {1.06188, Null} {12.6128, Null} {0.623087, Null} {0.69472, Null} True (I test first with integers so that there's less ambiguity in the test for equality.) Clear[reals] reals[d1_, d2_] := RandomInteger[10, {d1, d2, 3}] array = reals[3000, 4000]; Timing[one = array[[All, All, 1]] + array[[All, All, 2]] + array[[All, All, 3]];] Timing[two = Map[Total, array, {2}];] Timing[three = Plus @@ Transpose[array, {2, 3, 1}];] Timing[four = Total@Transpose[array, {2, 3, 1}];] one == two == three == four {1.07193, Null} {12.323, Null} {0.624647, Null} {0.705247, Null} True > The advantage of Map[Total, array, {2}] is that it allows arrays of > dimension {d1,d2,d3}, with d3 arbitrary. I believe my methods also have that property. integers[d1_, d2_, d3_] := RandomInteger[10, {d1, d2, d3}] array = integers[3000, 400, 100]; Timing[two = Map[Total, array, {2}];] Timing[three = Plus @@ Transpose[array, {2, 3, 1}];] Timing[four = Total@Transpose[array, {2, 3, 1}];] two == three {2.13325, Null} {2.18372, Null} {1.98925, Null} True array = integers[300, 4000, 100]; Timing[two = Map[Total, array, {2}];] Timing[three = Plus @@ Transpose[array, {2, 3, 1}];] Timing[four = Total@Transpose[array, {2, 3, 1}];] two == three {2.13839, Null} {2.18131, Null} {1.97734, Null} True > Is there a way to get closer to the speed advantages of hand-coding > the addition of the final dimension, while > allowing the number of elements in the final dimension to be > arbitrary? On average, I suspect Total@Transpose is competitive. Bobby > Let there be, for example, an array of reals with dimensions > {d1,d2,3}. I have noticed that the command array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]]; is much faster than Map[Total, array, {2}]; even though they return the same answer. The advantage of Map[Total, array, {2}] is that it allows arrays of > dimension {d1,d2,d3}, with d3 arbitrary. Is there a way to get closer to the speed advantages of hand-coding > the addition of the final dimension, while > allowing the number of elements in the final dimension to be > arbitrary? > -- DrMajorBob@longhorns.com === Subject: Re: Performance of Array Addition Hi Jeremy, > Let there be, for example, an array of reals with dimensions > {d1,d2,3}. I have noticed that the command array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]]; is much faster than Map[Total, array, {2}]; even though they return the same answer. The advantage of Map[Total, array, {2}] is that it allows arrays of > dimension {d1,d2,d3}, with d3 arbitrary. Is there a way to get closer to the speed advantages of hand-coding > the addition of the final dimension, while > allowing the number of elements in the final dimension to be > arbitrary? yes This is my first try, it just literally does programmatically what you have done for 3: Plus@@Table[array[[All, All, i]], {i, 1, Last[Dimensions[array]]}] But if you look at the documentation for Total you will find that it accepts additional arguments: Total[array, {3}] or: Total[array,{Total[array, {Depth[array] - 1}]}] which is even faster by a factor of about 3 on my machine... hth, albert === Subject: Re: Performance of Array Addition Hi Jeremy, Let there be, for example, an array of reals with dimensions > {d1,d2,3}. I have noticed that the command array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]]; is much faster than Map[Total, array, {2}]; even though they return the same answer. The advantage of Map[Total, array, {2}] is that it allows arrays of > dimension {d1,d2,d3}, with d3 arbitrary. Is there a way to get closer to the speed advantages of hand-coding > the addition of the final dimension, while > allowing the number of elements in the final dimension to be > arbitrary? How about, AbsoluteTiming[ res3 = Plus @@@ Transpose[array, {1, 3, 2}]; ] Hth, Oliver === Subject: Re: Performance of Array Addition > Let there be, for example, an array of reals with dimensions > {d1,d2,3}. I have noticed that the command array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]]; is much faster than Map[Total, array, {2}]; even though they return the same answer. The advantage of Map[Total, array, {2}] is that it allows arrays of > dimension {d1,d2,d3}, with d3 arbitrary. Is there a way to get closer to the speed advantages of hand-coding > the addition of the final dimension, while > allowing the number of elements in the final dimension to be > arbitrary? Why not using the second argument of Total[]? Total[array, {3}] The above expression is scalable and on average three times faster than the hand-coded solution. In[1]:= array = RandomReal[{-1, 1}, {100, 50, 3}]; Timing[tot1 = array[[All, All, 1]] + array[[All, All, 2]] + array[[All, All, 3]]; ][[1]] Timing[tot2 = Map[Total, array, {2}]; ][[1]] Timing[tot3 = Total[array, {3}]; ][[1]] tot1 == tot2 == tot3 Out[2]= 0.00095 Out[3]= 0.010702 Out[4]= 0.000432 Out[5]= True In[6]:= Table[(array = RandomReal[{-1, 1}, {100, 50, 3}]; t1 = Timing[array[[All, All, 1]] + array[[All, All, 2]] + array[[All, All, 3]]; ][[1]]; t2 = Timing[Map[Total, array, {2}]; ][[1]]; t3 = Timing[Total[array, {3}]; ][[1]]; {t1 , t2 , t3}), {10}] Out[6]= {{0.000772, 0.009676, 0.000262}, {0.000771, 0.009517, 0.000257}, {0.000739, 0.009531, 0.000262}, {0.000794, 0.00963, 0.00026}, {0.000766, 0.009561, 0.000284}, {0.000812, 0.009681, 0.000264}, {0.00074, 0.009579, 0.000261}, {0.000823, 0.009585, 0.000266}, {0.000751, 0.009764, 0.00029}, {0.000807, 0.009716, 0.000276}} In[7]:= Mean[%] Out[7]= {0.0007775, 0.009624, 0.0002682} === Subject: Constructing vector using table I am trying to create a vector using Table in which I enter a function that depends on other functions. An excerpt from the code is: u2[i_] := 1 + Log[[CapitalPhi][[i]]]; un[i_] := Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; U = Table[un[i], {i, 1, 3*m}] // MatrixForm; Dimensions[U] Output: {1} Everything runs fine and even the vector is generated when I see the form of U. But, I am not able to do any operations on this matrix (like inverse, transpose etc). Even the Dimensions[U] give me 1 while it should be 60. Please help me through if you can. If I am not clear or you need more info, please let me know Jha === Subject: Re: Constructing vector using table That solves my problem. Prateek beside you code is not working at all, remove the MatrixForm[] > from U. Jens > I am trying to create a vector using Table in which I enter a >> function that depends on other functions. An excerpt from the code is: >> u2[i_] := 1 + Log[[CapitalPhi][[i]]]; >> un[i_] := >> Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; >> U = Table[un[i], {i, 1, 3*m}] // MatrixForm; >> Dimensions[U] >> Output: >> {1} >> Everything runs fine and even the vector is generated when I see the >> form of U. But, I am not able to do any operations on this matrix >> (like inverse, transpose etc). Even the Dimensions[U] give me 1 while >> it should be 60. >> Please help me through if you can. If I am not clear or you need more >> info, please let me know >> Jha > > === Subject: Re: Constructing vector using table beside you code is not working at all, remove the MatrixForm[] from U. Jens > I am trying to create a vector using Table in which I enter a > function that depends on other functions. An excerpt from the code is: u2[i_] := 1 + Log[[CapitalPhi][[i]]]; > un[i_] := > Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; U = Table[un[i], {i, 1, 3*m}] // MatrixForm; > Dimensions[U] Output: > {1} Everything runs fine and even the vector is generated when I see the > form of U. But, I am not able to do any operations on this matrix > (like inverse, transpose etc). Even the Dimensions[U] give me 1 while > it should be 60. Please help me through if you can. If I am not clear or you need more > info, please let me know Jha > === Subject: Re: Constructing vector using table > I am trying to create a vector using Table in which I enter a > function that depends on other functions. An excerpt from the code is: u2[i_] := 1 + Log[[CapitalPhi][[i]]]; > un[i_] := > Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; U = Table[un[i], {i, 1, 3*m}] // MatrixForm; > Dimensions[U] Output: > {1} Everything runs fine and even the vector is generated when I see the > form of U. But, I am not able to do any operations on this matrix > (like inverse, transpose etc). Even the Dimensions[U] give me 1 while > it should be 60. Please help me through if you can. If I am not clear or you need more > info, please let me know Jha > Yo will discover the reason for yourself if you execute: U//FullForm David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Constructing vector using table Hi Prateek, > I am trying to create a vector using Table in which I enter a > function that depends on other functions. An excerpt from the code is: u2[i_] := 1 + Log[[CapitalPhi][[i]]]; > un[i_] := > Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; U = Table[un[i], {i, 1, 3*m}] // MatrixForm; > Dimensions[U] Output: > {1} Everything runs fine and even the vector is generated when I see the > form of U. But, I am not able to do any operations on this matrix > (like inverse, transpose etc). Even the Dimensions[U] give me 1 while > it should be 60. Please help me through if you can. If I am not clear or you need more > info, please let me know Jha > m = 20; [CapitalPhi] = Range[3*m]; u2[i_] := 1 + Log[[CapitalPhi][[i]]]; u1n[i_] := 1; un[i_] := Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; u = Table[un[i], {i, 1, 3*m}]; Dimensions[u] Dimensions[ Transpose[{u}] ] I have added the u1n, which you use in the Table command. Hth, Oliver === Subject: Re: Constructing vector using table > I am trying to create a vector using Table in which I enter a > function that depends on other functions. An excerpt from the code is: u2[i_] := 1 + Log[[CapitalPhi][[i]]]; > un[i_] := > Switch[IntegerPart[i/(m + 1)], 0, u1n[i], 1, u2[i], 2, u2[i]]; U = Table[un[i], {i, 1, 3*m}] // MatrixForm; > Dimensions[U] Output: > {1} Everything runs fine and even the vector is generated when I see the > form of U. But, I am not able to do any operations on this matrix > (like inverse, transpose etc). Even the Dimensions[U] give me 1 while > it should be 60. Please help me through if you can. If I am not clear or you need more > info, please let me know MatrixForm[] is a wrapper from printing purpose only. The expression U = Table[un[i], {i, 1, 3*m}] // MatrixForm; is equivalent to U = MatrixForm[Table[un[i], {i, 1, 3*m}]]; What you want is either, U = Table[un[i], {i, 1, 3*m}]; MatrixForm[U] or MatrixForm[U = Table[un[i], {i, 1, 3*m}];] === Subject: Manipulate[] concurrent sliders the Manipulate[] below calculates x^2. one can slide x to get y=x^2. But you can not slide y to get Sqrt[y]. I understand the behaviour, the expression just assigns y with x^2 and the prior value of y is lost, that is the reason why the code doesn't work. How can this be fixed within one single Manipulate[] ? any suggestions ? Manipulate[ y = x^2; x = Sqrt[y]; {x, y}, {x, 0, 10}, {y, 0, 100} ] === Subject: Fisher scoring algorithm technical but a technical advice might help. I am trying to find the expectation by solving the following below: FullSimplify[ Sum[(1/(n! Gamma[[Alpha]]) z^ n [Beta]^[Alpha] (z + [Beta])^(-n - [Alpha]) Gamma[n + [Alpha]])*(PolyGamma[1, a] - PolyGamma[1, a + n]), {n, 0, Infinity}]] It's the product of the log of the 2nd derivative of alpha (from the likelihood) by the likelihood: negative binomial distribution (n is integer z is real, and likelihood and 2nd deriv should be products and sums respectively of many n(s) and z(s) but taken here as only one point for simplicity). This has come from a poisson-gamma marginal distribution, for which I am trying to find the (parameters) alpha and the beta by using the fisher scoring algorithm. But mathematica does not find a solution to the above. Any hints or help appreciated. === Subject: Colors in Plot[] It is interesting behavour and I do not understand the reason for this: g[x_, n_] := x^n Plot[g[x, 1], {x, 0, 1}] Plot[g[x, 1], {x, 0, 1}, PlotStyle -> {Red, Blue}] Plot[g[x, 1], {x, 0, 1}, PlotStyle -> {Red, Red}] Why the second plot is Blue but the third is Red? === Subject: Re: Colors in Plot[] Because in the middle one you specified a style in which Blue came second and superseded the previous Red. Had you used {Red,Blue,Green}, it would have been Green. If you just used PlotStyle->{Red} or even PlotStyle->Red, you would be fine. Kevin > It is interesting behavour and I do not understand the reason for > this: g[x_, n_] := x^n > Plot[g[x, 1], {x, 0, 1}] > Plot[g[x, 1], {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[g[x, 1], {x, 0, 1}, PlotStyle -> {Red, Red}] Why the second plot is Blue but the third is Red? > === Subject: Re: When is a List not a List? >g[x_, n_] := x^n >FullForm[Table[g[x, n], {n, 1, 2}]] >FullForm[{g[x, 1], g[x, 2]}] >Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] >Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] >The FullForm[]s are identical. Right. Since FullForm displays the form of the evaluated expression and each evaluates the same, the two should have the same FullForm >One Plot[] has red and blue curves; the other has two blue curves. This too should be expected once you understand how Plot works. Specifically, Plot has the attribute HoldAll which means the first argument to Plot is not evaluated until after Plot has substituted a numeric value for the variable (x in this case). So, in the first case where there is an explicit list, Plot sees a list of two functions and colors each according to your PlotStyle specification. In the second case, Plot sees a single function with multiple values for each x. Since Plot only sees a single function, it plots it with the first PlotStyle only. You can get the same result as the first Plot by using Evaluate@Table so that Plot sees a list of two functions rather than a single multi-valued function. === Subject: Exported PDFs are too big in file size. I usually export Mathematica plots to PDF format. I don't like bitmap formats. The problem is the file size. Most of the 3D graphics on Mathematica 6 are exported to PDF files as large as several megabytes (even several tens MB sometimes). For example, this simple 3D graphics ContourPlot3D[ Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, Mesh -> None] generates a PDF as large as 3.7 MB!! With Mathematica 5, the file size was reasonable. Is there something I'm missing with Mathematica 6? mahn-soo === Subject: Re: Exported PDFs are too big in file size. > I usually export Mathematica plots to PDF format. I don't like bitmap > formats. The problem is the file size. Most of the 3D graphics on Mathematica 6 > are exported to PDF files as large as several megabytes > (even several tens MB sometimes). For example, this simple 3D graphics ContourPlot3D[ > Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, > Mesh -> None] generates a PDF as large as 3.7 MB!! With Mathematica 5, the file size was reasonable. Is there something I'm missing with Mathematica 6? mahn-soo I have found one partial solution. I say partial as it shrinks the PDF to about 2/3 the size, which is still much larger than people achieve with Adobe's software. 1) Export as an EPS file - this makes a massive 18 GB file for the above example 2) Use the tool ps2pdf which uses Ghostscript. I would add, this was done on Mathematica 6.0.2 on a machine running Solaris x86, on an Intel CPU. This involved the modifications (posted on here some time back) to run on an Intel CPU. However, I very much doubt this would change the result. But running ps2pdf on Windows Linux or Mac might well give differerate results. === Subject: Re: Exported PDFs are too big in file size. > I would add, this was done on Mathematica 6.0.2 on a machine running > Solaris x86, on an Intel CPU. This involved the modifications (posted > on here some time back) to run on an Intel CPU. However, I very much > doubt this would change the result. But running ps2pdf on Windows > Linux or Mac might well give differerate results. Sorry, before anyone waste's there time looking for it, the method to run Mathematica 6 on Solaris with an Intel CPU was posted on another newsgroup. === Subject: Re: Exported PDFs are too big in file size. name to get the program, which is free). Once installed, it is a virtual printer to which you can send files and get a pdf. With your example, I get a 3.7 Mb pdf file using the export command from Mathematica, and a 164 Kb pdf file with pdfcreator (and it looks good once opened). Thibaut Jonckheere Mahn-Soo Choi a =E9crit : > I usually export Mathematica plots to PDF format. I don't like bitmap > formats. The problem is the file size. Most of the 3D graphics on Mathematica 6 > are exported to PDF files as large as several megabytes > (even several tens MB sometimes). For example, this simple 3D graphics ContourPlot3D[ > Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, > Mesh -> None] generates a PDF as large as 3.7 MB!! With Mathematica 5, the file size was reasonable. Is there something I'm missing with Mathematica 6? mahn-soo === Subject: Re: Exported PDFs are too big in file size. > name to get the program, which is free). Once installed, it is a > virtual printer to which you can send files and get a pdf. With your > example, I get a 3.7 Mb pdf file using the export command from > Mathematica, and a 164 Kb pdf file with pdfcreator (and it looks good > once opened). Thibaut Jonckheere Mahn-Soo Choi a =E9crit : > I usually export Mathematica plots to PDF format. I don't like bitma= p > formats. > The problem is the file size. Most of the 3D graphics on Mathematica= 6 > are exported to PDF files as large as several megabytes > (even several tens MB sometimes). > For example, this simple 3D graphics > ContourPlot3D[ > Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, > Mesh -> None] > generates a PDF as large as 3.7 MB!! > With Mathematica 5, the file size was reasonable. > Is there something I'm missing with Mathematica 6? > mahn-soo Note that PDFCreator is a Windows program. Is there something similar that also works with Mac OS X? -Bob === Subject: Re: Exported PDFs are too big in file size. >> name to get the program, which is free). Once installed, it is a >> virtual printer to which you can send files and get a pdf. With your >> example, I get a 3.7 Mb pdf file using the export command from >> Mathematica, and a 164 Kb pdf file with pdfcreator (and it looks good >> once opened). that also works with Mac OS X? Mac OS X can *natively* save files and documents as PDF files from any applications that have print capability, because Mac OS X comes with a built-in PDF writer and reader engine. In the lower-left of every Print dialog you can see a PDF button that allows to save your document to a PDF file. Even more, in the same print dialog, you also have a Preview button that will render your document the Mac OS X built-in program *Preview*, form there you can save your work as a PDF or to a variety of image formats. (Note that Preview is also accessible as a stand alone program and can merge different files or reorganize the layout of the document, and much more...) === Subject: Re: Exported PDFs are too big in file size. > I usually export Mathematica plots toPDFformat. I don't like bitmap > formats. The problem is the file size. Most of the 3D graphics on Mathematica 6 > are exported toPDFfiles aslargeas several megabytes > (even several tens MB sometimes). For example, this simple 3D graphics ContourPlot3D[ > Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, > Mesh -> None] generates aPDFaslargeas 3.7 MB!! With Mathematica 5, the file size was reasonable. Is there something I'm missing with Mathematica 6? mahn-soo See the discussion at read/1656afeb09496586/4a9711e06f69abc0?lnk=gst&q=large+PDF#4a9711e06f69= abc0 It covers this in much detail... -Bob === Subject: Re: Exported PDFs are too big in file size. > I usually export Mathematica plots to PDF format. I don't like bitmap > formats. The problem is the file size. Most of the 3D graphics on Mathematica 6 > are exported to PDF files as large as several megabytes > (even several tens MB sometimes). For example, this simple 3D graphics ContourPlot3D[ > Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, > Mesh -> None] generates a PDF as large as 3.7 MB!! With Mathematica 5, the file size was reasonable. Is there something I'm missing with Mathematica 6? On my system (Mac OS X Leopard 1.5.4) I would select the plot, then use menu Print Selection and choose PDF. The Mac built-in PDF rendering engine produces a file of only 628 KB (rather than the 3.6 MB file produce by Mathematica), file that is rendered virtually instantaneously within Preview (built-in PDF viewer) rather than showing a animation of the polygons being drawn. Having say that, if you need an even smaller size, setting a lower value for the option *MaxRecursion* might dramatically decrease the size of the PDF file generated by Mathematica. For instance, ContourPlot3D[ Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, Mesh -> None, MaxRecursion -> 0] yields a 68 KB PDF file when the plot is exported by Mathematica. === Subject: Re: Printing and Exporting graphics images from Mathematica 6 to PDF? 0, > PlotPoints -> 20, Mesh -> Full, NormalsFunction -> None] > This gives a version 5-like plot but the white lines of spurious polygons, remain visible when exported as pdf. One solution to this problem can be found in http://library.wolfram.com/infocenter/MathSource/7029/ by Will Robertson. Saving as print selection PDF, or using bitmap, also remove these lines. Is Wolfram Research planing to solve this issue in a future upgrade? A. Verga. Aix-Marseille Universite === Subject: Re: Printing and Exporting graphics images from Mathematica 6 to PDF? > The following quote appears in a recent post to this group: > File > Print Selection > Save As PDF causes the graphic to be > rasterized. This is why it displays so much quicker in the viewer > application. You can get the same behavior from File > Save Select= ion > As > PDF by clicking on the Options button in the Save As dialog and > setting Graphics Containing Smooth Shading > Use Bitmap > Representation. > Unfortunately, this results in a larger file size because of a > limitation of Mathematica 6 where it does not compress exported > bitmaps. This limitation has been removed for a future release. > -Rob > Wolfram Research As best I can tell these statements are not correct, or at least do not > apply directly, for Mathematica 6 on Macs. Is this statement limited t= o other > non-Mac platforms? These statements compare the behavior of PDF export when using the Mac OS X PDF printing support (from File > Print [Selection] > Save As PDF, which is only available on Mac) to Mathematica's built in PDF export (from File > Save [Selection] As > PDF or Export[_, _, PDF], which is available on all platforms). > And some related questions: 1) Following the most straightforward Print Selection to PDF procedure= s > on a Mac seems to produce a vector graphics file Mathematica will create a vector graphics file wherever possible. The only time the graphics will be rasterized is when they contain smooth shading (VertexColors/VertexNormals) AND the Graphics Containing Smooth Shading option I mentioned earlier is set to Use Bitmap Representation. > in which all the text > has been converted into outline form, which means it can no longer be > readily edited in Illustrator. Mathematica does this for spanning characters which cannot be represented as standard glyphs from any font. Mathematica does not do this for any other text. Are you perhaps testing this theory using Mathematica's PDF Import[] (because PDF import currently *does* convert text to outlines) or some other application? > Is there a way to prevent this behavior, and keep all the text as > characters in embedded fonts, so that one can edit the text, make font > changes, change font sizes, and the like? This should just work. If it doesn't it would be a bug and should be reported to Wolfram Research with a specific reproducible example. > 2) Following the alternative chain of steps involved in Save Selection > to PDF (again, on a Mac) leads one to a menu of options that includes > choosing between Highest Quality Vector Representation and Most > Compatible Vector Representation. What do these terms mean? [Or is this a Mac OS X question rather than an Matheamtica question? I= t's not > clear to me whether the dialog box that presents these options is a Mac > OS dialog box or an Mathematica 6 dialog box . . . ] These settings apply to all platforms. See this earlier message and read below: /thread/a669fd00915cbbf5/6b0387ea4f8732d4?#6b0387ea4f8732d4 > 3) More broadly, if one's overall objective is to routinely transfer > Mathematica 6-generated graphics from Mathematica 6 notebooks into vector= graphics PDF files > on a Mac HD, such that the resulting PDF files will be: * Of primary concern, most fully and readily editable in > some other graphic application such as Illustrator, and * Of secondary importance, not excessively large in file size, what is the _best_ way to do this in Mathematica 6, on a Mac? The problem is, there is not a *best* way to do this. Arbitrary Mathematica 6 graphics can contain features which are not supported by the PDF vector graphics format. There is not one setting that will give you exactly what you want in all cases. You have to decide which criteria are the most important to you for a given graphic. If the graphic contains smooth shading (as graphics created by most 3D and some 2D visualization functions do), use one of the following settings. Each has advantages and disadvantages. * Use Bitmap Representation. The graphic to look *exactly* identical to how it looks on screen in Mathematica. It will open quickly in viewer applications. The file size may be large (particularly in 6.0.x). Printing may take a long time due to large size. Use the bitmap resolution option to fine tune the file size vs. image quality issue. If the PDF is only ever intended to be viewed, you can use screen resolution for the bitmap (72 or Screen). If it is intended for print you might want something higher like 300 or 600. * Use Highest Quality Vector Representation. The graphic will look very close to how it looks on screen in Mathematica. It will be editable by applications such as Illustrator. The file size may be slightly large. The graphic will likely take a long time to load in a viewer application. Not all viewer applications support these features (notably Preview.app prior to Mac OS X 10.5) so they may appear blank. * Use Most Compatible Vector Representation. The graphic will look approximately (but not exactly) how it looks on screen in Mathematica. The file size will be relatively small. It will be editable by applications such as Illustrator. The other alternative is to change your graphics using various options to the plotting functions. There are certain combinations of options that will produce graphics that, when exported to PDF, are editable and look the same as in Mathematica. Unfortunately, this typically means losing lots of neat version 6 plotting features. Here's an example: Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, MaxRecursion -> 0, PlotPoints -> 20, Mesh -> Full, NormalsFunction -> None] -Rob Wolfram Research === Subject: Re: Printing and Exporting graphics images from Mathematica 6 to PDF? > Has this been msg also been posted to the cssmm newsgroup? I've never quite > sure how these combined groups and email lists work, but I'd prefer to > respond there. Yes. I send it to you as email (so you can get a faster answer) and to MathGroup (aka comp.soft-sys.math.mathematica) via the mailing list mathgroup@smc.vnet.net. The message should be visible on the newsgroup by tomorrow. - Jean-Marc 2) Following the alternative chain of steps involved in Save Selection to > PDF (again, on a Mac) leads one to a menu of options that includes choosing > between Highest Quality Vector Representation and Most Compatible Vector > Representation. What do these terms mean? The quote below is from ragfield's answer to one of these many similar > questions asked in this forum: [...] * Use Highest Quality Vector Representation. This should match what > you see in Mathematica nearly exactly, but it will not be compatible > with all viewer applications. For PS/EPS this uses PS level 3 > features. For PDF it uses features that are not supported by Apple's > PDF engine prior to Mac OS X 10.5. * Use Most Compatible Vector Representation. This will not exactly > match what you see on screen in Mathematica, but it will produce a > small file that works in all viewers. (ragfield, Re: version 6 Plot3D exporting results in HUGE files, > http://forums.wolfram.com/mathgroup/archive/2007/Aug/msg00981.html) > -- Jean-Marc === Subject: Re: Exported PDFs are too big in file size. If you are using OS X, you can open the pdf in Preview, and do a SaveAs... In the resulting dialog, you can change the Quartz Filter from 'None' to 'Reduce file size'. 148 kb. I don't use Acrobat anymore, but I'm pretty sure that the same thing can be done there. george >> File > Print Selection > Save As PDF causes the graphic to be >> rasterized. This is why it displays so much quicker in the viewer >> application. You can get the same behavior from File > Save >> Selection >> As > PDF by clicking on the Options button in the Save As dialog and >> setting Graphics Containing Smooth Shading > Use Bitmap >> Representation. >> Unfortunately, this results in a larger file size because of a >> limitation of Mathematica 6 where it does not compress exported >> bitmaps. This limitation has been removed for a future release. >> -Rob >> Wolfram Research Is there any way to post-rocess the pdf to compress the bitmap? === Subject: Re: Exported PDFs are too big in file size. > File > Print Selection > Save As PDF causes the graphic to be > rasterized. This is why it displays so much quicker in the viewer > application. You can get the same behavior from File > Save Selection > As > PDF by clicking on the Options button in the Save As dialog and > setting Graphics Containing Smooth Shading > Use Bitmap > Representation. Unfortunately, this results in a larger file size because of a > limitation of Mathematica 6 where it does not compress exported > bitmaps. This limitation has been removed for a future release. -Rob > Wolfram Research Is there any way to post-rocess the pdf to compress the bitmap? === Subject: Printing and Exporting graphics images from Mathematica 6 to PDF? The following quote appears in a recent post to this group: > File > Print Selection > Save As PDF causes the graphic to be > rasterized. This is why it displays so much quicker in the viewer > application. You can get the same behavior from File > Save Selection > As > PDF by clicking on the Options button in the Save As dialog and > setting Graphics Containing Smooth Shading > Use Bitmap > Representation. > Unfortunately, this results in a larger file size because of a > limitation of Mathematica 6 where it does not compress exported > bitmaps. This limitation has been removed for a future release. > -Rob > Wolfram Research As best I can tell these statements are not correct, or at least do not apply directly, for Mathematica 6 on Macs. Is this statement limited to other non-Mac platforms? And some related questions: 1) Following the most straightforward Print Selection to PDF procedures on a Mac seems to produce a vector graphics file in which all the text has been converted into outline form, which means it can no longer be readily edited in Illustrator. Is there a way to prevent this behavior, and keep all the text as characters in embedded fonts, so that one can edit the text, make font changes, change font sizes, and the like? 2) Following the alternative chain of steps involved in Save Selection to PDF (again, on a Mac) leads one to a menu of options that includes choosing between Highest Quality Vector Representation and Most Compatible Vector Representation. What do these terms mean? [Or is this a Mac OS X question rather than an Matheamtica question? It's not clear to me whether the dialog box that presents these options is a Mac OS dialog box or an Mathematica 6 dialog box . . . ] 3) More broadly, if one's overall objective is to routinely transfer Mathematica 6-generated graphics from Mathematica 6 notebooks into vector graphics PDF files on a Mac HD, such that the resulting PDF files will be: * Of primary concern, most fully and readily editable in some other graphic application such as Illustrator, and * Of secondary importance, not excessively large in file size, what is the _best_ way to do this in Mathematica 6, on a Mac? === Subject: Re: Printing and Exporting graphics images from Mathematica 6 to to PDF (again, on a Mac) leads one to a menu of options that includes > choosing between Highest Quality Vector Representation and Most > Compatible Vector Representation. What do these terms mean? The quote below is from ragfield's answer to one of these many similar questions asked in this forum: [...] * Use Highest Quality Vector Representation. This should match what you see in Mathematica nearly exactly, but it will not be compatible with all viewer applications. For PS/EPS this uses PS level 3 features. For PDF it uses features that are not supported by Apple's PDF engine prior to Mac OS X 10.5. * Use Most Compatible Vector Representation. This will not exactly match what you see on screen in Mathematica, but it will produce a small file that works in all viewers. (ragfield, Re: version 6 Plot3D exporting results in HUGE files, http://forums.wolfram.com/mathgroup/archive/2007/Aug/msg00981.html) === Subject: Re: Exported PDFs are too big in file size. File > Print Selection > Save As PDF causes the graphic to be rasterized. This is why it displays so much quicker in the viewer application. You can get the same behavior from File > Save Selection As > PDF by clicking on the Options button in the Save As dialog and setting Graphics Containing Smooth Shading > Use Bitmap Representation. Unfortunately, this results in a larger file size because of a limitation of Mathematica 6 where it does not compress exported bitmaps. This limitation has been removed for a future release. -Rob Wolfram Research === Subject: Re: Exported PDFs are too big in file size. > I usually export Mathematica plots to PDF format. I don't like bitmap > formats. The problem is the file size. Most of the 3D graphics on Mathematica 6 > are exported to PDF files as large as several megabytes > (even several tens MB sometimes). For example, this simple 3D graphics ContourPlot3D[ > Exp[-(x^2 + y^2 + z^2)/2], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}, > Mesh -> None] generates a PDF as large as 3.7 MB!! With Mathematica 5, the file size was reasonable. Is there something I'm missing with Mathematica 6? mahn-soo Export[your countour plot 3D.pdf] gives indeed awful results: huge files with a mesh of white lines (it is a know unsolved issue...) You may try to use, after selecting your graphics, Print Selection from the File menu, and then save the selected graphics to a PDF file (this step depends on your system: on Mac OS you habe a PDF button). The problem is that you lose the bounding box. Alberto Verga. === Subject: solve question Frieds: I have a question, as always I imagine it is quite simple. I have made several functions. I give the following example: newsubstraction[a_List, b_List]:=Module[{k=((b[[2]]+a[[2]])-(b[[1]]+a[[= 1]]))/2},{middle[a]-middle[b]-k, middle[a]-middle[b]+k}] This function takes two lists of the form {a1,b1} and {a2,b2} and returns a list of identical form. Now, suppose I have an equation with an unknown (of the form {u1,u2}). My question is: how to solve it? I would like something of the sort: IMAGINEDSOLVE[newsubstraction[firstlist, UNKNOWN]==secondlist, UNKNOWN] Fg === Subject: Re: solve question > Frieds: I have a question, as always I imagine it is quite simple. > > I have made several functions. I give the following example: > > newsubstraction[a_List, b_List]:=Module[{k=((b[[2]]+a[[2]])-(b[[1]]+a[[= > 1]]))/2},{middle[a]-middle[b]-k, middle[a]-middle[b]+k}] > > This function takes two lists of the form {a1,b1} and {a2,b2} and returns a list of identical form. Now, suppose I have an equation with an unknown (of the form {u1,u2}). My question is: how to solve it? > I would like something of the sort: > IMAGINEDSOLVE[newsubstraction[firstlist, UNKNOWN]==secondlist, UNKNOWN] Something along the lines, mySolve[l1_, l2_, uk_] := Solve[Thread[newsub[l1, uk] == newsub[l2, uk]], uk] should do it. === Subject: Re: RowReduce for SparseArray I am Not sure if my response is going to be useful, or even interesting for you, but I will give it a try anyway. The Bra-Ket Dirac Notation, as used in Quantum Mechanics, could be regarded as a special notation for sparse arrays (or sparse tensors), with the difference that a given Dirac Notation expression usually does Not carry information about the actual dimension of the tensor, it only carries information about the non-zero elements of the matrix (tensor) My point is that Dirac Notation can ALSO be used for NON-Quantum Mechanics applications. Here you have some simple examples, where some calculations are performed using Dirac Notation, and the same calculations are repeated with normal matrices, and there is also conversion between matrices and Dirac Notation (please notice that long-urls are usually broken in e-mails and posts to this group, so you might have to manually reconstruct the links below if they get broken in several lines): http://homepage.cem.itesm.mx/lgomez/quantum/matrices/matrices.html http://homepage.cem.itesm.mx/lgomez/quantum/powerseries/powerseries.html So, if it seems interesting to use Dirac Notation for operators as an alternative to Sparse Arrays, you could download and use our package for Dirac Notation in Mathematica: http://homepage.cem.itesm.mx/lgomez/quantum/index.htm If you do so, please let me know. It would be great for us to have examples of our Quantum package applied to Non-Quantum-Mechanical applications. Jose Mexico -----Mensaje original----- De: brey_maastricht@hotmail.com [mailto:brey_maastricht@hotmail.com] Enviado el: Jueves, 31 de Julio de 2008 01:57 Para: mathgroup@smc.vnet.net Asunto: RowReduce for SparseArray Unfortunately, the Mathematica function RowReduce does not work with sparse datatypes. To be precise: it accepts matrices of type SparseArray as input but the output, the reduced matrix, is always a non sparse datatype. Because of this my computations crash because storing the matrix as a Normal[] type just uses too much memory, whereas it could be stored when it was a SparseArray type. Now I was wondering; does someone have an efficient RowReduce method in Mathematica which is capable of returning SparseArrays, and also is able to use arithmetic modulo p ( RowReduce[M, Modulo->p] ) ?? Brey The Netherlands === Subject: RowReduce for SparseArray Unfortunately, the Mathematica function RowReduce does not work with sparse datatypes. To be precise: it accepts matrices of type SparseArray as input but the output, the reduced matrix, is always a non sparse datatype. Because of this my computations crash because storing the matrix as a Normal[] type just uses too much memory, whereas it could be stored when it was a SparseArray type. Now I was wondering; does someone have an efficient RowReduce method in Mathematica which is capable of returning SparseArrays, and also is able to use arithmetic modulo p ( RowReduce[M, Modulo->p] ) ?? Brey The Netherlands === Subject: Need a Faster Solution to Number Theory Problem I got hooked on the following little number theory problem which appears in the August issue of Discovery magazine. Susan has more than one dollar in change, but she still can't make exact change for a dollar bill. What is the maximum amount of money that Susan could have in pennies, nickels, dimes and quarters for this to be true? I solved the problem using the following Mathematica code: coins={1,5,10,25}; dollar=FrobeniusSolve[coins,100]; Catch[Do[t=Times@@Length/@(Cases[dollar,{p_,n_,d_,q_}/; (p<=#1&&n<=#2 && d<=#3 && q<=#4)]&@@@FrobeniusSolve[coins,a]); If[t==0,Throw[a]],{a,130,101,-1}]] Starting with a maximum guess of $1.30 this gives the correct answer of $1.19 in about 5 seconds. The problem is that if the problem is made more complicated by adding more possible coin denominations (and/or paper currency) the execution time become very long indeed. Is there a way to speed up the solution to this type of problem so that I can handle more complicated cases in a reasonable time? John === Subject: Using [Breve] as a substitute for underscore In mathematica you cannot use underscore _ as part of a variable name as you could in other computer languages. Has anyone tried using [Breve] as an underscore substitute instead. for example: mass[Breve]of[Breve]earth = 5.97*^24 or mass[esc]bv[esc]of[esc]bv[esc]earth = 5.97*^24 I kinda like breve because it looks like the standard underscore character. What other characters do other people uses? Steven Siew === Subject: Re: Using [Breve] as a substitute for underscore the other people use capital letters in variable names because MassOfEarth is the usual Mathematica style and [Breve] can mixed up with Pattern[] and that make the code nearly unreadable. You have to look very hard to see that A[Breve]Integer is not A_Integer Jens > In mathematica you cannot use underscore _ as part of a variable name > as you could in other computer languages. Has anyone tried using [Breve] as an underscore substitute instead. for example: mass[Breve]of[Breve]earth = 5.97*^24 or mass[esc]bv[esc]of[esc]bv[esc]earth = 5.97*^24 I kinda like breve because it looks like the standard underscore > character. What other characters do other people uses? Steven Siew > === Subject: Re: Using [Breve] as a substitute for underscore > In mathematica you cannot use underscore _ as part of a variable name > as you could in other computer languages. Has anyone tried using [Breve] as an underscore substitute instead. for example: mass[Breve]of[Breve]earth = 5.97*^24 or mass[esc]bv[esc]of[esc]bv[esc]earth = 5.97*^24 I kinda like breve because it looks like the standard underscore > character. What other characters do other people uses? Steven Siew > I also use [Breve] extensively for this purpose in my Super Widget Package, and in other code I have written for my clients. I think it is a shame that underscore got used for patterns, and since I also write some Java and C code, I regularly forget and create 'variables' containing underscores. Unfortunately, the breve character does not paste well into non-mathematica UNICODE environments because it would seem that it is a diacritic character. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: When is a List not a List? I don't see why you think your message was ridiculed. If you refer to the remark: > To quote from a related thread: You and I, I'm afraid, just think differently. ;-) I was only quoting your principal ally's remark to another user on the same matter and, in my case, it was of course a joke. As for the rest, I argued that, to me, the Wolfram manual was a boring book to read as are all software manual? That happens to be true and I can't see why this is supposed to constitute a ridicule of anyone. I also added that I found Wolfram's book a useful online reference. In any case, I am sure all of this is besides the point as far as WOlfram is concerned. Wolfram Research Inc. is not a charitable institution; if it thinks something is going to be profitable it will do so. A new printed manual would be huge and costly (much more so if it has to be mailed oversees) so the question is how many people will buy it and how much they are going to be willing to pay for it. My own personal answer is that the maximum price I would pay for such a thing is negative. I also have not noticed any visible groundswell of enthusiasm on this issue on this forum. I am sure if you and a book at whatever it may cost, they would at least consider publishing it. Short of that, I think, you, and I think two or three others who have expressed a similar view, are just wasting your time. Andrzej Kozlowski > I said in a post to the group a few months back that the much lamented > printed Wolfram manual was superb, and that it had clearly taken > enormous effort and planning to produce. My message was ridiculed by > one regular contributer but I still feel I was right. > Wolfram really need to listen to their fan-base, if I can put it like > that. We know that Wolfram read these posts. > Come on guys, you know it makes sense. Publish the manual that > Mathematica deserves ! P 2008/8/1 AES : >> just a crazy off-the-top-of-my-head idea here: Why don't Wolfram > publish a > manual for Mathematica ? >> Peter Lindsay >> Amen! >> And question really is Why? --- Why have they neither published >> anything >> themselves, nor did they (apparently) even encourage or assist or >> promote >> any timely third-person efforts during the (lengthy?) preparation >> of M6? > > -- > peter lindsay > computing officer > mathematical institute > university of st andrews > ky16 9ss phone: 01334463756 Don't anthropomorphise computers - they hate that. The University of St Andrews is a charity registered in Scotland : > No SC013532 > === Subject: Re: When is a List not a List? >just a crazy off-the-top-of-my-head idea here: Why don't Wolfram >publish a manual for Mathematica ? Peter Lindsay Amen! And question really is Why? --- Why have they neither published anything themselves, nor did they (apparently) even encourage or assist or promote any timely third-person efforts during the (lengthy?) preparation of M6? === Subject: Re: When is a List not a List? Agreed. And I'm wondering what advantage HoldAll has, in the case of Plot, since a plot can't result without evaluating the arguments? Why NOT evaluate the first argument, at least, before making style decisions/assignments? The defense that everybody already knows this is irrelevant to the question of how we'd LIKE Plot to behave. Naturally, we won't necessarily GET what we want... but we're entitled to say what that is. I'm trying to think how David Park's Presentations package handles such things. Bobby >> Plot COULD assign colors after evaluation, OTOH... the fact that it >> doesn't is a design choice/artifact, not a necessity preordained by >> fate. >> That being so, users are entitled to find it odd at first glance. (Or >> even second... maybe third.) If the above is true -- and I'd suppose it is -- then I'd say it's also > very much an unfortunate, not to say flat-out *bad* design choice or > artifact. An innocent novice-level user creates a Plot[ ] with three curves using > the {f1, f2, f3} List form of the first argument, and discovers that M > by default assigns a different color to each curve -- a good and helpful > default design choice on M's part, I'd say. Maybe this novice user wants to go a bit further: Thicken certain > curves, change the Dashing, and so on. He or she discovers the > PlotStyle option (or equivalent); learns how to do this; is happy. And then this user also realizes: Hey, I could plot 8 or 10 curves this > way, without having to type in f1 thru f8 by just using a Table[ ] > command for the first argument and iterating over some appropriate > parameter. A Table[ ] creates a List, right? So he/she does this; the 8 or 10 curves appear exactly as desired; > except the styling behavior is suddenly all screwed up. Once again, a > classic M-style Gotcha!!! -- and a particularly nasty Gotcha: Am I > getting this unwanted result because of the way I structured the > PlotStyle commands I used? -- or because of something mysterious with > using Table[ ]? The coloring and so on in the default {f1, f2, f3} > case has the nice default cycling behavior for the styling -- Why am I > not getting it now? Andrzej says this unfortunate result _has_ to be the case because Plot[ > ] doesn't pre-Evaluate the first argument. Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, f7, > f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) this > argument at least enough to know that it's not only a List, but how many > elements that List has. Is it somehow impossible for Plot[ ] to know > that Table will also produce a List, and to similarly pre-evaluate how > many elements that List will have? I suspect it's not impossible. And if that is indeed impossible with the PlotStyle option in Plot[ ] > then can Andrzej explain how it _is _ possible for Plot[ ] to somehow > handle the PlotRange->All option correctly (i.e., identically) with > either form of the first argument -- even though that option needs to > determine not only the number of curves in the first argument, but the > maximum and minimum values over all those curves, in order to set the > axes and axis Tick locations and values for the plot. Is just getting > the number of curves and picking the colors for them really harder than > that? I very much like DrMajorBob's wording here: I'll bet the coloring > problem with List vs Table is precisely an [accidental] design > choice/artifact, not a necessity preordained by fate -- and an > unfortunately unfortunate design choice/artifact. The only things more unfortunate are (a) that M has a fair (and > increasing?) number of these Gotchas; (b) M's documentation is > substantially less helpful than it could or should be either in > diagnosing or in warning about them; and (c) it's far from clear that > anyone at WRI really recognizes these points. -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? I am not sure about the no argument part. First, it seems to me obvious that one should try to learn Mathematica before trying to use it, and reading the documentation is a pretty basic part of learning. Why should you then call something a quirk if it is both documented and even exemplified. However, there is more to that. In view of what you have been arguing, perhaps you could tell us if it seems odd to you that Plot does not use different colors in the example below. It does not seem odd to me at all, and I doubt that even beginners (AES excepting, of course) will find it a quirk. Plot[x /. Solve[x^3 - 3 x + a x == 0, x], {a, -3, 3}] Andrzej Kozlowski > No argument here. That's the behavior, and we've seen it a thousand > times. > A quirk is only a quirk the first 100 times we see it, or > thereabouts. > (Pick a number.) Plot COULD assign colors after evaluation, OTOH... the fact that it > doesn't is a design choice/artifact, not a necessity preordained by > fate. That being so, users are entitled to find it odd at first glance. > (Or even > second... maybe third.) Bobby >> usual (although inaccurate) sense that people frequently use in this >> context, namely: that the so called Evaluator does not pre-evaluate >> the >> arguments of Plot (if you do not like to thing of the Evaluator, >> another way of saying this is that Mathematica does not evaluate >> the >> arguments before Plot is applied and leaves any evaluating to >> Plot.) Of >> course, you are right that Plot does evaluate its arguments in some >> way >> (this sort of behavior is also referred in the often used phrase: >> Plot >> evaluates its arguments in a non-standard way). The fact that this >> non-standard evaluation results in a plot of a function is actually >> new in version 6; in all previous versions all you will get is an >> error >> message about the values of the function being plotted not being >> numeric. >> Anyway, my point was that this has been a normal (non quirky) >> behavior >> of Mathematica since version 1 and has been discussed here a number >> of >> times. (It must be at least the fourth of fifth time in 10 years >> that I >> am addressing this issue on this forum). It is also fully documented >> (with examples) in the Mathematica online documentation, all past >> printed documentation and a vast number of books dealing with >> Mathematica. >> Andrzej Kozlowski > But Plot DOES evaluate its arguments, of course, and DOES > (eventually) > see that multiple functions are being plotted. (Else they couldn't > be > plotted.) >> It's just not happening before colors are assigned. >> Nonetheless, it's prudent to take note of what functions actually > do, > and get used to it. Calling everything in sight a quirk serves no > purpose. >> (Paraphrasing Andrzej, perhaps.) >> Bobby >> There is nothing at all quirky about this. Yes, FullForm[Table[g[x, >> n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed >> identical, >> but that is because FullForm evaluates its argument. But Plot has >> attribute: >> In[2]:= Attributes[Plot] >> Out[2]= {HoldAll, Protected} >> so, unlike FullForm, it does not evaluate its argument. In your >> first >> example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, >> Blue}], the first argument of Plot has an explicit List bracket, so >> Plot can see that it supposed to treat the argument as two >> different >> functions, without evaluating the argument. But in the second >> case, it >> does not see an explicit bracket, so it treats the entire >> expression >> as the graph of a single function (in versions of Mathematica >> before 6 >> you would not have got any plot at all in this case). >> If you use Evaluate in the second code you will get the same >> result as >> you get form the first: >> Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] >> Finally, since you have given ample proof that, in spite of many >> years >> of using Mathematica, you have not mastered its basics (this >> particular issue has been raised and answered a countless number of >> times on this forum), why do you keep assuming that the problems >> that >> you keep coming across are Mathematica's quirks rather than (as >> is >> much more likely) gaps in your won understanding? What do you >> think of >> first year undergraduate students who whenever they do not >> understand >> something in their introductory lectures claim that it is wrong, or >> blame their textbook or their lecture rather then themselves? >> Andrzej Kozlowski > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, > Blue}] >> The FullForm[]s are identical. One Plot[] has red and blue > curves; > the > other has two blue curves. >> Quirky! > --DrMajorBob@longhorns.com > > -- > DrMajorBob@longhorns.com > === Subject: Re: When is a List not a List? just a crazy off-the-top-of-my-head idea here: Why don't Wolfram publish a manual for Mathematica ? Peter Lindsay >> Plot COULD assign colors after evaluation, OTOH... the fact that it >> doesn't is a design choice/artifact, not a necessity preordained by >> fate. >> That being so, users are entitled to find it odd at first glance. >> (Or even second... maybe third.) If the above is true -- and I'd suppose it is -- then I'd say it's > also very much an unfortunate, not to say flat-out *bad* design > choice or artifact. An innocent novice-level user creates a Plot[ ] with three curves > using the {f1, f2, f3} List form of the first argument, and discovers > that M by default assigns a different color to each curve -- a good > and helpful default design choice on M's part, I'd say. Maybe this novice user wants to go a bit further: Thicken certain > curves, change the Dashing, and so on. He or she discovers the > PlotStyle option (or equivalent); learns how to do this; is happy. And then this user also realizes: Hey, I could plot 8 or 10 curves > this way, without having to type in f1 thru f8 by just using a Table[ > ] command for the first argument and iterating over some appropriate > parameter. A Table[ ] creates a List, right? So he/she does this; the 8 or 10 curves appear exactly as desired; > except the styling behavior is suddenly all screwed up. Once again, > a classic M-style Gotcha!!! -- and a particularly nasty Gotcha: Am I > getting this unwanted result because of the way I structured the > PlotStyle commands I used? -- or because of something mysterious with > using Table[ ]? The coloring and so on in the default {f1, f2, f3} > case has the nice default cycling behavior for the styling -- Why am > I not getting it now? Andrzej says this unfortunate result _has_ to be the case because > Plot[ ] doesn't pre-Evaluate the first argument. Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, f7, > f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) this > argument at least enough to know that it's not only a List, but how > many elements that List has. Is it somehow impossible for Plot[ ] to > know that Table will also produce a List, and to similarly > pre-evaluate how many elements that List will have? I suspect it's > not impossible. And if that is indeed impossible with the PlotStyle option in Plot[ ] > then can Andrzej explain how it _is _ possible for Plot[ ] to > somehow handle the PlotRange->All option correctly (i.e., > identically) with either form of the first argument -- even though > that option needs to determine not only the number of curves in the > first argument, but the maximum and minimum values over all those > curves, in order to set the axes and axis Tick locations and values > for the plot. Is just getting the number of curves and picking the > colors for them really harder than that? I very much like DrMajorBob's wording here: I'll bet the coloring > problem with List vs Table is precisely an [accidental] design > choice/artifact, not a necessity preordained by fate -- and an > unfortunately unfortunate design choice/artifact. The only things more unfortunate are (a) that M has a fair (and > increasing?) number of these Gotchas; (b) M's documentation is > substantially less helpful than it could or should be either in > diagnosing or in warning about them; and (c) it's far from clear that > anyone at WRI really recognizes these points. === Subject: Re: When is a List not a List? the world is full of functions with parameters that can be evaluated pointwise (once numeric parameters have been substituted) but cannot be evaluated [properly] by Evaluate Ah! I see your point, and a good point it is. Bobby >> In light of all that, in what way have the rest of us failed to >> understand a bit of mathematics? Te bit of mathematics (and computer algebra) you clearly do not > understand is the very basic fact when you solve many kinds of algebraic > equations with symbolic parameters you inevitably introduce parasite > solutions. When you use numeric parameters Solve can verify which of > theses are correct. The rest of the discussion is totally besides the > point, and so is using Reduce (for example, because one can easily come > up with equations that Reduce will not manage). > The example was meant to illustrate the very trivial and elementary fact > that the world is full of functions with parameters that can be > evaluated pointwise (once numeric parameters have been substituted) but > cannot be evaluated by Evaluate. This is so basic and there are so many > examples of it that I do not see any point in discussion this farther. Andrzej Kozlowski -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? But I obviously DO understand those facts. I illustrated them in detail. I also illustrated the fact that Plot has a Line for each branch, so each COULD be colored differently, if Plot were built to do so. I also agreed with your basic point that it's fruitless to call this a quirk, after all these years. Bobby > In light of all that, in what way have the rest of us failed to >> understand a bit of mathematics? Te bit of mathematics (and computer algebra) you clearly do not > understand is the very basic fact when you solve many kinds of algebraic > equations with symbolic parameters you inevitably introduce parasite > solutions. When you use numeric parameters Solve can verify which of > theses are correct. The rest of the discussion is totally besides the > point, and so is using Reduce (for example, because one can easily come > up with equations that Reduce will not manage). > The example was meant to illustrate the very trivial and elementary fact > that the world is full of functions with parameters that can be > evaluated pointwise (once numeric parameters have been substituted) but > cannot be evaluated by Evaluate. This is so basic and there are so many > examples of it that I do not see any point in discussion this farther. Andrzej Kozlowski -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? > In light of all that, in what way have the rest of us failed to > understand a bit of mathematics? Te bit of mathematics (and computer algebra) you clearly do not understand is the very basic fact when you solve many kinds of algebraic equations with symbolic parameters you inevitably introduce parasite solutions. When you use numeric parameters Solve can verify which of theses are correct. The rest of the discussion is totally besides the point, and so is using Reduce (for example, because one can easily come up with equations that Reduce will not manage). The example was meant to illustrate the very trivial and elementary fact that the world is full of functions with parameters that can be evaluated pointwise (once numeric parameters have been substituted) but cannot be evaluated by Evaluate. This is so basic and there are so many examples of it that I do not see any point in discussion this farther. Andrzej Kozlowski === Subject: Re: When is a List not a List? By the by, should all three branches in the following have the same color (and style, if styles were specified)? Plot[x /. Solve[x^2 + x - 1/Sqrt[x + a] == 1, x], {a, 2, 4}] In this case Solve gives FIVE solutions: Solve[x^2 + x - 1/Sqrt[x + a] == 1, x] {{x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 1]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 2]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 3]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 4]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 5]}} However: Cases[Plot[ x /. Solve[x^2 + x - 1/Sqrt[x + a] == 1, x], {a, 2.5, 2.7}], _Line, Infinity] // Length 3 There are three lines; there's no reason Plot could not assign colors and styles to them. (Although, perhaps, we couldn't know which branches would match which colors, a priori.) Bobby > Just in case I have not made my point clearly enough, I suggest > pondering over the difference between: > Plot[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x], {a, -1, 3}] and Plot[Evaluate[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x]], {a, -1, 3}] > The second graph uses three colors, just as you and AES would have > wished, but unfortunately there is a slight problem with it :it is quite > wrong. Understanding a bit of mathematics often helps to understand Mathematica. > Andrzej Kozlowski >> Because there are lots of plots of the kind which I just sent (Plot[x >> /. Solve[x^3 - 3 x^2 + a == 0, x], {a, -3, 5}]) but where you have >> FindRoot or NMaximize etc., instead of Solve and the first argument >> can't be evaluated until the value of the parameter a has been >> supplied. There have been lots of post of this kind on this forum so >> its kind if weird you managed to miss them all. >> Andrzej Kozlowski > Agreed. >> And I'm wondering what advantage HoldAll has, in the case of Plot, > since a plot can't result without evaluating the arguments? >> Why NOT evaluate the first argument, at least, before making style > decisions/assignments? >> The defense that everybody already knows this is irrelevant to the > question of how we'd LIKE Plot to behave. >> Naturally, we won't necessarily GET what we want... but we're entitled > to say what that is. >> I'm trying to think how David Park's Presentations package handles > such things. >> Bobby > Plot COULD assign colors after evaluation, OTOH... the fact that it > doesn't is a design choice/artifact, not a necessity preordained by > fate. >> That being so, users are entitled to find it odd at first glance. > (Or even second... maybe third.) >> If the above is true -- and I'd suppose it is -- then I'd say it's >> also very much an unfortunate, not to say flat-out *bad* design >> choice or artifact. >> An innocent novice-level user creates a Plot[ ] with three curves >> using the {f1, f2, f3} List form of the first argument, and discovers >> that M by default assigns a different color to each curve -- a good >> and helpful default design choice on M's part, I'd say. >> Maybe this novice user wants to go a bit further: Thicken certain >> curves, change the Dashing, and so on. He or she discovers the >> PlotStyle option (or equivalent); learns how to do this; is happy. >> And then this user also realizes: Hey, I could plot 8 or 10 curves >> this way, without having to type in f1 thru f8 by just using a Table[ >> ] command for the first argument and iterating over some appropriate >> parameter. A Table[ ] creates a List, right? >> So he/she does this; the 8 or 10 curves appear exactly as desired; >> except the styling behavior is suddenly all screwed up. Once again, >> a classic M-style Gotcha!!! -- and a particularly nasty Gotcha: Am I >> getting this unwanted result because of the way I structured the >> PlotStyle commands I used? -- or because of something mysterious with >> using Table[ ]? The coloring and so on in the default {f1, f2, f3} >> case has the nice default cycling behavior for the styling -- Why am >> I not getting it now? >> Andrzej says this unfortunate result _has_ to be the case because >> Plot[ ] doesn't pre-Evaluate the first argument. >> Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, f7, >> f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) this >> argument at least enough to know that it's not only a List, but how >> many elements that List has. Is it somehow impossible for Plot[ ] to >> know that Table will also produce a List, and to similarly >> pre-evaluate how many elements that List will have? I suspect it's >> not impossible. >> And if that is indeed impossible with the PlotStyle option in Plot[ ] >> then can Andrzej explain how it _is _ possible for Plot[ ] to >> somehow handle the PlotRange->All option correctly (i.e., >> identically) with either form of the first argument -- even though >> that option needs to determine not only the number of curves in the >> first argument, but the maximum and minimum values over all those >> curves, in order to set the axes and axis Tick locations and values >> for the plot. Is just getting the number of curves and picking the >> colors for them really harder than that? >> I very much like DrMajorBob's wording here: I'll bet the coloring >> problem with List vs Table is precisely an [accidental] design >> choice/artifact, not a necessity preordained by fate -- and an >> unfortunately unfortunate design choice/artifact. >> The only things more unfortunate are (a) that M has a fair (and >> increasing?) number of these Gotchas; (b) M's documentation is >> substantially less helpful than it could or should be either in >> diagnosing or in warning about them; and (c) it's far from clear that >> anyone at WRI really recognizes these points. >> --DrMajorBob@longhorns.com > > -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? The second evaluation could/should result in a plot of 7 functions in 7 colors, not 3, since: x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x] {Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 1], Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 2], Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 3], Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 4], Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 5], Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 6], Root[-1 + a + (1 - 2 a) #1 + (-2 + a) #1^2 + (1 - 2 a) #1^3 + (-2 + 2 a) #1^4 + 2 #1^5 + a #1^6 + #1^7 &, 7]} Three of these are real-valued at a==2, just as the second plot indicates: % /. a -> 2. {-1.99157, 0.311967, 0.888061, -0.419459 - 1.30719 I, -0.419459 + 1.30719 I, -0.18477 - 0.963069 I, -0.18477 + 0.963069 I} (That's why, I suppose, only 3 colors are visible in the chart.) Two of the real solutions are spurious here, while 2 of the complex solutions ARE correct to machine precision: x^3 + x - 1/Sqrt[x + a] - 1 /. {x -> #, a -> 2} & /@ % // Chop {-21.7816, -1.31534, 0, 0, 0, -1.35391 - 0.336917 I, -1.35391 + 0.336917 I} Perhaps Reduce could help, since it allows us to restrict the domain of the variables? Reduce[x^3 + x - 1/Sqrt[x + a] == 1, {x, a}, Reals] x > Root[-1 + #1 + #1^3 &, 1] && a == (1 - x + 2 x^2 - x^3 + 2 x^4 - 2 x^5 - x^7)/( 1 - 2 x + x^2 - 2 x^3 + 2 x^4 + x^6) Now consider the lower limit on x: Root[-1 + #1 + #1^3 &, 1] // ToRadicals % // N -(2/(3 (9 + Sqrt[93])))^(1/3) + (1/2 (9 + Sqrt[93]))^(1/3)/3^(2/3) 0.682328 Since your first Plot includes x values smaller than this, the output of Reduce is contradicted, no? (Oh, woe is me, who CAN we trust?!?) If HoldAll were not in the picture, we could get the first plot SOMEHOW, I'm sure... probably with f[a_?NumericQ] := x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x] Plot[f[a], {a, -1, 3}] since the same plot results now from Plot[f[a] // Evaluate, {a, -1, 3}] So, in my estimation, HoldAll in your example is compensating for the fact that Solve doesn't return real solutions and doesn't identify parameter ranges that ALLOW real solutions, neither of which seems (to me) to be a natural responsibility for a Plot attribute. (It may be the reason this artifact exists, however, and if so... so be it, quirkiness be damned!) > Understanding a bit of mathematics often helps to understand Mathematica. In light of all that, in what way have the rest of us failed to understand a bit of mathematics? Bobby > Just in case I have not made my point clearly enough, I suggest > pondering over the difference between: > Plot[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x], {a, -1, 3}] and Plot[Evaluate[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x]], {a, -1, 3}] > The second graph uses three colors, just as you and AES would have > wished, but unfortunately there is a slight problem with it :it is quite > wrong. Understanding a bit of mathematics often helps to understand Mathematica. > Andrzej Kozlowski >> Because there are lots of plots of the kind which I just sent (Plot[x >> /. Solve[x^3 - 3 x^2 + a == 0, x], {a, -3, 5}]) but where you have >> FindRoot or NMaximize etc., instead of Solve and the first argument >> can't be evaluated until the value of the parameter a has been >> supplied. There have been lots of post of this kind on this forum so >> its kind if weird you managed to miss them all. >> Andrzej Kozlowski > Agreed. >> And I'm wondering what advantage HoldAll has, in the case of Plot, > since a plot can't result without evaluating the arguments? >> Why NOT evaluate the first argument, at least, before making style > decisions/assignments? >> The defense that everybody already knows this is irrelevant to the > question of how we'd LIKE Plot to behave. >> Naturally, we won't necessarily GET what we want... but we're entitled > to say what that is. >> I'm trying to think how David Park's Presentations package handles > such things. >> Bobby > Plot COULD assign colors after evaluation, OTOH... the fact that it > doesn't is a design choice/artifact, not a necessity preordained by > fate. >> That being so, users are entitled to find it odd at first glance. > (Or even second... maybe third.) >> If the above is true -- and I'd suppose it is -- then I'd say it's >> also very much an unfortunate, not to say flat-out *bad* design >> choice or artifact. >> An innocent novice-level user creates a Plot[ ] with three curves >> using the {f1, f2, f3} List form of the first argument, and discovers >> that M by default assigns a different color to each curve -- a good >> and helpful default design choice on M's part, I'd say. >> Maybe this novice user wants to go a bit further: Thicken certain >> curves, change the Dashing, and so on. He or she discovers the >> PlotStyle option (or equivalent); learns how to do this; is happy. >> And then this user also realizes: Hey, I could plot 8 or 10 curves >> this way, without having to type in f1 thru f8 by just using a Table[ >> ] command for the first argument and iterating over some appropriate >> parameter. A Table[ ] creates a List, right? >> So he/she does this; the 8 or 10 curves appear exactly as desired; >> except the styling behavior is suddenly all screwed up. Once again, >> a classic M-style Gotcha!!! -- and a particularly nasty Gotcha: Am I >> getting this unwanted result because of the way I structured the >> PlotStyle commands I used? -- or because of something mysterious with >> using Table[ ]? The coloring and so on in the default {f1, f2, f3} >> case has the nice default cycling behavior for the styling -- Why am >> I not getting it now? >> Andrzej says this unfortunate result _has_ to be the case because >> Plot[ ] doesn't pre-Evaluate the first argument. >> Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, f7, >> f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) this >> argument at least enough to know that it's not only a List, but how >> many elements that List has. Is it somehow impossible for Plot[ ] to >> know that Table will also produce a List, and to similarly >> pre-evaluate how many elements that List will have? I suspect it's >> not impossible. >> And if that is indeed impossible with the PlotStyle option in Plot[ ] >> then can Andrzej explain how it _is _ possible for Plot[ ] to >> somehow handle the PlotRange->All option correctly (i.e., >> identically) with either form of the first argument -- even though >> that option needs to determine not only the number of curves in the >> first argument, but the maximum and minimum values over all those >> curves, in order to set the axes and axis Tick locations and values >> for the plot. Is just getting the number of curves and picking the >> colors for them really harder than that? >> I very much like DrMajorBob's wording here: I'll bet the coloring >> problem with List vs Table is precisely an [accidental] design >> choice/artifact, not a necessity preordained by fate -- and an >> unfortunately unfortunate design choice/artifact. >> The only things more unfortunate are (a) that M has a fair (and >> increasing?) number of these Gotchas; (b) M's documentation is >> substantially less helpful than it could or should be either in >> diagnosing or in warning about them; and (c) it's far from clear that >> anyone at WRI really recognizes these points. >> --DrMajorBob@longhorns.com > > -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? Just in case I have not made my point clearly enough, I suggest pondering over the difference between: Plot[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x], {a, -1, 3}] and Plot[Evaluate[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x]], {a, -1, 3}] The second graph uses three colors, just as you and AES would have wished, but unfortunately there is a slight problem with it :it is quite wrong. Understanding a bit of mathematics often helps to understand Mathematica. Andrzej Kozlowski > Because there are lots of plots of the kind which I just sent > (Plot[x /. Solve[x^3 - 3 x^2 + a == 0, x], {a, -3, 5}]) but where > you have FindRoot or NMaximize etc., instead of Solve and the first > argument can't be evaluated until the value of the parameter a has > been supplied. There have been lots of post of this kind on this > forum so its kind if weird you managed to miss them all. Andrzej Kozlowski > Agreed. >> And I'm wondering what advantage HoldAll has, in the case of Plot, >> since a plot can't result without evaluating the arguments? >> Why NOT evaluate the first argument, at least, before making style >> decisions/assignments? >> The defense that everybody already knows this is irrelevant to >> the question of how we'd LIKE Plot to behave. >> Naturally, we won't necessarily GET what we want... but we're >> entitled to say what that is. >> I'm trying to think how David Park's Presentations package handles >> such things. >> Bobby >> Plot COULD assign colors after evaluation, OTOH... the fact that >> it doesn't is a design choice/artifact, not a necessity >> preordained by fate. >> That being so, users are entitled to find it odd at first glance. >> (Or even second... maybe third.) >> If the above is true -- and I'd suppose it is -- then I'd say it's > also very much an unfortunate, not to say flat-out *bad* design > choice or artifact. >> An innocent novice-level user creates a Plot[ ] with three curves > using the {f1, f2, f3} List form of the first argument, and > discovers that M by default assigns a different color to each > curve -- a good and helpful default design choice on M's part, I'd > say. >> Maybe this novice user wants to go a bit further: Thicken certain > curves, change the Dashing, and so on. He or she discovers the > PlotStyle option (or equivalent); learns how to do this; is happy. >> And then this user also realizes: Hey, I could plot 8 or 10 curves > this way, without having to type in f1 thru f8 by just using a > Table[ ] command for the first argument and iterating over some > appropriate parameter. A Table[ ] creates a List, right? >> So he/she does this; the 8 or 10 curves appear exactly as desired; > except the styling behavior is suddenly all screwed up. Once > again, a classic M-style Gotcha!!! -- and a particularly nasty > Gotcha: Am I getting this unwanted result because of the way I > structured the PlotStyle commands I used? -- or because of > something mysterious with using Table[ ]? The coloring and so on > in the default {f1, f2, f3} case has the nice default cycling > behavior for the styling -- Why am I not getting it now? >> Andrzej says this unfortunate result _has_ to be the case because > Plot[ ] doesn't pre-Evaluate the first argument. >> Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, > f7, f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) > this argument at least enough to know that it's not only a List, > but how many elements that List has. Is it somehow impossible for > Plot[ ] to know that Table will also produce a List, and to > similarly pre-evaluate how many elements that List will have? I > suspect it's not impossible. >> And if that is indeed impossible with the PlotStyle option in > Plot[ ] then can Andrzej explain how it _is _ possible for > Plot[ ] to somehow handle the PlotRange->All option correctly > (i.e., identically) with either form of the first argument -- even > though that option needs to determine not only the number of > curves in the first argument, but the maximum and minimum values > over all those curves, in order to set the axes and axis Tick > locations and values for the plot. Is just getting the number of > curves and picking the colors for them really harder than that? >> I very much like DrMajorBob's wording here: I'll bet the coloring > problem with List vs Table is precisely an [accidental] design > choice/artifact, not a necessity preordained by fate -- and an > unfortunately unfortunate design choice/artifact. >> The only things more unfortunate are (a) that M has a fair (and > increasing?) number of these Gotchas; (b) M's documentation is > substantially less helpful than it could or should be either in > diagnosing or in warning about them; and (c) it's far from clear > that anyone at WRI really recognizes these points. >> -- >> DrMajorBob@longhorns.com > === Subject: Re: When is a List not a List? I said in a post to the group a few months back that the much lamented printed Wolfram manual was superb, and that it had clearly taken enormous effort and planning to produce. My message was ridiculed by one regular contributer but I still feel I was right. Wolfram really need to listen to their fan-base, if I can put it like that. We know that Wolfram read these posts. Come on guys, you know it makes sense. Publish the manual that Mathematica deserves ! P 2008/8/1 AES : >> just a crazy off-the-top-of-my-head idea here: Why don't Wolfram publish a >> manual for Mathematica ? >> Peter Lindsay Amen! And question really is Why? --- Why have they neither published anything > themselves, nor did they (apparently) even encourage or assist or promote > any timely third-person efforts during the (lengthy?) preparation of M6? > -- peter lindsay computing officer mathematical institute university of st andrews ky16 9ss phone: 01334463756 Don't anthropomorphise computers - they hate that. The University of St Andrews is a charity registered in Scotland : No SC013532 === Subject: Re: When is a List not a List? Because there are lots of plots of the kind which I just sent (Plot[x /. Solve[x^3 - 3 x^2 + a == 0, x], {a, -3, 5}]) but where you have FindRoot or NMaximize etc., instead of Solve and the first argument can't be evaluated until the value of the parameter a has been supplied. There have been lots of post of this kind on this forum so its kind if weird you managed to miss them all. Andrzej Kozlowski > Agreed. And I'm wondering what advantage HoldAll has, in the case of Plot, > since a plot can't result without evaluating the arguments? Why NOT evaluate the first argument, at least, before making style > decisions/assignments? The defense that everybody already knows this is irrelevant to the > question of how we'd LIKE Plot to behave. Naturally, we won't necessarily GET what we want... but we're > entitled to say what that is. I'm trying to think how David Park's Presentations package handles > such things. Bobby > Plot COULD assign colors after evaluation, OTOH... the fact that > it doesn't is a design choice/artifact, not a necessity > preordained by fate. >> That being so, users are entitled to find it odd at first glance. > (Or even second... maybe third.) >> If the above is true -- and I'd suppose it is -- then I'd say it's >> also very much an unfortunate, not to say flat-out *bad* design >> choice or artifact. >> An innocent novice-level user creates a Plot[ ] with three curves >> using the {f1, f2, f3} List form of the first argument, and >> discovers that M by default assigns a different color to each curve >> -- a good and helpful default design choice on M's part, I'd say. >> Maybe this novice user wants to go a bit further: Thicken certain >> curves, change the Dashing, and so on. He or she discovers the >> PlotStyle option (or equivalent); learns how to do this; is happy. >> And then this user also realizes: Hey, I could plot 8 or 10 curves >> this way, without having to type in f1 thru f8 by just using a >> Table[ ] command for the first argument and iterating over some >> appropriate parameter. A Table[ ] creates a List, right? >> So he/she does this; the 8 or 10 curves appear exactly as desired; >> except the styling behavior is suddenly all screwed up. Once >> again, a classic M-style Gotcha!!! -- and a particularly nasty >> Gotcha: Am I getting this unwanted result because of the way I >> structured the PlotStyle commands I used? -- or because of >> something mysterious with using Table[ ]? The coloring and so on >> in the default {f1, f2, f3} case has the nice default cycling >> behavior for the styling -- Why am I not getting it now? >> Andrzej says this unfortunate result _has_ to be the case because >> Plot[ ] doesn't pre-Evaluate the first argument. >> Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, >> f7, f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) >> this argument at least enough to know that it's not only a List, >> but how many elements that List has. Is it somehow impossible for >> Plot[ ] to know that Table will also produce a List, and to >> similarly pre-evaluate how many elements that List will have? I >> suspect it's not impossible. >> And if that is indeed impossible with the PlotStyle option in >> Plot[ ] then can Andrzej explain how it _is _ possible for Plot[ ] >> to somehow handle the PlotRange->All option correctly (i.e., >> identically) with either form of the first argument -- even though >> that option needs to determine not only the number of curves in the >> first argument, but the maximum and minimum values over all those >> curves, in order to set the axes and axis Tick locations and values >> for the plot. Is just getting the number of curves and picking the >> colors for them really harder than that? >> I very much like DrMajorBob's wording here: I'll bet the coloring >> problem with List vs Table is precisely an [accidental] design >> choice/artifact, not a necessity preordained by fate -- and an >> unfortunately unfortunate design choice/artifact. >> The only things more unfortunate are (a) that M has a fair (and >> increasing?) number of these Gotchas; (b) M's documentation is >> substantially less helpful than it could or should be either in >> diagnosing or in warning about them; and (c) it's far from clear >> that anyone at WRI really recognizes these points. > > -- > DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? Of course it should have been something like Plot[x /. Solve[x^3 - 3 x^2 + a == 0, x], {a, -3, 5}] Andrzej Kozlowski > I am not sure about the no argument part. First, it seems to me > obvious that one should try to learn Mathematica before trying to > use it, and reading the documentation is a pretty basic part of > learning. Why should you then call something a quirk if it is both > documented and even exemplified. > However, there is more to that. In view of what you have been > arguing, perhaps you could tell us if it seems odd to you that > Plot does not use different colors in the example below. It does not > seem odd to me at all, and I doubt that even beginners (AES > excepting, of course) will find it a quirk. > Plot[x /. Solve[x^3 - 3 x + a x == 0, x], {a, -3, 3}] Andrzej Kozlowski > No argument here. That's the behavior, and we've seen it a thousand >> times. >> A quirk is only a quirk the first 100 times we see it, or >> thereabouts. >> (Pick a number.) >> Plot COULD assign colors after evaluation, OTOH... the fact that it >> doesn't is a design choice/artifact, not a necessity preordained by >> fate. >> That being so, users are entitled to find it odd at first glance. >> (Or even >> second... maybe third.) >> Bobby > the > usual (although inaccurate) sense that people frequently use in > this > context, namely: that the so called Evaluator does not pre- > evaluate the > arguments of Plot (if you do not like to thing of the Evaluator, > another way of saying this is that Mathematica does not evaluate > the > arguments before Plot is applied and leaves any evaluating to > Plot.) Of > course, you are right that Plot does evaluate its arguments in > some way > (this sort of behavior is also referred in the often used phrase: > Plot > evaluates its arguments in a non-standard way). The fact that this > non-standard evaluation results in a plot of a function is > actually > new in version 6; in all previous versions all you will get is an > error > message about the values of the function being plotted not being > numeric. > Anyway, my point was that this has been a normal (non quirky) > behavior > of Mathematica since version 1 and has been discussed here a > number of > times. (It must be at least the fourth of fifth time in 10 years > that I > am addressing this issue on this forum). It is also fully documented > (with examples) in the Mathematica online documentation, all past > printed documentation and a vast number of books dealing with > Mathematica. >> Andrzej Kozlowski > But Plot DOES evaluate its arguments, of course, and DOES >> (eventually) >> see that multiple functions are being plotted. (Else they >> couldn't be >> plotted.) >> It's just not happening before colors are assigned. >> Nonetheless, it's prudent to take note of what functions actually >> do, >> and get used to it. Calling everything in sight a quirk serves no >> purpose. >> (Paraphrasing Andrzej, perhaps.) >> Bobby > There is nothing at all quirky about this. Yes, > FullForm[Table[g[x, > n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed > identical, > but that is because FullForm evaluates its argument. But Plot has > attribute: >> In[2]:= Attributes[Plot] > Out[2]= {HoldAll, Protected} >> so, unlike FullForm, it does not evaluate its argument. In your > first > example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, > Blue}], the first argument of Plot has an explicit List bracket, > so > Plot can see that it supposed to treat the argument as two > different > functions, without evaluating the argument. But in the second > case, it > does not see an explicit bracket, so it treats the entire > expression > as the graph of a single function (in versions of Mathematica > before 6 > you would not have got any plot at all in this case). >> If you use Evaluate in the second code you will get the same > result as > you get form the first: >> Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle ->> {Red, Blue}] >> Finally, since you have given ample proof that, in spite of many > years > of using Mathematica, you have not mastered its basics (this > particular issue has been raised and answered a countless number > of > times on this forum), why do you keep assuming that the problems > that > you keep coming across are Mathematica's quirks rather than > (as is > much more likely) gaps in your won understanding? What do you > think of > first year undergraduate students who whenever they do not > understand > something in their introductory lectures claim that it is wrong, > or > blame their textbook or their lecture rather then themselves? >> Andrzej Kozlowski >> g[x_, n_] := x^n >> FullForm[Table[g[x, n], {n, 1, 2}]] >> FullForm[{g[x, 1], g[x, 2]}] >> Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] >> Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, >> Blue}] >> The FullForm[]s are identical. One Plot[] has red and blue >> curves; >> the >> other has two blue curves. >> Quirky! > --DrMajorBob@longhorns.com >> -- >> DrMajorBob@longhorns.com > === Subject: Re: When is a List not a List? Hi > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; the > other has two blue curves. Quirky! > Plot[Evaluate[ Table[g[x, n], {n, 1, 2}] ], {x, 0, 1}, PlotStyle -> {Red, Blue}] Oliver === Subject: Re: When is a List not a List? >Plot COULD assign colors after evaluation, OTOH... the fact that it >doesn't is a design choice/artifact, not a necessity preordained by >fate. That being so, users are entitled to find it odd at first glance. >(Or even second... maybe third.) If the above is true -- and I'd suppose it is -- then I'd say it's also very much an unfortunate, not to say flat-out *bad* design choice or artifact. An innocent novice-level user creates a Plot[ ] with three curves using the {f1, f2, f3} List form of the first argument, and discovers that M by default assigns a different color to each curve -- a good and helpful default design choice on M's part, I'd say. Maybe this novice user wants to go a bit further: Thicken certain curves, change the Dashing, and so on. He or she discovers the PlotStyle option (or equivalent); learns how to do this; is happy. And then this user also realizes: Hey, I could plot 8 or 10 curves this way, without having to type in f1 thru f8 by just using a Table[ ] command for the first argument and iterating over some appropriate parameter. A Table[ ] creates a List, right? So he/she does this; the 8 or 10 curves appear exactly as desired; except the styling behavior is suddenly all screwed up. Once again, a classic M-style Gotcha!!! -- and a particularly nasty Gotcha: Am I getting this unwanted result because of the way I structured the PlotStyle commands I used? -- or because of something mysterious with using Table[ ]? The coloring and so on in the default {f1, f2, f3} case has the nice default cycling behavior for the styling -- Why am I not getting it now? Andrzej says this unfortunate result _has_ to be the case because Plot[ ] doesn't pre-Evaluate the first argument. Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, f7, f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) this argument at least enough to know that it's not only a List, but how many elements that List has. Is it somehow impossible for Plot[ ] to know that Table will also produce a List, and to similarly pre-evaluate how many elements that List will have? I suspect it's not impossible. And if that is indeed impossible with the PlotStyle option in Plot[ ] then can Andrzej explain how it _is _ possible for Plot[ ] to somehow handle the PlotRange->All option correctly (i.e., identically) with either form of the first argument -- even though that option needs to determine not only the number of curves in the first argument, but the maximum and minimum values over all those curves, in order to set the axes and axis Tick locations and values for the plot. Is just getting the number of curves and picking the colors for them really harder than that? I very much like DrMajorBob's wording here: I'll bet the coloring problem with List vs Table is precisely an [accidental] design choice/artifact, not a necessity preordained by fate -- and an unfortunately unfortunate design choice/artifact. The only things more unfortunate are (a) that M has a fair (and increasing?) number of these Gotchas; (b) M's documentation is substantially less helpful than it could or should be either in diagnosing or in warning about them; and (c) it's far from clear that anyone at WRI really recognizes these points. === Subject: Re: When is a List not a List? > problem with List vs Table is precisely an [accidental] design > choice/artifact, not a necessity preordained by fate -- and an > unfortunately unfortunate design choice/artifact. The only things more unfortunate are (a) that M has a fair (and > increasing?) number of these Gotchas; (b) M's documentation is > substantially less helpful than it could or should be either in > diagnosing or in warning about them; and (c) it's far from clear that > anyone at WRI really recognizes these points. > I think it is rather too easy to criticise like this and forget the complexity and range of tasks that Plot can handle. In this context the confusion arises because the evaluation of the argument to Plot determines not only what is to be plotted, but also the number of graphs to plot. Flexibility like that probably always entails a few gotchas. The beauty of Mathematica is that you can always write your own function that does exactly what you want, calling the system-supplied function internally. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: When is a List not a List? No argument here. That's the behavior, and we've seen it a thousand times. A quirk is only a quirk the first 100 times we see it, or thereabouts. (Pick a number.) Plot COULD assign colors after evaluation, OTOH... the fact that it doesn't is a design choice/artifact, not a necessity preordained by fate. That being so, users are entitled to find it odd at first glance. (Or even second... maybe third.) Bobby > usual (although inaccurate) sense that people frequently use in this > context, namely: that the so called Evaluator does not pre-evaluate the > arguments of Plot (if you do not like to thing of the Evaluator, > another way of saying this is that Mathematica does not evaluate the > arguments before Plot is applied and leaves any evaluating to Plot.) Of > course, you are right that Plot does evaluate its arguments in some way > (this sort of behavior is also referred in the often used phrase: Plot > evaluates its arguments in a non-standard way). The fact that this > non-standard evaluation results in a plot of a function is actually > new in version 6; in all previous versions all you will get is an error > message about the values of the function being plotted not being numeric. > Anyway, my point was that this has been a normal (non quirky) behavior > of Mathematica since version 1 and has been discussed here a number of > times. (It must be at least the fourth of fifth time in 10 years that I > am addressing this issue on this forum). It is also fully documented > (with examples) in the Mathematica online documentation, all past > printed documentation and a vast number of books dealing with > Mathematica. Andrzej Kozlowski > But Plot DOES evaluate its arguments, of course, and DOES (eventually) >> see that multiple functions are being plotted. (Else they couldn't be >> plotted.) >> It's just not happening before colors are assigned. >> Nonetheless, it's prudent to take note of what functions actually do, >> and get used to it. Calling everything in sight a quirk serves no >> purpose. >> (Paraphrasing Andrzej, perhaps.) >> Bobby > There is nothing at all quirky about this. Yes, FullForm[Table[g[x, > n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed identical, > but that is because FullForm evaluates its argument. But Plot has > attribute: >> In[2]:= Attributes[Plot] > Out[2]= {HoldAll, Protected} >> so, unlike FullForm, it does not evaluate its argument. In your first > example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, > Blue}], the first argument of Plot has an explicit List bracket, so > Plot can see that it supposed to treat the argument as two different > functions, without evaluating the argument. But in the second case, it > does not see an explicit bracket, so it treats the entire expression > as the graph of a single function (in versions of Mathematica before 6 > you would not have got any plot at all in this case). >> If you use Evaluate in the second code you will get the same result as > you get form the first: >> Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle ->> {Red, Blue}] >> Finally, since you have given ample proof that, in spite of many years > of using Mathematica, you have not mastered its basics (this > particular issue has been raised and answered a countless number of > times on this forum), why do you keep assuming that the problems that > you keep coming across are Mathematica's quirks rather than (as is > much more likely) gaps in your won understanding? What do you think of > first year undergraduate students who whenever they do not understand > something in their introductory lectures claim that it is wrong, or > blame their textbook or their lecture rather then themselves? >> Andrzej Kozlowski >> g[x_, n_] := x^n >> FullForm[Table[g[x, n], {n, 1, 2}]] >> FullForm[{g[x, 1], g[x, 2]}] >> Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] >> Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] >> The FullForm[]s are identical. One Plot[] has red and blue curves; >> the >> other has two blue curves. >> Quirky! > --DrMajorBob@longhorns.com -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? usual (although inaccurate) sense that people frequently use in this context, namely: that the so called Evaluator does not pre-evaluate the arguments of Plot (if you do not like to thing of the Evaluator, another way of saying this is that Mathematica does not evaluate the arguments before Plot is applied and leaves any evaluating to Plot.) Of course, you are right that Plot does evaluate its arguments in some way (this sort of behavior is also referred in the often used phrase: Plot evaluates its arguments in a non- standard way). The fact that this non-standard evaluation results in a plot of a function is actually new in version 6; in all previous versions all you will get is an error message about the values of the function being plotted not being numeric. Anyway, my point was that this has been a normal (non quirky) behavior of Mathematica since version 1 and has been discussed here a number of times. (It must be at least the fourth of fifth time in 10 years that I am addressing this issue on this forum). It is also fully documented (with examples) in the Mathematica online documentation, all past printed documentation and a vast number of books dealing with Mathematica. Andrzej Kozlowski > But Plot DOES evaluate its arguments, of course, and DOES > (eventually) see that multiple functions are being plotted. (Else > they couldn't be plotted.) It's just not happening before colors are assigned. Nonetheless, it's prudent to take note of what functions actually > do, and get used to it. Calling everything in sight a quirk serves > no purpose. (Paraphrasing Andrzej, perhaps.) Bobby >> There is nothing at all quirky about this. Yes, FullForm[Table[g[x, >> n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed >> identical, >> but that is because FullForm evaluates its argument. But Plot has >> attribute: >> In[2]:= Attributes[Plot] >> Out[2]= {HoldAll, Protected} >> so, unlike FullForm, it does not evaluate its argument. In your first >> example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, >> Blue}], the first argument of Plot has an explicit List bracket, so >> Plot can see that it supposed to treat the argument as two different >> functions, without evaluating the argument. But in the second case, >> it >> does not see an explicit bracket, so it treats the entire expression >> as the graph of a single function (in versions of Mathematica >> before 6 >> you would not have got any plot at all in this case). >> If you use Evaluate in the second code you will get the same result >> as >> you get form the first: >> Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] >> Finally, since you have given ample proof that, in spite of many >> years >> of using Mathematica, you have not mastered its basics (this >> particular issue has been raised and answered a countless number of >> times on this forum), why do you keep assuming that the problems that >> you keep coming across are Mathematica's quirks rather than (as is >> much more likely) gaps in your won understanding? What do you think >> of >> first year undergraduate students who whenever they do not understand >> something in their introductory lectures claim that it is wrong, or >> blame their textbook or their lecture rather then themselves? >> Andrzej Kozlowski > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, > Blue}] >> The FullForm[]s are identical. One Plot[] has red and blue curves; > the > other has two blue curves. >> Quirky! >> > -- > DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? But Plot DOES evaluate its arguments, of course, and DOES (eventually) see that multiple functions are being plotted. (Else they couldn't be plotted.) It's just not happening before colors are assigned. Nonetheless, it's prudent to take note of what functions actually do, and get used to it. Calling everything in sight a quirk serves no purpose. (Paraphrasing Andrzej, perhaps.) Bobby > There is nothing at all quirky about this. Yes, FullForm[Table[g[x, > n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed identical, > but that is because FullForm evaluates its argument. But Plot has > attribute: In[2]:= Attributes[Plot] > Out[2]= {HoldAll, Protected} so, unlike FullForm, it does not evaluate its argument. In your first > example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, > Blue}], the first argument of Plot has an explicit List bracket, so > Plot can see that it supposed to treat the argument as two different > functions, without evaluating the argument. But in the second case, it > does not see an explicit bracket, so it treats the entire expression > as the graph of a single function (in versions of Mathematica before 6 > you would not have got any plot at all in this case). If you use Evaluate in the second code you will get the same result as > you get form the first: Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle - {Red, Blue}] Finally, since you have given ample proof that, in spite of many years > of using Mathematica, you have not mastered its basics (this > particular issue has been raised and answered a countless number of > times on this forum), why do you keep assuming that the problems that > you keep coming across are Mathematica's quirks rather than (as is > much more likely) gaps in your won understanding? What do you think of > first year undergraduate students who whenever they do not understand > something in their introductory lectures claim that it is wrong, or > blame their textbook or their lecture rather then themselves? Andrzej Kozlowski >> g[x_, n_] := x^n >> FullForm[Table[g[x, n], {n, 1, 2}]] >> FullForm[{g[x, 1], g[x, 2]}] >> Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] >> Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] >> The FullForm[]s are identical. One Plot[] has red and blue curves; >> the >> other has two blue curves. >> Quirky! > -- DrMajorBob@longhorns.com === Subject: Re: When is a List not a List? There is nothing at all quirky about this. Yes, FullForm[Table[g[x, n], {n, 1, 2}]] and FullForm[{g[x, 1], g[x, 2]}] are indeed identical, but that is because FullForm evaluates its argument. But Plot has attribute: In[2]:= Attributes[Plot] Out[2]= {HoldAll, Protected} so, unlike FullForm, it does not evaluate its argument. In your first example, Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}], the first argument of Plot has an explicit List bracket, so Plot can see that it supposed to treat the argument as two different functions, without evaluating the argument. But in the second case, it does not see an explicit bracket, so it treats the entire expression as the graph of a single function (in versions of Mathematica before 6 you would not have got any plot at all in this case). If you use Evaluate in the second code you will get the same result as you get form the first: Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] Finally, since you have given ample proof that, in spite of many years of using Mathematica, you have not mastered its basics (this particular issue has been raised and answered a countless number of times on this forum), why do you keep assuming that the problems that you keep coming across are Mathematica's quirks rather than (as is much more likely) gaps in your won understanding? What do you think of first year undergraduate students who whenever they do not understand something in their introductory lectures claim that it is wrong, or blame their textbook or their lecture rather then themselves? Andrzej Kozlowski > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; > the > other has two blue curves. Quirky! > === Subject: When is a List not a List? g[x_, n_] := x^n FullForm[Table[g[x, n], {n, 1, 2}]] FullForm[{g[x, 1], g[x, 2]}] Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; the other has two blue curves. Quirky! === Subject: Re: When is a List not a List? try g[x_, n_] := x^n FullForm[Table[g[x, n], {n, 1, 2}]] FullForm[{g[x, 1], g[x, 2]}] Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] because Plot[] has the attribute HoldAll, it find not out that the evaluate version of Table[g[x, n], {n, 1, 2}] is a list. Jens > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; the > other has two blue curves. Quirky! > === Subject: Re: When is a List not a List? > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; the > other has two blue curves. Quirky! Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] Don't ask why .... Has something to do with: Attributes[Plot] Attributes[Table] Out[28]= {HoldAll, Protected} Out[29]= {HoldAll, Protected} === Subject: Re: When is a List not a List? > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. Plot has Attribute HoldAll, and: FullForm[Hold[Table[g[x, n], {n, 1, 2}]]] FullForm[Hold[{g[x, 1], g[x, 2]}]] are not the same expressions. This means that Plot sees the unevaluated expressions which are different and so there is no quirk in that it behaves differently when it sees a list. Of course one could argue that it could analyze the Table command and find out that that will evaluate to a two element list, but this is in general not possible without complete evaluation. E.g.: can you tell how many elements the following table will have without evaluating it?: Table[If[RandomReal[]<0.5,x^i,Unevaluated[Sequence[]]],{i,1,10}] so in these cases it will not try to be smart. If you explicitly tell Plot to evaluate: Plot[Evaluate[Table[g[x, n], {n, 1, 2}]], {x, 0, 1}, PlotStyle -> {Red, Blue}] or in Version 6 also: Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}, Evaluated -> True] a red and blue curve are shown because now Plot handles identical expressions (the evaluated ones that you have been looking at). I think you would find a lot less bugs and quirks if you would try to understand the basic mechanisms of how mathematica works. I always recommend to read the tutorials which are linked here (copy the following to the adress field within the documentation center): tutorial/EvaluationOfExpressionsOverview By reading I mean you definitly should take the time to evaluate the examples and experiment with them to make sure you get the point. hth, albert === Subject: Re: When is a List not a List? > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; the > other has two blue curves. Quirky! > This is indeed strange. It is related to the HoldAll attribute of Plot since by forcing the evaluation with Plot[Table[g[x, n], {n, 1, 2}] // Evaluate, {x, 0, 1}, PlotStyle -> {Red, Blue}] one gets two colors. By looking at the FullForm of the resulting graphics, with g1=Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] we have for g1[[1]] a structure like {{{}, {}, {Hue[0.67, 0.6, 0.6], RGBColor[1, 0, 0], Line[{(*data points*)}]}, {Hue[0.906068, 0.6, 0.6], RGBColor[0, 0, 1], Line[{(* data points *)}]} }} which gives the two lines with different colors. For g2=Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] we have for g2[[1]] {{{}, {}, {Hue[0.67, 0.6, 0.6], RGBColor[1, 0, 0], RGBColor[0, 0, 1], Line[{(* data points *)}], Line[{(* data points *)}]} }} where the two color directives are present, but the first line data is provided after the second color directive and is thus drawn with the same color as the second one... This is indeed quite strange. Guy Lamouche === Subject: Re: When is a List not a List? > g[x_, n_] := x^n > FullForm[Table[g[x, n], {n, 1, 2}]] > FullForm[{g[x, 1], g[x, 2]}] > Plot[{g[x, 1], g[x, 2]}, {x, 0, 1}, PlotStyle -> {Red, Blue}] > Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] The FullForm[]s are identical. One Plot[] has red and blue curves; the > other has two blue curves. Quirky! Not at all, as it has already been explained many times in this very newsgroup (notwithstanding the online help that contains some examples illustrating this point). Plot does not evaluate immediately its arguments because it has the attribute HoldAll: Attributes[Plot] {HoldAll, Protected} So, having the attribute HoldHold, what Plot sees in first instance the unevaluated expression Table[g[x, n], {n, 1, 2}], which stands for only *one* function. Thus the choice of colors is just for one function/expression, not for the list of functions that will be returned after evaluation of the first argument. To force the evaluation of the first argument before doing anything else, one must use Evaluate, so Mathematica's main loop evaluates Table[g[x, n], {n, 1, 2}] to the list {g[x, 1], g[x, 2]} and feed Plot with this list as first argument. Then Plot is evaluated and sees a list of two function as its first argument and thus select two colors. As usual, Trace might be useful to have a glimpse at what's going on. Plot[Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] // Trace {Plot[Table[g[x,n],{n,1,2}],{x,0,1},PlotStyle->{Red,Blue}], {x=.,Null},{x=.,Null},{{x}=.,{x=.},{x=.,Null},{Null}}, {Table[g[x,n],{n,1,2}],{{x,0.0000204286},{n,1}, g[0.0000204286,1],0.0000204286^1,0.0000204286}, [...] Plot[Evaluate@Table[g[x, n], {n, 1, 2}], {x, 0, 1}, PlotStyle -> {Red, Blue}] // Trace {{Table[g[x,n],{n,1,2}],{{n,1},g[x,1],x^1,x}, {{n,2},g[x,2],x^2},{x,x^2}}, Plot[{x,x^2},{x,0,1},PlotStyle->{Red,Blue}], [...] === Subject: How can I make the colored lines inside a Mathematica Legend How can I change the thickness of colored lines inside a Mathematica legend? The default thickness that I am getting makes them barely visible, and hence makes it difficult to associate different colred curves with their labels in the legend. I checked the documentation for Graphics`Legend`, but didn't find options for the thickness of lines inside the legend. Any suggestions? === Subject: Re: How can I make the colored lines inside a Mathematica Legend > How can I change the thickness of colored lines inside a Mathematica legend? The default thickness that I am getting makes them barely visible, and hence makes it difficult to associate different colred curves with their labels in the legend. I checked the documentation for Graphics`Legend`, but didn't find options for the thickness of lines inside the legend. Any suggestions? For anything the least out of the ordinary, I compose my own legend using something like Epilog->Inset@Framed@GraphicsGrid[... Inside the grid cells, you can do just about anything you want to do. Hth, Fred Klingener === Subject: Demonstration Project Trouble Hi folks, I've written a small demonstration project program to illustrate a few points about bacterial growth, and the program seems to run fine in its natural setting of a mathematica notebook. When I tried to submit this file as a Demonstrations project, I was unable to successfully upload the file because Wolfram's server scanned the file and returned the following error: Please edit notebook to remove the following illegal symbols: CurrentValue, FEPrivate`FrontEndResource This is just cryptic enough to me that I don't know what to look at, particularly since Mathematica itself does not complain about the program. Have any of you come across such an error? I've included the code below which may make something standout to your eyes that I am missing. I appreciate any thoughts you might have. I have repeatedly tried to contact Wolfram support, but they are just not in a responsive mood these days. Todd final[init_, numgen_] := (init*(2^ numgen)); (* final number of cells calculation *) Manipulate[ plotfinal = ListPlot[Table[{init, final[init, numgen]}, {init, Range[init]}], PlotStyle -> {Red, PointSize[0.03]}, Frame -> True, FrameLabel -> {{Item[Style[Final # of Cells, Bold]], }, {Item[Style[Initial # of Cells, Bold]] , Item[Style[Absolute Scale, 14, Bold, Blue]]}}, ImageSize -> Scaled[0.35]]; plotfinallog = ListPlot[Table[{init, Log[10, final[init, numgen]]}, {init, Range[init]}], PlotStyle -> {Green, PointSize[0.03]}, Frame -> True, FrameLabel -> {{Item[Style[Final # of Cells (Log Scale), Bold]], }, {Item[Style[Initial # of Cells , Bold]], Item[Style[Semi-Log Scale, 14, Bold, Blue]]}}, ImageSize -> Scaled[0.35]]; Column[{Row[{plotfinal, Item[Style[ verses , 12, Bold, Red]], plotfinallog}], TextCell[Row[{Style[ Final Number of Cells (based on current values): , 14, Bold, Blue], Style[final[init, numgen], 14, Bold, Red]}]]}], (* Control Area *) Item[Style[Computing the Final Number of Bacterial Cells, 18, Red]], Delimiter, {{init, 1, Item[Style[Initial # Cells, 12, Bold, Red]]}, 1, 100, 1, Appearance -> Labeled}, {{numgen, 1, Item[Style[# of Generations, 12, Bold, Red]]}, 1, 25, 1, Appearance -> Labeled}, SaveDefinitions -> True, TrackedSymbols -> {init, numgen}] === Subject: Re: Demonstration Project Trouble Have you tried copying the cell(s) into a new, blank notebook? The select everything in the notebook (Ctrl-a), and show it as the underlying expression: either use Ctrl-Shift-E or else from the menu select Cell > Show Expression. You'll now see the actual text behind what the front end displays, in other words, you'll see what you would if you viewed the file in plain text editor. Now search for CurrentValue, etc., about which you received the complaint and see if they're there. If so ... have you modified any Mathematica init.m file for your installation? > Hi folks, I've written a small demonstration project program to illustrate a few points about bacterial growth, and the program seems to run fine in its natural setting of a mathematica notebook. When I tried to submit this file as a Demonstrations project, I was unable to successfully upload the file because Wolfram's server scanned the file and returned the following error: Please edit notebook to remove the following illegal symbols: CurrentValue, FEPrivate`FrontEndResource This is just cryptic enough to me that I don't know what to look at, particularly since Mathematica itself does not complain about the program. Have any of you come across such an error? I've included the code below which may make something standout to your eyes that I am missing. I appreciate any thoughts you might have. I have repeatedly tried to contact Wolfram support, but they are just not in a responsive mood these days. Todd > final[init_, > numgen_] := (init*(2^ > numgen)); (* final number of cells calculation *) Manipulate[ > plotfinal = > ListPlot[Table[{init, final[init, numgen]}, {init, Range[init]}], > PlotStyle -> {Red, PointSize[0.03]}, Frame -> True, > FrameLabel -> {{Item[Style[Final # of Cells, Bold]], > }, {Item[Style[Initial # of Cells, Bold]] , > Item[Style[Absolute Scale, 14, Bold, Blue]]}}, > ImageSize -> Scaled[0.35]]; > > plotfinallog = > ListPlot[Table[{init, Log[10, final[init, numgen]]}, {init, > Range[init]}], PlotStyle -> {Green, PointSize[0.03]}, > Frame -> True, FrameLabel -> {{Item[Style[Final # of Cells > (Log Scale), Bold]], > }, {Item[Style[Initial # of Cells , Bold]], > Item[Style[Semi-Log Scale, 14, Bold, Blue]]}}, > ImageSize -> Scaled[0.35]]; > > Column[{Row[{plotfinal, Item[Style[ verses , 12, Bold, Red]], > plotfinallog}], TextCell[Row[{Style[ > Final Number of Cells (based on current values): , 14, Bold, > Blue], Style[final[init, numgen], 14, Bold, Red]}]]}], > > (* Control Area *) > Item[Style[Computing the Final Number of Bacterial Cells, 18, > Red]], > > Delimiter, > > {{init, 1, Item[Style[Initial # Cells, 12, Bold, Red]]}, 1, 100, 1, > Appearance -> Labeled}, > > {{numgen, 1, Item[Style[# of Generations, 12, Bold, Red]]}, 1, 25, > 1, Appearance -> Labeled}, > > SaveDefinitions -> True, > > TrackedSymbols -> {init, numgen}] -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Demonstration Project Trouble > I've written a small demonstration project program to illustrate a few points about bacterial growth, > and the program seems to run fine in its natural setting of a mathematica notebook. > When I tried to submit this file as a Demonstrations project, I was unable to successfully upload > the file because Wolfram's server scanned the file and returned the following error: Please edit notebook to remove the following illegal symbols: CurrentValue, > FEPrivate`FrontEndResource Have any of you come across such an error? I've included the code below which may make something standout to your eyes that I am missing. I have had a similar error in the past. My problem arose when I tried to submit a demo that used Combinatorica. Evidently, they don't want you use that package and they symbol Combinatorica is flagged as illegal. In your case, however, I took your code, put it in a fresh Demonstration notebook and uploaded it to my workspace without any problem. I even inserted the symbol FEPrivate`FrontEndResource to try to make it complain. The result is here: http://demonstrations.wolfram.com/preview.html?draft/99919/000006/BlahBlah Perhaps, you should just try again from a fresh demo notebook. Mark McClure === Subject: Re: Recognize vector expression Ciao Ramiro, > I have the following problem. Working in tensorial algebra I > wondering if exist a package of rules able to a clever managing of > the vector components. As example able to recognize that {-b3c2+b2c3, > b3c1+b1c3, -b2c1+b1c2} is Cross[b,c] and many others to a better > lecture of long expression. A simple rule, just for this, is not > enough, I need a package the contain all! > Ramiro I am not sure this is what you are looking for, but xAct is a tensor algebra package for Mathematica. Have a look, maybe it helps you http://metric.iem.csic.es/Martin-Garcia/xAct/ Oliver === Subject: Recognize vector expression I have the following problem. Working in tensorial algebra I wondering if exist a package of rules able to a clever managing of the vector components. As example able to recognize that {-b3c2+b2c3, b3c1+b1c3, -b2c1+b1c2} is Cross[b,c] and many others to a better lecture of long expression. A simple rule, just for this, is not enough, I need a package the contain all! Ramiro PhD. Ramiro dell'Erba, Lab address: ENEA CR Casaccia ENEA - New Physic Technology and New Materials: Robotic Section Edificio F65 Via Anguillarese 301, Roma 00123 Italy Sacco Postale 088 Tel. 0039-06-30486128 Fax 0039-06-30486038 E-mail: dellerba AT casaccia.enea.it URL: http://robotica.casaccia.enea.it/ Home address: Via Posillipo 102/2 Napoli 80123 Italy Tel. 0039-081-7691954 Handy:Tel. 0039-347-5041920 E-mail home:dellerba2 AT iol.it In case of failure: dellerba61 AT hotmail.com or ramirodellerba AT libero.it Note that AT stay for @ Skype ramiro.dellerba === Subject: Re: Recognize vector expression On Aug 2, 1:31 pm, Ramiro dell'Erba wondering if exist a package of rules able to a clever managing of > the vector components. As example able to recognize that {-b3c2+b2c3, > b3c1+b1c3, -b2c1+b1c2} is Cross[b,c] and many others to a better > lecture of long expression. A simple rule, just for this, is not > enough, I need a package the contain all! So far, I've fumbled along, making up replacement rules for symbolic expressions like cross, the triple products, and some quaternion forms. They're ad hoc, some require special forms of definitions, and they have to be explicitly applied. They work, but they are not satisfactory, and none are what I would call ready to be packaged. Should we start writing function paclets? Fred Klingener === Subject: Re: Recognize vector expression > On Aug 2, 1:31 pm, Ramiro dell'Erba I have the following problem. Working in tensorial algebra I > wondering if exist a package of rules able to a clever managing of > the vector components. As example able to recognize that {-b3c2+b2c3, > b3c1+b1c3, -b2c1+b1c2} is Cross[b,c] and many others to a better > lecture of long expression. A simple rule, just for this, is not > enough, I need a package the contain all! So far, I've fumbled along, making up replacement rules for symbolic > expressions like cross, the triple products, and some quaternion > forms. They're ad hoc, some require special forms of definitions, and > they have to be explicitly applied. They work, but they are not > satisfactory, and none are what I would call ready to be packaged. Should we start writing function paclets? Fred Klingener Take a look at Tensorial on David Park's website. It does facilitate simplification of tensor expressions. === Subject: Re: Using [Breve] as a substitute for underscore I suspect that most folks use what Mathematica itself uses for multi-word names: camel-case MassOfEarth=5.97*^24 or, if you don't want to infringe upon a possible built-in name, massOfEarth=6.97*^24 It's a LOT quicker to type than using [Breve] or its shortcut [esc]bv[esc]. > In mathematica you cannot use underscore _ as part of a variable name > as you could in other computer languages. Has anyone tried using [Breve] as an underscore substitute instead. for example: mass[Breve]of[Breve]earth = 5.97*^24 or mass[esc]bv[esc]of[esc]bv[esc]earth = 5.97*^24 I kinda like breve because it looks like the standard underscore > character. What other characters do other people uses? Steven Siew > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Using [Breve] as a substitute for underscore Steven, One of the new small things in Mathematica 6 (so it seems) is the non-printing character [LetterSpace]. The alias is Esc_Esc (Esc underscore Esc). Try this (on diferent Input cells): x[LetterSpace]y x[LetterSpace]y//Head x[LetterSpace]y=1 x[LetterSpace]y+1 Clear[x[LetterSpace]y] Hope this might help you in some way. Carlos C.8esar de Ara.9cjo Gregos & Troianos Educacional http://www.gregosetroianos.mat.br MSN: cca_gregosetroianos@hotmail.com Belo Horizonte, MG, Brasil (31) 3283-1122 === Subject: Re: Using [Breve] as a substitute for underscore can add some extra characters if they wish. I am still eagerly awaiting the day when WRI will similarly supply us with 'PrimeCharacter' and 'DoublePrimeCharacter' that display at the correct height and don't sit on the floor. Then users will easily be able to use some of the most common notation in math books. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Steven, One of the new small things in Mathematica 6 (so it seems) is the > non-printing character [LetterSpace]. The alias is Esc_Esc (Esc > underscore Esc). Try this (on diferent Input cells): x[LetterSpace]y x[LetterSpace]y//Head x[LetterSpace]y=1 x[LetterSpace]y+1 Clear[x[LetterSpace]y] Hope this might help you in some way. Carlos C=E9sar de Ara=FAjo > Gregos & Troianos Educacional > http://www.gregosetroianos.mat.br > MSN: cca_gregosetroianos@hotmail.com > Belo Horizonte, MG, Brasil > (31) 3283-1122 === Subject: Re: Using [Breve] as a substitute for underscore I am not sure if this is what you want, but I routinely use primed characters by Symbolizing (character)_superscript_esc'esc In which the superscript is the usual ctl-^. This actually makes a nice large prime. Here is A': !(*SuperscriptBox[A, [Prime]]) Kevin > can add some extra characters if they wish. I am still eagerly awaiting the day when WRI will similarly supply us with > 'PrimeCharacter' and 'DoublePrimeCharacter' that display at the correct > height and don't sit on the floor. Then users will easily be able to use > some of the most common notation in math books. -- > David Park > djmpark@comcast.net > http://home.comcast.net/~djmpark/ >> Steven, >> One of the new small things in Mathematica 6 (so it seems) is the >> non-printing character [LetterSpace]. The alias is Esc_Esc (Esc >> underscore Esc). >> Try this (on diferent Input cells): >> x[LetterSpace]y >> x[LetterSpace]y//Head >> x[LetterSpace]y=1 >> x[LetterSpace]y+1 >> Clear[x[LetterSpace]y] >> Hope this might help you in some way. >> Carlos C=E9sar de Ara=FAjo >> Gregos & Troianos Educacional >> http://www.gregosetroianos.mat.br >> MSN: cca_gregosetroianos@hotmail.com >> Belo Horizonte, MG, Brasil >> (31) 3283-1122 === Subject: help with no more memory at mathematica we have the next code in mathematica 6, when we use n = 200 we get the next error h = Import[h.dat]; v = Import[v.dat]; n = 200 MSE2 = Sum[(a[i - 1, j] - v[[i, j]] a[i, j])^2 + (a[i, j - 1] - h[[i, j]] a[i, j])^2, {i, 2, n}, {j, 2, n}] + Sum[(a[1, j - 1] - h[[1, j]] a[1, j])^2, {j, 2, n}] + Sum[(a[i - 1, 1] - v[[i, 1]] a[i, 1])^2, {i, 2, n}]; s1 = Table[Simplify[D[MSE2, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, 1, (n*n) - 1}]; s3 = SparseArray[ Table[Simplify[D[s1, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, 1, (n*n) - 1}]]; ar = ArrayRules[s3]; Export[matrix1.txt, ar]; b = SparseArray[Table[Simplify[-1*D[s1, a[1, 1]]]]]; b2 = ArrayRules[b];[B.txt, b2]; No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. How to solve? === Subject: Re: help with no more memory at mathematica > we have the next code in mathematica 6, when we use n = 200 we get > the next error > h = Import[h.dat]; v = Import[v.dat]; > n = 200 > MSE2 = > Sum[(a[i - 1, j] - v[[i, j]] a[i, j])^2 + (a[i, j - 1] - > h[[i, j]] a[i, j])^2, {i, 2, n}, {j, 2, n}] + > Sum[(a[1, j - 1] - h[[1, j]] a[1, j])^2, {j, 2, n}] + > Sum[(a[i - 1, 1] - v[[i, 1]] a[i, 1])^2, {i, 2, n}]; s1 = Table[Simplify[D[MSE2, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, > 1, (n*n) - 1}]; s3 = SparseArray[ > Table[Simplify[D[s1, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, > 1, (n*n) - 1}]]; > ar = ArrayRules[s3]; > Export[matrix1.txt, ar]; b = SparseArray[Table[Simplify[-1*D[s1, a[1, 1]]]]]; > b2 = ArrayRules[b];[B.txt, b2]; > No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. How to solve? You have not told us what is in the array 'a', or indeed in the two files the you import, so it is hard to answer this specifically. However, I would start by adding Print statements between each part of the calculation to see where this error happens. I suspect 'a' contains symbolic expressions and you are creating some horrendously complicated expressions that are using up the memory (it is awfully easy to do this with any symbolic algebra system). It might also help to describe what your code is meant to do. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: help with no more memory at mathematica > we have the next code in mathematica 6, when we use n = 200 we get > the next error > h = Import[h.dat]; v = Import[v.dat]; > n = 200 > MSE2 = > Sum[(a[i - 1, j] - v[[i, j]] a[i, j])^2 + (a[i, j - 1] - > h[[i, j]] a[i, j])^2, {i, 2, n}, {j, 2, n}] + > Sum[(a[1, j - 1] - h[[1, j]] a[1, j])^2, {j, 2, n}] + > Sum[(a[i - 1, 1] - v[[i, 1]] a[i, 1])^2, {i, 2, n}]; s1 = Table[Simplify[D[MSE2, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, > 1, (n*n) - 1}]; s3 = SparseArray[ > Table[Simplify[D[s1, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, > 1, (n*n) - 1}]]; > ar = ArrayRules[s3]; > Export[matrix1.txt, ar]; b = SparseArray[Table[Simplify[-1*D[s1, a[1, 1]]]]]; *Erroneous Code Above*: Either you do not want a table or Table is missing a counter. So you must choose between, b = SparseArray[Table[Simplify[-1*D[s1, a[1, 1]]], {Some_Counter} ]] or b = SparseArray[Simplify[-1*D[s1, a[1, 1]]]] > b2 = ArrayRules[b];[B.txt, b2]; ??? What [B.txt, b2] is supposed to do? As written it is a nonsense. Perhaps you had in mind Export[B.txt, b2]? > No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. How to solve? So, what do you try to compute? Could you post an example (or give a description) of h.dat and v.dat? The tests I have done (with own interpretation -- assumptions about -- the code you posted) shows that the matrices matrix1.txt and B.txt are dense (the files contain rules, but since there is a rule for each matrix entry, we can hardly claim that the matrices are sparse). Does this matches your own results? Module[{h, v, MSE2, s1, s3, sr, b2, a}, For[n = 10, n <= 400, n *= 2, Print[n: , n, , CPU: , Timing[ h = RandomReal[{0, n}, {n, n}]; v = RandomReal[{0, n}, {n, n}]; MSE2 = Sum[(a[i - 1, j] - v[[i, j]] a[i, j])^2 + (a[i, j - 1] - h[[i, j]] a[i, j])^2, {i, 2, n}, {j, 2, n}] + Sum[(a[1, j - 1] - h[[1, j]] a[1, j])^2, {j, 2, n}] + Sum[(a[i - 1, 1] - v[[i, 1]] a[i, 1])^2, {i, 2, n}]; s1 = Table[Simplify[D[MSE2, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, 1, (n*n) - 1}]; s3 = SparseArray[ Table[Simplify[D[s1, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i, 1, (n*n) - 1}]]; ar = ArrayRules[s3]; Export[matrix1_n <> ToString[n] <> .txt, ar]; b = SparseArray[Simplify[-1*D[s1, a[1, 1]]]]; b2 = ArrayRules[b]; Export[B_n <> ToString[n] <> .txt, b2];][[1]], s, Max mem used: , MaxMemoryUsed[]/2^20 // Round, MB, Mem in use: , MemoryInUse[]/2^20 // Round, MB]]] n: 10, CPU: 0.309607 s, Max mem used: 18 MB, Mem in use: 18 MB n: 20, CPU: 3.2838 s, Max mem used: 21 MB, Mem in use: 20 MB n: 40, CPU: 45.3366 s, Max mem used: 42 MB, Mem in use: 23 MB n: 80, CPU: 574.157 s, Max mem used: 345 MB, Mem in use: 37 MB [... I stopped the evaluation here ...] === Subject: Can not run Mathematica 6.0.3 on Fedora 9 I have just installed Mathematica 6.0.3 on Fedora 9, but when I start it, I get the following error: An error has occurred while Mathematica was starting up. Mathematica may not function properly until this problem is resolved. You may choose to continue anyway, but you could encounter additional problem. Any ideas? Paul === Subject: Re: Can not run Mathematica 6.0.3 on Fedora 9 I have just installed Mathematica 6.0.3 on Fedora 9, but when I start > it, I get the following error: An error has occurred while Mathematica was starting up. Mathematica > may not function properly until this problem is resolved. You may > choose to continue anyway, but you could encounter additional > problem. Any ideas? Paul I have the same problem, however, since I have several computers I checked that: 1) running Mathematica on the (x86_64) machine in a local X session dies 2) running math (the kernel only) in terminal local to the machine works 3) running Mathematica via remote ssh session from a fedora 5 box works! My suspicion is very much font/font-server related at the moment. FC9 has xfs off by default for some reason... cheers, .p. === Subject: Re: Can not run Mathematica 6.0.3 on Fedora 9 I have just installed Mathematica 6.0.3 on Fedora 9, but when I start > it, I get the following error: An error has occurred while Mathematica was starting up. Mathematica > may not function properly until this problem is resolved. You may > choose to continue anyway, but you could encounter additional > problem. Any ideas? > Paul Same here. It was working until I did yum update today.... === Subject: Re: Can not run Mathematica 6.0.3 on Fedora 9 > I have just installed Mathematica 6.0.3 onFedora9, but when I start > it, I get the following error: > An error has occurred while Mathematica was starting up. Mathematica > may not function properly until this problem is resolved. You may > choose to continue anyway, but you could encounter additional > problem. > Any ideas? > Paul > Same here. It was working until I did yum update today.... >Someone, meanwhile, has suggested to me to install >xorg-x11-fonts-ISO8859-1-75dpi-7.2-6.fc9.noarch >that solved the problem. >Paul The above fonts were needed, but no joy came from them alone: The following has done the trick: yum -y install xorg-x11-xfs-utils xorg-x11-xfs chkconfig --levels 345 xfs on cd /etc/X11/fontpath.d/ ln -s /usr/local/Wolfram/Mathematica/6.0/SystemFiles/Fonts/BDF mathematica-bdf ln -s /usr/local/Wolfram/Mathematica/6.0/SystemFiles/Fonts/Type1 mathematica-type1 ln -s /usr/local/Wolfram/Mathematica/6.0/SystemFiles/Fonts/TTF mathematica-ttf service xfs start Add a fontpath to the Files section of /etc/X11/xorg.conf, e.g., Section Files # Use a font server independent of the X server to render fonts. FontPath unix/:7100 EndSection restart X (reboot for those unsure of how to restart X as needed) then things worked. cheers, .p. === Subject: Re: Can not run Mathematica 6.0.3 on Fedora 9 > I have just installed Mathematica 6.0.3 onFedora9, but when I start > it, I get the following error: > An error has occurred while Mathematica was starting up. Mathematica > may not function properly until this problem is resolved. You may > choose to continue anyway, but you could encounter additional > problem. > Any ideas? > Paul Same here. It was working until I did yum update today.... It seems to be related to X and FC9. I have installations of mathematica 6.0 on i386 and x86_64 machines, of both fc5 and fc9 vintages. selinux is _disabled_ on all machines. displays without a problem. After an ssh login to the fc9 remote machine, mathematica can start and run normally with display on the mathematica works and displays on the local fc9 X display. Local running of mathematica on the fc9 machines is hooped (including - defaultvisual) and ssh to another fc9 machine does not either give a functional system. luck. .p. === Subject: Re: Can not run Mathematica 6.0.3 on Fedora 9 > I have just installed Mathematica 6.0.3 on Fedora 9, but when I start > it, I get the following error: > An error has occurred while Mathematica was starting up. Mathematica > may not function properly until this problem is resolved. You may > choose to continue anyway, but you could encounter additional > problem. > Any ideas? > Paul Same here. It was working until I did yum update today.... Someone, meanwhile, has suggested to me to install xorg-x11-fonts-ISO8859-1-75dpi-7.2-6.fc9.noarch that solved the problem. Paul === Subject: Re: Can not run Mathematica 6.0.3 on Fedora 9 > I have just installed Mathematica 6.0.3 on Fedora 9, but when I start > it, I get the following error: > An error has occurred while Mathematica was starting up. Mathematica > may not function properly until this problem is resolved. You may > choose to continue anyway, but you could encounter additional > problem. > Any ideas? Same here. It was working until I did yum update today.... Perhaps, Wolfram should use a more universal sort of gui, and pay more attention to the most popular Linux distributions like Fedora. Paul === Subject: Help with LeastSquares (v. 6) Howdy, Anyone know about what algorithm is used by LeastSquares, please help me? I know there is the option Method->Direct or IterativeRefinement, but I do not know what exactly is used by these methods. For example, does Method->IterativeRefinement use the damped least-square pseudo-inverse (i.e. Levenberg-Marquardt ?), or does it use one of the decomposition methods for solving linear systems of equations, etc... ? Where would I be able to get a more detailed description? ~Hoa Bui === Subject: Re: Using [Breve] as a substitute for underscore >In mathematica you cannot use underscore _ as part of a variable >name as you could in other computer languages. True >Has anyone tried using [Breve] as an underscore substitute instead. >for example: >mass[Breve]of[Breve]earth = 5.97*^24 >or >mass[esc]bv[esc]of[esc]bv[esc]earth = 5.97*^24 >What other characters do other people uses? My preference is for camel case, i.e., massOfEarth. Or more likely, I would have used earthMass. === Subject: Missing Posts Group - I have been notified that some posts have not been going out in the last week. I have done a search and found a number of them in posting these tonight and am very sorry for the delays. I believe I can avoid this particular problem from now on, but if you do not see your post after 24 hours, email me about it. Please do not send a second copy unless I suggest that so we can avoid duplicates. As I have said before, I never reject a valid post without letting the sender know why. So, if you don't see your post, it is because I did not get it - either because it just did not come to me or it got stuck Steve Christensen Moderator === Subject: Re: Colors in Plot[] You gave one style directive not two. This directive could include dashing or thickness as well as color. You are overriding the first color command within the single directive by issuing a second color command (i.e., it is the last color (or thickness or dashing) command that matters not the previous one(s)). It is interesting behavour and I do not understand the reason for this: g[x_, n_] := x^n Plot[g[x, 1], {x, 0, 1}] Plot[g[x, 1], {x, 0, 1}, PlotStyle -> {Red, Blue}] Plot[g[x, 1], {x, 0, 1}, PlotStyle -> {Red, Red}] Why the second plot is Blue but the third is Red? === Subject: Re: Method Option Bad Method messages: Cases[{#, ToExpression[# <> ::bdmtd]} & /@ Names[*], {_, _String}] // Column > A lot of build-in functions in Mathematica have the option Method. Usually > this is mentioned in the More Information section of the reference page. > Most of the time there is the statement Method->Automatic. > Take for example ContourPlot: > Method Automatic the method to use for refining contours > OK, but what other methods do I have then? Even though Method -> Automatic appears in the list generated by Options[ContourPlot], the option appears to be ignored. Otherwise, ContourPlot[x^2 + y^2, {x, -2, 2}, {y, -2, 2}, Method -> Bogus] would generate error messages. Actually, this is a good technique find possible options. Here's an example with NIntegrate: ----------------------------- Mathematica 6.0 for Mac OS X x86 (32-bit) Copyright 1988-2008 Wolfram Research, Inc. In[1]:= NIntegrate[x^2, {x,-2,2}, Method -> Bogus] NIntegrate::bdmtd: The Method option should be one of Automatic, CartesianRule, ClenshawCurtisRule, GaussBerntsenEspelidRule, GaussKronrodRule, LobattoKronrodRule, LobattoPeanoRule, MultiPanelRule, NewtonCotesRule, TrapezoidalRule, AdaptiveMonteCarlo, AdaptiveQuasiMonteCarlo, DoubleExponential, DuffyCoordinates, ExtrapolatingOscillatory, MonteCarlo, QuasiMonteCarlo, Trapezoidal, EvenOddSubdivision, SymbolicPiecewiseSubdivision, OscillatorySelection, UnitCubeRescaling, or a user-implemented integration strategy or rule. NIntegrate::nsr: Bogus is not a valid specification of an integration strategy or rule. 2 Out[1]= NIntegrate[x , {x, -2, 2}, Method -> Bogus] ------------------------------- You can find information on the method types by searching the documentation. I don't believe there is standard way to do this, though. I'd like to know a general technique to detect which method is selected when Method is set to Automatic. Mark McClure === Subject: Package conversion to V6 Is there a way to get Mathematica to give recommendations/hints when it reads in a package file created with an earlier version of -Bob === Subject: Re: Package conversion to V6 > Is there a way to get Mathematica to give recommendations/hints when > it reads in a package file created with an earlier version of -Bob This is a package I got off the internet and don't have the original notebook files that created this package. The package is from Roman Maeder's book Computer Science with Mathematica and was written about 1999 and there is no newer version on his website. So Bill's assumption was spot on about this being for a package I did not write. Has anyone converted his CSM package to work with version 6 and would -Bob === Subject: Re: Package conversion to V6 the marvelous Wolfram Workbench has an option to re factor the package source code. This should resolve the most problems. Jens > Is there a way to get Mathematica to give recommendations/hints when > it reads in a package file created with an earlier version of -Bob > === Subject: Re: How can I make the colored lines inside a Mathematica I have this problem with the plot as well as the legend. However, they are linked so just change the PlotStyle. Plot[{Sin[x], Cos[x]}, {x, -2 Pi, 2 Pi}, PlotStyle -> AbsoluteThickness[2], PlotLegend -> {Sine, Cosine}] How can I change the thickness of colored lines inside a Mathematica legend? The default thickness that I am getting makes them barely visible, and hence makes it difficult to associate different colred curves with their labels in the legend. I checked the documentation for Graphics`Legend`, but didn't find options for the thickness of lines inside the legend. Any suggestions? === Subject: Re: as a substitute for underscore Nice! But... is it such a good idea to use a name including [LetterSpace] in code? The underscore is printed faintly, so it's easy = to mistake the parts of the symbol as separate symbols -- and hence mistake the entire thing as a product of two things. > Steven, One of the new small things in Mathematica 6 (so it seems) is the non-p= rinting character [LetterSpace]. The alias is Esc_Esc (Esc underscore Es= c). Try this (on diferent Input cells): x[LetterSpace]y x[LetterSpace]y//Head x[LetterSpace]y=1 x[LetterSpace]y+1 Clear[x[LetterSpace]y] Hope this might help you in some way. Carlos C=E9sar de Ara=FAjo > Gregos & Troianos Educacional > http://www.gregosetroianos.mat.br > MSN: cca_gregosetroianos@hotmail.com > Belo Horizonte, MG, Brasil > (31) 3283-1122 -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Incoherent value for partial derivative Let In[1]: g[x_]:=3x^2+5x; FullForm[g'[x]] Out[1]: Plus[5,Times[6,x]] In[2]: g'[2] Out[2]: 17 Mathematica works fine and the result is correct. First, it executes the derivation and then the delayed substitution/assignation. But for partial derivative Mathematica works different way (not correspondig to FullForm In[3]: f[x_,y_]:=x^2+x y^2; FullForm[!( *SubscriptBox[([PartialD]), (x)] (f[x, y]))] Out[3]: Plus[Times[2,x],Power[y,2]] In[4]: !( *SubscriptBox[([PartialD]), (x)] (f[1, 2])) Out[4]: 0 I dont understand the reason. === Subject: Re: Incoherent value for partial derivative > Let In[1]: g[x_]:=3x^2+5x; > FullForm[g'[x]] Out[1]: Plus[5,Times[6,x]] In[2]: g'[2] > Out[2]: 17 Mathematica works fine and the result is correct. First, it executes > the derivation and then the delayed substitution/assignation. But for > partial derivative Mathematica works different way (not correspondig > to FullForm In[3]: f[x_,y_]:=x^2+x y^2; > FullForm[!( > *SubscriptBox[([PartialD]), (x)] (f[x, y]))] Out[3]: Plus[Times[2,x],Power[y,2]] In[4]: !( > *SubscriptBox[([PartialD]), (x)] (f[1, 2])) > Out[4]: 0 I dont understand the reason. Others have answered your question, but there is something that might make clearer what the reason for this might be, at least as far as I can tell: g' is just a short notation for Derivative[1][g] which, as others have mentioned, works correctly if there are suitable definitions for g even without arguments given. The same is true for the more general forms of Derivative, e.g. Derivative[0,1][f], for which there is also a nice notation in StandardForm, which you can generate by evaluating it for an f with no definition. The reason why it works (and can work) is because both notations implicitly work by positional arguments. On the other hand D[f[x,y],y] and the nicer looking StandardForm-Notation with [PartialD] you have used work with the names of the arguments, and of course can only work correctly when arguments are given. To my understanding this is the deeper reason why g'[x] and !(*SubscriptBox[([PartialD]), (x)] (f[x, y])) behave so differently. hth, albert This will create the Standard-Form Notation for Derivative[1,0][f] if evaluated in a notebook: SuperscriptBox[f, TagBox[ RowBox[{(, RowBox[{1, ,, 0}], )}], Derivative ]] // DisplayForm === Subject: Re: Incoherent value for partial derivative > Let In[1]: g[x_]:=3x^2+5x; > FullForm[g'[x]] Out[1]: Plus[5,Times[6,x]] In[2]: g'[2] > Out[2]: 17 Mathematica works fine and the result is correct. First, it executes > the derivation and then the delayed substitution/assignation. This is true only for the *special* form g'[2]. If you use D[g[2],x], you get similar result and behavior as for D[f[1,2],x]. The operator D always evaluates its arguments in the same and consistent way, regardless of the name and number of variables. However, the ' (prime) form is a special form that does *not* evaluate its argument as the operator D does. (And prime works only for a function of one variable.) In other words, the ' (prime) form and the operator D form are *not* equivalent and they are not interchangeable without care. In[1]:= g[x_] := 3 x^2 + 5 x; g'[2] // Trace D[g[2], x] // Trace Out[2]= 2 2 {{g', {g[#1], 3 #1 + 5 #1, 5 #1 + 3 #1 }, 5 + 6 #1 & }, (5 + 6 #1 & )[2], 5 + 6 2, {6 2, 12}, 5 + 12, 17} Out[3]= 2 2 {{g[2], 3 2 + 5 2, {{2 , 4}, 3 4, 12}, {5 2, 10}, 12 + 10, 22}, D[22, x], 0} As we can see above, the ' (prime) form first the function into an pure function and takes its first derivative, then applies the resulting pure function to the numeric value (2) passed as argument of the original function. On the other hand, the operator D first evaluates its argument, which yields a numeric value, i.e. a constant, and since the derivative of a constant with respect to whatever variable is zero, the result is zero. > But for > partial derivative Mathematica works different way (not correspondig > to FullForm FullForm is irrelevant here: what matters is when the arguments are evaluated and how they are transformed before before applying numeric value. Trace is more appropriate to visualize what is going on. You can see the the reasoning (and behavior) is similar to what we did above. In[4]:= f[x_, y_] := x^2 + x y^2; FullForm[D [f[x, y], x]] D[f[1, 2], x] // Trace Out[5]//FullForm= Plus[Times[2, x], Power[y, 2]] Out[6]= 2 2 2 2 {{f[1, 2], 1 + 1 2 , {1 , 1}, {{2 , 4}, 1 4, 4}, 1 + 4, 5}, D[5, x], 0} > In[3]: f[x_,y_]:=x^2+x y^2; > FullForm[!( > *SubscriptBox[([PartialD]), (x)] (f[x, y]))] Out[3]: Plus[Times[2,x],Power[y,2]] In[4]: !( > *SubscriptBox[([PartialD]), (x)] (f[1, 2])) > Out[4]: 0 I dont understand the reason. Hope this helps, === Subject: Re: When is a List not a List You should Evaluate before plotting soln = x /. Solve[x^2 + x - 1/Sqrt[x + a] == 1, x]; Reduce[soln[[2]] > soln[[1]], a, Reals][[2]] // N a>2.55171 Plot[soln, {a, 2, 4}, Exclusions -> 2.55171, Frame -> True, Axes -> False, PlotStyle -> { {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Gray}, {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Green}, {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Blue}, {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Brown}, {AbsoluteThickness[2], AbsoluteDashing[{10, 10}], Red}}] Plot[Evaluate[x /. Solve[x^2 + x - 1/Sqrt[x + a] == 1, x]], {a, 2, 4}, Exclusions -> 2.55171, Frame -> True, Axes -> False, PlotStyle -> { {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Gray}, {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Green}, {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Blue}, {AbsoluteThickness[2], AbsoluteDashing[{7, 7}], Brown}, {AbsoluteThickness[2], AbsoluteDashing[{10, 10}], Red}}] By the by, should all three branches in the following have the same color (and style, if styles were specified)? Plot[x /. Solve[x^2 + x - 1/Sqrt[x + a] == 1, x], {a, 2, 4}] In this case Solve gives FIVE solutions: Solve[x^2 + x - 1/Sqrt[x + a] == 1, x] {{x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 1]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 2]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 3]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 4]}, {x -> Root[-1 + a + (1 - 2 a) #1 + (-2 - a) #1^2 + (-1 + 2 a) #1^3 + (2 + a) #1^4 + #1^5 &, 5]}} However: Cases[Plot[ x /. Solve[x^2 + x - 1/Sqrt[x + a] == 1, x], {a, 2.5, 2.7}], _Line, Infinity] // Length 3 There are three lines; there's no reason Plot could not assign colors and styles to them. (Although, perhaps, we couldn't know which branches would match which colors, a priori.) Bobby > Just in case I have not made my point clearly enough, I suggest > pondering over the difference between: > Plot[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x], {a, -1, 3}] and Plot[Evaluate[x /. Solve[x^3 + x - 1/Sqrt[x + a] == 1, x]], {a, -1, 3}] > The second graph uses three colors, just as you and AES would have > wished, but unfortunately there is a slight problem with it :it is quite > wrong. Understanding a bit of mathematics often helps to understand Mathematica. > Andrzej Kozlowski >> Because there are lots of plots of the kind which I just sent (Plot[x >> /. Solve[x^3 - 3 x^2 + a == 0, x], {a, -3, 5}]) but where you have >> FindRoot or NMaximize etc., instead of Solve and the first argument >> can't be evaluated until the value of the parameter a has been >> supplied. There have been lots of post of this kind on this forum so >> its kind if weird you managed to miss them all. >> Andrzej Kozlowski > Agreed. >> And I'm wondering what advantage HoldAll has, in the case of Plot, > since a plot can't result without evaluating the arguments? >> Why NOT evaluate the first argument, at least, before making style > decisions/assignments? >> The defense that everybody already knows this is irrelevant to the > question of how we'd LIKE Plot to behave. >> Naturally, we won't necessarily GET what we want... but we're entitled > to say what that is. >> I'm trying to think how David Park's Presentations package handles > such things. >> Bobby > Plot COULD assign colors after evaluation, OTOH... the fact that it > doesn't is a design choice/artifact, not a necessity preordained by > fate. >> That being so, users are entitled to find it odd at first glance. > (Or even second... maybe third.) >> If the above is true -- and I'd suppose it is -- then I'd say it's >> also very much an unfortunate, not to say flat-out *bad* design >> choice or artifact. >> An innocent novice-level user creates a Plot[ ] with three curves >> using the {f1, f2, f3} List form of the first argument, and discovers >> that M by default assigns a different color to each curve -- a good >> and helpful default design choice on M's part, I'd say. >> Maybe this novice user wants to go a bit further: Thicken certain >> curves, change the Dashing, and so on. He or she discovers the >> PlotStyle option (or equivalent); learns how to do this; is happy. >> And then this user also realizes: Hey, I could plot 8 or 10 curves >> this way, without having to type in f1 thru f8 by just using a Table[ >> ] command for the first argument and iterating over some appropriate >> parameter. A Table[ ] creates a List, right? >> So he/she does this; the 8 or 10 curves appear exactly as desired; >> except the styling behavior is suddenly all screwed up. Once again, >> a classic M-style Gotcha!!! -- and a particularly nasty Gotcha: Am I >> getting this unwanted result because of the way I structured the >> PlotStyle commands I used? -- or because of something mysterious with >> using Table[ ]? The coloring and so on in the default {f1, f2, f3} >> case has the nice default cycling behavior for the styling -- Why am >> I not getting it now? >> Andrzej says this unfortunate result _has_ to be the case because >> Plot[ ] doesn't pre-Evaluate the first argument. >> Well, somehow, if the first argument is {f1, f2, f3, f4, f5, f6, f7, >> f8}, Plot[ ] somehow pre-evaluates (lower-case pre-evaluate) this >> argument at least enough to know that it's not only a List, but how >> many elements that List has. Is it somehow impossible for Plot[ ] to >> know that Table will also produce a List, and to similarly >> pre-evaluate how many elements that List will have? I suspect it's >> not impossible. >> And if that is indeed impossible with the PlotStyle option in Plot[ ] >> then can Andrzej explain how it _is _ possible for Plot[ ] to >> somehow handle the PlotRange->All option correctly (i.e., >> identically) with either form of the first argument -- even though >> that option needs to determine not only the number of curves in the >> first argument, but the maximum and minimum values over all those >> curves, in order to set the axes and axis Tick locations and values >> for the plot. Is just getting the number of curves and picking the >> colors for them really harder than that? >> I very much like DrMajorBob's wording here: I'll bet the coloring >> problem with List vs Table is precisely an [accidental] design >> choice/artifact, not a necessity preordained by fate -- and an >> unfortunately unfortunate design choice/artifact. >> The only things more unfortunate are (a) that M has a fair (and >> increasing?) number of these Gotchas; (b) M's documentation is >> substantially less helpful than it could or should be either in >> diagnosing or in warning about them; and (c) it's far from clear that >> anyone at WRI really recognizes these points. >> --DrMajorBob@longhorns.com > > -- DrMajorBob@longhorns.com === Subject: Derivative of Dot[] I would like to compute the gradient F' of a scalar-valued function F of a vector-valued argument, without knowing a-priori the dimensions of the vector. I am having some trouble with a very simple case. Consider the following function: F[x_] := Dot[x,x] Evaluating this function works as expected: F[{1,2}] evaluates to 5. I differentiate this function w.r.t. its sole argument, F' evaluates to 1.#1+#1.1& This is reasonable, and as expected. I would think that, since the argument of Dot must be a list, the derivative of Dot would have been designed to return something that is useful. While I presume that this is the case, I have been unable to move ahead. I evaluate the derivative at {1,2}: F'[{1, 2}] returns 1.{1,2}+{1,2}.1 The Dot is not defined for scalar arguments, and therefore Simplify does not reduce this further. I could of course program a rule so that Dot[1,x_]->x, but my intent here is to understand why the derivative of Dot was designed the way it was---presumably there is a reason, and there is a proper way to make use of the derivative. Once I have the derivative, I should be able to contract it with a (tangent) vector to obtain the (linearized) change the (scalar) function value: F'[{1, 2}].{3,4} Alas, this returns (1.{1,2}+{1,2}.1).{3,4} which does not simplify (even after Distribute) because Dot does not operate on scalar arguments. I'd like some help in understanding how to use Derivative with Dot (it was evidently designed to be used, or there would not be a rule built in). Eitan === Subject: Re: Derivative of Dot[] > I think the rule for D[X[t] . Y[t], t] is necessary, rather than > useful. Compare these two In[1]:= D[Dot[X[t] , Y[t]], t] > Out[1]= X[t] . Derivative[1][Y][t] + Derivative[1][X][t] . Y[t] In[2]:= D[dot[X[t], Y[t]], t] > Out[2]= Derivative[1][Y][t]*Derivative[0, 1][dot][X[t], > Y[t]] + Derivative[1][X][t]*Derivative[1, 0][dot][ > X[t], Y[t]] If there was no built-in rule for D and Dot, then exactly the same > thing that happens for dot would happen for Dot, which would be > somewhat less convenient (you would need to define Derivative[1, 0] > [Dot] and Derivative[0, 1][Dot] yourself). > Other than that, I do not know of any obvious application. Note > however, that Derivative is always first converted to D[ ], so any > rules that are applied to Derivative and Dot are actually derived from > rules for D and Dot. I don't see any direct use for them and actually > I think they are basically an slightly unfortunate side effect. If I understand correctly, what you are saying is that if Dot' had not been defined, I would have to do the work of defining it. What I am saying is that the way it is defined, it does not seem to be useful, and I am assuming that this means that I am misunderstanding something (i.e., that it must have a useful definition). As far as I can see, Dot' = #1.1 + 1.#1& is useful iff 1 is interpreted as the identity map, and not useful if 1 is a scalar (which mathematica refuses to treat as the identity map). I could write rules/patterns to manipulate this, but I was assuming that the developers had something in mind. Eitan === Subject: Re: Derivative of Dot[] >>I differentiate this function w.r.t. its sole argument, F' evaluates >>to 1.#1+#1.1& >This is reasonable, and as expected. Expected yes given the way the form F' works, but reasonable? A > dot product of vector and any other vector is a scalar. If you > give specific values for the vector components, I would think it > would be reasonable to return a value zero. Further, the > gradient of a vector isn't given by the derivative of the dot > product. Instead, it is the sum of partial derivatives of each > component with respect to the corresponding basis function. That > is the gradient of vector {x, y w, z^2} is given by In[27]:= Tr@D[{x, y w, z^2}, {{x, y, z}}] Out[27]= w+2 z+1 I would say that the derivative of x.x with respect to some other vector y is given by 2x.(dx/dy), where dx/dy is a tensor. When mathematica returns 1.#1+#1.1&, it is reasonable if the 1 is interpreted as the identity map, so that, e.g., (#1.1&)[x].(dx/dy)=x.1.(dx/dy)=x.(dx/dy). Unfortunately, x.1 does not simplify to x, as it would if 1 were interpreted as the identity map. Eitan === Subject: Re: Derivative of Dot[] > I differentiate this function w.r.t. its sole argument, F' evaluates > to 1.#1+#1.1& > This is reasonable, and as expected. >> Expected yes given the way the form F' works, but reasonable? A >> dot product of vector and any other vector is a scalar. If you >> give specific values for the vector components, I would think it >> would be reasonable to return a value zero. Further, the >> gradient of a vector isn't given by the derivative of the dot >> product. Instead, it is the sum of partial derivatives of each >> component with respect to the corresponding basis function. That >> is the gradient of vector {x, y w, z^2} is given by >> In[27]:= Tr@D[{x, y w, z^2}, {{x, y, z}}] >> Out[27]= w+2 z+1 I would say that the derivative of x.x with respect to some other > vector y is given by 2x.(dx/dy), where dx/dy is a tensor. When > mathematica returns 1.#1+#1.1&, it is reasonable if the 1 is > interpreted as the identity map, so that, e.g., > (#1.1&)[x].(dx/dy)=x.1.(dx/dy)=x.(dx/dy). Unfortunately, x.1 does not > simplify to x, as it would if 1 were interpreted as the identity map. Eitan > Forgetting for a moment what may or may not be reasonable, the best way to pursue such calculations is to define your own grad (say) operation. If it is going to operate on mixed scalar/vector expressions where the vectors are just symbols, you will have to provide a method by which your code can identify vectors - say: isVector[x_]:=MemberQ[{v1,v2,v3},x]; isVector[_]:=False; David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Derivative of Dot[] > Consider the following function: >> F[x_] := Dot[x,x] >> Evaluating this function works as expected: F[{1,2}] evaluates to 5. >> I differentiate this function w.r.t. its sole argument, F' evaluates > to 1.#1+#1.1& >> This is reasonable, and as expected. I would think that, since the >> The above expression make sense only for one dimensional vectors, say on >> the real line; in other words, a vector space where the unit vector is >> {1} and any vector {x} has only one component x. Why? Even of a vector {x}, the resulting derivative cannot be > evaluated successfully: (1.#1+#1.1&)[{x}] does not simplify (the 1. > remains). Oops! You are right, of course. (I was too fast to answer did not spot that the dot was for the dot product and not associated with the ones (1.) as floating-point numbers (and so there was no implicit multiplication)! Sorry for any confusion. >> You may want to write you own differentiating function such as the >> following: Note that I missed the point that you wanted to compute the gradient. As pointed out by Bill Rowe, the derivative of the dot product is not the gradient. So beware that the function I gave you in example differentiates a dot product but does not compute the gradient. > I have done so before; but the question is what is the intended use of > the built in derivative of Dot? I can't find one. I believe that Andrzej Kozlowski's replies (note that there are two of them) clearly explain how the derivative of the dot product is derived the way it is, as well as the rational behind it. Be sure to read both of them if you have not done so yet. - Jean-Marc > Eitan > In[1]:= >> SetAttributes[myDiff, HoldFirst] >> myDiff[fun_[x_?VectorQ]] := >> Module[{v = Array[a, Length[x]]}, >> D[fun[v], {v}] /. Thread[v -> x]] >> f[x_?VectorQ] := Dot[x, x] >> myDiff[f[{1, 2}]] >> myDiff[f[{1, 2}]].{3, 4} >> g[y_] := 2 f[y] >> myDiff[g[{1, 2}]] >> myDiff[g[{1, 2}]].{3, 4} >> Out[4]= {2, 4} >> Out[5]= 22 >> Out[7]= {4, 8} >> Out[8]= 44 === Subject: Re: Derivative of Dot[] >> Consider the following function: >> F[x_] := Dot[x,x] >> Evaluating this function works as expected: F[{1,2}] evaluates to 5. >> I differentiate this function w.r.t. its sole argument, F' evaluates >> to 1.#1+#1.1& >> This is reasonable, and as expected. I would think that, since the The above expression make sense only for one dimensional vectors, say on > the real line; in other words, a vector space where the unit vector is > {1} and any vector {x} has only one component x. Why? Even of a vector {x}, the resulting derivative cannot be evaluated successfully: (1.#1+#1.1&)[{x}] does not simplify (the 1. remains). > You may want to write you own differentiating function such as the > following: I have done so before; but the question is what is the intended use of the built in derivative of Dot? I can't find one. Eitan In[1]:= > SetAttributes[myDiff, HoldFirst] > myDiff[fun_[x_?VectorQ]] := > Module[{v = Array[a, Length[x]]}, > D[fun[v], {v}] /. Thread[v -> x]] f[x_?VectorQ] := Dot[x, x] > myDiff[f[{1, 2}]] > myDiff[f[{1, 2}]].{3, 4} g[y_] := 2 f[y] > myDiff[g[{1, 2}]] > myDiff[g[{1, 2}]].{3, 4} Out[4]= {2, 4} Out[5]= 22 Out[7]= {4, 8} Out[8]= 44 === Subject: Re: Derivative of Dot[] I think the rule for D[X[t] . Y[t], t] is necessary, rather than useful. Compare these two In[1]:= D[Dot[X[t] , Y[t]], t] Out[1]= X[t] . Derivative[1][Y][t] + Derivative[1][X][t] . Y[t] In[2]:= D[dot[X[t], Y[t]], t] Out[2]= Derivative[1][Y][t]*Derivative[0, 1][dot][X[t], Y[t]] + Derivative[1][X][t]*Derivative[1, 0][dot][ X[t], Y[t]] If there was no built-in rule for D and Dot, then exactly the same thing that happens for dot would happen for Dot, which would be somewhat less convenient (you would need to define Derivative[1, 0] [Dot] and Derivative[0, 1][Dot] yourself). Other than that, I do not know of any obvious application. Note however, that Derivative is always first converted to D[ ], so any rules that are applied to Derivative and Dot are actually derived from rules for D and Dot. I don't see any direct use for them and actually I think they are basically an slightly unfortunate side effect. Andrzej Kozlowski > I agree with what you write, and I am aware of this. But: can you show > me one actually effective use of Derivative applied to Dot (anything > of your choice). In particular, I mean one where the arguments are not > explicitly labeled, i.e., using Derivative or prime, but not using D. I cannot find one useful example, the way it is set up. > Eitan >> I would like to compute the gradient F' of a scalar-valued > function F > of a vector-valued argument, without knowing a-priori the dimensions > of the vector. >> I am having some trouble with a very simple case. >> Consider the following function: >> F[x_] := Dot[x,x] >> Evaluating this function works as expected: F[{1,2}] evaluates to 5. >> I differentiate this function w.r.t. its sole argument, F' evaluates > to 1.#1+#1.1& >> This is reasonable, and as expected. I would think that, since the > argument of Dot must be a list, the derivative of Dot would have > been > designed to return something that is useful. While I presume that > this > is the case, I have been unable to move ahead. >> I evaluate the derivative at {1,2}: F'[{1, 2}] returns 1. > {1,2}+{1,2}.1 >> The Dot is not defined for scalar arguments, and therefore Simplify > does not reduce this further. I could of course program a rule so > that > Dot[1,x_]->x, but my intent here is to understand why the derivative > of Dot was designed the way it was---presumably there is a reason, > and > there is a proper way to make use of the derivative. >> Once I have the derivative, I should be able to contract it with a > (tangent) vector to obtain the (linearized) change the (scalar) > function value: >> F'[{1, 2}].{3,4} >> Alas, this returns (1.{1,2}+{1,2}.1).{3,4} which does not simplify > (even after Distribute) because Dot does not operate on scalar > arguments. >> I'd like some help in understanding how to use Derivative with Dot > (it > was evidently designed to be used, or there would not be a rule > built > in). > Eitan > The problem is that you are deriving wrong conclusion (that the >> formula you >> get must have some meaning) from a correct premise (that >> Mathematica has >> some meaningful buil-in rules for differentiating Dot). The built >> in rule >> is: >> D[X[t] . Y[t], t] >> X[t] . Derivative[1][Y][t] + Derivative[1][X][t] . Y[t] >> where of course X[t] and Y[t] should be vectors of the same dimension >> dependent on t. It is not valid for scalars. But what you are doing >> in >> effect is defining: >> X[t] := t; Y[t_] = t; >> and then getting >> D[X[t] . Y[t], t] >> 1 . t + t . 1 >> which is meaningless since X[t] and Y[t] cannot be scalars. >> Andrzej Kozlowski >> === Subject: Re: Derivative of Dot[] > I would like to compute the gradient F' of a scalar-valued function F > of a vector-valued argument, without knowing a-priori the dimensions > of the vector. I am having some trouble with a very simple case. Consider the following function: F[x_] := Dot[x,x] Evaluating this function works as expected: F[{1,2}] evaluates to 5. I differentiate this function w.r.t. its sole argument, F' evaluates > to 1.#1+#1.1& This is reasonable, and as expected. I would think that, since the > argument of Dot must be a list, the derivative of Dot would have been > designed to return something that is useful. While I presume that this > is the case, I have been unable to move ahead. I evaluate the derivative at {1,2}: F'[{1, 2}] returns 1.{1,2}+{1,2}.1 The Dot is not defined for scalar arguments, and therefore Simplify > does not reduce this further. I could of course program a rule so that > Dot[1,x_]->x, but my intent here is to understand why the derivative > of Dot was designed the way it was---presumably there is a reason, and > there is a proper way to make use of the derivative. Once I have the derivative, I should be able to contract it with a > (tangent) vector to obtain the (linearized) change the (scalar) > function value: F'[{1, 2}].{3,4} Alas, this returns (1.{1,2}+{1,2}.1).{3,4} which does not simplify > (even after Distribute) because Dot does not operate on scalar > arguments. I'd like some help in understanding how to use Derivative with Dot (it > was evidently designed to be used, or there would not be a rule built > in). > Eitan > The problem is that you are deriving wrong conclusion (that the formula you get must have some meaning) from a correct premise (that Mathematica has some meaningful buil-in rules for differentiating Dot). The built in rule is: D[X[t] . Y[t], t] X[t] . Derivative[1][Y][t] + Derivative[1][X][t] . Y[t] where of course X[t] and Y[t] should be vectors of the same dimension dependent on t. It is not valid for scalars. But what you are doing in effect is defining: X[t] := t; Y[t_] = t; and then getting D[X[t] . Y[t], t] 1 . t + t . 1 which is meaningless since X[t] and Y[t] cannot be scalars. Andrzej Kozlowski === Subject: Re: Derivative of Dot[] > I would like to compute the gradient F' of a scalar-valued function F > of a vector-valued argument, without knowing a-priori the dimensions > of the vector. I am having some trouble with a very simple case. Consider the following function: F[x_] := Dot[x,x] Evaluating this function works as expected: F[{1,2}] evaluates to 5. I differentiate this function w.r.t. its sole argument, F' evaluates > to 1.#1+#1.1& This is reasonable, and as expected. I would think that, since the The above expression make sense only for one dimensional vectors, say on the real line; in other words, a vector space where the unit vector is {1} and any vector {x} has only one component x. Also, keep in mind that Mathematica does not have the notion of vector. Vectors, in the mathematical sense, are represented by one dimensional lists in Mathematica. (Note that there is no explicit notion of row or column vectors.) the syntactic level. For instance, exact -- infinite precision -- zero times a string returns zero, while multiplying floating-point zero by a string returns unevaluated. In[1]:= 0*Infinity During evaluation of In[1]:= [Infinity]::indet: Indeterminate expression 0 [Infinity] encountered. >> Out[1]= Indeterminate In[2]:= 0*Infinity Out[2]= 0 In[3]:= 0.*Infinity Out[3]= 0. Infinity > argument of Dot must be a list, the derivative of Dot would have been > designed to return something that is useful. While I presume that this > is the case, I have been unable to move ahead. I evaluate the derivative at {1,2}: F'[{1, 2}] returns 1.{1,2}+{1,2}.1 The Dot is not defined for scalar arguments, and therefore Simplify > does not reduce this further. I could of course program a rule so that > Dot[1,x_]->x, but my intent here is to understand why the derivative > of Dot was designed the way it was---presumably there is a reason, and > there is a proper way to make use of the derivative. Once I have the derivative, I should be able to contract it with a > (tangent) vector to obtain the (linearized) change the (scalar) > function value: F'[{1, 2}].{3,4} Alas, this returns (1.{1,2}+{1,2}.1).{3,4} which does not simplify > (even after Distribute) because Dot does not operate on scalar > arguments. I'd like some help in understanding how to use Derivative with Dot (it > was evidently designed to be used, or there would not be a rule built > in). You may want to write you own differentiating function such as the following: In[1]:= SetAttributes[myDiff, HoldFirst] myDiff[fun_[x_?VectorQ]] := Module[{v = Array[a, Length[x]]}, D[fun[v], {v}] /. Thread[v -> x]] f[x_?VectorQ] := Dot[x, x] myDiff[f[{1, 2}]] myDiff[f[{1, 2}]].{3, 4} g[y_] := 2 f[y] myDiff[g[{1, 2}]] myDiff[g[{1, 2}]].{3, 4} Out[4]= {2, 4} Out[5]= 22 Out[7]= {4, 8} Out[8]= 44 === Subject: GPU vs CPU in Mathematica 6 Is it possible, or has anyone already tried, to use the GPU processing instead of the CPU in Mathematica 6? I ask this question in particular for these new graphic boards (Nvidia series 8x) http://en.wikipedia.org/wiki/Comparison_of_Nvidia_Graphics_Processing_Units# GeForce_8_series It should be advantageous to exploit the parallel processing capabilities of the GPU. Any hint as to access these Graphics functions via Mathematica? Antonio === Subject: Re: GPU vs CPU in Mathematica 6 here is a CUDA example that make a 1d Fourier transform TEMPLATE CODE BEGIN-------------------------------------- #include #include #include #include #include mathlink.h #include cuda.h #include cufft.h #include cutil.h typedef float2 Complex; :Begin: :Function: cuFourier1d :Pattern: cuFourier1d[forwardQ_Integer,data:{__?NumericQ}] :Arguments: {forwardQ,data} :ArgumentTypes: {Integer,RealList} :ReturnType:Manual :End: void cuFourier1d(int forwardQ,double *data, long n) { cufftHandle plan; Complex *signal; cufftComplex *fftData; long i; float norm=sqrt((float) n); int mem_size = sizeof(Complex) * n; norm=1.0/norm; signal=(Complex*)malloc(sizeof(Complex) * n); for(i=0; i instead of the CPU in Mathematica 6? I ask this question in particular for these new graphic boards (Nvidia > series 8x) > http://en.wikipedia.org/wiki/Comparison_of_Nvidia_Graphics_Processing_Units#G eForce_8_series It should be advantageous to exploit the parallel processing > capabilities of the GPU. Any hint as to access these Graphics > functions via Mathematica? Antonio > === Subject: Re: GPU vs CPU in Mathematica 6 write a CUDA program + the MathLink templates, preprocess it with mprep and compile the output with nvcc. Install it in a Mathematica session and you are done ... But keep in mind, that if you can only parallelize 50 % of your code, than an infinite number of processors will speed up you calculation only by a factor of 2. Jens Is it possible, or has anyone already tried, to use the GPU processing > instead of the CPU in Mathematica 6? I ask this question in particular for these new graphic boards (Nvidia > series 8x) > http://en.wikipedia.org/wiki/Comparison_of_Nvidia_Graphics_Processing_Units#G eForce_8_series It should be advantageous to exploit the parallel processing > capabilities of the GPU. Any hint as to access these Graphics > functions via Mathematica? Antonio > === Subject: New spherical functions not efficient When using the new built-in spherical functions (SphericalBesselJ and SphericalHankelH1, my mathematica programs slowed quit a bit. Writting out the following code: In[1]:= Do[y=RandomReal[{0,10}];n=RandomInteger[{1,20}];Sqrt[(y [Pi])/2](BesselJ[n+1/2,y]+[ImaginaryI] BesselY[n+1/2,y]),{20000}]//Timing Do[y=RandomReal[{0,10}];n=RandomInteger[{1,20}];y SphericalHankelH1[n,y],{20000}]//Timing Out[1]= {0.951,Null} Out[2]= {2.823,Null} We can see that the new functions are slower to evaluate. Is something wrong? For now I will stick with the faster code for the spherical functions. Antonio === Subject: How to get objects closer to each other in a Graphics Grid? In the following code, what option would be equivalent to zooming in by about a factor of 1.2 so that the elements in the grid are tighter to each other? That would require clipping the bounding box. Changing R doesn't work since it actually clips the circles. The circles must remain to scale, so I am only looking for tightness in the last line. Aaron PlotEquilibriumConfiguration[ [CapitalPsi]_, [CapitalSigma]_, [CapitalPi]_, n_] := ( RhoN = BesselJZero[0, n]; Gn = ((RhoN^2 [CapitalPsi])/([Pi] [CapitalSigma]))^(1/3); a = ([CapitalPi] Gn)/[CapitalSigma]; f[a_, y_] = y^4 - y - a; ySol = y /. FindRoot[(f[A, y] /. A -> a) == 0, {y, 4}, MaxIterations -> 1000]; G = Gn/ySol; R = 3.3; circle = ParametricPlot3D[{G Cos[x], G Sin[x], 0}, {x, 0, 2 Pi}, Axes -> None, Boxed -> False, PlotRange -> {{-R, R}, {-R, R}} ]; Show[circle] ); grid = GraphicsGrid[ Table[PlotEquilibriumConfiguration[1, 1, P, n], {n, 1, 3}, {P, {-.1, 0, .1}}]] === Subject: Re: How to get objects closer to each other in a Graphics Grid? Hi Aaron, the problem is that the invisible BoundingBox takes too much space because of the view point. If you change this, you may improve. E.g.: Show[circle, ViewPoint -> {0, 0, 10}] hope this helps, In the following code, what option would be equivalent to zooming in > by about a factor of 1.2 so that the elements in the grid are tighter > to each other? That would require clipping the bounding box. Changing > R doesn't work since it actually clips the circles. The circles must > remain to scale, so I am only looking for tightness in the last line. > Aaron PlotEquilibriumConfiguration[ [CapitalPsi]_, [CapitalSigma]_, > [CapitalPi]_, n_] := ( > RhoN = BesselJZero[0, n]; > Gn = ((RhoN^2 [CapitalPsi])/([Pi] [CapitalSigma]))^(1/3); > a = ([CapitalPi] Gn)/[CapitalSigma]; > f[a_, y_] = y^4 - y - a; > ySol = > y /. FindRoot[(f[A, y] /. A -> a) == 0, {y, 4}, > MaxIterations -> 1000]; > G = Gn/ySol; > R = 3.3; > circle = ParametricPlot3D[{G Cos[x], G Sin[x], 0}, {x, 0, 2 Pi}, > Axes -> None, > Boxed -> False, > PlotRange -> {{-R, R}, {-R, R}} > ]; Show[circle] > ); > grid = GraphicsGrid[ > Table[PlotEquilibriumConfiguration[1, 1, P, n], {n, 1, > 3}, {P, {-.1, 0, .1}}]] > -- === Subject: Re: How to get objects closer to each other in a Graphics Grid? can you post code that is *working* so that we can see what you mean ?? May dta = Table[ Graphics[If[EvenQ[i], Disk[{0, 0}, 1], Circle[{0, 0}, 1]]], {i, 1, 9}]; Manipulate[ GraphicsGrid[Partition[dta, 3], Spacings -> {Scaled[a], Scaled[b]}], {{a, 0}, -1, 1}, {{b, 0}, -1, 1}] solve your problem? Jens In the following code, what option would be equivalent to zooming in > by about a factor of 1.2 so that the elements in the grid are tighter > to each other? That would require clipping the bounding box. Changing > R doesn't work since it actually clips the circles. The circles must > remain to scale, so I am only looking for tightness in the last line. > Aaron PlotEquilibriumConfiguration[ [CapitalPsi]_, [CapitalSigma]_, > [CapitalPi]_, n_] := ( > RhoN = BesselJZero[0, n]; > Gn = ((RhoN^2 [CapitalPsi])/([Pi] [CapitalSigma]))^(1/3); > a = ([CapitalPi] Gn)/[CapitalSigma]; > f[a_, y_] = y^4 - y - a; > ySol = > y /. FindRoot[(f[A, y] /. A -> a) == 0, {y, 4}, > MaxIterations -> 1000]; > G = Gn/ySol; > R = 3.3; > circle = ParametricPlot3D[{G Cos[x], G Sin[x], 0}, {x, 0, 2 Pi}, > Axes -> None, > Boxed -> False, > PlotRange -> {{-R, R}, {-R, R}} > ]; Show[circle] > ); > grid = GraphicsGrid[ > Table[PlotEquilibriumConfiguration[1, 1, P, n], {n, 1, > 3}, {P, {-.1, 0, .1}}]] > === Subject: Re: Denoting a Cartesian Product (* We use [CircleTimes] for the input and output of Quantum Products and Quantum Powers of Quantum-Computing qubits in our Quantum Mathematica Add-on. As you can see in this part Quantum's documentation, they behave = in a similar way to the sigma notation for sums and the exponent notation = for arithmetic powers: http://homepage.cem.itesm.mx/lgomez/quantum/tprodtpow/tprodtpow.html Below I include internal programming code from that add-on. I hope this code can be useful for you Jose Mexico *) (*Attributes for zz020TensorProduct: *) SetAttributes[zz020TensorProduct, {HoldAll}]; (*Rules for zz020TensorProduct notice in the following definition the weird way to check that some of the patterns are integer. This is because of the HoldAll attribute:those patterns must be or evolve to integers,but I need HoldAll because I need two pattens that must not evolve,j and data[j],to shield from possible global variable with the same name as the dummy index j *) zz020TensorProduct[data_, {j_Symbol, ini_, end_}] := (Apply[zz075NonCommutativeTimes, Reverse[Table[data, {j, ini, end}]]]) /; (*The final user will be able to obtain the tensor product template by pressing [ESC]tprod[ESC] after evaluating next code*) SetOptions[InputNotebook[], InputAliases -> {tprod -> TagBox[RowBox[{UnderoverscriptBox[[CircleTimes], TagBox[RowBox[{[Placeholder], =, [Placeholder]}], zz020TPini, Editable -> True, Selectable -> True], TagBox[[Placeholder], zz020TPend, Editable -> True, Selectable -> True]], TagBox[[Placeholder], zz020TPdat, Editable -> True, Selectable -> True]}], zz020TP, Editable -> False, Selectable -> False]}] (*The template that was programmed above will be transformed into a Mathematica expression after evaluating next code *) MakeExpression[ TagBox[ RowBox[{UnderoverscriptBox[[CircleTimes], TagBox[RowBox[{j_, =, ini_}], zz020TPini, opts1___], TagBox[end_, zz020TPend, opts2___]], TagBox[data_, zz020TPdat, opts3___]}], zz020TP, opts0___], form_] := MakeExpression[ RowBox[{zz020TensorProduct, [, data, ,{, j, ,, ini, ,, end, }]}], form]; (*Output of zz020TensorProduct: if the template did Not evaluate (maybe because the end value is not an integer, but a variable), then zz020TensorProduct will produce again the same template *) zz020TensorProduct /: MakeBoxes[ zz020TensorProduct[data_, {j_, ini_, end_}], form_] := TagBox[ RowBox[{UnderoverscriptBox[[CircleTimes], TagBox[RowBox[{MakeBoxes[j, form], =, MakeBoxes[ini, form]}], zz020TPini, Editable -> True, Selectable -> True], TagBox[MakeBoxes[end, form], zz020TPend, Editable -> True, Selectable -> True]], TagBox[RowBox[{(, MakeBoxes[data, form], )}], zz020TPdat, Editable -> True, Selectable -> True]}], zz020TP, Editable -> False, Selectable -> False]; (* -----Mensaje original----- De: Bruce Colletti [mailto:bwcolletti@verizon.net] Enviado el: Mi=E9rcoles, 30 de Julio de 2008 02:54 Para: mathgroup@smc.vnet.net Asunto: Denoting a Cartesian Product Re Mathematica 6.0.3 under WinXP. In a text cell, how would I denote the n-fold Cartesian Product of set B (without saying B x B x ... x B)? I've used the basic input palette's summation button, replacing sigma by = X, but the look isn't right (by setting ScriptLevel to 0, indexing appears = over and under the X). Am hoping there's an easy way. Bruce *) === Subject: Re: Denoting a Cartesian Product Ordinarily, the n-fold cartesian product of a single set B would be denoted B^n (with a superscript)! If you want the cartesian product of a family of sets B_1, B_2, ..., B_n, then the usual notation would be the one you get from the Basic Math Input palette, with a large pi-type product sign. Unfortunately, that's a rotten notation -- and this has nothing to do with Mathematica per se, but with mathematicians and, more likely, typographers. The obvious thing to do is what you almost suggest, that is, to have a large Times sign instead of that large pi-like product sign. But one cannot simply magnify the small Times sign, since the proportions will be wrong: the width needs to have a smaller ratio to the height after the magnification. > Re Mathematica 6.0.3 under WinXP. In a text cell, how would I denote the n-fold Cartesian Product of set B (without saying B x B x ... x B)? I've used the basic input palette's summation button, replacing sigma by X, but the look isn't right (by setting ScriptLevel to 0, indexing appears over and under the X). Am hoping there's an easy way. > Bruce > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Denoting a Cartesian Product Re Mathematica 6.0.3 under WinXP. In a text cell, how would I denote the n-fold Cartesian Product of set B (without saying B x B x ... x B)? I've used the basic input palette's summation button, replacing sigma by X, but the look isn't right (by setting ScriptLevel to 0, indexing appears over and under the X). Am hoping there's an easy way. Bruce === Subject: Problem with Sliders on IBM Thinkpad I wonder if anyone's heard of a problem getting sliders to recognize the left mouse button down on an IBM Thinkpad (laptop). Everything else works for me (Radio buttons, CheckBox, etc.) But to use either a regular or 2D slider I have to set AutoAction->True. It just doesn't seem to recognize it when I click down on the slider. Any ideas? I'm not having much luck getting an answer from Wolfram. I have a student license, and they send you to a different support queue (fair enough I guess, since I only had to pay a fraction of the normal price.) -Mike === Subject: Running Notebooks inside a notebook: Hi Mathematica Friends, I wanted to execute a notebook inside a notebook. Say I have a notebook Outer.nb and Inner.nb. I tried to do it using NotebookOpen[], Please see the code in the bottom for the same. Inner.nb has a list of data input and commands and then outputs. Now I want to put this Inner.nb inside a Do[] loop in the Outer.nb, such that for each loop increment, I could change the input of the Inner.nb, and as well as write the output to a separate file (say Excel), or variable. Here it opens the notebook but doesn't do any calculations. One thing to note here is the parameters vel,nmx,n are all needed for successful execution of Inner.nb but I hope that because the kernel remembers these values from Outer.nb, I did not include them in the Inner.nb. Moreover, I wanted to access these from Outer.nb because I wanted to change these values in the loop. ******************************* (* Code starts here -- This is Outer.nb file *) vel = 20; nmx = 3; n = 31; set = {}; While[0 <= vel <= 40, file = G:/somefolder/Inner.nb; nb = NotebookOpen[file, Visible -> True]; (* True/False visible/hidden does not matter for me *) SelectionMove[nb, All, Notebook]; SelectionEvaluate[nb]; set = Append[set, newc]; vel = 1.5 vel; NotebookClose[nb]]; set // MatrixForm (* Code ends here *) Gopinath === Subject: Re: Running Notebooks inside a notebook: > Hi Mathematica Friends, I wanted to execute a notebook inside a notebook. Say I have a notebook Outer.nb and Inner.nb. I tried to do it using NotebookOpen[], Please see the code in the bottom for the same. Inner.nb has a list of data input and commands and then outputs. Now I want to put this Inner.nb inside a Do[] loop in the Outer.nb, such that for each loop increment, I could change the input of the Inner.nb, and as well as write the output to a separate file (say Excel), or variable. Here it opens the notebook but doesn't do any calculations. One thing to note here is the parameters vel,nmx,n are all needed for successful execution of Inner.nb but I hope that because the kernel remembers these values from Outer.nb, I did not include them in the Inner.nb. Moreover, I wanted to access these from Outer.nb because I wanted to change these values in the loop. ******************************* > (* Code starts here -- This is Outer.nb file *) > vel = 20; > nmx = 3; > n = 31; > set = {}; > While[0 <= vel <= 40, > file = G:/somefolder/Inner.nb; > nb = NotebookOpen[file, Visible -> True]; (* True/False visible/hidden does not matter for me *) > SelectionMove[nb, All, Notebook]; > SelectionEvaluate[nb]; > set = Append[set, newc]; > vel = 1.5 vel; > NotebookClose[nb]]; > set // MatrixForm (* Code ends here *) Gopinath > Forget about NotebookOpen, SelectionEvaluate, and related functions. These are for more specialised applications, such as writing palettes that perform various notebook manipulations. Your notebook inner.nb should consist of one or more function definitions - say just myInnerNotebook[] - containing the code that you want to execute repeatedly. Once you have executed this definition, you can call it as required from the code in the outer notebook. However, you need to be very careful that you do not inadvertently re-use a variable in the two notebooks. Ideally your functions will be defined using Module, and most of the variables will be local to avoid unwanted interactions. Most code developers embed almost all their code inside functions. Writing a set of raw Mathematica statements, as you have done, works well to begin with, but as you have found, this technique rapidly becomes very clumsy. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Call for papers in K-16 Math Education Academic Exchange Quarterly announces a call for papers on K-16 mathematics education for its Winter 2009 issue. The theme, Engaging Mathematics Students as Holistic Learners, is described at http://www.rapidintellect.com/AEQweb/6math.htm . Early submissions accepted through the end of July 2009. See submission guidelines at http://rapidintellect.com/AEQweb/rufen1.htm . Mathematica users might wish to consider the role of technology in modeling real-world phenomena or interdisciplinary contexts, or its significance to issues of diversity, math attitudes, or disability. === Subject: A 3D plot, x and y is log coordinates. How plot? The function is z = f(x,y) === Subject: Re: A 3D plot, x and y is log coordinates. How plot? the function is f(x,y) and not g(x,y) or q(x,y) I'm surprised ! Try Plot3D[Exp[-x*y], {x, 1, 10}, {y, 1, 10}, PlotRange -> All] /. GraphicsComplex[pnts_, gr___] :> GraphicsComplex[{Log[#[[1]]], Log[#[[2]]], #[[3]]} & /@ pnts, gr] if you function is Exp[-x*y] Jens > The function is z = f(x,y) > === Subject: Re: Incoherent value for partial derivative >Let >In[1]: g[x_]:=3x^2+5x; FullForm[g'[x]] >Out[1]: Plus[5,Times[6,x]] >In[2]: g'[2] Out[2]: 17 >Mathematica works fine and the result is correct. First, it executes >the derivation and then the delayed substitution/assignation. Unless I had either tested this or found something specific in the documentation to say things would work this way, I would not have relied on this particular sequence of execution. Without checking, I would have expected Mathematica to substitute a particular value for x then take the derivative getting 0 since f evaluates as a constant. >But for partial derivative Mathematica works different way (not >correspondig to FullForm This really isn't a correct conclusion. FullForm[expr] gives the form corresponding to the evaluation of expr. >In[3]: f[x_,y_]:=x^2+x y^2; FullForm[!( >*SubscriptBox[([PartialD]), (x)] (f[x, y]))] >Out[3]: Plus[Times[2,x],Power[y,2]] >In[4]: !( *SubscriptBox[([PartialD]), (x)] (f[1, 2])) >Out[4]: 0 Here, the sequence of evaluation is more along the lines of what I would expect. That is values for x and y are substituted resulting in a real value then the derivative is computed. You can verify this works as I've described by using Trace. === Subject: Re: Using [Breve] as a substitute for underscore >It shows that WRI >can add some extra characters if they wish. Undoubtedly they can. For example, I remember when I discovered [InvisibleTimes] in Mathematica 4.1 and [LongEqual] in Mathematica 5.0. It was great! In Mathematica 6 they introduced ImplicitPlus. Great again! Like you, I«m always looking for typesetting enhacements. And I am still eagerly awaiting the day when WRI will supply us with a true PERCENT sign (%). As I said elsewhere, I now use Item[KeyEvent[F5, Modifiers -> {Control}], KernelExecute[ NotebookApply[InputNotebook[], InterpretationBox[%,1/100,SelectWithContents->True]]], MenuEvaluator -> Automatic] Carlos C.8esar de Ara.9cjo Gregos & Troianos Educacional http://www.gregosetroianos.mat.br MSN: cca_gregosetroianos@hotmail.com Belo Horizonte, MG, Brasil (31) 3283-1122 === Subject: Re: Using [Breve] as a substitute for underscore >Nice! But... is it such a good idea to use a name including >[LetterSpace] in code? The underscore is printed faintly, so it's >easy to mistake the parts of the symbol as separate symbols -- and >hence mistake the entire thing as a product of two things. After trying this and seeing how carefully one would have to look to distinguish this from a space, my reaction was this would be a disaster in code. Particularly, after some time had passed and you didn't recall using this approach. === Subject: Simplify I have a simple question about to simplify a expression (a list/matrices). I have a list like {2 cet1, 0, -2 cet1, cet1, 0, -cet1} And I want to extract if possible the factor cet1, so I become a list like cet1{2, 0, -2, 1, 0, -1} How can I extract the factor? Cetin === Subject: Re: Simplify Note that MatrixForm is not required here with FactorOut. You could equally well use: v = {2 cet1, 0, -2 cet1, cet1, 0, -cet1}; Needs[Presentations`Master`] FactorOut[cet1,HoldForm][v] cet1 {2,0,-2,1,0,-1} > list = {{2 cet1, 0, -2 cet1, cet1, 0, -cet1}}; cet1 MatrixForm[list/cet1] > cet1 (2 0 -2 1 0 -1) Or using the Presentations package: Needs[Presentations`Master`] list // FactorOut[cet1, MatrixForm] > cet1 (2 0 -2 1 0 -1) > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Simplify David, My naive expectation would be that the following would work: v = {2 cet1,0,-2 cet1,cet1,0,-cet1}; FactorOut[cet1][v] cet1 {2,0,-2,1,0,-1} But of course that will NOT work as things stand right now. I need to use, instead: FactorOut[cet1,HoldForm][v] Moreover, I was initially mislead into thinking FactorOut[cet1][v] would work, in view of the example in the documentation: step1=5(x-1)(x-3)(x-7)x^2//Expand step1 // FactorOut[x^2] Murray > list = {{2 cet1, 0, -2 cet1, cet1, 0, -cet1}}; cet1 MatrixForm[list/cet1] > cet1 (2 0 -2 1 0 -1) Or using the Presentations package: Needs[Presentations`Master`] list // FactorOut[cet1, MatrixForm] > cet1 (2 0 -2 1 0 -1) > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Simplify list = {{2 cet1, 0, -2 cet1, cet1, 0, -cet1}}; cet1 MatrixForm[list/cet1] cet1 (2 0 -2 1 0 -1) Or using the Presentations package: Needs[Presentations`Master`] list // FactorOut[cet1, MatrixForm] cet1 (2 0 -2 1 0 -1) -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I have a simple question about to simplify a expression (a list/matrices). > I > have a list like {2 cet1, 0, -2 cet1, cet1, 0, -cet1} And I want to extract if possible the factor cet1, so I become a list like cet1{2, 0, -2, 1, 0, -1} How can I extract the factor? > Cetin > === Subject: Re: Simplify lst = {2 cet1, 0, -2 cet1, cet1, 0, -cet1}; and lst /. r : {(cet1*_. | 0) ..} :> cet1 HoldForm @@ { r/cet1} Jens I have a simple question about to simplify a expression (a list/matrices). I > have a list like {2 cet1, 0, -2 cet1, cet1, 0, -cet1} And I want to extract if possible the factor cet1, so I become a list like cet1{2, 0, -2, 1, 0, -1} How can I extract the factor? > Cetin > === Subject: Re: Simplify > I have a simple question about to simplify a expression (a list/matrices). I > have a list like {2 cet1, 0, -2 cet1, cet1, 0, -cet1} And I want to extract if possible the factor cet1, so I become a list like cet1{2, 0, -2, 1, 0, -1} Note that the above expression is *not* a list: This is the product of a symbol by a list. Evaluating such an expression will result in the original list (cet1 is distributed over the list). > How can I extract the factor? Among many other methods, you could use a transformation rule or a function such as *Coefficient[]* (Note that the last expression uses the non-commutative multiplication sign ** to prevent distributivity): In[1]:= lst = {2 cet1, 0, -2 cet1, cet1, 0, -cet1} lst /. cet1 -> 1 Coefficient[lst, cet1] cet1 (lst /. cet1 -> 1) cet1 ** (lst /. cet1 -> 1) Out[1]= {2 cet1, 0, -2 cet1, cet1, 0, -cet1} Out[2]= {2, 0, -2, 1, 0, -1} Out[3]= {2, 0, -2, 1, 0, -1} Out[4]= {2 cet1, 0, -2 cet1, cet1, 0, -cet1} Out[5]= cet1 ** {2, 0, -2, 1, 0, -1} === Subject: Re: Package conversion to V6 This is probably obvious, and an example of closing the barn door after the horse has escaped, but... If you initially prepare your package code within an ordinary notebook, then Mathematica 6 can do the scanning in the notebook. Once you fix that up, you simply save again as a package. > Is there a way to get Mathematica to give recommendations/hints when > it reads in a package file created with an earlier version of -Bob > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Package conversion to V6 >Is there a way to get Mathematica to give recommendations/hints when >it reads in a package file created with an earlier version of >Mathematica like it does for notebook files? I suspect you are asking how to set Mathematica to do this for a package you did not write but want to use. If so, this is something that has to be coded in the package and isn't something you can change later without modifying the package. But it would be a simple matter to add this type of feature to the package. Basically, all you would need to do is look at the string returned by $Version and return the desired message/hint. === Subject: RadioButton Question functions, rather than just set a variable? This is a statement to create two buttons that set a value:- RadioButtonBar[Dynamic[state], {Existing, New}] The following code runs functions, but also shows the buttons in a list, along with some output. Any suggestions how I can achieve this functionality but with only the buttons and labels showing, as above? dofunction1[] := x = 1; dofunction2[] := x = 2; Module[{state = Existing}, {RadioButtonBar[Dynamic[state], {Existing, New}], Dynamic[If[state == Existing, dofunction1[], dofunction2[]]]}] === Subject: Re: RadioButton Question Hi Chris,The following works: RadioButtonBar[Dynamic[x], {1 -> Existing, 2 -> New}] Dynamic[x] Namrata > functions, rather than just set a variable? This is a statement to create two buttons that set a value:- RadioButtonBar[Dynamic[state], {Existing, New}] > The following code runs functions, but also shows the buttons in a > list, along with some output. Any suggestions how I can achieve > this functionality but with only the buttons and labels showing, as > above? > dofunction1[] := x = 1; dofunction2[] := x = 2; Module[{state = Existing}, > {RadioButtonBar[Dynamic[state], {Existing, New}], > Dynamic[If[state == Existing, dofunction1[], dofunction2[]]]}] === Subject: Re: RadioButton Question > functions, rather than just set a variable? This is a statement to create two buttons that set a value:- RadioButtonBar[Dynamic[state], {Existing, New}] > The following code runs functions, but also shows the buttons in a > list, along with some output. Any suggestions how I can achieve > this functionality but with only the buttons and labels showing, as > above? > dofunction1[] := x = 1; dofunction2[] := x = 2; Module[{state = Existing}, > {RadioButtonBar[Dynamic[state], {Existing, New}], > Dynamic[If[state == Existing, dofunction1[], dofunction2[]]]}] > This is what the second argument of Dynamic can be used for: DynamicModule[{state = Existing}, RadioButtonBar[ Dynamic[state, (If[# == Existing, dofunction1[], dofunction2[]]; state = #) &], {Existing, New} ]] I have also used DynamicModule instead of Module, which seems to make more sense in this case (Module will have finished when you see the output in the notebook, the local variable state will leak from that module as something like state$145 which usually does no harm but is not what Module is intended to do...) hth, albert === Subject: Re: RadioButton Question hu, that sound complicated, what is with RadioButtonBar[Dynamic[x], {1 -> Existing, 2 -> New}] Jens > functions, rather than just set a variable? This is a statement to create two buttons that set a value:- RadioButtonBar[Dynamic[state], {Existing, New}] > The following code runs functions, but also shows the buttons in a > list, along with some output. Any suggestions how I can achieve > this functionality but with only the buttons and labels showing, as > above? > dofunction1[] := x = 1; dofunction2[] := x = 2; Module[{state = Existing}, > {RadioButtonBar[Dynamic[state], {Existing, New}], > Dynamic[If[state == Existing, dofunction1[], dofunction2[]]]}] === Subject: Re: RadioButton Question Hi CHris, Take a look at the documentation for Dynamic where one makes use of a second argument. The second argument of dynamic allows you to cause a function to be executed when the state of the dynamic is changed. Your expression would then have the generic form: RadioButtonBar[Dynamic[state,secondArgument&], {Existing, New}] I hope this helps... --David > functions, rather than just set a variable? This is a statement to create two buttons that set a value:- RadioButtonBar[Dynamic[state], {Existing, New}] The following code runs functions, but also shows the buttons in a > list, along with some output. Any suggestions how I can achieve > this functionality but with only the buttons and labels showing, as > above? dofunction1[] := x = 1; dofunction2[] := x = 2; Module[{state = Existing}, > {RadioButtonBar[Dynamic[state], {Existing, New}], > Dynamic[If[state == Existing, dofunction1[], dofunction2[]]]}] === Subject: Re: Warning for use of 3D Graphics manipulation I don't think, that the simple graphics of Mathematica can overheat the chip. AFAIK the problem comes form a insufficient cooling in the laptop. You should ask your laptop manufacturer if you model apply to the problems. But official neither nVidia nor a laptop manufacturer have confirmed the problems. Jens > it would be very helpful, if you can give a hint on requirements to > graphic chips of the laptops to avoid this problem. I am just going to > buy one. > Best, Alexei >> that is not a problem of Mathematica, this is a problem of >> the nVidia chips for laptops. Any complex 3d scene may burn the >> chip. You don't need Mathematica for that, Crisis or Half Life will >> burn the graphics chip better and faster than Mathematica *and* >> for a more affordable prize ! > *AND* if your VGA signal on an external monitor is still right, >> you graphics chip is ok, but you lcd-display may be broken and this >> has *nothing* to do with the overheating of the GeForce mobile chips. > Jens >> After installing Mathematica 6 and programming some group-mechanical > 3D-manipulations the nvidia go graphics chip of my Samsung laptop > stopped working at the performance of a complex 3d-manipulation. Its > internal digital lcd-part gave up with a crack noise. The external > analog VGA is still working. > On the internet, some hints can be found saying that certain laptop > computers are in danger to burn their graphics chips because of > insufficent cooling under high permanent load. > === Subject: Re: Evaluate part of rhs of RuleDelayed Here is a rather obvious although, perhaps, not a very elegant solution: SomeComplexFunction[a_] := Module[{x, SCF}, x = a*a; {value -> SCF[x + a]} /. {Rule -> RuleDelayed, SCF -> SomeComplexFunction}] In[2]:= SomeComplexFunction[5] Out[2]= {value :> SomeComplexFunction(30)} Andrzej Kozlowski > I am writing a lazy recursive function (actually, a tree of UI widgets > that is too large to be constructed at once). > Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value : SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for > anything useful. Question: > How should I fix the code of SomeComplexFunction so that the value of > SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} -- > Eugene Kirpichov > Web IR developer, Yandex > === Subject: Re: Evaluate part of rhs of RuleDelayed >I am writing a lazy recursive function (actually, a tree of UI widgets >that is too large to be constructed at once). >Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value :SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for >anything useful. Question: >How should I fix the code of SomeComplexFunction so that the value of >SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} > You can try either of the following: SomeComplexFunction[a_] := With[{x = a*a}, {value :> SomeComplexFunction[x + a]}] SomeComplexFunction2[a_] := {value :> SomeComplexFunction2[# + a]} &[a a] Carl Woll Wolfram Research === Subject: Evaluate part of rhs of RuleDelayed I am writing a lazy recursive function (actually, a tree of UI widgets that is too large to be constructed at once). Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, x = a*a; {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value :> SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for anything useful. Question: How should I fix the code of SomeComplexFunction so that the value of SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, x = a*a; {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} -- Eugene Kirpichov Web IR developer, Yandex === Subject: Re: Evaluate part of rhs of RuleDelayed > I am writing a lazy recursive function (actually, a tree of UI widgets > that is too large to be constructed at once). > Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value : SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for > anything useful. Question: > How should I fix the code of SomeComplexFunction so that the value of > SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} What you want to do is evaluating the argument of a function without evaluating the function itself (You use RuleDelayed to prevent the evaluation of the function and the infinite loop that would result in doing so). You can use ReplacePart to modify selectively any parts of the rule, so you can replace the unevaluated argument by its result. (Note that the right sequence of indices can be found by using FullForm or TreeForm, for instance.) SomeComplexFunction[a_] := Module[{x}, x = a*a; ReplacePart[{value :> SomeComplexFunction[x + a]}, {1, 2, 1} -> x + a]] SomeComplexFunction[5] {value :> SomeComplexFunction[30]} === Subject: Re: Evaluate part of rhs of RuleDelayed > I am writing a lazy recursive function (actually, a tree of UI widgets > that is too large to be constructed at once). > Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value : SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for > anything useful. Question: > How should I fix the code of SomeComplexFunction so that the value of > SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} > Try function head Replace-ment after expression construction and evaluation SomeComplexFunction[a_] := Module[{x}, x = a*a; {(RuleDelayed @@ {value, scf[x + a]}) /. {scf -> SomeComplexFunction}}] SomeComplexFunction[30] {value :> SomeComplexFunction[930]} -- Roland Franzius === Subject: Re: Evaluate part of rhs of RuleDelayed > I am writing a lazy recursive function (actually, a tree of UI widgets > that is too large to be constructed at once). > Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value : SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for > anything useful. Question: > How should I fix the code of SomeComplexFunction so that the value of > SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} > If I understood correctly what you try to do you should look at With, which is your friend when working with partially evaluated expressions: SomeComplexFunction[a_] := Module[{x}, x = a*a; With[{arg = x + a}, {value :> SomeComplexFunction[arg]} ] ] On the other hand, I have the feeling that your problem might be solved in a better way if you give more detailed information on what you are trying to achieve with SomeComplexFunction... hth, albert === Subject: Re: Evaluate part of rhs of RuleDelayed SomeComplexFunction[a_] := Module[{x, f}, x = a*a; {RuleDelayed @@ {value, f[x + a]}} /. f -> SomeComplexFunction] ?? Jens > I am writing a lazy recursive function (actually, a tree of UI widgets > that is too large to be constructed at once). > Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value : SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for > anything useful. Question: > How should I fix the code of SomeComplexFunction so that the value of > SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} > === Subject: Re: Evaluate part of rhs of RuleDelayed > I am writing a lazy recursive function (actually, a tree of UI widgets > that is too large to be constructed at once). > Consider, for example, the following code: SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[x + a]}] The value of SomeComplexFunction[5] is {value : SomeComplexFunction[x$7418 + 5]} and seemingly can'd be used for > anything useful. Question: > How should I fix the code of SomeComplexFunction so that the value of > SomeComplexFunction[5] be {value :> SomeComplexFunction[30]} ? Unfortunately, this one SomeComplexFunction[a_] := Module[{x}, > x = a*a; > {value :> SomeComplexFunction[Evaluate[x + a]]}] yields {value :> SomeComplexFunction[Evaluate[x$7421 + 5]]} > The With function is extremely useful for injecting values inside code that does not immediately evaluate: SomeComplexFunction[a_]:=Module[{x}, x=a*a; With[{xx=x+a},{value:>SomeComplexFunction[xx]}] ] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Find count of binary number pattern within concatenated number Math folks, Can someone tell me how to find the count of the occurrences of 1101 within 11011100101110111100010011010101111001101 generated with the n=13 11011100101110111100010011010101111001101. 1101 Diana === Subject: Re: Find count of binary number pattern within concatenated number > Can someone tell me how to find the count of the occurrences of 1101 > within 11011100101110111100010011010101111001101 generated with the n=13 > 11011100101110111100010011010101111001101. > 1101 Here is two almost identical versions of the counting function: the first one seeks for overlapping sequences, the second looks only for non-overlapping sequences. Of course the results might be very different for a same number. (* Overlapping sequences *) myCount[n_Integer] := Module[{nb2 = IntegerDigits[n, 2]}, Flatten[Position[ Partition[Flatten[IntegerDigits[Range[n], 2]], Length[nb2], 1], nb2]]] myCount[13] {1, 12, 25, 38} (* Non-Overlapping sequences *) myCount[n_Integer] := Module[{nb2 = IntegerDigits[n, 2]}, Flatten[Position[ Partition[Flatten[IntegerDigits[Range[n], 2]], Length[nb2]], nb2]]] myCount[13] {1, 7} === Subject: Re: Find count of binary number pattern within concatenated number > Math folks, Can someone tell me how to find the count of the occurrences of 1101 > within 11011100101110111100010011010101111001101 generated with the n=13 > 11011100101110111100010011010101111001101. > 1101 Diana > I think you'd be better off to use the lists than transform to numbers. Is this what you are after? digitlist = Flatten[IntegerDigits[Range[n], 2]] digitpattern = IntegerDigits[n, 2] Count[Partition[digitlist, Length[digitpattern], 1], digitpattern] hth, albert === Subject: Re: Find count of binary number pattern within concatenated number > Can someone tell me how to find the count of the occurrences of 1101 >> within 11011100101110111100010011010101111001101 generated with the >> n=13 >> 11011100101110111100010011010101111001101. >> 1101 Here is two almost identical versions of the counting function: the first > one seeks for overlapping sequences, the second looks only for > non-overlapping sequences. Of course the results might be very different for > a same number. (* Overlapping sequences *) > myCount[n_Integer] := > Module[{nb2 = IntegerDigits[n, 2]}, > Flatten[Position[ > Partition[Flatten[IntegerDigits[Range[n], 2]], Length[nb2], 1], > nb2]]] myCount[13] {1, 12, 25, 38} (* Non-Overlapping sequences *) > myCount[n_Integer] := > Module[{nb2 = IntegerDigits[n, 2]}, > Flatten[Position[ > Partition[Flatten[IntegerDigits[Range[n], 2]], Length[nb2]], > nb2]]] myCount[13] {1, 7} Please, disregard this nonsense about the Non-Overlapping function: it is too restrictive and does not produce the desired result. The first fucntion does work correctly -- at least as far as I can tell. What I mean by overlapping is that for a sequence such as {1, 1, 0, 1, 1, 0, 1} the function will count 2 subsequences 1101 starting at 1 and 4, respectively. (Note that the beginning of the second sequence is also the end of the first sequence.) StringPosition[1101101, 1101] {{1, 4}, {4, 7}} Another possible approach is to convert the numbers into strings and use the string search functions. myCount[n_Integer] := StringPosition[ myCount[13] {1, 12, 25, 38} Sorry for the confusion, === Subject: Re: Find count of binary number pattern within concatenated number > Jean, pattern with n = 13 ? Correct. Indeed, the Non-Overlapping is too restrictive and does not produce the desired result. Please, just disregard it. What I mean by overlapping is that for a sequence such as {1, 1, 0, 1, 1, 0, 1} the function will count 2 subsequence 1101 starting at 1 and 4, respectively. Note that the beginning of the second sequence is also the end of the first sequence. StringPosition[1101101, 1101] {{1, 4}, {4, 7}} Another possible approach is to convert the numbers into strings and use the string search functions. myCount[n_Integer] := StringPosition[ myCount[13] {1, 12, 25, 38} - Jean-Marc > Diana >> Can someone tell me how to find the count of the occurrences of 1101 > within 11011100101110111100010011010101111001101 generated with the >> n=13 > 11011100101110111100010011010101111001101. > 1101 >> Here is two almost identical versions of the counting function: the first >> one seeks for overlapping sequences, the second looks only for >> non-overlapping sequences. Of course the results might be very different for >> a same number. >> (* Overlapping sequences *) >> myCount[n_Integer] := >> Module[{nb2 = IntegerDigits[n, 2]}, >> Flatten[Position[ >> Partition[Flatten[IntegerDigits[Range[n], 2]], Length[nb2], 1], >> nb2]]] >> myCount[13] >> {1, 12, 25, 38} >> (* Non-Overlapping sequences *) >> myCount[n_Integer] := >> Module[{nb2 = IntegerDigits[n, 2]}, >> Flatten[Position[ >> Partition[Flatten[IntegerDigits[Range[n], 2]], Length[nb2]], >> nb2]]] >> myCount[13] >> {1, 7} === Subject: Re: Please help me..... > Hi all I'm an international studentat RMIT University Melbourne. Currently, I'm > doing my master degree in Statistics and Operations Research. This > following 6 months will be my last semester to finish my master degree. > Therefore, I have been doing minor thesis about estimating unknown > parameter of Burr distribution by using Mathematica. I was wondering if this forum could assist me to detect where I got wrong > with my program since it works for Burr distribution in some data but not > with my data. Additionally, this program (I attached my program along with > my data) also works for non-normal distribution, such as Gamma and Weibull > since my data are non-normally distributed and they are closely to gamma > and weibull distribution. The data are treatment time of cervical cancer patients in a hospital. > Frequently, they come to the hospital in the late satge of cancer, thus > the minimum time for the treatment is 2 days and the maximum treatment on > the data is 21 days. The following is my program to run MLE of Burr distribution. However, > it comes up with comment results in finding the coefficient of unknown > parameters when I run it. > n = 69; > x2 = {5, 6, 5.5, 5, 8.4, 4.5, 4, 6, 7, 6, 7, 8, 5.4, 5, 4, 3.5, 4.5, > 6.5, 5, 3.5, 5.7, 5.8, 5, 4.8, 4.5, 5.8, 3.2, 6, 4, 6, 7, > 6.5, > 10.7, 7, 4.7, 7, 8.3, 10, 6.5, 4.9, 3.4, 9, 6, 3.1, 5, 4.8, 4, > 6, > 6, 5.6, 4.2, 4.3, 4.5, 8.4, 8.6, 5.8, 6.8, 4.8, 3.4, 8, 8, > 8.3, 8, > 4.5, 6, 4.5, 7, 7, 8}; > BurrDistribution[x2_, c_, > k_] := (c*k)*(x2^(c - 1)/(1 + x2^c)^(k + 1)) > pdf = BurrDistribution[x2, c, k] > logl = Plus @@ Log[pdf] > maxlogl = FindMinimum[-logl, {c, 1}, {k, 2}] > mle = maxlogl[[2]] Please assist me in finding the problem I face now. This is very important > for my thesis. I look forward for any comments and advices, thank you. Dewi I am not sure what is the issue but I suspect you refer to the warning messages. They indicate that some log arguments probably became negative, hence caused complex values to appear. There are various ways to address that and make the job easier. One is to expand the logs, under the assumption that the parameters c and k are nonnegative. This can be done as below. logl = PowerExpand[Total[Log[pdf]], Assumptions->{c>=0,k>=0}]; Also you can restrict FindMinimum by giving constraints, or instead use NMinimize and likewise give constraints. Either of the calls below will do this. In[23]:= maxlogl = FindMinimum[{-logl,c>=0,k>=0}, {c,1}, {k,2}] FindMinimum::eit: -6 The algorithm does not converge to the tolerance of 4.80622 10 in 500 iterations. The best estimated solution, with feasibility residual, KKT -12 residual or complementary residual of {7.10845 10 , 0.0000304113, -12 5.93765 10 }, is returned. Out[23]= {226.436, {c -> 20.2248, k -> 0.0285432}} In[24]:= maxloglb = NMinimize[{-logl,c>=0,k>=0}, {{c,1,2}, {k,2,4}}] Out[24]= {226.436, {c -> 15.1598, k -> 0.0380797}} You might observe that they give the same minimum, to six digits, but give quite different values for the parameters {c,k}. Whether this is reasonable is something I cannot address. Lichtblau Wolfram Research === Subject: Re: Please help me..... > Hi all I'm an international studentat RMIT University Melbourne. Currently, I'm > doing my master degree in Statistics and Operations Research. This > following 6 months will be my last semester to finish my master degree. > Therefore, I have been doing minor thesis about estimating unknown > parameter of Burr distribution by using Mathematica. I was wondering if this forum could assist me to detect where I got wrong > with my program since it works for Burr distribution in some data but not > with my data. Additionally, this program (I attached my program along with > my data) also works for non-normal distribution, such as Gamma and Weibull > since my data are non-normally distributed and they are closely to gamma > and weibull distribution. The data are treatment time of cervical cancer patients in a hospital. > Frequently, they come to the hospital in the late satge of cancer, thus > the minimum time for the treatment is 2 days and the maximum treatment on > the data is 21 days. The following is my program to run MLE of Burr distribution. However, > it comes up with comment results in finding the coefficient of unknown > parameters when I run it. > n = 69; > x2 = {5, 6, 5.5, 5, 8.4, 4.5, 4, 6, 7, 6, 7, 8, 5.4, 5, 4, 3.5, 4.5, > 6.5, 5, 3.5, 5.7, 5.8, 5, 4.8, 4.5, 5.8, 3.2, 6, 4, 6, 7, > 6.5, > 10.7, 7, 4.7, 7, 8.3, 10, 6.5, 4.9, 3.4, 9, 6, 3.1, 5, 4.8, 4, > 6, > 6, 5.6, 4.2, 4.3, 4.5, 8.4, 8.6, 5.8, 6.8, 4.8, 3.4, 8, 8, > 8.3, 8, > 4.5, 6, 4.5, 7, 7, 8}; > BurrDistribution[x2_, c_, > k_] := (c*k)*(x2^(c - 1)/(1 + x2^c)^(k + 1)) > pdf = BurrDistribution[x2, c, k] > logl = Plus @@ Log[pdf] > maxlogl = FindMinimum[-logl, {c, 1}, {k, 2}] > mle = maxlogl[[2]] Please assist me in finding the problem I face now. This is very important > for my thesis. I look forward for any comments and advices, thank you. Dewi > The problem is that without knowledge of the constraints on the parameter values the method steps to invalid values for the parameters which results in a complex log likelihood. Adding the positivity constraints on the parameters and increasing the number of iterations gets a result. In[1]:= n = 69; In[2]:= x2 = {5, 6, 5.5, 5, 8.4, 4.5, 4, 6, 7, 6, 7, 8, 5.4, 5, 4, 3.5, 4.5, 6.5, 5, 3.5, 5.7, 5.8, 5, 4.8, 4.5, 5.8, 3.2, 6, 4, 6, 7, 6.5, 10.7, 7, 4.7, 7, 8.3, 10, 6.5, 4.9, 3.4, 9, 6, 3.1, 5, 4.8, 4, 6, 6, 5.6, 4.2, 4.3, 4.5, 8.4, 8.6, 5.8, 6.8, 4.8, 3.4, 8, 8, 8.3, 8, 4.5, 6, 4.5, 7, 7, 8}; In[3]:= BurrDistribution[x2_, c_, k_] := (c*k)*(x2^(c - 1)/(1 + x2^c)^(k + 1)); In[4]:= pdf = BurrDistribution[x2, c, k]; In[5]:= logl = Plus @@ Log[pdf]; In[6]:= maxlogl = FindMinimum[{-logl, c > 0 && k > 0}, {c, 1}, {k, 2}, MaxIterations -> 1000] Out[6]= {226.436, {c -> 22.4199, k -> 0.0257487}} In[7]:= mle = maxlogl[[2]] Out[7]= {c -> 22.4199, k -> 0.0257487} Darren Glosemeyer Wolfram Research === Subject: Please help me..... Hi all I'm an international studentat RMIT University Melbourne. Currently, I'm doing my master degree in Statistics and Operations Research. This following 6 months will be my last semester to finish my master degree. Therefore, I have been doing minor thesis about estimating unknown parameter of Burr distribution by using Mathematica. I was wondering if this forum could assist me to detect where I got wrong with my program since it works for Burr distribution in some data but not with my data. Additionally, this program (I attached my program along with my data) also works for non-normal distribution, such as Gamma and Weibull since my data are non-normally distributed and they are closely to gamma and weibull distribution. The data are treatment time of cervical cancer patients in a hospital. Frequently, they come to the hospital in the late satge of cancer, thus the minimum time for the treatment is 2 days and the maximum treatment on the data is 21 days. The following is my program to run MLE of Burr distribution. However, it comes up with comment results in finding the coefficient of unknown parameters when I run it. n = 69; x2 = {5, 6, 5.5, 5, 8.4, 4.5, 4, 6, 7, 6, 7, 8, 5.4, 5, 4, 3.5, 4.5, 6.5, 5, 3.5, 5.7, 5.8, 5, 4.8, 4.5, 5.8, 3.2, 6, 4, 6, 7, 6.5, 10.7, 7, 4.7, 7, 8.3, 10, 6.5, 4.9, 3.4, 9, 6, 3.1, 5, 4.8, 4, 6, 6, 5.6, 4.2, 4.3, 4.5, 8.4, 8.6, 5.8, 6.8, 4.8, 3.4, 8, 8, 8.3, 8, 4.5, 6, 4.5, 7, 7, 8}; BurrDistribution[x2_, c_, k_] := (c*k)*(x2^(c - 1)/(1 + x2^c)^(k + 1)) pdf = BurrDistribution[x2, c, k] logl = Plus @@ Log[pdf] maxlogl = FindMinimum[-logl, {c, 1}, {k, 2}] mle = maxlogl[[2]] Please assist me in finding the problem I face now. This is very important for my thesis. I look forward for any comments and advices, thank you. Dewi === Subject: Re: Please help me..... n = 69; x2 = {5, 6, 5.5, 5, 8.4, 4.5, 4, 6, 7, 6, 7, 8, 5.4, 5, 4, 3.5, 4.5, 6.5, 5, 3.5, 5.7, 5.8, 5, 4.8, 4.5, 5.8, 3.2, 6, 4, 6, 7, 6.5, 10.7, 7, 4.7, 7, 8.3, 10, 6.5, 4.9, 3.4, 9, 6, 3.1, 5, 4.8, 4, 6, 6, 5.6, 4.2, 4.3, 4.5, 8.4, 8.6, 5.8, 6.8, 4.8, 3.4, 8, 8, 8.3, 8, 4.5, 6, 4.5, 7, 7, 8}; BurrDistribution[x2_, c_, k_] := (c*k)*(x2^(c - 1)/(1 + x2^c)^(k + 1)) pdf = BurrDistribution[x2, c, k] logl = Plus @@ Log[pdf]; maxlogl = NMinimize[{-logl, c > 0 && k > 0}, {c, k}] mle = maxlogl[[2]] ?? Jens > Hi all I'm an international studentat RMIT University Melbourne. Currently, I'm > doing my master degree in Statistics and Operations Research. This > following 6 months will be my last semester to finish my master degree. > Therefore, I have been doing minor thesis about estimating unknown > parameter of Burr distribution by using Mathematica. I was wondering if this forum could assist me to detect where I got wrong > with my program since it works for Burr distribution in some data but not > with my data. Additionally, this program (I attached my program along with > my data) also works for non-normal distribution, such as Gamma and Weibull > since my data are non-normally distributed and they are closely to gamma > and weibull distribution. The data are treatment time of cervical cancer patients in a hospital. > Frequently, they come to the hospital in the late satge of cancer, thus > the minimum time for the treatment is 2 days and the maximum treatment on > the data is 21 days. The following is my program to run MLE of Burr distribution. However, > it comes up with comment results in finding the coefficient of unknown > parameters when I run it. > n = 69; > x2 = {5, 6, 5.5, 5, 8.4, 4.5, 4, 6, 7, 6, 7, 8, 5.4, 5, 4, 3.5, 4.5, > 6.5, 5, 3.5, 5.7, 5.8, 5, 4.8, 4.5, 5.8, 3.2, 6, 4, 6, 7, > 6.5, > 10.7, 7, 4.7, 7, 8.3, 10, 6.5, 4.9, 3.4, 9, 6, 3.1, 5, 4.8, 4, > 6, > 6, 5.6, 4.2, 4.3, 4.5, 8.4, 8.6, 5.8, 6.8, 4.8, 3.4, 8, 8, > 8.3, 8, > 4.5, 6, 4.5, 7, 7, 8}; > BurrDistribution[x2_, c_, > k_] := (c*k)*(x2^(c - 1)/(1 + x2^c)^(k + 1)) > pdf = BurrDistribution[x2, c, k] > logl = Plus @@ Log[pdf] > maxlogl = FindMinimum[-logl, {c, 1}, {k, 2}] > mle = maxlogl[[2]] Please assist me in finding the problem I face now. This is very important > for my thesis. I look forward for any comments and advices, thank you. Dewi === Subject: Use of RuleDelayed in PaneSelector I'm trying to implement a potentially infinite GUI tree control using PaneSelector's and Opener's. The issue is that I use RuleDelayed in the PaneSelector's first argument to make the contents of panels lazy, so that the contents would be constructed only when the corresponding panel is activated. For example: {Toggler[Dynamic[x]], PaneSelector[{False -> Inactive, True :> Print[Activated!]}, Dynamic[x]]} I want this to produce a widget that prints Activated! each time x transitions to True. However, all I get is an expression Print[Activated!]. If I wrap it into Evaluate[], I get Activated! printed immediately and only once. How should this code be written to satisfy the condition above? ...OK, perhaps is a 'potentially infinite GUI tree control' already written somewhere in the standard library? :) -- Eugene Kirpichov Web IR developer, Yandex === Subject: Re: Use of RuleDelayed in PaneSelector > I'm trying to implement a potentially infinite GUI tree control using > PaneSelector's and Opener's. > The issue is that I use RuleDelayed in the PaneSelector's first > argument to make the contents of panels lazy, so that the contents > would be constructed only when the corresponding panel is activated. > For example: {Toggler[Dynamic[x]], PaneSelector[{False -> Inactive, True : Print[Activated!]}, Dynamic[x]]} I want this to produce a widget that prints Activated! each time x > transitions to True. However, all I get is an expression > Print[Activated!]. > If I wrap it into Evaluate[], I get Activated! printed immediately > and only once. How should this code be written to satisfy the condition above? The following works, although I'm not sure whether I would recommend to build on it. The trick is to use Dynamic in the content of the pane selector and make x appear within that dynamic, so we use x as a dummy argument for the activate function. There are of course other possibilities to achieve the above but having an extra activate function might be a good idea anyway. With these changes, Activated! will be printed if the pane becomes visible _and_ x changes, which in this case always happens when pane becomes visible by toggling the Toggler, but not if e.g. the pane selector is scrolled out of sight and back. ClearAll[activate] activate[x_] := Print[Activated!] { Toggler[Dynamic[x]], PaneSelector[ {False -> Inactive, True -> Dynamic[activate[x]]}, Dynamic[x] ] } > ....OK, perhaps is a 'potentially infinite GUI tree control' already > written somewhere in the standard library? :) honestly, I have problems to imagine what a potentially infinity GUI would look like on my 1280x1024 pixel screen :-). hth, albert === Subject: Re: A 3D plot, x and y is log coordinates. How plot? >The function is z = f(x,y) If you want a meaningful answer provide some details. Specifically, what is f and what is it you want to show. There are a variety of commands in Mathematica for plotting mulit-variate data. The most commonly used include Plot3D, DensityPlot and ContourPlot. === Subject: Histogram package Hi All, I am attempting to make a simple histogram from some frequency data. I understand I need to load the Histograms package. I followed some instructions from the internet and was subsequently pleased to discover that I had completed the required task. I then made some simple histograms. When I returned to Mathematica after closing down the program, I discovered I needed to reload the package, which I did. However, I can no longer successfully make histograms anymore. I receive error messages telling me that my range specification does not have appropriate bounds. I am confused since the same data worked fine just a few hours ago. Can anyone help me please? Pete === Subject: Re: Derivative of Dot[] >I would like to compute the gradient F' of a scalar-valued function >F of a vector-valued argument, without knowing a-priori the >dimensions of the vector. >I am having some trouble with a very simple case. >Consider the following function: >F[x_] := Dot[x,x] >Evaluating this function works as expected: F[{1,2}] evaluates to 5. >I differentiate this function w.r.t. its sole argument, F' evaluates >to 1.#1+#1.1& >This is reasonable, and as expected. Expected yes given the way the form F' works, but reasonable? A dot product of vector and any other vector is a scalar. If you give specific values for the vector components, I would think it would be reasonable to return a value zero. Further, the gradient of a vector isn't given by the derivative of the dot product. Instead, it is the sum of partial derivatives of each component with respect to the corresponding basis function. That is the gradient of vector {x, y w, z^2} is given by In[27]:= Tr@D[{x, y w, z^2}, {{x, y, z}}] Out[27]= w+2 z+1 === Subject: No preferences for OSX Hi everyone! I am new to Mathematica, since I just got my license from my university. So, forgive if this is a recurrent topic, but in the archives I didn't find anything about this problem. I copied the application and registered just fine, I tried it and the kernel works. Unfortunately, the Preferences menu is disabled, so I can't set, for example, my own color scheme. Is this a normal behavior for university licenses? Did you see something like this in your experience? PS. I am running OSX 10.5 and Mathematica 6.0.3. -- Franco Milicchio DiS - Dept. of Studies on Structures DIA - Dept. of Computer Science and Engineering University Roma Tre http://www.dia.uniroma3.it/~milicchi/ === Subject: Re: No preferences for OSX > I am new to Mathematica, since I just got my license from my > university. So, forgive if this is a recurrent topic, but in the > archives I didn't find anything about this problem. I copied the application and registered just fine, I tried it and the > kernel works. Unfortunately, the Preferences menu is disabled, so I > can't set, for example, my own color scheme. Is this a normal behavior for university licenses? Did you see > something like this in your experience? PS. I am running OSX 10.5 and Mathematica 6.0.3. This is not a normal behavior. This might be an issue related to -- erroneous -- file permissions. The following procedure might solve your problem. Start Disk Utility (located in /Applications/Utilities), then select the disk where Mathematica is installed, check the check box Show details and click on Verify Disk Permissions. If any incorrect file permissions are reported, click on Repair Disk Permissions. Note that it might be a good idea to check the hard disk itself. Click on Verify Disk, then on Repair Disk (grayed by default) if needed. HTH, === Subject: Re: No preferences for OSX > You might check the permissions of the ~/Library/Mathematica/FrontEnd > directory (you should have read and write priviledges and the ~ refers > to your home directory) and also see if there is an init.m file there > that you can read and write to, although if this is a new install not > sure if the file will even be there yet, but at least the directory > should be readable and writable by you. If you want you can try to > hold down Shift and Option on the keyboard when starting Mathematica > -- CAUTION - this will recreate the init.m file in the FrontEnd > directory and if you have anything there it will be reset and gone if > you do this, so if you have anything there you may want make a spare > copy of the file before doing this. Things like the list of recently > opened notebooks, and the palettes and their positions that are opened > at startup, and kernel configurations, etc. Does a Command+, (command or apple key and the comma at the same time) > do anything? No, unfortunately nothing worked so I had to use Shift+Option keys while launching Mathematica. Now it works all fine (I didn't modify init.m or any other file). -- Franco Milicchio DiS - Dept. of Studies on Structures DIA - Dept. of Computer Science and Engineering University Roma Tre http://www.dia.uniroma3.it/~milicchi/ === Subject: Re: No preferences for OSX On Aug 6, 3:33 am, Franco Milicchio university. So, forgive if this is a recurrent topic, but in the > archives I didn't find anything about this problem. I copied the application and registered just fine, I tried it and the > kernel works. Unfortunately, the Preferences menu is disabled, so I > can't set, for example, my own color scheme. Is this a normal behavior for university licenses? Did you see > something like this in your experience? > PS. I am running OSX 10.5 and Mathematica 6.0.3. -- > Franco Milicchio DiS - Dept. of Studies on Structures > DIA - Dept. of Computer Science and Engineering > University Roma Trehttp://www.dia.uniroma3.it/~milicchi/ You might check the permissions of the ~/Library/Mathematica/FrontEnd directory (you should have read and write priviledges and the ~ refers to your home directory) and also see if there is an init.m file there that you can read and write to, although if this is a new install not sure if the file will even be there yet, but at least the directory should be readable and writable by you. If you want you can try to hold down Shift and Option on the keyboard when starting Mathematica -- CAUTION - this will recreate the init.m file in the FrontEnd directory and if you have anything there it will be reset and gone if you do this, so if you have anything there you may want make a spare copy of the file before doing this. Things like the list of recently opened notebooks, and the palettes and their positions that are opened at startup, and kernel configurations, etc. Does a Command+, (command or apple key and the comma at the same time) do anything? Good luck... -Bob === Subject: Re: Help with StyleSheets Stephen, A few months ago, Bob Ueland posted a link to two pages of detailed step-by-step instructions for creating a Style Sheet. http://bobueland.com/2008/06/14/create-a-style-sheet/ Also notice the link to a tutorial by David Park. Both of these should help you. Good luck. Richard Richard Hofler Professor Department of Economics -----Original Message----- === Subject: Help with StyleSheets I'm working with Mathematica 6, and I'm having trouble working with StyleSheets. What I'm looking to do is to change the formatting of the Input style. Here's what I did: 1. Open a new Notebook. 2. Format > Edit StyleSheet 3. Choose a Style to Modify > Input 4. Make sure the Input cell is selected and go to: Format > Font 5. Make the appropriate changes. After I did that, the appropriate sections in the Untitled-1 notebook changed to reflect the size and bold/normal status, but that's it. The font itself didn't change. What did I miss? Stephen === Subject: Re: Help with StyleSheets His steps are almost identical to mine. There is nothing there I can see that explains why the procedure I'm following doesn't work. Stephen > Stephen, A few months ago, Bob Ueland posted a link to two pages of detailed > step-by-step instructions for creating a Style Sheet. http://bobueland.com/2008/06/14/create-a-style-sheet/ Also notice the link to a tutorial by David Park. Both of these should help you. Good luck. Richard > Richard Hofler > Professor > Department of Economics -----Original Message----- === > Subject: Help with StyleSheets > I'm working with Mathematica 6, and I'm having trouble working with > StyleSheets. What I'm looking to do is to change the formatting of the > Input style. > Here's what I did: > 1. Open a new Notebook. 2. Format > Edit StyleSheet 3. Choose a Style to Modify > Input 4. Make sure the Input cell is selected and go to: Format > Font 5. Make the appropriate changes. > After I did that, the appropriate sections in the Untitled-1 notebook > changed to reflect the size and bold/normal status, but that's it. The > font > itself didn't change. What did I miss? Stephen === Subject: Help with StyleSheets I'm working with Mathematica 6, and I'm having trouble working with StyleSheets. What I'm looking to do is to change the formatting of the Input style. Here's what I did: 1. Open a new Notebook. 2. Format > Edit StyleSheet 3. Choose a Style to Modify > Input 4. Make sure the Input cell is selected and go to: Format > Font 5. Make the appropriate changes. After I did that, the appropriate sections in the Untitled-1 notebook changed to reflect the size and bold/normal status, but that's it. The font itself didn't change. What did I miss? Stephen === Subject: Re: Help with StyleSheets > I'm working with Mathematica 6, and I'm having trouble working with > StyleSheets. What I'm looking to do is to change the formatting of the > Input style. Here's what I did: 1. Open a new Notebook. 2. Format > Edit StyleSheet 3. Choose a Style to Modify > Input 4. Make sure the Input cell is selected and go to: Format > Font 5. Make the appropriate changes. After I did that, the appropriate sections in the Untitled-1 notebook > changed to reflect the size and bold/normal status, but that's it. The= font > itself didn't change. What did I miss? Stephen Hello Stephen I am not an expert for Style Sheets. But I hope the following comments will help you. Note: A) The style input (which is defined in Core.nb) has the option FormatType (which is set to InputForm) and the option DefaultFormatType (which is set to DefaultInputFormatType) B) The style InputForm (which is defined in Core.nb; see the Format Type Styles at Styles for Mathematica System-specific Elements) sets the option FontFamily to Courier. C) The default setting of the FormatType for input cells in the Mathematica FrontEnd is StandardForm. Use the menu item Edit / Preferences / Evaluation / Format type of new input cells to change that. To change the FontFamily option for input cells, you can do (e.g.) the following: A) Open the private stylesheet definitions (using the menu item Format / Edit Sylesheet) B) Modify the style Input to e.g. Cell[StyleData[Input], DefaultFormatType->InputForm] C) Modify the style InputForm to e.g. Cell[StyleData[InputForm],FontFamily->Times New Roman] You could also use the StandardForm in the following way: Cell[StyleData[Input], DefaultFormatType->StandardForm] Cell[StyleData[StandardForm],FontFamily->Times New Roman] But this would modify the style for input, output, graphics ... cells. Norbert Marxer === Subject: Re: Help with StyleSheets > I'm working with Mathematica 6, and I'm having trouble working with > StyleSheets. What I'm looking to do is to change the formatting of the > Input style. > Here's what I did: > 1. Open a new Notebook. 2. Format > Edit StyleSheet 3. Choose a Style to Modify > Input 4. Make sure the Input cell is selected and go to: Format > Font 5. Make the appropriate changes. > After I did that, the appropriate sections in the Untitled-1 notebook > changed to reflect the size and bold/normal status, but that's it. The font > itself didn't change. What did I miss? Stephen > One peculiar point is that you have to save the modified style sheet explicitly using Save As (not just Save) - maybe this caught you out. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Mathematica and Mathieu DEQ Results? Hi All, 1. I am using Mathematica, to solve the following DEQ: DSolve[x''[t] + (4[Pi]^2 - 2((-Pi^2/5) Cos[2 (Pi t)/100])))x[t] == 0, x[t], t] (1) This results in a solution of even and odd Mathieu functions as follows: x[t] = C[1] MathieuC[40000, -2000, Pi*t/100] + C[2] MathieuS[40000, -2000, Pi*t/100] 2. However, according to 1. I am using Mathematica, to solve the following DEQ: > DSolve[x''[t] + (4[Pi]^2 - 2((-Pi^2/5) Cos[2 (Pi t)/100])))x[t] == 0, > x[t], t] (1) This results in a solution of even and odd Mathieu functions as > follows: x[t] = C[1] MathieuC[40000, -2000, Pi*t/100] + C[2] MathieuS[40000, > -2000, Pi*t/100] 2. However, according to MathieuDifferentialEquation.html, > the result is: x[t] = C[1] MathieuC[4 Pi ^2, -Pi^2/5, Pi*t/100] + C[2] MathieuS[4 Pi > ^2, -Pi^2/5, Pi*t/100] (2) a. I am confused why I am getting these totally different results. b. The paper I am reading three different plots that match with (2) - where I am able to > duplicate the results/plots of the paper exactly using this method. Can someone out there shed light on why this is the case? Why can't Mathematica get the same result (or is it that the DEQ does > not have a unique solution based on some properties of Mathieu > functions)? Any insights are appreciated! It seems you have misread or interpreted what the arguments of Mathieu differential equation are and how they relate to the general solution. If the cosine has for argument two times the complex variable z, i.e. cos(2z) (Cos[2 z] in Mathematica syntax), then the solution is as follows: In[1]:= DSolve[y''[z] + (a - 2 q Cos[2 z]) y[z] == 0, y, z] Out[1]= {{y -> Function[{z}, C[1] MathieuC[a, q, z] + C[2] MathieuS[a, q, z]]}} In your case the cosine does match this pattern, so the expected solution cannot be so straightforwardly deduced as above. However, note that the solution returned by Mathematica is correct. In[2]:= mathieu = x''[t] + (4*Pi^2 - (2/5)*((-Pi^2)*Cos[(2*(Pi*t))/100]))*x[t] == 0; sol = DSolve[mathieu, x, t] mathieu /. sol[[1]] // Simplify Out[3]= {{x -> Function[{t}, C[1]*MathieuC[40000, -2000, (Pi*t)/100] + C[2]*MathieuS[40000, -2000, (Pi*t)/100]]}} Out[4]= True The following tutorial might be of some help: http://reference.wolfram.com/mathematica/tutorial/MathieuAndRelatedFunctions .html === Subject: Re: Mathematica and Mathieu DEQ Results? Surely your input wasn't DSolve[x''[t] + (4[Pi]^2 - 2((-Pi^2/5) Cos[2 (Pi t)/100])))x[t] == 0, x[t], t] since it (a) has an unmatched right parenthesis and (b) involves the (nonexistent) function 4 applied to Pi, 4[Pi]. Paste in the actual input, and we might get started. Bobby > Hi All, 1. I am using Mathematica, to solve the following DEQ: > DSolve[x''[t] + (4[Pi]^2 - 2((-Pi^2/5) Cos[2 (Pi t)/100])))x[t] == 0, > x[t], t] (1) This results in a solution of even and odd Mathieu functions as > follows: x[t] = C[1] MathieuC[40000, -2000, Pi*t/100] + C[2] MathieuS[40000, > -2000, Pi*t/100] 2. However, according to MathieuDifferentialEquation.html, > the result is: x[t] = C[1] MathieuC[4 Pi ^2, -Pi^2/5, Pi*t/100] + C[2] MathieuS[4 Pi > ^2, -Pi^2/5, Pi*t/100] (2) a. I am confused why I am getting these totally different results. b. The paper I am reading three different plots that match with (2) - where I am able to > duplicate the results/plots of the paper exactly using this method. Can someone out there shed light on why this is the case? Why can't Mathematica get the same result (or is it that the DEQ does > not have a unique solution based on some properties of Mathieu > functions)? Any insights are appreciated! ~A -- DrMajorBob@longhorns.com === Subject: Re: Mathematica and Mathieu DEQ Results? > 1. I am using Mathematica, to solve the following DEQ: > DSolve[x''[t] + (4[Pi]^2 - 2((-Pi^2/5) Cos[2 (Pi t)/100])))x[t] == 0, > x[t], t] (1) This results in a solution of even and odd Mathieu functions as > follows: x[t] = C[1] MathieuC[40000, -2000, Pi*t/100] + C[2] MathieuS[40000, > -2000, Pi*t/100] Looks correct (or at least consistent within Mathematica :-) to me (crosschecking symbolic results is always a good idea, whatever system you are using...): Simplify[ReleaseHold[ Hold[D[x[t], t, t] + (4 [Pi]^2 - 2 (-[Pi]^2/5) Cos[2 [Pi] t/100]) x[t] == 0] /. x[t] -> C[1] MathieuC[40000, -2000, ([Pi] t)/100] + C[2] MathieuS[40000, -2000, ([Pi] t)/100] ]] > 2. However, according to MathieuDifferentialEquation.html, > the result is: x[t] = C[1] MathieuC[4 Pi ^2, -Pi^2/5, Pi*t/100] + C[2] MathieuS[4 Pi > ^2, -Pi^2/5, Pi*t/100] (2) Can't find that result there, and FullSimplify[ReleaseHold[ Hold[D[x[t],t,t]+(4[Pi]^2-2(-[Pi]^2/5) Cos[2 [Pi] t/100])x[t]==0]/.x[t]->C[1] MathieuC[4 Pi^2,-Pi^2/5,Pi*t/100]+C[2] MathieuS[4 Pi^2,-Pi^2/5,Pi*t/100] ]] indicates that this is no solution. (Note that in general differentiating symbolically is much easier than solving differential equations symbolically, so these checks have proven to be very reliable for me in the past). I think you need to be more careful when applying the coordinate transformation from t -> t Pi/100. It will give a factor (100/Pi)^2 for the derivative, which can be rearranged to disappear by modifying a and q. So I think the result from Mathematica is perfectly correct, maybe it is easier to see what happens with this: DSolve[{x''[t] + (a - 2 q Cos[2 b t]) x[t] == 0}, x[t], t] > a. I am confused why I am getting these totally different results. Hm, I don't think Mathematica has anything to do with this :-) > b. The paper I am reading three different plots that match with (2) - where I am able to > duplicate the results/plots of the paper exactly using this method. Can someone out there shed light on why this is the case? No, but if they really get the above result I would wonder what was going wrong in the reviewing process :-) > Why can't Mathematica get the same result Hm, you could teach it to get wrong results, but it tries to be correct by default. > (or is it that the DEQ does > not have a unique solution based on some properties of Mathieu > functions)? I'm not an expert in Mathieu functions, so I can't tell, but the following indicates that there are no such properties (this of course also relies on a correct implementation of them in Mathematica): Solve[ Flatten@Table[{ C[1] MathieuC[40000, -2000, ([Pi] t)/100] + C[2] MathieuS[40000, -2000, ([Pi] t)/100] == C[1] MathieuC[4 Pi^2, -Pi^2/5, Pi*t/100] + C[2] MathieuS[4 Pi^2, -Pi^2/5, Pi*t/100] }, {t, 1, 2} ], {C[1], C[2]} ] {{C[1] -> 0, C[2] -> 0}} hth, albert === Subject: Re: Mathematica and Mathieu DEQ Results? 1) your DEQ is misspelled. I'll assume you meant DSolve[x''[t] + (4 Pi^2 - 2 ((-Pi^2/5) Cos[2 (Pi t)/100])) x[t] == 0, x[t], t] 2) your DEQ is of second order, so there are only two independent solutions; AFAIK there is no way that there could be more non-unique solutions. 3) the easiest way of checking the answers is back-substitution: you'll see that one answer (by Mathematica) is correct and the other (by mathworld) is not. Roman. === Subject: Re: Workaround for an unexpected behavior of Sum Yes Andrzej, I agree, you are right, I can see know very important advantages of your approach over mine: ONE: Using the flag, you avoid an infinite loop (actually, infinite recursion). The equivalent action in my approach was to verify if Unevaluated[dummyindex] is the same as the evaluated dummyindex. In my case, the evaluation of dummyindex could take a long time. We actually cannot know in advance how much time would that evaluation take, it depends whatever the end user has stored in dummyindex, which could be a long program that takes a lot of time to evaluate. Even worst, the evaluation of dummyindex could have unwanted results or side effects, again it depends on the content of dummyindex. Therefore my approach is potentially inefficient and potentially dangerous. On the other hand, in your approach you only verify if the flag is True or False: always fast, always safe, always reliable, great! TWO: It is easier also for a human being to understand your code. Mine is so full Hold, ReleaseHold, HoldPattern, it is just ugly. THREE: Your are using standard Mathematica scoping, while I was creating my own version of scoping. Although the dollar sign is (I think) kind of ugly, it is actually a good idea that appears as it does in your approach, because anyone with a minimum knowledge of scoping in Mathematica will recognize So, I totally surrender, your approach is better (though I would change the name of sumFlag to something like sumEnterOneTimeFlag, or something like that). Jose Mexico -----Mensaje original----- De: Andrzej Kozlowski [mailto:akoz@mimuw.edu.pl] Enviado el: Mi=E9rcoles, 06 de Agosto de 2008 10:40 Para: Mathematica news group mailing list CC: Jose Luis Gomez Asunto: Re: Workaround for an unexpected behavior of Sum Sorry, a silly error crept into the code: > Protect[sumFlag]; should have been (of course) Protect[Sum] Andrzej Kozlowski > Actually, you can also do that with the Module approach, which I > think is simpler than yours, and the only minor nuisance is having > to set a global flag. Here is the standard way to do this: Unprotect[Sum]; > sumFlag = True; Sum[sumand_, before___, {dummyindex_, rest___}, after___] := > Block[{sumFlag = False}, > Module[{dummyindex}, Sum[sumand, before, {dummyindex, rest}, > after]]] /; > Protect[sumFlag]; j = 7; > Sum[j^2, {j, 1, n}] > (1/6)*n*(n + 1)*(2*n + 1) Sum[f[j], {j, 1, n}] > Sum[f[j$550], {j$550, 1, n}] Note that in the case of Product you get somewhat different behavior > from the case of Sum: Product[j^2, {j, 1, n}] > 49^n Product[f[j], {j, 1, n}] > During evaluation of In[15]:= General::ivar:7 is not a valid > variable. > During evaluation of In[15]:= General::ivar:7 is not a valid > variable. > Product[f[7], {j, 1, n}] This confirms that the behavior of Sum is a bug. Andrzej Kozlowski === Subject: Re: Workaround for an unexpected behavior of Sum Albert Another issue, somehow related with your answer, Albert, is that Mathematica has two different ways to specify double sums, the two of them format the same in standard form (with the sigma notation), but they are not consider to be equal by Mathematica (I already posted this in another thread of this forum, however I considered relevant to mention it again): Evaluate in a Mathematica notebook this code: Sum[Sum[f[j], {j, 1, k}], {k, 1, n}]==Sum[f[j], {k, 1, n}, {j, 1, k}] As you can see, both sides of the equation display exactly equal in a notebook, using two sigmas, etc. However Mathematica does not simplify this to True, not even using Simplify or Reduce: Simplify[ Sum[Sum[f[j], {j, 1, k}], {k, 1, n}]==Sum[f[j], {k, 1, n}, {j, 1, k}] ] Mathematica is a great software, I feel happy of making a small contribution to possible improvements/fixes. I already reported these two issues (dummy index versus global variables, and nested sums not equal to two-indices form) to the support team of Wolfram Research. Please if anyone has further ideas besides those of Andrzej and Albert, I will certainly be happy to read about them Jose Mexico -----Mensaje original----- De: Albert Retey [mailto:awnl@gmx-topmail.de] Enviado el: Viernes, 08 de Agosto de 2008 06:15 Para: mathgroup@smc.vnet.net Asunto: Re: Workaround for an unexpected behavior of Sum > Yes Andrzej, I agree, you are right, I can see know very important > advantages of your approach over mine: ONE: Using the flag, you avoid an infinite loop (actually, infinite > recursion). The equivalent action in my approach was to verify if > Unevaluated[dummyindex] is the same as the evaluated dummyindex. In my case, > the evaluation of dummyindex could take a long time. We actually cannot know > in advance how much time would that evaluation take, it depends whatever the > end user has stored in dummyindex, which could be a long program that takes > a lot of time to evaluate. Even worst, the evaluation of dummyindex could > have unwanted results or side effects, again it depends on the content of > dummyindex. Therefore my approach is potentially inefficient and potentially > dangerous. On the other hand, in your approach you only verify if the flag > is True or False: always fast, always safe, always reliable, great! I'm not in a position to criticize Adrzejs approach, but the following solution seems to achieve the same in a different way and has some advantages in my opinion, so it might also be of interest. By using ValueQ (or accessing OwnValues directly) you can easily decide whether or not a Symbol has a value without evaluating. So something like this would also do the job: Unprotect[Sum]; Sum[ sumand_, before___, {dummyindex_Symbol /; ValueQ[dummyindex], rest___}, after___ ] := Module[{dummyindex}, Sum[sumand, before, {dummyindex, rest}, after] ]; Protect[Sum]; I'm sure this approach has it's limits too (there could be additional trouble with UpValues or DownValues of the index), but I like it for the following reasons: 1) no dependence on the state of a global variable, which for whatever reason could be left in an inappropriate state (see e.g. nested sums below). 2) it is minimal invasive: it only intervenes when obviously necessary 3) it works also with nested sums: j=1;k=2; Sum[Sum[f[j], {j, 1, k}], {k, 1, n}] j = 1; k = 2; Sum[f[j, k], {k, 1, n}, {j, 1, k}] >> This confirms that the behavior of Sum is a bug. >> Andrzej Kozlowski After all a reliable solution can only be achieved by Wolfram in this case, everything else is just a workaround... hth, albert === Subject: Re: Workaround for an unexpected behavior of Sum > Yes Andrzej, I agree, you are right, I can see know very important > advantages of your approach over mine: ONE: Using the flag, you avoid an infinite loop (actually, infinite > recursion). The equivalent action in my approach was to verify if > Unevaluated[dummyindex] is the same as the evaluated dummyindex. In my case, > the evaluation of dummyindex could take a long time. We actually cannot know > in advance how much time would that evaluation take, it depends whatever the > end user has stored in dummyindex, which could be a long program that takes > a lot of time to evaluate. Even worst, the evaluation of dummyindex could > have unwanted results or side effects, again it depends on the content of > dummyindex. Therefore my approach is potentially inefficient and potentially > dangerous. On the other hand, in your approach you only verify if the flag > is True or False: always fast, always safe, always reliable, great! I'm not in a position to criticize Adrzejs approach, but the following solution seems to achieve the same in a different way and has some advantages in my opinion, so it might also be of interest. By using ValueQ (or accessing OwnValues directly) you can easily decide whether or not a Symbol has a value without evaluating. So something like this would also do the job: Unprotect[Sum]; Sum[ sumand_, before___, {dummyindex_Symbol /; ValueQ[dummyindex], rest___}, after___ ] := Module[{dummyindex}, Sum[sumand, before, {dummyindex, rest}, after] ]; Protect[Sum]; I'm sure this approach has it's limits too (there could be additional trouble with UpValues or DownValues of the index), but I like it for the following reasons: 1) no dependence on the state of a global variable, which for whatever reason could be left in an inappropriate state (see e.g. nested sums below). 2) it is minimal invasive: it only intervenes when obviously necessary 3) it works also with nested sums: j=1;k=2; Sum[Sum[f[j], {j, 1, k}], {k, 1, n}] j = 1; k = 2; Sum[f[j, k], {k, 1, n}, {j, 1, k}] >> This confirms that the behavior of Sum is a bug. >> Andrzej Kozlowski After all a reliable solution can only be achieved by Wolfram in this case, everything else is just a workaround... hth, albert === Subject: Re: Workaround for an unexpected behavior of Sum Sorry, a silly error crept into the code: > Protect[sumFlag]; should have been (of course) Protect[Sum] Andrzej Kozlowski > Actually, you can also do that with the Module approach, which I > think is simpler than yours, and the only minor nuisance is having > to set a global flag. Here is the standard way to do this: Unprotect[Sum]; > sumFlag = True; Sum[sumand_, before___, {dummyindex_, rest___}, after___] := > Block[{sumFlag = False}, > Module[{dummyindex}, Sum[sumand, before, {dummyindex, rest}, > after]]] /; > Protect[sumFlag]; j = 7; > Sum[j^2, {j, 1, n}] > (1/6)*n*(n + 1)*(2*n + 1) Sum[f[j], {j, 1, n}] > Sum[f[j$550], {j$550, 1, n}] Note that in the case of Product you get somewhat different behavior > from the case of Sum: Product[j^2, {j, 1, n}] > 49^n Product[f[j], {j, 1, n}] > During evaluation of In[15]:= General::ivar:7 is not a valid > variable. > During evaluation of In[15]:= General::ivar:7 is not a valid > variable. > Product[f[7], {j, 1, n}] This confirms that the behavior of Sum is a bug. Andrzej Kozlowski > second I >> will ask if you can do something for me >> The advantage (not really an advantage, better: the behavior that >> I like) >> is that, after evaluating one time the (yes, very complex) code of my >> approach, after that the behavior of Sum is changed for ever (in >> that >> Mathematica session, of course), then you can use Sum (even better, >> you can >> use the palette BasicMathInput) as many times as you want, using the >> standard notation for sums, and not worrying about names of dummy >> indices >> conflicting with names of global variables. >> Oversimplifying: if I want to do only few sums, it is better your >> Module >> approach. I want to use many many times the command Sum, and I do >> Not want >> to check for possible conflicts with global variables, neither use >> Module >> every time I use sum, then evaluating one time the complex code I >> posted >> could be a good idea. >> Now Andrzej, would you be so kind to use some of your time to >> comment on the >> documentation for my Mathematica package Quantum in the following >> two links? >> Both are related with this issue, and I am very very interested in >> your >> comments and criticisms to the behavior of our package. These are >> the two >> links: >> (please notice that long urls are usually broken in this forum, so >> you might >> have to glue together each hyperlink) >> http://homepage.cem.itesm.mx/lgomez/quantum/sums/sums.html >> http://homepage.cem.itesm.mx/lgomez/quantum/tprodtpow/tprodtpow.html >> I really hope you find them interesting enough to comment >> Jose >> Mexico >> -----Mensaje original----- >> De: Andrzej Kozlowski [mailto:akoz@mimuw.edu.pl] >> Enviado el: Martes, 05 de Agosto de 2008 03:02 >> Para: mathgroup@smc.vnet.net >> Asunto: Workaround for an unexpected >> behavior of Sum >> I don't understand what you consider to be the advantage of your >> approach over the (to my mind) much simpler: >> j = 7; >> Module[{j}, Sum[g[j], {j, 1, n}]] >> Sum[g[j$679], {j$679, 1, n}] >> Andrzej Kozlowski > Workaround for an unexpected behavior of Sum >> Let me describe the problem, before describing the solution > (workaround) > that I found. >> First: Next calculation works fine for me: >> j = 7; >> Sum[j^2, {j, 1, n}] >> Mathematica gave the answer I was expecting (n*(1 + n)*(1 + 2*n))/6, > It > means the global j and the dummy index j are actually different That > is > o.k., that is what I was expecting >> HOWEVER Next calculation gives an unexpected answer: >> Clear[f]; >> j = 7; >> Sum[f[j], {j, 1, n}] >> Now Mathematica answers n*f[7]. That is NOT what I was expecting >> I was expecting that Mathematica will return the Sum unevaluated, > Sum[f[j], > {j, 1, n}], and also with j unevaluated, so that the global j and > the dummy > index j remain different. >> NOW MY WORKAROUND FOR THIS PROBLEM: AUTOMATICALLY CREATE A NEW > DUMMY INDEX > Evaluate > this in your Mathematica session: >> Unprotect[Sum]; > ReleaseHold[ >> Hold[Sum[sumando, before, {dummyindex, rest}, after]] /. >> HoldPattern[dummyindex] :> Evaluate[ >> Unique[ToString[Unevaluated[dummyindex]]]]] /; >> (dummyindex =!= Unevaluated[dummyindex]); Protect[Sum]; >> Now, after the evaluation of the previous code, Mathematica behaves > the way > I was expecting: >> Clear[f]; >> j = 7; >> Sum[f[j], {j, 1, n}] >> This time Mathematica answers Sum[f[j1],{j1,1,n}]. >> The price we have to pay is that the dummy index was renamed. >> But it is a DUMMY INDEX, it can have any name. >> command. >> AFAIK this code does Not affect the answers of Sum in other cases. >> I hope this simple solution is somehow useful. >> Notice that the command Integrate has a similar (in my opinion odd) > behavior, mixing dummy integration variables with global variables > when the > definite integral cannot be immediately performed. > Jose Luis Gomez-Munoz >> Mexico > === Subject: Re: Workaround for an unexpected behavior of Sum Actually, you can also do that with the Module approach, which I think is simpler than yours, and the only minor nuisance is having to set a global flag. Here is the standard way to do this: Unprotect[Sum]; sumFlag = True; Sum[sumand_, before___, {dummyindex_, rest___}, after___] := Block[{sumFlag = False}, Module[{dummyindex}, Sum[sumand, before, {dummyindex, rest}, after]]] /; Protect[sumFlag]; j = 7; Sum[j^2, {j, 1, n}] (1/6)*n*(n + 1)*(2*n + 1) Sum[f[j], {j, 1, n}] Sum[f[j$550], {j$550, 1, n}] Note that in the case of Product you get somewhat different behavior from the case of Sum: Product[j^2, {j, 1, n}] 49^n Product[f[j], {j, 1, n}] During evaluation of In[15]:= General::ivar:7 is not a valid variable. >> During evaluation of In[15]:= General::ivar:7 is not a valid variable. >> Product[f[7], {j, 1, n}] This confirms that the behavior of Sum is a bug. Andrzej Kozlowski second I > will ask if you can do something for me The advantage (not really an advantage, better: the behavior that > I like) > is that, after evaluating one time the (yes, very complex) code of my > approach, after that the behavior of Sum is changed for ever (in > that > Mathematica session, of course), then you can use Sum (even better, > you can > use the palette BasicMathInput) as many times as you want, using the > standard notation for sums, and not worrying about names of dummy > indices > conflicting with names of global variables. Oversimplifying: if I want to do only few sums, it is better your > Module > approach. I want to use many many times the command Sum, and I do > Not want > to check for possible conflicts with global variables, neither use > Module > every time I use sum, then evaluating one time the complex code I > posted > could be a good idea. Now Andrzej, would you be so kind to use some of your time to > comment on the > documentation for my Mathematica package Quantum in the following > two links? > Both are related with this issue, and I am very very interested in > your > comments and criticisms to the behavior of our package. These are > the two > links: > (please notice that long urls are usually broken in this forum, so > you might > have to glue together each hyperlink) http://homepage.cem.itesm.mx/lgomez/quantum/sums/sums.html http://homepage.cem.itesm.mx/lgomez/quantum/tprodtpow/tprodtpow.html I really hope you find them interesting enough to comment > Jose > Mexico > -----Mensaje original----- > De: Andrzej Kozlowski [mailto:akoz@mimuw.edu.pl] > Enviado el: Martes, 05 de Agosto de 2008 03:02 > Para: mathgroup@smc.vnet.net > Asunto: Workaround for an unexpected > behavior of Sum I don't understand what you consider to be the advantage of your > approach over the (to my mind) much simpler: j = 7; > Module[{j}, Sum[g[j], {j, 1, n}]] > Sum[g[j$679], {j$679, 1, n}] Andrzej Kozlowski >> Workaround for an unexpected behavior of Sum >> Let me describe the problem, before describing the solution >> (workaround) >> that I found. >> First: Next calculation works fine for me: >> j = 7; >> Sum[j^2, {j, 1, n}] >> Mathematica gave the answer I was expecting (n*(1 + n)*(1 + 2*n))/6, >> It >> means the global j and the dummy index j are actually different That >> is >> o.k., that is what I was expecting >> HOWEVER Next calculation gives an unexpected answer: >> Clear[f]; >> j = 7; >> Sum[f[j], {j, 1, n}] >> Now Mathematica answers n*f[7]. That is NOT what I was expecting >> I was expecting that Mathematica will return the Sum unevaluated, >> Sum[f[j], >> {j, 1, n}], and also with j unevaluated, so that the global j and >> the dummy >> index j remain different. >> NOW MY WORKAROUND FOR THIS PROBLEM: AUTOMATICALLY CREATE A NEW >> DUMMY INDEX >> Evaluate >> this in your Mathematica session: >> Unprotect[Sum]; >> ReleaseHold[ >> Hold[Sum[sumando, before, {dummyindex, rest}, after]] /. >> HoldPattern[dummyindex] :> Evaluate[ >> Unique[ToString[Unevaluated[dummyindex]]]]] /; >> (dummyindex =!= Unevaluated[dummyindex]); Protect[Sum]; >> Now, after the evaluation of the previous code, Mathematica behaves >> the way >> I was expecting: >> Clear[f]; >> j = 7; >> Sum[f[j], {j, 1, n}] >> This time Mathematica answers Sum[f[j1],{j1,1,n}]. >> The price we have to pay is that the dummy index was renamed. >> But it is a DUMMY INDEX, it can have any name. >> command. >> AFAIK this code does Not affect the answers of Sum in other cases. >> I hope this simple solution is somehow useful. >> Notice that the command Integrate has a similar (in my opinion odd) >> behavior, mixing dummy integration variables with global variables >> when the >> definite integral cannot be immediately performed. >> Jose Luis Gomez-Munoz >> Mexico > === Subject: Re: Workaround for an unexpected behavior of Sum will ask if you can do something for me The advantage (not really an advantage, better: the behavior that I like) is that, after evaluating one time the (yes, very complex) code of my approach, after that the behavior of Sum is changed for ever (in that Mathematica session, of course), then you can use Sum (even better, you can use the palette BasicMathInput) as many times as you want, using the standard notation for sums, and not worrying about names of dummy indices conflicting with names of global variables. Oversimplifying: if I want to do only few sums, it is better your Module approach. I want to use many many times the command Sum, and I do Not want to check for possible conflicts with global variables, neither use Module every time I use sum, then evaluating one time the complex code I posted could be a good idea. Now Andrzej, would you be so kind to use some of your time to comment on the documentation for my Mathematica package Quantum in the following two links? Both are related with this issue, and I am very very interested in your comments and criticisms to the behavior of our package. These are the two links: (please notice that long urls are usually broken in this forum, so you might have to glue together each hyperlink) http://homepage.cem.itesm.mx/lgomez/quantum/sums/sums.html http://homepage.cem.itesm.mx/lgomez/quantum/tprodtpow/tprodtpow.html I really hope you find them interesting enough to comment Jose Mexico -----Mensaje original----- De: Andrzej Kozlowski [mailto:akoz@mimuw.edu.pl] Enviado el: Martes, 05 de Agosto de 2008 03:02 Para: mathgroup@smc.vnet.net Asunto: Workaround for an unexpected behavior of Sum I don't understand what you consider to be the advantage of your approach over the (to my mind) much simpler: j = 7; Module[{j}, Sum[g[j], {j, 1, n}]] Sum[g[j$679], {j$679, 1, n}] Andrzej Kozlowski > Workaround for an unexpected behavior of Sum Let me describe the problem, before describing the solution > (workaround) > that I found. First: Next calculation works fine for me: j = 7; Sum[j^2, {j, 1, n}] Mathematica gave the answer I was expecting (n*(1 + n)*(1 + 2*n))/6, > It > means the global j and the dummy index j are actually different That > is > o.k., that is what I was expecting HOWEVER Next calculation gives an unexpected answer: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] Now Mathematica answers n*f[7]. That is NOT what I was expecting I was expecting that Mathematica will return the Sum unevaluated, > Sum[f[j], > {j, 1, n}], and also with j unevaluated, so that the global j and > the dummy > index j remain different. NOW MY WORKAROUND FOR THIS PROBLEM: AUTOMATICALLY CREATE A NEW > DUMMY INDEX > Evaluate > this in your Mathematica session: Unprotect[Sum]; > ReleaseHold[ Hold[Sum[sumando, before, {dummyindex, rest}, after]] /. HoldPattern[dummyindex] : > Evaluate[ Unique[ToString[Unevaluated[dummyindex]]]]] /; (dummyindex =!= Unevaluated[dummyindex]); Protect[Sum]; Now, after the evaluation of the previous code, Mathematica behaves > the way > I was expecting: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] This time Mathematica answers Sum[f[j1],{j1,1,n}]. The price we have to pay is that the dummy index was renamed. But it is a DUMMY INDEX, it can have any name. command. AFAIK this code does Not affect the answers of Sum in other cases. I hope this simple solution is somehow useful. Notice that the command Integrate has a similar (in my opinion odd) > behavior, mixing dummy integration variables with global variables > when the > definite integral cannot be immediately performed. > Jose Luis Gomez-Munoz Mexico === Subject: Re: Workaround for an unexpected behavior of Sum I don't understand what you consider to be the advantage of your approach over the (to my mind) much simpler: j = 7; Module[{j}, Sum[g[j], {j, 1, n}]] Sum[g[j$679], {j$679, 1, n}] Andrzej Kozlowski > Workaround for an unexpected behavior of Sum Let me describe the problem, before describing the solution > (workaround) > that I found. First: Next calculation works fine for me: j = 7; Sum[j^2, {j, 1, n}] Mathematica gave the answer I was expecting (n*(1 + n)*(1 + 2*n))/6, > It > means the global j and the dummy index j are actually different That > is > o.k., that is what I was expecting HOWEVER Next calculation gives an unexpected answer: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] Now Mathematica answers n*f[7]. That is NOT what I was expecting I was expecting that Mathematica will return the Sum unevaluated, > Sum[f[j], > {j, 1, n}], and also with j unevaluated, so that the global j and > the dummy > index j remain different. NOW MY WORKAROUND FOR THIS PROBLEM: AUTOMATICALLY CREATE A NEW > DUMMY INDEX > Evaluate > this in your Mathematica session: Unprotect[Sum]; Sum[sumando_, before___, {dummyindex_, rest___}, after___] := ReleaseHold[ Hold[Sum[sumando, before, {dummyindex, rest}, after]] /. HoldPattern[dummyindex] : > Evaluate[ Unique[ToString[Unevaluated[dummyindex]]]]] /; (dummyindex =!= Unevaluated[dummyindex]); Protect[Sum]; Now, after the evaluation of the previous code, Mathematica behaves > the way > I was expecting: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] This time Mathematica answers Sum[f[j1],{j1,1,n}]. The price we have to pay is that the dummy index was renamed. But it is a DUMMY INDEX, it can have any name. command. AFAIK this code does Not affect the answers of Sum in other cases. I hope this simple solution is somehow useful. Notice that the command Integrate has a similar (in my opinion odd) > behavior, mixing dummy integration variables with global variables > when the > definite integral cannot be immediately performed. > Jose Luis Gomez-Munoz Mexico === Subject: Workaround for an unexpected behavior of Sum Workaround for an unexpected behavior of Sum Let me describe the problem, before describing the solution (workaround) that I found. First: Next calculation works fine for me: j = 7; Sum[j^2, {j, 1, n}] Mathematica gave the answer I was expecting (n*(1 + n)*(1 + 2*n))/6, It means the global j and the dummy index j are actually different That is o.k., that is what I was expecting HOWEVER Next calculation gives an unexpected answer: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] Now Mathematica answers n*f[7]. That is NOT what I was expecting I was expecting that Mathematica will return the Sum unevaluated, Sum[f[j], {j, 1, n}], and also with j unevaluated, so that the global j and the dummy index j remain different. NOW MY WORKAROUND FOR THIS PROBLEM: AUTOMATICALLY CREATE A NEW DUMMY INDEX this in your Mathematica session: Unprotect[Sum]; Sum[sumando_, before___, {dummyindex_, rest___}, after___] := ReleaseHold[ Hold[Sum[sumando, before, {dummyindex, rest}, after]] /. HoldPattern[dummyindex] :> Evaluate[ Unique[ToString[Unevaluated[dummyindex]]]]] /; (dummyindex =!= Unevaluated[dummyindex]); Protect[Sum]; Now, after the evaluation of the previous code, Mathematica behaves the way I was expecting: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] This time Mathematica answers Sum[f[j1],{j1,1,n}]. The price we have to pay is that the dummy index was renamed. But it is a DUMMY INDEX, it can have any name. AFAIK this code does Not affect the answers of Sum in other cases. I hope this simple solution is somehow useful. Notice that the command Integrate has a similar (in my opinion odd) behavior, mixing dummy integration variables with global variables when the definite integral cannot be immediately performed. Jose Luis Gomez-Munoz Mexico === Subject: Re: Workaround for an unexpected behavior of Sum > Workaround for an unexpected behavior of Sum Let me describe the problem, before describing the solution (workaround) > that I found. First: Next calculation works fine for me: j = 7; Sum[j^2, {j, 1, n}] Mathematica gave the answer I was expecting (n*(1 + n)*(1 + 2*n))/6, It > means the global j and the dummy index j are actually different That is > o.k., that is what I was expecting HOWEVER Next calculation gives an unexpected answer: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] Now Mathematica answers n*f[7]. That is NOT what I was expecting I was expecting that Mathematica will return the Sum unevaluated, Sum[f[j], > {j, 1, n}], and also with j unevaluated, so that the global j and the dummy > index j remain different. NOW MY WORKAROUND FOR THIS PROBLEM: AUTOMATICALLY CREATE A NEW DUMMY INDEX > this in your Mathematica session: Unprotect[Sum]; Sum[sumando_, before___, {dummyindex_, rest___}, after___] := ReleaseHold[ Hold[Sum[sumando, before, {dummyindex, rest}, after]] /. HoldPattern[dummyindex] : > Evaluate[ Unique[ToString[Unevaluated[dummyindex]]]]] /; (dummyindex =!= Unevaluated[dummyindex]); Protect[Sum]; Now, after the evaluation of the previous code, Mathematica behaves the way > I was expecting: Clear[f]; j = 7; Sum[f[j], {j, 1, n}] This time Mathematica answers Sum[f[j1],{j1,1,n}]. The price we have to pay is that the dummy index was renamed. But it is a DUMMY INDEX, it can have any name. > AFAIK this code does Not affect the answers of Sum in other cases. I hope this simple solution is somehow useful. Notice that the command Integrate has a similar (in my opinion odd) > behavior, mixing dummy integration variables with global variables when the > definite integral cannot be immediately performed. > Jose Luis Gomez-Munoz Mexico It is very kind of Jose to call this odd behaviour, I would call it a serious bug. It means the that the iteration variables are not really localized, at least in some cases. WRI should correct it asap. === Subject: NDSolve::mconly in algebraic differential equations I have a bunch of algebraic differential equations. Right now they are 12 first order differential equations in 12 time dependent variables, but in the future they can be a little bit more. The coefficients are complex numbers. When I try to integrate them numerically in time, I get the following error: NDSolve::mconly: For the method IDA, only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions. In the NDSolve documentation though it says: The differential equations in NDSolve can involve complex numbers. I tried other methods but I get another error urging me to set the method to Automatic. Is Mathematica able to solve algebraic differential equations? How? -- Adel Elsabbagh http://www.svlab-asu.com/aelsabbagh.html === Subject: Re: Find count of binary number pattern within concatenated number Diana: StringCount[11011100101110111100010011010101111001101, 1101] http://reference.wolfram.com/mathematica/ref/StringCount.html Jose Mexico -----Mensaje original----- De: Diana [mailto:diana.mecum@gmail.com] Enviado el: Mi=E9rcoles, 06 de Agosto de 2008 04:04 Para: mathgroup@smc.vnet.net Asunto: Find count of binary number pattern within = concatenated number Math folks, Can someone tell me how to find the count of the occurrences of 1101 within 11011100101110111100010011010101111001101 generated with the n=13 11011100101110111100010011010101111001101. 1101 Diana === Subject: Re: Find count of binary number pattern within concatenated n = 13; Count[Partition[Flatten@IntegerDigits[Range[n], 2], 4], {1, 1, 0, 1}] 2 or Length@Position[ Partition[Flatten@IntegerDigits[Range[n], 2], 4], {1, 1, 0, 1}] 2 Bobby > Math folks, Can someone tell me how to find the count of the occurrences of 1101 > within 11011100101110111100010011010101111001101 generated with the n=13 > 11011100101110111100010011010101111001101. > 1101 Diana > -- DrMajorBob@longhorns.com === Subject: Re: Find count of binary number pattern within concatenated number If it is permissible to convert to a string, I suppose you could use: In[25]= StringCount[ToString[exp], 1101] Out[25]= 4 In[26]= StringPosition[ToString[exp], 1101] Out[26]= {{1, 4}, {12, 15}, {25, 28}, {38, 41}} Tom Dowling > Math folks, Can someone tell me how to find the count of the occurrences of 1101 > within 11011100101110111100010011010101111001101 generated with the n=13 > 11011100101110111100010011010101111001101. > 1101 Diana > === Subject: Re: Find count of binary number pattern within concatenated number StringCount? StringCount[%, 1101] Out[5]= 11011100101110111100010011010101111001101 Out[6]= 4 Adriano Pascoletti 2008/8/6 Diana within 11011100101110111100010011010101111001101 generated with the n=13 > 11011100101110111100010011010101111001101. > 1101 Diana > === Subject: Re: Find count of binary number pattern within concatenated > Math folks, Can someone tell me how to find the count of the occurrences of 1101 > within 11011100101110111100010011010101111001101 generated with the n=13 > 11011100101110111100010011010101111001101. > 1101 Diana list of digits, with offset of 1 and length of the number of digits in n. Then call on the Count (the Mathematica function, not Dracula). countValInRangeVal[n_,base_] := Module[ {digits=IntegerDigits[n,base], alldigits}, alldigits = Flatten[IntegerDigits[Range[n],base]]; Count[Partition[alldigits,Length[digits],1], digits] ] If you are fond of long one liners: countValInRangeVal2[n_,base_] := Count[Partition[Flatten[ IntegerDigits[Range[n],base]],Length[#],1],#]& [IntegerDigits[n,base]] Other long one-liners might include http://en.wikipedia.org/wiki/Long_line_(topology) or perhaps the final sentence of Joyce's Ulysses. Lichtblau Wolfram Research === Subject: Re: question about sorting lists I just want to thank everyone who provided answers to my question about sorting lists. This information has been very helpful. Tatyana === Subject: Re: Histogram package .. and here's the code and the error massage... Histogram[{4/54, 5/54, 5/54, 5/54, 8/54, 7/54, 5/54, 7/54, 8/54}, FrequencyData -> True] Range::range: Range specification in Range[Ceiling[-0.05+0./Histograms`Private`TickSpacing[9.,7,{1,2,2.5,5, 10}]],Floor[0.05+9./<<1>>]] does not have appropriate bounds. >> Range::range: Range specification in Range[Ceiling[-0.05+0./Histograms`Private`TickSpacing[9.,7.,{1.,2.,2. 5,5.,10.}]],Floor[0.05+9./<<1>>]] does not have appropriate bounds. >> === Subject: Re: Histogram package Works on my system 6.0 for Microsoft Windows (32-bit) (May 21, 2008) > .. and here's the code and the error massage... Histogram[{4/54, 5/54, 5/54, 5/54, 8/54, 7/54, 5/54, 7/54, 8/54}, > FrequencyData -> True] Range::range: Range specification in > Range[Ceiling[-0.05+0./Histograms`Private`TickSpacing[9.,7,{1,2,2.5,5, > 10}]],Floor[0.05+9./<<1>>]] does not have appropriate bounds. Range::range: Range specification in > Range[Ceiling[-0.05+0./Histograms`Private`TickSpacing[9.,7.,{1.,2.,2. > 5,5.,10.}]],Floor[0.05+9./<<1>>]] does not have appropriate bounds. > === Subject: Re: Histogram package > ... and here's the code and the error massage... Histogram[{4/54, 5/54, 5/54, 5/54, 8/54, 7/54, 5/54, 7/54, 8/54}, > FrequencyData -> True] Range::range: Range specification in > Range[Ceiling[-0.05+0./Histograms`Private`TickSpacing[9.,7,{1,2,2.5,5, > 10}]],Floor[0.05+9./<<1>>]] does not have appropriate bounds. Range::range: Range specification in > Range[Ceiling[-0.05+0./Histograms`Private`TickSpacing[9.,7.,{1.,2.,2. > 5,5.,10.}]],Floor[0.05+9./<<1>>]] does not have appropriate bounds. >> The following works fine on my system (64-bit Intel Mac OS X Leopard 1.5.4 Mathematica 6.0.3). You should tell us more about your system configuration and also try the following code from within a new Mathematica session. In[1]:= $Version Needs[Histograms`] Histogram[{4/54, 5/54, 5/54, 5/54, 8/54, 7/54, 5/54, 7/54, 8/54}, FrequencyData -> True] Out[1]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) Out[3]= [... Histogram displayed without any error messages ...] === Subject: Multiplying a vector over multiple vectors How does one get a vector to distribute over a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow when the vectors are large (consisting of thousands of elemets). Don === Subject: Re: Multiplying a vector over multiple vectors > How does one get a vector to distribute over >> a list of vectors under multiplication? >> For example: >> {{1,2}, {3,4}, {5,6}} times {a,b} should >> equal (under this operation) >> {{a, 2b}, {3a, 4b}, {5a, 6b}} >> If {a,b} is duplicated three times one can >> use MapThread as in: >> MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, >> b}}}] >> but duplicating {a,b} using Table is very slow >> when the vectors are large (consisting of thousands >> of elemets). FWIW, here are some possible ways with their respective timings: In[1]:= lst = RandomInteger[{-100, 100}, {10^5, 2}]; > Array[{lst[[#, 1]] a, lst[[#, 2]] b} &, Length@lst]; // > Timing // First > # {a, b} & /@ lst; // Timing // First > MapThread[Times, {lst, Table[{a, b}, {Length[lst]}]}]; // > Timing // First > MapThread[Times, {lst, ConstantArray[{a, b}, Length[lst]]}]; // > Timing // First > Table[{lst[[i, 1]] a, lst[[i, 2]] b}, {i, Length@lst}]; // > Timing // First > Transpose[{a lst[[All, 1]], b lst[[All, 2]]}]; // Timing // First Out[2]= 0.555598 Out[3]= 0.522737 Out[4]= 0.510453 Out[5]= 0.474941 Out[6]= 0.407999 Out[7]= 0.323102 > Somewhat surprisingly no-one seems to have suggested the approach that seems to me the most obvious: lst /. x_?VectorQ :> x {a, b} This seems to be the second fastest approach, on my machine loosing only slightly to Jean-Marc's last one. Andrzej Kozlowski === Subject: Re: Multiplying a vector over multiple vectors In[1]:= m = Table[Random[Integer,{-100,100}],{10^5},{2}]; First@Timing[p = Transpose[{a,b} Transpose@m];] First@Timing[q = Transpose[{a m[[All,1]], b m[[All,2]]}];] First@Timing[r = Inner[Times,m,{a,b},List];] SameQ[p,q,r] Out[2]= 0.7 Second Out[3]= 0.71 Second Out[4]= 0.55 Second Out[5]= True > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1,2}, {3,4}, {5,6}}, {{a,b}, {a,b}, {a,b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). > Don === Subject: Re: Multiplying a vector over multiple vectors lst={{1,2}, {3,4}, {5,6}}; and {a, b}*# & /@ lst or Transpose[{a, b}*Transpose[lst]] Jens > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). > Don > === Subject: Re: Multiplying a vector over multiple vectors > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). FWIW, here are some possible ways with their respective timings: In[1]:= lst = RandomInteger[{-100, 100}, {10^5, 2}]; Array[{lst[[#, 1]] a, lst[[#, 2]] b} &, Length@lst]; // Timing // First # {a, b} & /@ lst; // Timing // First MapThread[Times, {lst, Table[{a, b}, {Length[lst]}]}]; // Timing // First MapThread[Times, {lst, ConstantArray[{a, b}, Length[lst]]}]; // Timing // First Table[{lst[[i, 1]] a, lst[[i, 2]] b}, {i, Length@lst}]; // Timing // First Transpose[{a lst[[All, 1]], b lst[[All, 2]]}]; // Timing // First Out[2]= 0.555598 Out[3]= 0.522737 Out[4]= 0.510453 Out[5]= 0.474941 Out[6]= 0.407999 Out[7]= 0.323102 === Subject: Re: Multiplying a vector over multiple vectors First /@ Outer[Times, {{1, 2}, {3, 4}, {5, 6}}, {{a, b}}, 1] {{a,2 b},{3 a,4 b},{5 a,6 b}} > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). > Don > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Multiplying a vector over multiple vectors > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). You can just use Map {a,b} #&/@{{1,2},{3,4},{5,6}} === Subject: Re: Multiplying a vector over multiple vectors Don, > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). > Don > you can Map v1 over v2 v1 = {a,b}; v2 = {{1,2}, {3,4}, {5,6}}; Times[v1,#]& /@ v2 Oliver === Subject: Re: Multiplying a vector over multiple vectors > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} Thread[Times[Transpose@{{1, 2}, {3, 4}, {5, 6}}, {a, b}]] hth, albert === Subject: Re: Multiplying a vector over multiple vectors testmatrix = {{1, 2}, {3, 4}, {5, 6}}; {a, b} # & /@ testmatrix {{a, 2 b}, {3 a, 4 b}, {5 a, 6 b}} First@Outer[Times, {a, b}, testmatrix] {{a, 2 a}, {3 a, 4 a}, {5 a, 6 a}} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > How does one get a vector to distribute over > a list of vectors under multiplication? For example: {{1,2}, {3,4}, {5,6}} times {a,b} should > equal (under this operation) {{a, 2b}, {3a, 4b}, {5a, 6b}} If {a,b} is duplicated three times one can > use MapThread as in: MapThread[Times, {{{1, 2}, {3, 4}, {5, 6}}, {{a, b}, {a, b}, {a, b}}}] but duplicating {a,b} using Table is very slow > when the vectors are large (consisting of thousands > of elemets). > Don > === Subject: simple pattern match question Hello UG: I am trying to understand simple pattern rule evaulation. The following trivial examples baffles me: --------------------------------------------------- In[1]:= f[x_Number] := x ^ 2 In[2]:= f[3] Out[2]= f[3] In[3]:= f[3.3] Out[3]= f[3.3] In[4]:= NumberQ[3.3] Out[4]= True -------------------------------------------------- Why is it that f[3.3] does not evaluate?? TIA. === Subject: Re: simple pattern match question > Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? TIA. > Didn't you want the following? f[x_?NumberQ] := x^2 f[3] = 9 f[3.3] = 10.89 f[p] = f[p] You could also do thing like f[x_?IntegerQ] := x^2 f[3] = 9 f[3.3] = f[3.3] Hope I understood your original question correctly . ~W === Subject: Re: simple pattern match question You should use the query (?) In[1]:= f[x_?NumberQ] := x ^ 2 In[2]:= f[3] Out[2]= 9 In[3]:= f[3.3] Out[3]= 10.89 In[4]:= f[r] Out[4]= f[r] This means function f only works on things that return True on the NumberQ[expr_] function Steven Siew > Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? TIA. > === Subject: Re: simple pattern match question > I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? The pattern x_Number matches any expression with head Number. The head Number does not exist natively in Mathematica. The numbers 3 and 3.3 have head Integer and Real, respectively. In[1]:= Head[3] Head[3.3] Out[1]= Integer Out[2]= Real So, except if you define some expression with head Number, the definition of the function f will match nothing and the function f will return unevaluated in all cases. The pattern x_?NumberQ tests whether the expression x is a number, that is if upon evaluation the resulting expression has head Integer, Rational, Real, or Complex. (Note that Number[Pi] failed.) The pattern x_?NumericQ test whether the expression x can be evaluated to a numeric quantity. (NumericQ[Pi] returns True.) In[3]:= f[x_?NumberQ] := x^2 f[3] f[3.3] Out[4]= 9 Out[5]= 10.89 HTH, === Subject: Re: simple pattern match question Roger, the Mathematica help says that Number represents an exact integer or an approximate real number in Read. Use NumericQ: In[1]:= f[(x_)?NumericQ] := x^2 In[2]:= f[3] Out[2]= 9 In[3]:= f[3.3] Out[3]= 10.889999999999999 If you are tempted to use NumberQ note that In[4]:= NumberQ[Pi] Out[4]= False In[5]:= NumericQ[Pi] Out[5]= True Adriano Pascoletti 2008/8/7 Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? TIA. === Subject: Re: simple pattern match question > Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? for the same reason f[3] does not evaluate, the pattern _Number matches expressions whose head is Number, the head of 3 is Integer the head of 3.3 is Real, neither match. If you want f to only evaluate for real values define it as f[x_Real]. Ssezi === Subject: Re: simple pattern match question > Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? Because neither 3 nor 3.3 have Head Number: In[31]:= Head[3] Out[31]= Integer In[32]:= Head[3.3] Out[32]= Real Also NumberQ and Number are different things, actually Number is only used to define Formats for Read. What you probably want is one of the following: f[x_Real]:=x^2 f[x_Integer]:=x^2 f[x_?NumberQ]:=x^2 (if playing around with these make sure to ClearAll[f] before redefining f, otherwise the definitions will accumulate). Note that more often this is useful: f[x_?NumericQ]:=x^2 you will find more information about NumberQ, NumericQ and Heads in the documentation... hth, albert === Subject: Re: simple pattern match question Just a small error in syntax. What you want is: f[x_?NumberQ] := x^2 f[3] 9 f[3.3] 10.89 -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? TIA. === Subject: Re: simple pattern match question because you mean f[x_?NumericQ]:=x^2 Jens > Hello UG: I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] In[3]:= f[3.3] > Out[3]= f[3.3] In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? TIA. === Subject: User-Supplied Jacobian in NDSolve I am using compiled functions (values computed with Compile or Mathlink) and so I wrap my functions to ensure only numerical values are supplied to these functions: f[x_Real]:=fCompiled[x]; Therefore, if NDSolve could derive a symbolic Jacobian, then I assume that NDSolve can not elucidate it for f[x_Real] since the functions are numeric. I guess I have two questions: 1) Does NDSolve use an analytic Jacobian an any case and 2) Is it possible to supply a User-Defined Jacobian to NDSolve I think that it can be done in general, given experience with GSL, LSODA,= etc. Eric === Subject: Re: Find count of binary number pattern within n = 13; data1 = Flatten[IntegerDigits[Range[n], 2]] {1,1,0,1,1,1,0,0,1,0,1,1,1,0,1,1,1,1,0,0,0,1,0,0,1,1,0,1,0,1,0,1,1,1, 1,0,0,1,1,0,1} Count[Partition[data1, 4, 1], {1, 1, 0, 1}] 4 IntegerDigits[Range[n], 2]]] 11011100101110111100010011010101111001101 Count[Partition[IntegerDigits[data2], 4, 1], {1, 1, 0, 1}] 4 Length[StringCases[ToString[data2], 1101]] 4 StringCount[ToString[data2], 1101] 4 Math folks, Can someone tell me how to find the count of the occurrences of 1101 within 11011100101110111100010011010101111001101 generated with the n=13 11011100101110111100010011010101111001101. 1101 Diana === Subject: Solving complex equations If I have a complex equation in the form of a+b I + c+d I == 3+ 4 I where a, b, c, and d are all assumed to be real. How do I tell Mathematica 6 to separate the real and imaginary parts to make two equations in the form of a + c == 3, and b + d == 4. I need this to apply it on a long list of equations. -- Adel Elsabbagh http://www.svlab-asu.com/aelsabbagh.html === Subject: Re: Solving complex equations > If I have a complex equation in the form of > a+b I + c+d I == 3+ 4 I > where a, b, c, and d are all assumed to be real. How do I tell Mathematica 6 to separate the real and imaginary parts to make > two equations in the form of > a + c == 3, and > b + d == 4. I need this to apply it on a long list of equations. A possible approach could be the following thought it might need some tweaking depending on the actual structure of your equations. expr = a + b I + c + d I == 3 + 4 I; Thread[ComplexExpand[expr] /. Plus[r___, Times[Complex[0, 1], Plus[i___]]] :> {Plus[r], i} /. Complex[a_, b_] -> List[a, b]] {a + c == 3, b + d == 4} === Subject: Re: Solving complex equations One method: ceqn1 = a1 + b1 I + c1 + d1 I == 3 + 4 I; ceqn2 = a2 + b2 I + c2 + d2 I == 6 - 5 I; cequations = {ceqn1, ceqn2}; f = Function[eqn, ComplexExpand[{Re[#], Im[#]}] & /@ eqn]; Thread[f@#] & /@ cequations // Flatten {a1 + c1 == 3, b1 + d1 == 4, a2 + c2 == 6, b2 + d2 == -5} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ If I have a complex equation in the form of > a+b I + c+d I == 3+ 4 I > where a, b, c, and d are all assumed to be real. How do I tell Mathematica 6 to separate the real and imaginary parts to > make > two equations in the form of > a + c == 3, and > b + d == 4. I need this to apply it on a long list of equations. > -- > Adel Elsabbagh > http://www.svlab-asu.com/aelsabbagh.html === Subject: Re: Solving complex equations