mm-839 === Subject: Re: perplexed by blank sequence in pattern replacement > I expected Out[1]={a,b,c}, from a naieve reading of the full form of > a*b*c > In[2]:=FullForm[a*b*c] > Out[2]//FullForm=Times[a,b,c] Incidentally, it's worth mentioning that in this example all you want to do is change the head of an expression (from Times to List). Apply does that very very quickly, without messing around with patterns. In[20]:= Apply[List,a*b*c] Out[20]= {a,b,c} List@@(a*b*c) is a variant syntax for the same thing. Of course, this example may be simpler than what you ultimately intended to do. === Subject: Re: Several functions in a single 2D-plot Needs[Statistics`]; Plot[ Evaluate[ Table[ PDF[NormalDistribution[m, 1],x], {m,0,2}]], {x,-3,5}, PlotStyle->{Red,Green,Blue}]; Bob Hanlon > > I am new to Mathematica, and I have a quick question that will be very > easy for you, I guess. > > How can I plot several functions within the same 2D graphic? > > For example, I want to draw the PDF of 3 continuous statistical > distributions (I mean, 3 functions), but put together into the same 2D > plot. > > > -- > Vicent > === Subject: memory issues Hi! Pro. I get the message: No more memory available. Mathematica Kernel has shut down... How do I find out: 2) How much memory can Mathematica store on the Hard disk (swap file)? 3) At which memory limit does Mathematica begin writting to the had disk? 3) Can I influence these limit 3) using the OS or in Mathematica? 4) How do I find out at which point in the calculation the kernel stops? 5) Why does my dual core processor does not work higher than with 50% Doing some tests on my own I got the following riddle: In[]:=ByteCount[1] Out[]:=16 In[]:=2000000000/16 Out[]:=125000000 In[]:=DAT=Table[i,{i,1,125000000}]; In[]:=ByteCount[DAT] Out[]:=500000056 In[]:=MaxMemoryUsed[] Out[]:= 502133312 Why is a list of 125 000 000 different integers (a 16 Byte) only 500 000 000 Bytes long? How should I estimate the memory limits in my algorithms, when designing them on this basis? Christoph === Subject: Preventing NIntegrate from reevaluating after DumpSave and Get I have been running a computation in Mathematica which attempts to NIntegrate[myformula,{t,0,infinity}] for many different model parameters. The results are in a large list. e.g. resultslist = {0, 7, 13.33, NIntegrate[myformula_at_tricky_parameter_vals,{t,0,infinity}],11,2,...} Notice that sometimes NIntegrate does not converge for particular model parameters. At the end of a long-running batch job, I DumpSave this results list. Now, my question is this: When I load the results back into Mathematica and try to use them things are very slow. I suspect that this is because Mathematica retries evaluating all the NIntegrate[...] on which it got stuck the first time around. I have tried e.g. Get[MyFile.mx] sanelist = resultslist /. NIntegrate[___]->NotANumber but this also takes ages evaluating the NIntegrate[...]. Is there an easy way to load the .mx file and eliminate any of the non-converged NIntegrate[...] entries without having to wait for them to all be evaluated another time? Chris Rodgers. === Subject: RE: Several functions in a single 2D-plot Hi Vicent, > I am new to Mathematica, and I have a quick question that > will be very easy for you, I guess. > > How can I plot several functions within the same 2D graphic? > > For example, I want to draw the PDF of 3 continuous > statistical distributions (I mean, 3 functions), but put > together into the same 2D plot. > It's straightforward -- see examples in online help for Show[]. As an example, after defining a list of colours and a series of plots, we can display them on the same axes using Show[]. col = Hue[#/11.] & /@ Range[10]; plt = Plot[BesselJ[#, x], {x, 0, 10}, PlotStyle -> col[[#]], DisplayFunction -> Identity] & /@ Range[10]; Show[plt, DisplayFunction -> $DisplayFunction, PlotRange -> All]; Dave. === Subject: NonlinearFit + Sums I want to do a mulitdimensional nonlinear fitting and I'm not sure how to define the mathematica statement for that. I have a matrix data of dimensions 140x37 that contains 36 samples of 140 functions. The 37th column contains the resulting value of a mapping of the type R36->R1. I want to calculate the parameter mu of a function that integrates over the samples - i posted a simplified version of the function below. My problem is, that I don't know what to write instead of x_i. For the second x_ it should be something like {x1, x2, x3, x4, ..., x36}. But the first x_i should be something like x[[i]] (this doesn't work ofc). How do i assign the data to the sum? NonlinearFit[data, Sum[E^(mu)*x_i, {i, 1, 36}], x_i, {mu}] I hope you can help :-) === Subject: Re: Complexity of quantifier elimination > I would like to know the computational complexity of the algorithm > used by > Mathematica for eliminating quantifiers from polynomials, > preferably in the > domain of Reals. It would be very helpful if someone could let me > know about > it or point me towards some relevant literature from where I can > figure it > out. I assume Mathematica exploits the algorithms with the best > complexity. If > not, any reference to the algorithm with the best complexity will be > appreciated. Bonny. I believe Mathematica uses Collins's Cylindrical Algebraic Decomposition for quantifier elimination. The complexity of this algorithm is huge : double exponential in the number of variables. A much faster algorithm exists and is due to Basu, Pollack and Roy (see their book Algorithms in Real Algebraic Geometry). The complexity of this algorithm is still double exponential but not in the number of variables but in the number of blocks of variables, where the blocks of variables are delimited by alternations of the existential and universal quantifiers. I am not sure if this algorithm has ever been implemented in practice. Certainly, at the time when the book state so in the preface). Having glanced at their argument, it seems to me that such an implementation would be a highly non-trivial task. Of course, if you really wish to know, you could try searching the Internet for this topic. Another possibility is that Adam Strzebonski will post a more accurate answer than mine ;-) Andrzej Kozlowski === Subject: Re: too many special linear matrices >p = 3; >r = Reduce[Mod[o l - m n, p] == 1 && 0 <= l < p && >0 <= m < p && 0 <= n < p && 0 <= o < p, >{l, m, n, o}, Integers] and the list of matrices: s = {{l,m},{n,o}} /. {ToRules[r]} Carl Woll >Wolfram Research > > > > Carl K. Woll, It always helps if you separate the Mathemaica code for cut and pasting to Mathematica! Here's my effort to get a 24 element (SL[2,3] group) mass Klein-Gordon quantum equation. It appears that the result doesn't have the right angular content for an SU(5) like isomorphic group. If you use p=2 in this it will go much faster to test if it works for your version of Mathematica. Oh, sorry , your code doesn't work at p=2, I just tried it. and got {}. I got it to work for p=3,5. I haven't tried p=7. Roger Bagula Mathematica code: (*SL[2, Prime] : from Carl K.Woll *) p = 3; r = Reduce[Mod[o l - m n, p] == 1 && 0 <= l < p && 0 <= m < p && 0 <= n < p && 0 <= o < p, {l, m, n, o}, Integers]; s0 = {{l, m}, {n, o}} /. {ToRules[r]}; (* Cayley multiplication table*) MatrixForm[Table[Mod[s0[[n]].s0[[m]], p], {n, 1, Length[s]}, {m, 1, Length[s]}]] (* exponential Wave Function definitions space partition functions*) phi[n_] := Exp[x[n]*s0[[n]]] (* Jacobian from Paul Abbott*) jacobian = D[Table[phi[n], {n, 1, Length[ s]}], {Table[x[n], {n, 1, Length[s]}]}]; a = Tr[ Transpose[jacobian] . jacobian, List] // Simplify (* metric as a vector*) guv = a.a (* hyperplane full quantum number wave function of 24 group *) PhiX = Exp[Sum[q[n]*x[n]*s0[[n]], {n, 1, Length[s]}]] (* Klein - Gordon Mass gap*) dd = Sum[D[PhiX, {x[n], 2}], {n, 1, Length[s]}] Aut = FullSimplify[dd/PhiX] FullSimplify[Det[Aut]] === Subject: Re: too many special linear matrices >The code below will produce the list of elements of SL[n,p] (as long >as n and p are not too large): SL[n_, p_] := Module[{vars = > Table[Unique[ > a], {n^2}], iters, mat}, iters = Map[{#, 0, p - 1} &, vars]; mat = > Partition[vars, n]; Reap[ > Do[If[Det[mat, > Modulus -> p] == 1, Sow[mat], Continue[]], Evaluate[Sequence @@ > iters]]][[2, 1]]] >For n=2 it gives the lengths: >Table[Length[SL[2,Prime[i]]],{i,1,7}] >{6,24,120,336,1320,2184,4896} which agree with the formula I sent earlier: In[16]:= >Table[f[2,Prime[i]],{i,1,7}] Out[16]= >{6,24,120,336,1320,2184,4896} Andrzej Kozlowski > > Andrzej Kozlowski, You give the correct anwers in this post, but your code doesn't run in my 5.1 version. Roger Bagula === Subject: Re: too many special linear matrices >p = 3; >r = Reduce[Mod[o l - m n, p] == 1 && 0 <= l < p && >0 <= m < p && 0 <= n < p && 0 <= o < p, >{l, m, n, o}, Integers] and the list of matrices: s = {{l,m},{n,o}} /. {ToRules[r]} Carl Woll >Wolfram Research > > > > Carl K. Woll Roger Bagula === Subject: Re: product formula in mathematica In general, if you have a list lis of numbers, you can find their product by Apply[Times, lis] or, in abbreviated format: Times @@ lis So a strategy would be to form first the list of numbers to be multiplies, and then use the above. Now I'm not quite sure what you mean by x_i in your posting. Are you trying to explicitly use subscripts (via the Notation package)? Indices via the x[[i]] notation? Ordinary arguments via the x[i] notation. In any case, since you have no particular pattern in mind for the subscripts, you'll somehow have to specify them one-by-one. For example (doing it slowly, step by step): x = Table[i^2, {i, 1, 10}] {1, 4, 9, 16, 25, 36, 49, 64, 81, 100} indices = {1,3,4,9} {1, 3, 4, 9} x[[indices]] {1, 9, 16, 81} f[x_] := 1/x (* for example *) f[x[[indices]]] {1, 1/9, 1/16, 1/81} Times @@ f[x[[indices]]] 1/11664 In the above, I'm using, and assuming you have, a function f that has attribute Listable. (Also, I actually showed the InputForm of the two results that have fractions in them.) > Hi I am interested in doing a product over a set of indices that are > not continuous > Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears > that the iterator wouldonly take sequences such as 1...10 etc. > > > -- 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: product formula in mathematica > Hi I am interested in doing a product over a set of indices > that are not continuous > Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears > that the iterator wouldonly take sequences such as 1...10 etc. Depends exactly what you want .... There is a form of the product function that takes a step, eg. Product[i, {i, 1, 10, 2}] However, if you want something particularly unusual, then you can simulate Product by applying Times[] to a list, eg. Times @@ Range[1, 10, 2] Or Times @@ (# &) /@ {2, 3, 5, 7, 11, 13, 17, 19} Which should be the same as Product[Prime[x], {x, 8}] Dave. === Subject: Re: Memory leak - Table & Export just a guss -- Mathematica unpack the array for the Export[] and forgott to repack it ?? Jens > Some of the following code is specific to Windows XP professional, > i.e. the use of < > If the following behavior is not due to my ignorance of Mathematica I'll > submit a bug report to Wolfram. > I'd appreciate any suggestions about: > a) How to stop Mathematica leaking memory in the following code? > b) Why the MemoryInUse[] results are so vastly different from what I > see in the windows taskmanager, and how can I get get the 'real' > memory in use to be the number that the Mathematica function MemoryInUse[] > reports. > > I came across the following behavior while importing some data files, > checking if they contained symbols and then exporting them. However > the following code shows the same type of behavior. > > Some observations. > Share[] and ClearCache[] seem to have negligible effects. > MemoryInUse[] understaes the memory actually in use by the kernel; > initially by a factor of close to 3 which eventually grows to a factor > of close to 10! > This renders Mathematica unusable for data analysis in situations that involve > more than trivial sized datasets. > > I've shown the first and last line of the Mathematica output and done the same > for the temp.txt file that is written to in the For[...] loop. > > Mark > > (* -------------- Start mma input lines -------------- *) > > $HistoryLength = 0; > $Version > << Developer` > << Utilities`MemoryConserve` > SetDirectory[d:temp]; > << !tasklist /FI ImageName eq MathKernel.exe>temp.txt; > > For[idx =1,idx<=15,idx++, > data=Table[Random[],{i,1000},{j,50*idx}]; > Export[ToString[idx]<>.csv,data,CSV]; > Print[ MemoryInUse[]]; > time=AbsoluteTiming[Share[];]; > Print[time,, , MemoryInUse[]]; > time=AbsoluteTiming[ClearCache[];]; > Print[time,, , MemoryInUse[]]; > <>temp.txt; > ] > > (* -------------- End mma input lines -------------- *) > > (* -------------- Start mma output lines -------------- *) > Out[2]= > 5.2 for Microsoft Windows (June 20, 2005) > > [ snip ] > > 3651312 > {0.0781250 Second,Null}[InvisibleSpace], [InvisibleSpace]3422968 > {0. Second,Null}[InvisibleSpace], [InvisibleSpace]3425832 > > [ snip ] > > 9020464 > {0.2500000 Second,Null}[InvisibleSpace], [InvisibleSpace]9020496 > {0. Second,Null}[InvisibleSpace], [InvisibleSpace]9020496 > > (* -------------- End mma output lines -------------- *) > > (* -------------- Start temp.txt output lines -------------- *) > > Image Name PID Session Name Session# Mem Usage > MathKernel.exe 276 Console 0 10,760 K > > [ snip ] > > Image Name PID Session Name Session# Mem Usage > MathKernel.exe 276 Console 0 87,936 K > > (* -------------- Start temp.txt output lines -------------- *) > === Subject: Re: distance function Hi Murray, at least you should compute the distances not twice because the matrix is symmetric with zero diagonal ... d[{p_,p_}]:=0.0 d[{q_,p_}]/; OrderedQ[{q,p}]:=d[{q,p}]= Norm[p - q] d[{q_,p_}]:=d[{p,q}] Jens > If you don't mind an extravagant solution -- one that is conceptually > simple and short but is probably inefficient due to redundant > calculations -- then this works, I believe: > > d[{p_, q_}] := Norm[p - q] > allDistances[pts_] := Union[Flatten[Outer[d, pts, pts]]] > > > >> In the book of Gaylord et al. (1996) there is one exercise which asks >> (see page 113) >> Given a list of points in the plane, write a function that finds the >> set of all distances >> between the points. >> Although there is one solution, that solution makes use of the Table >> and Length commands. >> Is it a way to define the same function using Higher-Order functions >> like Outer, MapThread etc? > === Subject: Re: distance function > In the book of Gaylord et al. (1996) there is one exercise which asks > (see page 113) Given a list of points in the plane, write a function that finds the > set of all distances > between the points. Although there is one solution, that solution makes use of the Table > and Length commands. Is it a way to define the same function using Higher-Order functions > like Outer, MapThread etc? > Outer[ Norm[Plus[##]]&, coordlist, -coordlist, 1] where coordlist is an n x m array containing the coordinates of n points in an m-dimensional space. === Subject: Re: word problem you must have installed the Mathematica fonts, or prevent Mathematica to use its own fonts. But I don't know what fonts you have in your graphs and at least Adobe Acrobat should be able to enbed the fonts into a pdf-file. Jens > > I have a big problem. > > I have prepared a lot of graphs (more specifically plots of some > functions I am interested in.) > I copy and paste these graphs in a word file and everything seems okay. > The graphs are presented in full detail how I wish. > > However, when I open the same word file from a p.c. in which is not > installed the Mathematica, the graphs look destroyed. The situation > becomes even worse if I try to print this file from the same p.c. > > Is it a way to fix this problem; Word to depicts normally pasted > Mathematica graphs regardless if Mathematica is installed? > > I need this, because my professor wants this word file to write some > notes for a presentation/publication and after to convert to pdf and > PowerPoint. And he does not want to installed in his p.c. Mathematica > or MathReader. I try to persuade him that we can send a copy of > MathReader to the editors of the journal but he denies. He just wants a > normal word file with the plots. If I cannot follow his proposed way, I > must work > with other graph programs, which I want to avoid since I have prepared > many plots and I prefer the graphical capabilities of Mathematica. > > === Subject: Re: word problem Hi This group covered this topic, from a different angle, a couple of weeks ago. See my message of 24th July. Then ditch your professor. But seriously, Word is truly appalling when it comes to including vector graphic formats, but you can probably make things a little better by ensuring that all the fonts your graphics use are standard Windows fonts. You might even want to experiment with bitmaps (GIFs etc); if you do, make sure that you set the image dimensions in Mathematica before exporting and importing and do not resize them. Enjoy yourself Mark Westwood I have a big problem. I have prepared a lot of graphs (more specifically plots of some > functions I am interested in.) > I copy and paste these graphs in a word file and everything seems okay. > The graphs are presented in full detail how I wish. However, when I open the same word file from a p.c. in which is not > installed the Mathematica, the graphs look destroyed. The situation > becomes even worse if I try to print this file from the same p.c. Is it a way to fix this problem; Word to depicts normally pasted > Mathematica graphs regardless if Mathematica is installed? I need this, because my professor wants this word file to write some > notes for a presentation/publication and after to convert to pdf and > PowerPoint. And he does not want to installed in his p.c. Mathematica > or MathReader. I try to persuade him that we can send a copy of > MathReader to the editors of the journal but he denies. He just wants a > normal word file with the plots. If I cannot follow his proposed way, I > must work > with other graph programs, which I want to avoid since I have prepared > many plots and I prefer the graphical capabilities of Mathematica. > === Subject: Re: Skip this Input cell module? You could use the option inspector to set the Evaluatable option to False. If that's too slow, you could try ctrl+shift+e and put Evaluatable->False as the last option to the cell expression. If you want something visually apparent, you could try turning the cell into a different type of non-evaluable cell, such as text. > How about a module or command called, say, skipThis that's defined in > the opening cells of a notebook, such that if you put skipThis; as the first line in any subsequent Input cell in the notebook, the > remainder of that Input cell will be skipped, i.e. not executed -- > without your having to wrap the remainder of the cell in an explicit > If[] statement or similar coding. Or, an inputOff statement such that inputOff; as the first line of any Input cell will turn off execution of any > subsequent Input cells (and perhaps the remainder of the cell containing > the statement), until an Input cell beginning with inputOn is encountered. [I trust the utility of these will be reasonably obvious . . . ] -- http://chris.chiasson.name/ === Subject: Re: Skip this Input cell module? this sound very complicated but may be skipThis /: CompoundExpression[skipThis, a___] := Hold[ CompoundExpression[a]] will help you and it is more complicated than change the type of the Input cells into Text ... or to create your own cell style that can not evaluated ... and switch the cell style of that cells to that style ... Jens > How about a module or command called, say, skipThis that's defined in > the opening cells of a notebook, such that if you put > > skipThis; > > as the first line in any subsequent Input cell in the notebook, the > remainder of that Input cell will be skipped, i.e. not executed -- > without your having to wrap the remainder of the cell in an explicit > If[ ] statement or similar coding. > > Or, an inputOff statement such that > > inputOff; > > as the first line of any Input cell will turn off execution of any > subsequent Input cells (and perhaps the remainder of the cell containing > the statement), until an Input cell beginning with > > inputOn > > is encountered. > > [I trust the utility of these will be reasonably obvious . . . ] > === Subject: Re: Skip this Input cell module? > How about a module or command called, say, skipThis that's defined in > the opening cells of a notebook, such that if you put > > skipThis; I think there is no need for such a package: Are you aware of the Cell-Option Evaluatable? If you set this to False (e.g. with the option inspector or Cell -> Cell Properties -> Cell Evaluatable) you can achieve what you want without writing extra code into your cells. You will see that the cell brackets look slightly different for cells that are not Evaluatable. I think this is the recommended way to achieve what you want. If you think that changing the cell property Evaluatable via option-inspector or Cell -> CellProperties is too complicated you might want to automate that, e.g. by constructing a palette that will toggle this setting for the selected cells. Another approach that I probably would use is to define a stylesheet which has a style UnevaluatableInput which is just like Input but will have Evaluatable set to False an maybe change the layout of those cells so you don't have to search for differences in cell brackets. Then you can change the cell style, which can be done easily by keyboard-shortcuts. hth, albert === Subject: Beginner--Beginner: Calculating Ave Intensity in a domain of n points Hi All I am a stranger to mathematica. I would like to calculate the average intensity in a UV reactor. (The reactor is a cylinder with a UV lamp placed parallel to the height of the cylinder.) cylinder dimensions(say)base=40 mm, height=600mm; length of UV lamp=450mm). The Intensity at a point due to the UV lamp is given by:I= P/(2*pi*r*L). where r=distance of the pt. from the centre of the lamp; pi=3.14; L= lamp length P=power of the lamp. If i want to calculate the Ave. Intensity in the reactor, how to program this in Mathematica. Ave. Intensity I_ave=Summation(I) over all the points of the volume. Please give me a hint how to write a program for this in Mathematica. Here i am giving my procedure, which doesn't give desired result x = 0; y = 0;(x,y) is the coordinates of the lamp centre. P = 10.3; Power of the lamp . l = 0.45; Length of the lamp. r0 = 0.025; Radius of the lamp. r[xk_, yk_] := Sqrt[(x - xk)^2 + (y - yk)^2]; distances from the centre of the lamp to Kth point in the domain. Intensity[xk_, yk_] := (P/(2*[Pi]*(Sqrt[(x - xk)^2 + (y - yk)^2])*l)); Integrate[Intensity[xk, yk], {xk, -0.1, 0.1}, {yk, 0, 0.2}] Actually i need to calculate the ave. intensity in a volume V of a Reactor. For this i have to find the Intensity at a point P(Xk,Yk), which is at a dist. of 'r' from the centre of the lamp ie (0,0). Please anyone tell me how to do this and how to plot the Intensity field. Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=12752#p12752 === Subject: Re: Re: Change CellTags with FrontEnd Here's what you want... LinkWrite[$ParentLink, FrontEnd`SelectionAddCellTags[FrontEnd`InputNotebook[], newtag]] That last argument can be a list as well as a single string, and there's a complementary SelectionRemoveCellTags[] command, too, which accepts the same syntax. Sorry for not sending this out in response to your first request, which I saw, but hit me at a particularly busy time and slipped through the cracks. And, while we're talking about notebook programming, let me add one more important point. In 5.2 (and future) front ends, the preferred incantation is no longer LinkWrite, but MathLink`CallFrontEnd. In this case, for example, it would be... MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[nb, newtag]] It is generally true that anyplace where LinkWrite of $ParentLink used to be used to communicate with the FE, MathLink`CallFrontEnd is recommended in 5.2 and will be required in all future versions of Mathematica. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Unfortunately this is not what I was looking for. But I found a possibility how to do it with the FrontEnd: SetOptions[NotebookSelection@InputNotebook[], CellTags -> ...]; One problem still remains: You can only set CellTags this way (and > overwrite existing ones), not add CellTags (that is what I was looking > for). Markus Huber >> Ingolf Dahl has an extensive package for manipulating cell tags. It is >> available at >> And a new version of my package is available at >> http://web.telia.com/~u31815170/Mathematica/ >> and his email address for more information is ingolf.dahl@telia.com. >> David Park >> djmp@earthlink.net >> http://home.earthlink.net/~djmp/ > >> I'd like to change the celltags of several cells that are not adjacent >> via a program (not via the menu). Doing this for one cell is no >> problem: I use a rule like >> {Cell[a_, st_String, b___, CellTags -> tgs_, c___] :> Cell[a, st, b, CellTags -> Union[Flatten[{tgs, newtag}]], c], >> Cell[a_, st_String, b___ /; FreeQ[{b}, CellTags, [Infinity]]] :> Cell[a, st, b, CellTags -> settag]}. >> The problem arises now if several cells are selected: I read them in, >> apply the rule and paste them back, but the new cells appear now at the >> wrong place. One can simply imitate this behaviour of M by selecting >> several not adjacent cells and doing copy and paste: One will see that >> the cells are pasted at the wrong place. >> Doing the same thing via the menu entry Find > Add/Remove Cell Tags >> this is no problem at all. So it appears to me that a solution using >> the FrontEnd would be the best thing. But: I can find no documentation >> about a FrontEndToken like AddCellTags. The best thing I can do is >> use >> FrontEndTokenExecute[CellTagsEditDialog] >> to open the dialog to change CellTags, but this is not what I want. >> So can anybody tell me if there is an additional FrontEndToken that can >> do what I want or has another idea? It should work for M4.0 - M5.2. === Subject: Re: position lists > have > In: a = {1, 1, 2, 2, 1, 4} > want > {{1, 2, 5}, {3, 4}, {0}, {6}}; > > more effectively than just > In: Position[a, #] & /@ Range[4] > Out: {{{1}, {2}, {5}}, {{3}, {4}}, {}, {{6}}} > > Ideas? Known one-liners? > Igor > Hi Igor, I compared some different approaches to this task. the obvious one, which you do not like: Pos[1][a_, n_] := Flatten /@ (Position[a, #1] & ) /@ Range[n] /. {} -> {0}; one with Case[]: Pos[2][a_, n_] := Module[{ao = Ordering[a], as}, as = a[[ao]]; (Cases[Transpose[{as, ao}], {#1, x_} :> x] & ) /@ Range[n] /. {} -> {0}]; this one uses Pick[] Pos[3][a_, n_] := Module[{ao = Ordering[a], as}, as = a[[ao]]; (Pick[ao, as, #1] & ) /@ Range[n]] /. {} -> {0}; Sow/Reap: Pos[4][a_, n_] := Flatten /@ (Reap[(MapThread[Sow, {#1, a[[#1]]}] & )[Ordering[a]], Range[n]][[2]] /. {} -> {{0}}) and the Sow/Reap variant by dkr: Pos[5][a_, n_] := Flatten[Reap[MapIndexed[Sow[#2[[1]], #1] & , a], Range[n]][[ 2]] /. {} :> {{0}}, 1] The winner is the fourth version. See http://people.freenet.de/Peter_Berlin/Mathe/Igor_Pos.nb or if you're sitting in front of a box without Mathematica/MathReader: http://people.freenet.de/Peter_Berlin/Mathe/Igor_Pos.pdf Peter === Subject: Re: position lists In[469]:= a={1,1,2,2,1,4}; Flatten@Position[a,#]&/@Range[4] Out[470]= {{1,2,5},{3,4},{},{6}} But it grows linear with the number of bins (=4). It searches for each bin among all the positions, even those that have been previously identified as belonging to differetn bins. A more effective solution is to use linked-list arrays: In[473]:= PositionListsC=Compile[{{a,_Integer,1},{nBins,_Integer}}, Module[{heads = Table[0,{nBins}],linkedlist=Table[0,{Length@a}],bin}, Do[ bin = a[i]; linkedlist[i]=heads[bin]; heads[bin]=i, {i,Length@a}]; (*To avoid the Non-tensor object generated;proceeding with uncompiled evaluation*) Join[heads,linkedlist]] ]; (joined=PositionListsC[a,4] ;{Take[joined,4],Take[joined,-Length@a]}) Out[474]= {{5,4,0,6},{0,1,0,3,2,0}} It gives two lists: heads -- the last point that fell in the bin and a linked list of all the other points in the same bin (terminated by 0). For example in the bin #1 we have 5->2->1. So we do get the same information, but in a different structure. Let's see their performance In[478]:= nBins = 1000; b = Table[Random[Integer, {1, nBins}], {100000}]; (joined = PositionListsC[b, nBins] ; { Take[joined, nBins], Take[joined, -Length@b]};) // Timing Flatten@Position[b, #] & /@ Range[nBins]; // Timing Out[479]= {0.031 Second, Null} Out[480]= {15.329 Second, Null} My questions was whether there's such a built-in list function. Or perhaps a package that could give lists of points sorted into bins. === Subject: Re: Several functions in a single 2D-plot > How can I plot several functions within the same 2D graphic? Plot[{f_1, f_2, ... }, {x, x_min, x_max}] plots several functions f_i. http://documents.wolfram.com/mathematica/functions/Plot DisplayTogether[a, a, .89¥Ï , opts] combine the plots that result from the given plot commands in a Graphics object http://documents.wolfram.com/mathematica/Add-onsLinks/StandardPackages/Graph ics/Graphics.html HTH, Jean-Marc === Subject: Re: Several functions in a single 2D-plot I am new to Mathematica, and I have a quick question that will be very > easy for you, I guess. How can I plot several functions within the same 2D graphic? For example, I want to draw the PDF of 3 continuous statistical > distributions (I mean, 3 functions), but put together into the same 2D > plot. > -- > Vicent > You will need to perform a ListPlot for each PDF, but assign each ListPlot a name. So do: Bino = ListPlot[ your info] Hyper = ListPlot[ your info ] Chi = ListPlot [ your info] Then use the show command to put them all together. Show[ Bino, Hyper, Chi] You could also look up the MultipleListPlot function. Either way works. I like the former. === Subject: Re: Several functions in a single 2D-plot ?Plot Plot[f, {x, xmin, xmax}] generates a plot of f as a function of x from xmin to xmax. Plot[{f1, f2, ... }, {x, xmin, xmax}] plots several functions fi. More... For example, Plot[ {BesselJ[0,x],BesselJ[1,x], BesselJ[2,x] }, {x,0,10},PlotStyle[Rule]{Thickness[0.008],Thickness[0. 006],Thickness[0.004]}]; or g={BesselJ[0,x],BesselJ[1,x],BesselJ[2,x]}; Plot[Evaluate[g], {x, 0, 10}, PlotStyle -> { Thickness[0.008], Thickness[0.006], Thickness[0.004]}]; Of course, after you can change the default options and add legends to make the plot look better. For example, Plot[ {BesselJ[0, x], BesselJ[1, x], BesselJ[2, x] }, {x, 0, 10}, PlotStyle -> {AbsoluteThickness[1], AbsoluteThickness[ 2], AbsoluteThickness[3]}, TextStyle -> {FontFamily -> Times, FontSize -> 20}, AxesLabel -> {x, TraditionalForm[BesselJ[n, x]]}, PlotLegend -> {n=0, n=1, n=2}, LegendShadow -> None, LegendPosition -> {0, 0}, ImageSize -> {500, 300}]; Jim ëÄ/ë÷ Vicent ë[CapitalEth]ëÒìª[EDouble Dot]±ìÃë[Micro]: I am new to Mathematica, and I have a quick question that will be very > easy for you, I guess. How can I plot several functions within the same 2D graphic? For example, I want to draw the PDF of 3 continuous statistical > distributions (I mean, 3 functions), but put together into the same 2D > plot. > > > -- > Vicent === Subject: Re: word problem Mathematica graphics use Mathematica fonts (MathFonts) for the text and PCs without those fonts won't be able to display the graphics properly. You don't have to have Mathematica or MathReader installed, but you need to have at least the fonts installed. They can be downloaded from here: http://support.wolfram.com/mathematica/systems/windows/general/latestfonts.h tml You mentioned that this might not be an option, so you could instead generate your graphics without using those fonts: http://support.wolfram.com/mathematica/systems/windows/general/latestfonts.h tml Igor -- Igor C. Antonio Software Engineer Wolfram Research, Inc. http://support.wolfram.com/mathematica/graphics/textfonts/nomathfonts.html > > I have a big problem. > > I have prepared a lot of graphs (more specifically plots of some > functions I am interested in.) > I copy and paste these graphs in a word file and everything seems okay. > The graphs are presented in full detail how I wish. > > However, when I open the same word file from a p.c. in which is not > installed the Mathematica, the graphs look destroyed. The situation > becomes even worse if I try to print this file from the same p.c. > > Is it a way to fix this problem; Word to depicts normally pasted > Mathematica graphs regardless if Mathematica is installed? > > I need this, because my professor wants this word file to write some > notes for a presentation/publication and after to convert to pdf and > PowerPoint. And he does not want to installed in his p.c. Mathematica > or MathReader. I try to persuade him that we can send a copy of > MathReader to the editors of the journal but he denies. He just wants a > normal word file with the plots. If I cannot follow his proposed way, I > must work > with other graph programs, which I want to avoid since I have prepared > many plots and I prefer the graphical capabilities of Mathematica. > === Subject: Re: word problem I strongly suspect the problem that you're seeing is that the metafiles copied into Word are using the Mathematica fonts. If so, then it's not an issue of having all of Mathematica present, but only of the fonts...or of removing the dependence upon those fonts. Here are some possibilities... * Copy as bitmap and paste (using the Copy As submenu). Because this uses bitmaps, there will be no references to the fonts. On the downside, the bitmap will look great on screen, but really crummy when you print the Word file. * Don't use the Mathematica fonts. If you have typeset equations in the graphic, this may be hard to avoid. But if the only things that are messed up are regular characters like parentheses, braces, or brackets, then you can work around the problem by evaluating the following... SetOptions[$FrontEnd, PrivateFontOptions->{OperatorSubstitution->False}] Then re-evaluate the affected graphics. To restore the old behavior, do... SetOptions[$FrontEnd, PrivateFontOptions->{OperatorSubstitution->Inherited] This can be done through the Option Inspector, as well...just search for OperatorSubstitution. * Install the Mathematica fonts on the system where the Word file is being viewed. See this web page for a convenient way to download fonts... http://support.wolfram.com/mathematica/systems/windows/general/latestfonts. html and just drag the resulting .ttf files to the Fonts control panel. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. I have a big problem. I have prepared a lot of graphs (more specifically plots of some > functions I am interested in.) > I copy and paste these graphs in a word file and everything seems okay. > The graphs are presented in full detail how I wish. However, when I open the same word file from a p.c. in which is not > installed the Mathematica, the graphs look destroyed. The situation > becomes even worse if I try to print this file from the same p.c. Is it a way to fix this problem; Word to depicts normally pasted > Mathematica graphs regardless if Mathematica is installed? I need this, because my professor wants this word file to write some > notes for a presentation/publication and after to convert to pdf and > PowerPoint. And he does not want to installed in his p.c. Mathematica > or MathReader. I try to persuade him that we can send a copy of > MathReader to the editors of the journal but he denies. He just wants a > normal word file with the plots. If I cannot follow his proposed way, I > must work > with other graph programs, which I want to avoid since I have prepared > many plots and I prefer the graphical capabilities of Mathematica. > === Subject: RE: Several functions in a single 2D-plot Vicent, You can use the Plot statement with a list of functions. Plot[{function1, function2, function3}, {x, min, max}, PlotStyle -> {style1, style2, style3}]; That uses the same domain for all three functions. If you want different domains you could make separate plots and then combine then with DisplayTogether from the Graphics`Graphics` standard package. If you want further customization you could try the DrawGraphics package from my web site. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I am new to Mathematica, and I have a quick question that will be very easy for you, I guess. How can I plot several functions within the same 2D graphic? For example, I want to draw the PDF of 3 continuous statistical distributions (I mean, 3 functions), but put together into the same 2D plot. -- Vicent === Subject: RE: question? Mehri, I think so. Could you send me a sample list of data points containing {x, y, yerrormin, yerrormax} and I'll try a plot. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I would like to know if it is possible to make a logarithmic listplot with error bars. Something like LogLogErrorListPlot or LogLogMultipleListPlot? Mehri === Subject: RE: product formula in mathematica If you want a Table with unevenly spaced values then you could have an evenly spaced list index another list of values. However, in such cases I always think MapThread in which you can specify the list of values directly. Times @@ MapThread[f[x[#]] &, {{1, 3, 4, 9}}] f[x[1]] f[x[3]] f[x[4]] f[x[9]] David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi I am interested in doing a product over a set of indices that are not continuous Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears that the iterator wouldonly take sequences such as 1...10 etc. === Subject: RE: Skip this Input cell module? Why don't you select the cell bracket and use Alt-CRV (Menu Cell->Properties->Evaluable)? That keeps the Input cell but it won't be evaluated. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ How about a module or command called, say, skipThis that's defined in the opening cells of a notebook, such that if you put skipThis; as the first line in any subsequent Input cell in the notebook, the remainder of that Input cell will be skipped, i.e. not executed -- without your having to wrap the remainder of the cell in an explicit If[Ê] statement or similar coding. Or, an inputOff statement such that inputOff; as the first line of any Input cell will turn off execution of any subsequent Input cells (and perhaps the remainder of the cell containing the statement), until an Input cell beginning with inputOn is encountered. [I trust the utility of these will be reasonably obvious . . . ] === Subject: Simplifying a Boolean Expression Can Mathametica be used to simplify the following type of logic typically found in programming applications, and if so, how do I go about setting it up? Variables A and T can have the values none, dense, sparse The variable X will be assigned a value of either onepass or twopass based on the following logic: IF [(A=none) AND (T=none)] OR [(A=dense) OR (A=sparse) AND (T=none)] OR [(A=dense) AND (T=dense)] THEN X = onepass ELSE IF [{A=sparse) AND (T=sparse)] OR [(A=sparse) AND (T=dense)] THEN X = twopass I want to be able to express this type of problem in Mathematica and have it return the simplest logic for assigning a value to X. Jon Work: 401-752-3821 Cell: 508-873-9780 === Subject: General--Simplify exponents in exponential terms Hi! I have difficulties to simplify exponents in a big expression: Cov = E^(-(beta + 2eta)h(1 + k) lambda (-96beta^2 E^ (2 eta h(1 + k))(-1+E^beta h)^2 eta^3 mu2 + 24 E^2 eta h (1+ k)((-1+ E^(beta h)^2 eta^5 mu2 (4 + theta)^2 + 48 beta E^beta h(1 + k) .... I absolutely want to avoid exponentiels with positive exponents. For example, I could have eta>10, h=24 and k=1 when I apply this expression in the real world, which gives Cov=Nan. I don't know how to use ComplexityFunction in the function Simplify to tackle this problem. I simply want the term E^(-(beta + 2eta) to enter with the other exponential terms. Something like : Simplify[Cov, ComplexityFunction-> don't factorize exponential terms] would be perfect. Guillaume Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=12774#p12774 === Subject: RE: calculate Recurrence Equations Do you need exact answers as integer factions? In[1]:= anteil[0] := 1. ; anteil[n_] := 1.05 anteil[n - 1] - .01 ; In[6]:= Table[ { i, anteil[i]}, { i, 0, 35 } ] // TableForm Seems to execute quickly. I'm not sure why, but when there are two references, it seems to get lost. Paul -----Original Message----- === Subject: calculate Recurrence Equations hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... Thanx for your help frank === Subject: Need good reference for writing Stylesheets Hi All, I was wondering if there is a good reference for writing/constructing .....Terry === Subject: Re: calculate Recurrence Equations > hi, > > i?m in trouble with my Recurrence Equations: > > i?ve defined the following function > > anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 > > i want mathematica to calculate the values for anteil[30] and so on. > > Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). > > I don?t see where are the difficulties for mathematica... > > Thanx for your help > > frank > Hi Frank, Mathematika doesn't remeber the values it has alraedy calculated. So anteil[30] leads to 2^30 ~ 10^9 calls to anteil[]. If you store the calculated values, the calls to anteil[] are 31: In[1]:= anteil[0] = 1; anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100; AbsoluteTiming[anteil[30]] Out[3]= {0.*Second, 4909085745117164100520051333566036654601/13421772800000000000000000000000000 00000} But I prefer using RSolve[]: In[1]:= << DiscreteMath`RSolve` anteil = a /. First[RSolve[{a[0] == 1, a[n] == a[n - 1] + (a[n - 1]*5 - 1)/100}, a, n]] anteil[30] N[%] Out[2]= Function[{n}, (1/5)*(1 + 4^(1 - n)*(21/5)^n)] Out[3]= 4909085745117164100520051333566036654601/ 1342177280000000000000000000000000000000 Out[4]= 3.6575539001205297 HTH, Peter === Subject: Re: calculate Recurrence Equations The timing for that function fits very nicely to time[n]=10^(-5)*2^n with the prefactor of 10^-5 specific to my machine and the time in seconds. On my computer, at least, I'd estimate that anteil[30] would take almost exactly 3 hours. I had to look up how to define the functions so that Mathematica remembers the values of the functions as previously-calculated (otherwise it has to recalculate the things all over again each time it hits one). It takes only one little addition to your definition. Try this: anteil[0] = 1 anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 Now the thing should be virtually instantaneous (you could also define things to use numeric values rather than exact calculations by defining anteil[0] to be 1.0 or whatever, but I don't think it'll buy you much performance unless you're going up to n much larger than 30). Hope that helps! It helped me, by the way, by forcing me to look up how to define these things, which I'll need to do very shortly. C.O. > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... Thanx for your help frank > -- Curtis Osterhoudt gardyloo@mail.remove_this.wsu.and_this.edu PGP Key ID: 0x088E6D7A Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: calculate Recurrence Equations > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... The difficulties are subtle, for starters use anteil[0]:=1, also if you are not evaluating the series for large values of n, cache the values of intermediate n eg: anteil[0] := 1 anteil[n_] := anteil[n] =anteil[n - 1] + (anteil[n - 1] 5 - 1)/100 Timing[anteil[30]] {0.0014070000000003802 Second, 4909085745117164100520051333566036654601/1342177280000000000000000000000 000000000} Ssezi === Subject: Re: calculate Recurrence Equations > hi, > > i?m in trouble with my Recurrence Equations: > > i?ve defined the following function > > anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 > > i want mathematica to calculate the values for anteil[30] and so on. > > Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). Hi Frank, The following definition should help: anteil[0]=1; anteil[n_]:= anteil[n]= anteil[ n-1]+ ( anteil[ n-1]*5-1)/100 anteil[30] --> 4909085745117164100520051333566036654601/13421772800000000000000000000000000 00000 See Functions That Remember Values They Have Found http://documents.wolfram.com/mathematica/book/section-2.5.9 HTH, Jean-Marc === Subject: Re: calculate Recurrence Equations Hello If you modify (your expression) to: anteil[0] = 1; anteil[n_] := (anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 ) anteil[30]//N you can save the intermediate calculations. But even with this modification you will run into problems for large n (a few 100), because you build up your expression starting with the last index = n and you will get a deeply nested expression (which might use up the memory of your computer). I would rather use the following command (which forward calculates the expression starting with the starting value=1): n=1000;Nest[(# + (#*5 - 1)/100) &, 1, n]//N Even 1000 iterations work and need less than a second (on my computer). Norbert Marxer www.mec.li > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... > > Thanx for your help > > frank === Subject: Re: calculate Recurrence Equations > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... Short answer: Redefine the function as follows. (notice the extra = ???) anteil[0] = 1 anteil[n_] := anteil [n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 Longer Answer: They way you've inputed it, Mathematica needs to recalculate a[0 through n], every time it increments n. Adding the extra syntax; a[n_]:=a[n]= the function forces Mathematica to commit all calculations to the cache, so as not to re-evaluate what has already been evaluated. This will significantly decrease processing time. === Subject: Re: calculate Recurrence Equations Hi. I believe the syntax of your equations are a little off. This worked for me... In[1]:= equ = { v[0] == 1, v[n] == v[n - 1] + (v[n - 1]*5 - 1)/100 } ; In[2]:= RSolve[equ, v[n], n] Out[2]= {{v[n] -> (1/5)*(1 + 4^(1 - n)*(21/5)^n)}} -- HTH. :>) Dana DeLouis Mathematica 5.2 > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... Thanx for your help frank > === Subject: Re: calculate Recurrence Equations > hi, > > i?m in trouble with my Recurrence Equations: > > i?ve defined the following function > > anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 > perfect problem for a function that remembers values it has already calculated (see the mathematica book, section 2.5.9) Try the following: anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5-1)/100 if you need even more speed and an approximate result is o.k., the following might be even faster for large n, but could probably give you wrong results (it does not for n=10,20,30): anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5.-1.)/100. hth, albert === Subject: Re: calculate Recurrence Equations Frank Check the section 2.5.9 in The Mathematica Book for an explanation of this solution. Modify your second definition to read: anteil[n_] := anteil[n]=anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 The effect of this is that the values of anteil[n] are stored when first calculated, and not recalculated next time they are required. You can see the effect by executing ?anteil after executing the function. On my PC anteil[30] runs in a second or so. Mark Westwood > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... > > Thanx for your help > > frank === Subject: Re: calculate Recurrence Equations Hallo Frank, try: anteil[0] = 1 anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 and you might want to read the section on dynamic programming (section 2.5.9) in the HelpBrowser Oliver > hi, > > i?m in trouble with my Recurrence Equations: > > i?ve defined the following function > > anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 > > i want mathematica to calculate the values for anteil[30] and so on. > > Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). > > I don?t see where are the difficulties for mathematica... > > Thanx for your help > > frank > > Oliver Ruebenkoenig, Phone: ++49 +761 203 7388 === Subject: Re: calculate Recurrence Equations > hi, i?m in trouble with my Recurrence Equations: i?ve defined the following function anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 i want mathematica to calculate the values for anteil[30] and so on. Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). I don?t see where are the difficulties for mathematica... Frank, Your definition is memoryless. Let's make a slight modification that adds memory (note the = on the right hand side): In[1]:= anteil[0] = 1; anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 On an old 800MHz iMac it gives In[3]:= Timing[anteil[30]//InputForm] Out[3]= {0.004157 Second,4909085745117164100520051333566036654601/ 1342177280000000000000000000000000000000} The same result via RSolve: In[10]:= ClearAll[anteil]; RSolve[{anteil[n]==anteil[n-1]+(anteil[n-1]*5-1)/100,anteil[0] ==1},anteil, n]//InputForm Out[11]//InputForm= {{anteil -> Function[{n}, (1 + 4^(1 - n)*(21/5)^n)/5]}} Extract the solution In[22]:= sol=%[[1,1,2]]; and compute sol[30] In[23]:= sol[30]//InputForm Out[23]//InputForm= 4909085745117164100520051333566036654601/ 1342177280000000000000000000000000000000 Hope it helps Adriano Pascoletti === Subject: Re: calculate Recurrence Equations Add memory to the definition Clear[anteil1]; anteil1[0]=1; anteil1[n_Integer?Positive]:= anteil1[n]= anteil1[n-1]+(anteil1[n-1]*5-1)/100; anteil1[n_Integer?Negative]:= anteil1[n]=(1/105)*(100*anteil1[n+1]+1); anteil1[30]//Timing//N {0.002837 Second,3.65755} Clear[anteil2]; anteil2[n_]=anteil2[n]/.RSolve[{ anteil2[n]==anteil2[n-1]+(anteil2[n-1]*5-1)/100, anteil2[0]==1},anteil2[n],n][[1]] (1/5)*(1 + 4^(1 - n)*(21/5)^n) anteil2[30]//Timing//N {0.000229 Second,3.65755} Plot[anteil2[n],{n,-10,10}, PlotStyle->Blue,ImageSize[Rule]432, Epilog->{Red, AbsolutePointSize[4], Point/@Table[{n,anteil1[n]},{n,-10,20}]}]; Bob Hanlon > hi, > > i?m in trouble with my Recurrence Equations: > > i?ve defined the following function > > anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 > > i want mathematica to calculate the values for anteil[30] and so on. > > Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). > > I don?t see where are the difficulties for mathematica... > > Thanx for your help > > frank > === Subject: Re: FileNames subdirectory count discrepancy > >>from the help: FileNames[forms, dirs, n] includes files that are in >> subdirectories up to n levels down. > >> why does a file that is only one level down require n=2? > > I assume n = 1 would refer to the current level. And the choosing n = 1 to be the current level seems consistent with Mathematica's indexing of arrays that use 1 as a base rather than 0. > -- > To reply via email subtract one hundred and four > The device C: may be interpreted as file (as in Unix and cousins). The file (folder in Windows speech) WINDOWS is 1 level down and system ini is 2 levels under C:. explain the interpretation of file/device/folder, which is (mostly) irrelevant in OSs ending with a 'X' (except Windox ;-) ). Peter === Subject: Re: product formula in mathematica > Hi I am interested in doing a product over a set of indices that are > not continuous > Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears > that the iterator wouldonly take sequences such as 1...10 etc. > > The first method works for arbitrary lists: In[1]:= Times@@(f/@{1,3,4,9}) Out[1]= f[1] f[3] f[4] f[9] and the second is very specialized ;-) Out[2]= f[1] f[3] f[4] f[9] (just kidding - sorry) Peter === Subject: Re: product formula in mathematica > Hi I am interested in doing a product over a set of indices that are > not continuous > Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears > that the iterator wouldonly take sequences such as 1...10 etc. Times @@ MapThread[f[Subscript[x, #1]] & , {{1, 3, 4, 9}}] --> f[Subscript[x, 1]]*f[Subscript[x, 3]]*f[Subscript[x, 4]]*f[Subscript[x, 9]] Times @@ MapThread[f[x[#1]] & , {{1, 3, 4, 9}}] --> f[x[1]]*f[x[3]]*f[x[4]]*f[x[9]] http://documents.wolfram.com/mathematica/functions/Apply http://documents.wolfram.com/mathematica/functions/MapThread HTH, Jean-Marc === Subject: Re: product formula in mathematica no but iset={1,3,4,9}; Times @@ (f[Subscript[x,#]] & /@ iset) will do that .. Jens > Hi I am interested in doing a product over a set of indices that are > not continuous > Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears > that the iterator wouldonly take sequences such as 1...10 etc. > > === Subject: Re: product formula in mathematica Hello The iterator (i.e. the second argument of Product) has to be a standard iterator. Therefore your input will not work. But you can write your own product function, which does what you want. If you define myProduct[f_, arr_] := Apply[Times, Thread[f[arr]]] Then myProduct[Sin, {1, 3, 4, 9, 12}] will give Sin[1] Sin[3] Sin[4] Sin[9] Sin[12] Norbert Marxer www.mec.li > Hi I am interested in doing a product over a set of indices that are > not continuous > Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears > that the iterator wouldonly take sequences such as 1...10 etc. > === Subject: RE: product formula in mathematica >-----Original Message----- === >Subject: product formula in mathematica Hi I am interested in doing a product over a set of indices that are >not continuous >Product [ f(x_i) , { x_i, 1,3,4,9}] Is this possible it appears >that the iterator wouldonly take sequences such as 1...10 etc. (If necessary) to understand In[8]:= Product[f[x], {x, 1, 10, 3}] Out[8]= f[1] f[4] f[7] f[10] please look into Help. But perhaps you intend In[9]:= Times @@ f /@ {1, 3, 4, 9} Out[9]= f[1] f[3] f[4] f[9] -- Hartmut === Subject: Re: Several functions in a single 2D-plot >How can I plot several functions within the same 2D graphic? >For example, I want to draw the PDF of 3 continuous statistical >distributions (I mean, 3 functions), but put together into the same >2D plot. There are a number of ways this can be done. Here are two examples: Plot[{PDF[NormalDistribution[0, 1], x], PDF[NormalDistribution[0, 1/2], x], PDF[NormalDistribution[0, 2], x]}, {x, -6, 6}, PlotStyle -> {Red, Blue, Black}, PlotRange -> All, Axes -> None, Frame -> True]; Show[Block[{$DisplayFunction = Identity}, {Plot[PDF[LogNormalDistribution[0, 0.5], x], {x, 0, 5}], Plot[PDF[GammaDistribution[2, 1], x], {x, 0, 5}, PlotStyle -> Blue], Plot[PDF[ExponentialDistribution[1], x], {x, 0, 5},PlotStyle -> Red]}]]; -- To reply via email subtract one hundred and four