A24 ==== I¹m curious about the different ef\ficiencies of \ Export vs. Put; Import vs.Get.Eg. Saving a list called c with approx. 16,000 elements, each elementbeing a three element list of reals.Export[ac.dat,c] takes forever and consumes heaps of kernel memoryc>ac.dat all done in an instant (relatively speaking) and without thetransient burst of kernel memory usage.Ditto Import and Get. Can anyone explain this?Mike ==== Dear DrBob,I fear that your diagnosis of the ef\ficiency problemsin Husain's binary tree \ implementation is not correct.Furthermore your code is inef\ficient and awkward.Consider the following implementation using list to representthe tree. It is three lines long and is three times fasterthan yours on my computer though it uses twice as muchmemory as your representation. myadd[{},x_]:={x,{},{}};myadd[{v_,a_,b_},x_]:=If[v>x, {v,myadd[a,x],b}, {v,a,myadd[b,x]}]t={}; Timing[Do[t=myadd[t,Random[]],{5000}];]{1.98 Second,Null}The real problem with the implementation is probably thatthe tree structure has to be Ôcopied' each time whenadd \ is called. You have to writetree = add[tree, x]t2 = add[t1, x]then you have *two* trees t1 and t2 which differ by theone element inserted by add.To the best of my knowledge, the internal representationof t1 and t2 in Mathematica is a tree too. But in principlethe user code is duplicated in Mathematica.A further problem of all direct implementations is that theycannot be compiled (since they use pattern matching andthe tree is a nested structure).Thus I guess that the ef\ficient way to implementtree data structures is the indirect one using heaps(i.e. a combination of contiguous arrays with length knownin advance and hashing). Johannes Ludsteck> You're not doing anything dumb as far as I can see, but you're using far> more memory than necessary. Here are statistics for your algorithm on> my machine:> SeedRandom[5];> nums = Null> Do[nums = add[nums, Random[]], {5000}]; // Timing> nums // LeafCount> nums // ByteCount> Count[nums, Null, In\finity]> Count[nums, node[_, Null, _], In\finity]> Count[nums, node[_, _, Null], \ In\finity]> Count[nums, node[_, Null, Null], In\finity]> Count[nums, node[___], In\finity]> Count[nums, node[_, _node | _?NumericQ, _node | _?NumericQ], In\finity]> Depth[nums]> {4.406000000000001*Second, Null}> 15001> 240000> 5001 (* Null values in the tree *)> 2458 (* nodes without left offspring *)> 2543 (* nodes without right offspring *)> 1669 (* leaf nodes *)> 4999 (* total nodes *)> 1667 (* nodes with both left and right offspring *)> 28 (* minus one, makes 27 levels in the tree *)> It's clearly not ideal to store 5001 Nulls \ for 5000 actual values!> Here's a method that \ doesn't change the algorithm much, but changes the> storage method a great deal:> First of all, I'm lazy, so I'll \ rede\fine <,>,<=,>=, etc. to make the> code simpler:> Unprotect[Less, Greater, LessEqual, GreaterEqual];> Less[a : _node ..] := Less @@ (First /@ {a})> LessEqual[a : _node ..] := LessEqual @@ (First /@ {a})> Greater[a : _node ..] := Greater @@ (First /@ {a})> GreaterEqual[a : _node ..] := GreaterEqual @@ (First /@ {a})> Protect[Less, Greater, LessEqual, GreaterEqual];> Again because I'm lazy, I'll de\fine \ node so that I don't have to> consciously avoid leaf nodes and unnecessary nesting:> ClearAll[node]> node[a___, node[b_], c___] = node[a, b, c];> node[node[a__]] = node[a];> Here's my add function:> Clear[add]> add[Null, x_] = node[x];> add[x_, (y_)?NumericQ] := add[node[x], node[y]]> add[(x_)?NumericQ, y_] := add[node[x], node[y]]> add[node[x_], node[y_]] := If[x > y, node[x, y], node[y, x]] (* <--> THERE! *)> add[node[x_, lower_], y_node] :=> Which[y >= node[x], node[x, lower, y],> y <= node[lower], node[lower, y, x], True, node[y, lower, x]]> add[node[x_, lower_, higher_], y_node] /;> node[y] <= node[x] := node[x, add[lower, y], higher]> add[node[x_, lower_, higher_], y_node] := node[x, lower, add[higher,> y]]> Where I have a pointer is the code that prevents adding right-offspring> to a leaf node. That avoids nodes like your node[a,Null,c]. When you> would have node[a,b,Null], I have node[a,b]. When you would have> node[a,Null,Null], I use a itself.> Timing and space requirements are much better now:> SeedRandom[5];> nums = Null> Timing[Do[nums = add[nums, Random[]], {5000}]; ]> {2.109*Second, Null}> LeafCount[nums]> ByteCount[nums]> Count[nums, Null, In\finity]> Count[nums, node[_], In\finity]> Count[nums, node[_, _], \ In\finity]> Count[nums, node[_, _, _], In\finity]> Count[nums, node[___], In\finity]> Depth[nums]> 7852 (* 48% fewer leaf expressions,> mostly due to Nulls and right-offspring eliminated *)> 165624 (* 31% less storage *)> 0 (* no Nulls, versus 5001 *)> 0 (* no leaf nodes, versus 1669 *)> (* no nodes without left-offspring, versus 2458 *)> 705 (* nodes without right offspring, versus 2543 *)> 2146 (* nodes with both left and right offspring, versus 1667 *)> 2851 (* total nodes *)> 21 (* 21 tree levels versus 27 *)> The logical structure is identical to yours except that there are no> nodes with only right-offspring. This incidentally tends to reduce tree> depth.> The storage format is far different: there are no trivial (childless)> nodes, and nodes with left-offspring but no right-offspring are stored> without a Null on the right.> I could make this quite a bit faster, I think, if I spent time on the> code to eliminate changes to Less, Greater, etc. and the frequent> nesting followed by unnesting that goes on in the algorithm. It might> take twice as much code, however, so I like it as is.> You're probably better off storing these things in a heap, of course.> Or -- better yet -- use the built-in Sort and Ordering functions.> Bobby Treat> -----Original Message-----> I am trying to implement a very simple sorted tree to quickly store some> real numbers I need. I have written an add, delete, minimum, and pop> (delete the lowest value) function and they seem to work ok but are very> slow. Let's just look @ my implementation of the add part:> nums=Null;(*my initial blank Tree)> In[326]:=> Clear[add]> In[327]:=> add[Null,x_Real]:=node[x,Null,Null]> add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher]> In[328]:=> add[node[x_Real,lower_,higher_],y_Real]:=> If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y] ]]> In[288]:=> add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery _]]:=If[x>y> ,> node[x,add[lowerx,node[y,lowery,highery]],higherx],> node[x,lowerx,add[higherx,node[y,lowery,highery]]]> ]> Now this is my attempt to test how fast my add works:> SeedRandom[5];> Do[nums=add[nums,Random[]],{5000}];//Timing> Out[333]=> {13.279 Second,Null}> RH7.3> running on an 1.4GHz Athlon with 1GB of ram).> Questions:> 1. Is this as fast as I can get my code to run?> 2. Am I doing something obviously stupid?> 3. would Compiling things help?> Husain> <><><><><><><><><><><><>Johannes LudsteckEconomics DepartmentUniversity of RegensburgUniversitaetsstrasse 3193053 Regensburg ==== =Is it possible to con\figure a style sheet so that functions or data shown ingraphs are coloured (colored :)) in working but black in printing...withoutactually re-executing the function that created the graphics?thanksMikeReply-To: kuska@informatik.uni-leipzig.de ==== =no because the PostScript creation know nothingabout the notebook frontend. Mathematica does itsgraphics in PostScript since version 1.0 but the notebook frontend was introduced in version 2.x andthe actual typsetting/markup format was introducedin version 3.0. Jens> Is it possible to con\figure a style sheet so that functions or data shown in> graphs are coloured (colored :)) in working but black in printing...without> actually re-executing the function that created the graphics?> thanks> Mike ==== =A commonly used symbol for the Floor function is a square bracket with theupper indents removed. Is this symbol part of Mathematica's built-in symbols? Ithink not, so then, can it \ be constructed by hand.Jack ==== =It turns out that Mathematica does have the ßoor symbols! Use esc l f escfor the left ßoor and esc r f esc for the right ßoor. In fact, if you typein esc l f esc a esc r f esc Mathematica will interpret the input asFloor[a].Carl WollPhysics DeptU of Washington A commonly used symbol for the Floor function is a square bracket with the> upper indents removed. Is this symbol part of Mathematica's built-insymbols? I> think not, so then, can it be constructed by hand. Jack ==== => A commonly used symbol for the Floor function is a square bracket with> the upper indents removed. Is this symbol part of Mathematica's built-in> symbols?Sure. Just look for Floor in A.10 Listing of Major Built-In MathematicaObjects! For example, you can use [LeftFloor] and [RightFloor] to getthe symbols you want.DavidReply-To: kuska@informatik.uni-leipzig.de ==== =what may [LeftFloor] and [RightFloor]show on screen ? It's easy \ to \find in thecomplete characters palette | Operators | General Jens> A commonly used symbol for the Floor function is a square bracket with the> upper indents removed. Is this symbol part of Mathematica's built-in symbols? I> think not, so then, can it be constructed by hand.> Jack ==== => A commonly used symbol for the Floor function is a square bracket with the> upper indents removed. Is this symbol part of Mathematica's built-in symbols? I> think not, so then, can \ it be constructed by hand.> Jack[LeftFloor] and [RightFloor] can be used for this.Look at Chapter Advanced Mathematics/Mathematical and Other Notations/Operators.Yours, Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== =Needs[Graphics`Graphics`]LogLinearPlot[Sqrt[x], {x, 1., 1000}, ImageSize -> 500];David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ Approved: Steven M. Christensen , ModeratorReply-To: ==== =I don't know about elegance or simplicity, but I do have a FASTERsolution, incidentally using combinations code that often comes in handyfor me. Here's that code:<< DiscreteMath`Combinatorica`;ClearAll[combinations];r = Range[1, 9];combinations::usage = combinations[list,n:{__Integer}] lists the combinations of list taken n at a time;combinations[r_List, n_Integer, {}] := If[n > Length@r, {}, DiscreteMath`Combinatorica`KSubsets[r, n]];combinations[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@ DiscreteMath`Combinatorica`KSubsets[Complement[r, e], n];combinations[r_List, n_Integer, e : {__?VectorQ}] :=Flatten[combinations[r, n, #] & /@ e, 1];combinations[r_List, n : {__Integer}] := Which[Plus @@ n == Length@r, Join[#, Complement[r, #]] & /@ combinations[r, Drop[n, -1]], Plus @@ n> Length@r, {}, True, Fold[combinations[r, #2, #1] &, {}, n]]The following duplicates your fLPartitions function, but is about 40%faster and uses about 15% less memory (for this example):Quit<< DiscreteMath`Combinatorica`fLPartition[ksN_, r_] := With[{ks = KSubsets[ Range[r], ksN], ks1 = Partition[Range[r], 1]}, MapThread[ Complement[Append[#1, #2], (Sequence @@ {#1} & ) /@ Partition[#2, 1]] & , {Array[ks1 & , Length[ ks]], ks}]] Module[{ksN = 2}, While[ksN < r + 1, s = fLPartition[ksN, r]; ksN = ksN + 1; Print[s]]]Timing[fLPartition[3, 80]; ]{11.389999999999999*Second, Null}MaxMemoryUsed[]233956264QuitwantCombinations (* this loads my cominations function de\finition *)ClearAll[mine]mine[k_, n_] := (Join[List /@ Complement[ Range[n], #1], {#1}] & ) /@ combinations[Range[n], {k}]Timing[mine[3, 80]; ]{6.734999999999999*Second, Null}MaxMemoryUsed[]195828264However, I would change the storage structure to replace{{1},{2},...,{7}} with just {1,2,...7}. That cuts memory usage by 85%from your method for this example:QuitwantCombinationsClearAll[mySecond]mySecond[k_, n_] := (Join[Complement[Range[n], #1], {#1}] & ) /@ combinations[Range[n],{k}]Timing[mySecond[3, 80]; ]{2.922*Second, Null} (* versus 11.485 with your code, 6.7 with my othercode *)MaxMemoryUsed[]43996408 (* 44MB versus 234MB with your code, 196 MB with my other code*)Those comparisons include memory used during code execution; byte countsfor that example are 134,742,424 for my storage method and 287,560,024for yours.If you sometimes have to have a partition in your format, its easyenough to temporarily convert it from mine with the following function:f = Join[List /@ Drop[#1,-1], {Last[#1]}] & ;First[mySecond[2, 10]]f[%]{3, 4, 5, 6, 7, 8, 9, 10, {1, 2}}{{3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2}}First[fLPartition[2, 10]]{{3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2}}Bobby Treat-----Original Message-----[ksN<(r+1),s=fLPartition[ksN,r];ksN=ksN+1;Print[s ]]]However, I do not like this solution since to my taste is to complex andrather inelegant. Nest or Fold would do better. Any Idea?Just an additional remark.Besides, I do not need the whole taxonomy, but a subset satisfying aminimizing condition on connectivity implied by some relationships amongthe elements. This condition is satis\fied by one and only one element,orclass of equivalence in each level of the hierarchy. So it is that veryclass which matter and consequently the procedure should give control oneach class as the total structure is being generated. Once it is knownwhichclass satis\fies the condition it is possible to avoid generating thewholestructure and the subsequent combinatorial explosion. With justThis an addition to the previous postingIn fact, the thing is even worst. These are the CPU times for the following computationstimes1=First[Timing[fLPartition[3,10];]]/. Second->10.02times2=First[Timing[fLPartition[3,20];]]/. Second->10.18times3=First[Timing[fLPartition[3,30];]]/. Second->10.701times4=First[Timing[fLPartition[3,40];]]/. Second->11.913times5=First[Timing[fLPartition[3,50];]]/. Second->14.236times6=First[Timing[fLPartition[3,60];]]/. Second->18.222times7=First[Timing[fLPartition[3,70];]]/. Second->114.39times8=First[Timing[fLPartition[3,80];]]/. Second->123.563So far so good. But fortimes9=First[Timing[fLPartition[3,90];]]/. Second->1The computation does not always end. Some times it ends some times itdoes not (I aborted the process four times after 1 hour of computing and running out of, 2Gbites of, virtual memory)Emilio Martin-Serrano___________________________________Emilio Martin-SerranoSchlumbergerOil & Gas Business Consulting Principal1325 South Dairy Ashford RoadHouston, TX 77077 ==== =I am interested in creating a slide presentation using slide viewmode in Mathematica 4.2. I would like to have hyperlinks betweendifferent slides ( e.g., a hyperlink in say slide 6 takes me back toslide 3).I have no dif\ficulty in creating such a hyperlink (using tags) when Iam in the author mode. But the hyperlink does not work when a revertback to slide view mode.I guess it has somthing to do with the fact that in author view modeyour slides are a subset of a single notebook but in slide view modeeach slide becomes a distinct notebook.So my question: Is there a way to reference the individual slidesusing the hyperlink command?Brian ==== =This graphs f from 0 to 8 Pi on a logarithmic horizontal scale:f[x_] := 1 + Abs[Sin[x]/x]Plot[f@Exp@x, {x, 0, Log[8Pi]}, PlotRange -> All];If you want both scales to be logarithmic, usePlot[Log@f@Exp@x, {x, 0, Log[8Pi]}, PlotRange -> All];The \first is always possible if you only have positive x to deal with,and the second is possible if x and y are BOTH positive.Bobby Treat-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== => This graphs f from 0 to 8 Pi on a logarithmic horizontal scale: f[x_] := 1 + Abs[Sin[x]/x]> Plot[f@Exp@x, {x, 0, Log[8Pi]}, PlotRange -> All];The graph itself is indeed what is desired, but the labelling of the x-axisis then incorrect for a logarithmic scale. For example, regardless of thescale used, any proper graph must show that the \first minimum occurs atx = Pi. But the method you suggest makes it seem that it occurs at approx.1.14 (precisely Log[Pi]).David> -----Original Message-----> ==== =Jason, On item #1 I can help you. I have a notebook that explains thebasics of creating tables using either TableForm or Gridboxes. Shouldget you started.It can be downloaded from my Mathematica course web site:http://www.higgins.ucdavis.edu/ECH198.phpUse the link for lecture 3.Brian> I'm going to try using Mathematica to typeset some mathematics > because I know that my students would bene\fit from being able to do > the same., and \ they'll need someone who can answer their questions, > etc. etc.> \ I'm pretty comfortable with some things (e.g., Mathematica's > recognition of latex commands for most characters), and now I'm ready > to push the envelope a bit.> Q1: How can I typeset a table or array of information (e.g., list of > variables with de\finitions) so that information in one column is > centered and information in another column is aligned ßush left? I > know exactly how I would do this in LaTeX, but I \find no information > on how to do this in Mathematica.> Q2. How can I embed a Quicktime movie into a Mathematica notebook > (e.g., so someone with MathReader can play the animation)?> That's all for now. ==== => I'm pretty comfortable with some things (e.g., Mathematica's > recognition of latex commands for most characters), and now I'm ready > to push the envelope a bit.> Q1: How can I typeset a table or array of information (e.g., list of > variables with de\finitions) so that information in one column is > centered and information in another column is aligned ßush left? I > know exactly how I would do this in LaTeX, but I \find no information > on how to do this in Mathematica.See Section 2.8.11 of _The Mathematica Book_.http://documents.wolfram.com/v4/MainBook/2.8.11.htmlAt the beginning of that section, you will \find a description of the options that one may apply to GridBox[] objects, which are used to construct tables, matrices, and button palettes.More information on the values that these options may take can be found in the front end option documentation.http://documents.wolfram.com/v4/ OtherInformation/GridBoxOptions.htmlWith the current selection in your notebook being the table itself, you can use the Option Inspector dialog (with its scope set to selection) to change the ColumnAlignments option to {Center, Left}, which means that \first column elements should be centered, and that subsequent columns should be left justi\fied.-- User Interface Programmer paulh@wolfram.comWolfram Research, Inc. ==== => Stefan,> To \find n digits before the decimal point of a number, we can proceed in the> following way. We compute the number in suf\ficiently many digits, then take> the Floor of the result (i.e. we round it downwards to an integer) and> \finally take the result modulo 10^n.> Mod[Floor[ N[(Sqrt[2] + Sqrt[3])^2002 , 1000]], 10^2]> results in 9, so the last two digits before the decimal point are 09.> With a slight modi\fication we can \ \find the \first n digits after the decimal> point. Simply \ \find the last n digits before the decimal point of 10^n times> the number.> Mod[Floor[ N[10^2 (Sqrt[2] + Sqrt[3])^2002 , 1000]], 10^2]> results in 99, so these are the digits you are interested in.> But there is something curious about this number.> Mod[Floor[N[10^1000 (Sqrt[2] + Sqrt[3])^2002 , 2000]], 10^1000]> results in 996 digits 9 followed by 7405.> You can also play with the following command, resulting in the digits around> the decimal point:> Mod[ N[(Sqrt[2] + Sqrt[3])^2002, 2300], 10^6]> The decimal expansion of (Sqrt[2]+Sqrt[3])^2002 contains a sequence of> 997 consecutive digits 9. Do you have any idea why?Not unusual. Try other even exponents and there should be large blocks of 9s . Smaller number for small exponents. Some kind of propagation of 9s as the exponent grows. Try other odd values for 3 and the same thinghappens for some values. Also for other values for 2.Larry> Fred Simons> Eindhoven University of Technology> Reply-To: kuska@informatik.uni-leipzig.de ==== =Plot[{x,x^2},{x,-1,1}]may do it. Jens> How can I plot with Mathematica two function in the same graphic?> I explain better:> compare a and b).> Reply-To: kuska@informatik.uni-leipzig.de ==== =it works with any graphicsNotebookWrite[SelectedNotebook[], GridBox[{Cell[GraphicsData[PostScript, DisplayString[#, MPS]], Graphics] & /@ {leftGraphics, rightGraphics}}]] Jens> (1) Is there a way in Mathematica 4.2 to put two separate gifs into a> single, cell side by side (with some intervening space), without> having to combine them in some graphics program \first?> In particular, I'd like to do \ that within a text cell.> Even in a new Input cell, if I \first create a GridBox (via Inut>Create> Table/Matrix/Palette) and then try to insert the \first gif (via> Edit>Insert Object>Create from File ....), Mathematica promptly> crashes. (Mathematica 4.2 under Windows 2000.)> I just don't see how to get anything other than a single gif into a> cell.> (2) Is there a way to cause a gif imported into a Mathematica 4.2> notebook to become a hyperlink -- so that when the user clicks on the> gif the hyperlink's target is summoned?> (My aim in all this is to use Mathematica to create web pages with> high mathematical content -- saving the notebook as HTML+MathML --> without having to do any extensive editing of the resulting .xml and> related \files. That way as the source Mathematica notebook changes, I> would need only to re-export without further tinkering with the .xml> \file, etc.)> --> Murray Eisenberg Internet: murray@math.umass.edu> Mathematics & Statistics Dept. Voice: 413-545-2859 (W)> University of Massachusetts 413-549-1020 (H)Reply-To: kuska@informatik.uni-leipzig.de ==== =set the PlotRange explicit PlotRange->{{0,largeX},Automatic} Jens> I am using MultipleListPlot to plot a range of 2D graphs and have found that> the last graph, which has a much greater (by a factor of 4) x range than the> others does not plot completely but is truncated in the x direction. By> removing the Frame, I can see the points where these lie outside the Frame> but these are not joined etc. How do I get over this?> -> Malcolm WoodruffReply-To: kuska@informatik.uni-leipzig.de ==== =what may be in the *.m \files? Mathematica commands ? thatyou can load into the kernel ? Makr all your input cells in the notebook as initialization,save it as an *.m \file, add a Quit[] as the last commandto the *.m \file and run it withmath << yourJustGeneratedMFile JensRegardds> Probably a rather simple question: what is the easiest way to open a> notebook, execute it, then quit, from the command line? I would like to be> able to do this from a Make\file.> SidneyReply-To: kuska@informatik.uni-leipzig.de ==== =do you realy think that1.07577/( 1+7.12336*10^-7 (1. + z)^2 )with the z inside is numerical ? or do you meanF[z_?NumericQ]: = NIntegrate[f[y,z], {y, 0, In\finity}] Jens> I've \ this problem with NIntegrate:> **********************************************> In[1]=f[y_,z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[z]+1) )> In[2]=F[z_]: = NIntegrate[f[y,z], {z, 0, In\finity}> **********************************************> Mathematica 4.0 says:> ************************************************************* ***************> *> NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is not> numerical at {y}={1.}.> ************************************************************* ***************> **> What is it??> --> Rob_jack ==== = do you realy think that 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) with the z inside is numerical ? or do you mean F[z_?NumericQ]: = NIntegrate[f[y,z], {y, 0, In\finity}]>I'm a \ newbie, bat I mean:*************************In[1]= NumericQ[z]Out[1]=False*************************BTW, z is a real number.--Rob_jack ==== =There is an error in the previous message.This is the just msg:**********************************************In[1]=f[y_, z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[y]+1) )In[2]=F[z_]: = NIntegrate[f[y,z], {y, 0, In\finity}********************************************** Mathematica 4.0 says:******************************************************** ********************NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is notnumerical at {y}={1.}.**************************************************** ************************What is it??Moreover, I have used the following procedure:*************************************************** ***If z<<1,f[y,z]=Sum[(-1)^n*a^n*(1+z)^2n *(y^(2n+4)/(Exp[y]+1),{n, 0, N} ]here a=(8.44*10^-4)^2therefore:F[z]:=Sum[(-1)^n*a^n*(1+z)^2n *(y^(2n+4)/(Exp[y]+1) * Gamma[2 n+5]*Zeta[2n+5],{n, 0, N} ]this series (N<+oo) only approximates the function for small z, and me itinterests the behavior of F for z in the range 800-1300.Thx in advance.Rob_jack ==== => I've this problem with NIntegrate:> **********************************************> In[1]=f[y_,z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[z]+1) )> In[2]=F[z_]: = NIntegrate[f[y,z], {z, 0, In\finity}> **********************************************> Mathematica 4.0 says:> ************************************************************* ***************> *> NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is not> numerical at {y}={1.}.> ************************************************************* ***************> **> What is it??> I doubt that you could input your equations as you stated:The \first input has a missing )The second one a missing ]In both equations there should be no space in :=Apart from that the second de\finitions doesn't seem to make muchsense, maybe it should be F[y_] := ...Have you assigned y some value before (I get a different errormessage, when I mix up the y and z as you did.)Good luckAlois -- Vienna University of Technology,A-1040 Wiedner Hauptstr. 8-10 Reply-To: kuska@informatik.uni-leipzig.de ==== =not with Mathematica 4.2. But the problem can be the page widththat may be used to convert the Cell[], if you can you shoulduse the Graphics[]/Graphics3D[] .. inside the Cell orthe PostScript string in the GraphicsData[] Jens> The following is a button that will export a selected graphic as a JPEG,> ButtonBox[JPEG,> ButtonFunction : Module[{sel},> SelectionMove[InputNotebook[], All, Cell];> sel = NotebookRead[InputNotebook[]];> If[Head[sel] ==== Cell,> If[!ValueQ[dpi], dpi = Automatic];> ImageSize -> Automatic, ImageResolution -> dpi,> ConversionOptions -> {Quality -> 75}]]],> ButtonEvaluator -> Automatic, Active -> True]//DisplayForm> It works \fine as long as the graphic is no wider than about 330 pixels.> If the graphic is wider than 330 pixels, then the size of exported> graphic is correct, but everything on the right beyond the \first 330> pixels is blank. There seems to be no problem with the height though.> Any ideas on how to \fix or get around this problem?> ---> Selwyn HollisReply-To: kuska@informatik.uni-leipzig.de ==== =Needs[Graphics`Graphics`] LogPlot[Exp[-x],{x,0,10}]?? Jens> ==== =<-----Original Message----->Sent: Wednesday, September 11, 2002 9:28 AM>>A commonly used symbol for the Floor function is a square >bracket with the>upper indents removed. Is this symbol part of Mathematica's >built-in symbols? I>think not, so then, can it be constructed by hand.>>JackJack, yes it is already built-in! Bring up the palette with menu: File > Palettes> CompleteCharachters; there is a section Operators > General, where \ you'll\find what you want.Alternatively type Ôesc' l f \ Ôesc' Ôesc' r f Ôesc', \ orinstead of the esc-sequence use the corresponding mark-ups. For output tryTraditionalForm. If you don't like that for all of your output, you may justadd a formatting rule for Floor:In[7]:= Unprotect[Floor]In[8]:=Floor /: MakeBoxes[Floor[expr_], StandardForm] := RowBox[{[LeftFloor], MakeBoxes[expr, StandardForm], [RightFloor]}]In[9]:= Protect[Floor]In[11]:= Floor /@ ([Pi] + [Lambda])Out[11]= 3 + [LeftFloor][Lambda][RightFloor]Same thing with Ceiling, BTW.--Hartmut ==== =>-----Original Message----->Sent: Wednesday, September 11, 2002 9:28 AM>Is it possible to con\figure a style sheet so that functions or >data shown in>graphs are coloured (colored :)) in working but black in >printing...without>actually re-executing the function that created the graphics?>>thanks>>MikeMike, if for some reason you can't con\figure your color printer when \ printing, youmay rerender your graphics in Mathematica with different options, suchavoiding costly recalculation. You may either use something special, asin...In[1]:=ContourPlot[Sin[x]^2 Sin[y]^2, {x, 0, Pi}, {y, 0, Pi}, ColorFunction -> Hue, ContourStyle -> GrayLevel[1], PlotPoints -> 100]Out[1]=[SkeletonIndicator]ContourGraphics[ SkeletonIndicator]In[2]:=Show[%, ColorFunction -> (GrayLevel[1 - #] &)]...using a B/W color function. Or in general you may use the optionColorOutput:In[3]:=Plot3D[Sin[x]^2 Sin[y]^2, {x, 0, Pi}, {y, 0, Pi}]Out[3]=[SkeletonIndicator]SurfaceGraphics[ SkeletonIndicator]...In[5]:=Show[%%, ColorOutput -> GrayLevel]--HartmutReply-To: jmt@dxdydz.net ==== =mathematica -primaryModi\fierMask etcsee man mathematica for other (very useful) options> PS: One more quick one: Why does the front end act funny when I have the> Your X server is set up so that the NumLock key is mapped to Mod2. I> learned by accident that Mod2 is actually quite useful. Mod2-click on a> cell selects all cells of that type in the current notebook. This is an> easy way to delete all the graphics cells and output cells in a notebook to> reduce \file size. An annoying aspect is that Mod2-click means press> NumLock, click, then press NumLock again to turn it off. You should be able> to map a different key to Mod2 using xmodmap. Remapping modi\fier keys in X> is awfully annoying, though. I recommend xkeycaps> (http://www.jwz.org/xkeycaps/).> Reply-To: kuska@informatik.uni-leipzig.de ==== =a Mathematica pro\filer is described inThe Mathematica JournalVolume 5, Issue 3, Summer 1995 The Mathematica Toolbox: A Mathematica Pro\filer by Todd Gayley The electronic material for this issue isn not on MathSourcebut it may be that Todd has the code some where andcan make is acessible. Jens> I have been trying to code Sethian's Fast Marching Method in 2D but Mathematica> has been very slow (taking something like 1-2 hours for something that> should take much less than a second in C++). I am sure part of the problem> my time.> I looked at the list archives and there was mention of an pro\filing> package for Mathematica but a)I can't \find it & b)It may not work with \ Mathematica 4.*.> My questions:> 1. Any general suggestions on how to \figure out which functions are taking> most of the time? I guess I could manually have each function I am> interested in monitoring keep a variable that counts the amount of CPU> time that has been spent on it by doing something like:> function[args_]:=Module[{},functionTimer+=Timing[ .... My actual function> ..... ][[1]]]> but it would very cumbersome to do this to all of the functions in my> program and I am not sure I will get accurate results anyway.> 2. Compiling functions is not always that easy. I did read the on-line> docs and the archives and it does take some work to make a function> compile usefully. Is there an FAQ or a tutorial somewhere?> 3. Am I the only one who \finds the lack of a pro\filer really really> annoying ? Mathematica is powerful and it is usually easy to ask it to do what u> want. The challenge a lot of times is doing so without taking too long.> Husain> PS: One more quick one: Why does the front end act funny when I have the ==== => PS: One more quick one: Why does the front end act funny when I have theYour X server is set up so that the NumLock key is mapped to Mod2. Ilearned by accident that Mod2 is actually quite useful. Mod2-click on acell selects all cells of that type in the current notebook. This is aneasy way to delete all the graphics cells and output cells in a notebook toreduce \file size. An annoying aspect is that Mod2-click means pressNumLock, click, then press NumLock again to turn it off. You should be ableto map a different key to Mod2 using xmodmap. Remapping modi\fier keys in Xis awfully annoying, though. I recommend xkeycaps(http://www.jwz.org/xkeycaps/). ==== =I'm trying to write a fast empirical cummulative distribution function(CDF). Empirical CDFs are step functions that can be expressed interms of a Which statement. For example, given the list ofobservations {1, 2, 3},f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]&is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1}and f is continuous from the right.When the number of observations is large, the Which statementevaluates fairly slowly (even if it has been Compiled). SinceInterpolationFunction evaluates so much faster in general, I've triedto use Interpolation with InterpolationOrder -> 0. The problem is thatthe resulting InterpolatingFunction doesn't behave the way (I think)it ought to. For example, letg = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder ->0]Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.In addition, g is continuous from the left rather than from the right.Obviously I am not aware of the considerations that went intodetermining the behavior of InterpolationFunction whenInterpolationOrder -> 0.So I have two questions: (1) Does anyone have any opinions about how InterpolatingFunctionought to behave with InterpolationOrder -> 0?(2) Does anyone have a faster way to evaluate an empirical CDF than acompiled Which function?By the way, here's my current version:CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] := Block[{x}, Compile[{{x, _Real}}, Evaluate[ Which @@ Flatten[ Append[ Transpose[{ Thread[x < Sort[list]], Range[0, 1 - 1/#, 1/#] & @ Length[list] }], {True, 1}]] ]]]--Mark ==== =Daniel Lichtblau made two suggestions that allow one to useInterpolation the way I wanted. First, to make the resulting functionright-continuous, change the sign twice. Second, to make the end pointreturn the correct value, add an extra (phantom) observation (with anextra (irrelevant) value). (The phantom observation is made at thehigh end because of the sign reversals.) Here's the code I cooked upbased on his suggestions:MakeEmpiricalCDF::usage = MakeEmpiricalCDF[list] returns a functionthat evaluates the empirical CDF given the observations in the list.The function is de\fined on the entire real line.MakeEmpiricalCDF[list_?(VectorQ[#, NumericQ]&)] := Module[{n, s, a, r, idata}, n = Length[list]; s = Sort[list]; a = Append[s, s[[-1]] + 1]; (* phantom obs. *) r = Range[1/n, 1 + 1/n, 1/n]; (* phantom value 1 + 1/n *) idata = Last /@ Split[Transpose[{-a, r}], #1[[1]] == #2[[1]]&]; (* -a is the \first sign change *) Block[{x}, Function @@ {x, Which @@ { x < s[[ 1]], 0., x > s[[-1]], 1., True, Interpolation[idata, InterpolationOrder -> 0][-x] (* -x is the second sign change *) }}] ]The construction Last /@ Split[ ... ] accounts for duplicate values.Here are two examples. Needs[Statistics`ContinuousDistributions`]list1 = RandomArray[NormalDistribution[0, 1], 100];f1 = MakeEmpiricalCDF[list1];Plot[f1[x], {x, -4, 4}]list2 = Table[Random[Integer, {1, 10}], {10}];f2 = MakeEmpiricalCDF[list2];Plot[f2[x], {x, 0, 11}]--Mark> I'm trying to write a fast empirical cummulative distribution function> (CDF). Empirical CDFs are step functions that can be expressed in> terms of a Which statement. For example, given the list of> observations {1, 2, 3},> f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]&> is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1}> and f is continuous from the right.> When the number of observations is large, the Which statement> evaluates fairly slowly (even if it has been Compiled). Since> InterpolationFunction evaluates so much faster in general, I've tried> to use Interpolation with InterpolationOrder -> 0. The problem is that> the resulting InterpolatingFunction doesn't behave the way (I think)> it ought to. For example, let> g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder - 0]> Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.> In addition, g is continuous from the left rather than from the right.> Obviously I am not aware of the considerations that went into> determining the behavior of InterpolationFunction when> InterpolationOrder -> 0.> So I have two questions: > (1) Does anyone have any opinions about how InterpolatingFunction> ought to behave with InterpolationOrder -> 0?> (2) Does anyone have a faster way to evaluate an empirical CDF than a> compiled Which function?> By the way, here's my current version:> CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] :=> Block[{x}, Compile[{{x, _Real}}, Evaluate[> Which @@ Flatten[> Append[> Transpose[{> Thread[x < Sort[list]],> Range[0, 1 - 1/#, 1/#] & @ Length[list]> }],> {True, 1}]]> ]]]> --Mark ==== = I am new to numerical computing. I have a equation dQ/dz = exp(-i*4*a^2*z - i*pi/4)*f(z,t)/sqrt(4*pi*z) where z is the position range from 0 to 10, t is the time range from0 to 10 f(z,t) = integration of exp(i*(t-t1-z)^2/z)*g(t1) from t1=-100 to100 g(t1) = d^3 sech(t1) / dt^3 I would like to solve Q(z,t), however, I am a new to mathematica.Can anyone help me? ==== =I know that there is an input form. I want the output to have the sameform rather than look like Floor[x]. Sorry,Jack A commonly used symbol for the Floor function is a square bracket with the> upper indents removed. Is this symbol part of Mathematica's built-in symbols? I> think not, so then, can it be constructed by hand. JackReply-To: kuska@informatik.uni-leipzig.de ==== =doesMakeBoxes[Floor[x_], fmt_:StandardForm] := RowBox[{[LeftFloor], ToBoxes[x, fmt], [RightFloor]}]help you ? Jens> I know that there is an input form. I want the output to have the same> form rather than look like Floor[x]. Sorry,> Jack> A commonly used symbol for the Floor function is a square bracket with the> upper indents removed. Is this symbol part of Mathematica's built-in symbols? I> think not, so then, can it be constructed by hand. Jack ==== =Recent threads about word processing and typesetting have got me dreaming again...Wouldn't it be nice if someone developed a package that provided a function like this: DisplayTeX[ some TeX code ]which would cause the kernel to generate PostScript for the typeset text, to be displayed by the front end?I doubt that WRI will ever consider this, but surely there's someone out there who's both a TeXpert and a Mathematica guru who can do it. No doubt there's money to be made.Probably just a pipe dream...---Selwyn HollisReply-To: kuska@informatik.uni-leipzig.de ==== =you mean the inverse of TeXForm[] ?For what ? A TeXpert && Mathematica guru && MathLink experthas a TeX frontend, that translate a TeXNotebook(that is a TeX \file with some Mathematica Input/Output environments) and send the input cells to a kerneland insert the output into the \final TeX \ \file ...The most of the remaining work like creating hyperlinksto references and \figures is done my LaTeX and pdfLaTeX,with help of CTAN and some macros one generate almost everylayout *and* I have more than 20 books about TeX/LaTeX (including Don Knuths excelent manuals) but I have nota single book about the Mathematica Frontend.The way is not to teach TeX to the frontend, the way isto teach TeX a bit Mathematica.And a TeXpert will never switch from his beloved TeXto the Frontend and it's typesetting -- that's whyhe is a \ TeXpert. Jens> Recent threads about word processing and typesetting have got me> dreaming again...> Wouldn't it be nice if someone developed a package that provided a> function like this:> DisplayTeX[ some TeX code ]> which would cause the kernel to generate PostScript for the typeset> text, to be displayed by the front end?> I doubt that WRI will ever consider this, but surely there's someone out> there who's both a \ TeXpert and a Mathematica guru who can do it. No> doubt there's money to \ be made.> Probably just a pipe dream...> ---> Selwyn Hollis ==== => you mean the inverse of TeXForm[] ?> For what ? A TeXpert && Mathematica guru && MathLink expert> has a TeX frontend, that translate a TeXNotebook> (that is a TeX \file with some Mathematica Input/Output > environments) and send the input cells to a kernel> and insert the output into the \final TeX \file ...Congratulations to you if you can do that and if you're happy with it. I'd prefer life to be a \ bit simpler. The point is that many users of Mathematica already have suf\ficient knowledge of TeX/LaTeX to typeset very complicated mathematics and get excellent results with little or no grief. To achieve even close to the same quality with Mathematica alone can require ten times the effort and a hundred times the grief.---Selwyn> The most of the remaining work like creating hyperlinks> to references and \figures is done my LaTeX and pdfLaTeX,> with help of CTAN and some macros one generate almost every> layout *and* I have more than 20 books about TeX/LaTeX > (including Don Knuths excelent manuals) but I have not> a single book about the Mathematica Frontend.> The way is not to teach TeX to the frontend, the way is> to teach TeX a bit Mathematica.> And a TeXpert will never switch from his beloved TeX> to the Frontend and it's typesetting -- that's why> \ he is a TeXpert.> Jens>Recent threads about word processing and typesetting have got me>dreaming again...>Wouldn't it be \ nice if someone developed a package that provided a>function like this:> DisplayTeX[ some TeX code ]>which would cause the kernel to generate PostScript for the typeset>text, to be displayed by the front end?>I doubt that WRI will ever consider this, but surely there's someone out>there \ who's both a TeXpert and a Mathematica guru who can do it. No>doubt there's money to be made.>Probably just a pipe dream...>--->Selwyn Hollis> ==== =Mike,I don't think so. Style sheets do not control the styles used within anoutput graphics cell. I think you will have to set the plot style as astatement in the notebook, change it and re-evaluate for printing. Thismight not be all that inconvenient because you probably won't be printingthat often.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== =Dear MathGroup,To plot FrameTicks outward with the same style as the Frame, I useExtendGraphics in the following way.Needs[ExtendGraphics`Ticks`];tf[min_,max_] := TickFunction[min, max, MajorStyle -> {Thickness[0.003]}, MajorLength - > {0, 0.01}, MinorStyle -> {Thickness[0.003]},MinorLength -> {0, 0.005}]Plot [-2.4 (x+6) (x-8), {x, -6.2, 9.2}, FrameTicks -> {tf, tf, None, None},AspectRatio -> 18/25, Frame -> True, DefaultFont -> {Helvetica-Bold, 12},Axes -> None,FrameStyle -> Thickness[0.003], FrameLabel -> {x, y, None, None},PlotStyle -> Thickness[0.006],ImageSize -> 504];(instead of the same Plot statement with FrameTicks -> {Automatic,Automatic, None, None})This arrangement of major and minor ticks is clearly unacceptable. Theminor ticks do not divide intervals of adjacent labelled major ticks into equal parts.Are there other solutions? I have noticed that some major statistical(plotting) programs don't do minor ticks at all.Tom AldenbergRIVMBilthovenNetherlands ==== =I need to create an adjacency matrix from my data, which is currently inthe form of a .txt \file and is basically a two column incidence list.For example: 1 A 1 B 2 B 3 C . . . . . . m n Where 1 to m represent actors and A to n represent events. My goal is tohave an (m x m) matrix where cell i,j equals 1 if two actors areincident to the same event (in the sample above, 1 and 2 are bothincident to B) and 0 otherwise (w/ zeros on the diagonal). I'm new to Mathmatica, and so I'm \ on the steep part of the learningcurve ... All I've been able to \ \figure out so far is how to get myincidence list into the program using Import[\filename.txt]. But thenwhat? How do I convert to the adjacency matrix? I've found theToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can'tseem to get it to work ... Tom**********************************************Thomas P. MoliternoGraduate School of ManagementUniversity of California, Irvinetmoliter@uci.edu*************************************** *******Reply-To: kuska@informatik.uni-leipzig.de ==== =with In[]:=lst = {{1, A},{1, B},{2 , B},{3, C}, {3, D}, {1, D}};and In[]:=AdjacenceMatrix[lst : {{_, _} ..}] := Module[ {actors,events adj}, {events, actors} = Union /@ Transpose[lst]; adj = Table[0, {Length[events]}, {Length[actors]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, actors]]; adj ]you getIn[]:=AdjacenceMatrix[lst]Out[]={{1, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}} Jens> I need to create an adjacency matrix from my data, which is currently in> the form of a .txt \file and is basically a two column incidence list.> For example:> 1 A> 1 B> 2 B> 3 C> . .> . .> . .> m n> Where 1 to m represent actors and A to n represent events. My goal is to> have an (m x m) matrix where cell i,j equals 1 if two actors are> incident to the same event (in the sample above, 1 and 2 are both> incident to B) and 0 otherwise (w/ zeros on the diagonal).> I'm new to Mathmatica, and so I'm \ on the steep part of the learning> curve ... All I've been able to \ \figure out so far is how to get my> incidence list into the program using Import[\filename.txt]. But then> what? How do I convert to the adjacency matrix? I've found the> ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't> seem to get it to work ...> Tom> **********************************************> Thomas P. Moliterno> Graduate School of Management> University of California, Irvine> tmoliter@uci.edu> ********************************************** ==== =>Probably a rather simple question: what is the easiest way to open a>notebook, execute it, then quit, from the command line? I would like to be>able to do this from a Make\file.actually, this is not as simple as it should be and one needs theextremely useful JLink to really manipulate Notebooks from the similar under MacOSX and even Windows. Maybe others can try this. ==== ==============================================Execute this in the FrontEnd to create a test notebook, then quit the FrontEnd completely:NotebookSave[NotebookPut[Notebook[{Cell[, Input],Cell[Integrate[Log[1 - x]^2/(1 + x), {x, 0, 1}], Input]}]],/tmp/test.nb](* **************************** *)Next, create a \file t.m :[rolf@uranus tmp]$ cat t.mnb = /tmp/test.nb;(* ***************************** *)<, Input],Cell[NotebookSave[en, Interactive -> False], Input]}]];SelectionMove[m, All, Notebook];SelectionEvaluate[m];];Pause[1];(* **************************************** *)Now you can run it like this in the background:[rolf@uranus tmp]$ math < t.m > t.out &This will open /tmp/test.nb , evaluate it and save it under thesame name.(* ******************************* *)Maybe there is an easier and cleaner way, but the problem here is that the kernel and the FrontEnd are really two different programs, i.e., the kernel is not waiting until the FrontEnd \finished certain tasks (like NotebookSave), i.e., think of it as threads. Therefore I used the trick with a second steering notebook.(One usually has similar problems when writing more intricate buttons.)If you are not, e.g. you work remotely at a Unix-box without anvirtual frame buffer (Xvfb), like in webMathematica. ask Wolfram Tech Support.Rolf MertigMertig ConsultingEf\ficient Softwarehttp://www.mertig.com ==== => I'm curious about the different ef\ficiencies of Export vs. Put; Import vs.> Get.> Eg. Saving a list called c with approx. 16,000 elements, each element> being a three element list of reals.> Export[ac.dat,c] takes forever and consumes heaps of kernel memory> c>ac.dat all done in an instant (relatively speaking) and without the> transient burst of kernel memory usage.> Ditto Import and Get. Can anyone explain this?The comparison is that of apples and oranges.Get[] and Put[] deal with reading and writing Mathematica expressions inInputForm syntax. They are implemented in C, so they are fairly fast, andthe target format is human readable. However the output might not bereadily parsable by other computer programs. The functions may be usedwith Mathematica expressions of all kinds. In the event that humanreadability and platform independence are not important, one can useDumpSave[] in lieu of Put[].Export[] and Import[] for the cases you describe are using the Table target format. They are implemented in top-level Mathematica code, so they are not as fast as Get[] and Put[]. The target is a regularly formatted array of data, so not all Mathematica expressions are appropriate for this kind of conversion. In the case of Export[], the expression is formatted completely in memory using TableForm[] before being saved out to \file. In the case of Import[], there are a number of heuristics that are applied to each \field to determine whether the \field should be converted to a number or a string. This should explain why they are slower and require more memory.If you are dealing with a large collection of machine precision numbers, then neither of these approaches may be suitable for your purposes. You might be better off using the free add-on FastBinaryFiles, which is available up on MathSource at this URL:readable by C programs.-- User Interface Programmer paulh@wolfram.comWolfram Research, Inc. ==== => A commonly used symbol for the Floor function is a square bracket with> the upper indents removed. Is this symbol part of Mathematica's> built-in symbols? I think not, so then, can it be constructed by> hand.Is this what you're describing?In[1]:= [LeftFloor]x[RightFloor]Out[1]= Floor[x]This notation is documented in Section A.2.6 of _The Mathematica Book_ (Fourth Edition).-- User Interface Programmer paulh@wolfram.comWolfram Research, Inc. ==== =Jack,Check pages 959 and 960 in Section 3.10.4 of The Mathematica Book. You canuse LeftFloor and RightFloor as bracketing operators, which in turn areintrepreted as Floor.[LeftFloor] 3.2 [RightFloor]3These can also be entered as esc-lf-esc and esc-rf-esc.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== =Hugh Goyder and David Park gave a most elegant function to \find two vectorsthat are orthogonal to one vector in 3D. The key to coming up with theelegant solution is an understanding of Mathematica's NullSpace function.We can easily make the version from Hugh and David much more general withthe version below.-------------OrthogonalUnitVectors[vect__?VectorQ]:= #/Sqrt[#.#]&/@NullSpace[{vect}]-------------The version above will give a set of unit orthogonal vectors if given anynumber of vectors in any dimension. So besides giving it a 3D vector we can give it the following: OrthogonalUnitVectors[{2,1,0,-1,1}] or OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}]------------ But the short version above isn't very robust.(1) Clear[x,y,z];NullSpace[{{x,y,z}}] returns two vectors orthogonal to {x,y,z}, but the two vectorsNullSpace returns aren't orthogonal to each other. So (OrthogonalUnitVectors) should only work with numeric vectors.(2) We should ensure all the vectors have the same dimension and length >1.I give a less concise version below that corrects these problems.------------OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ]&)]/; (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= #/Sqrt[#.#]&/@NullSpace[{vect}]-------------- Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html ==== =I have installed 128 MB RAM extra in my computer. I had 64 before, so now Ihave 3 times as much.I expected some calculations that took very long before, to be executed inless time. To the contrary, my computer still goes to the hard drive fromemory for its calculations, and Mathematica stops with an out of memorymessage.Windows is recognizing this new memory. I dont know if Mathematica is. Howcan I \find out about this?Julio ==== => It seems there is an error in the BinCounts function of Mathematica's> standard < returns one more than the expected number of histogram bins. An example> of this is shown in the notebook code below where the comment in the> last notebook cell explicitly describes the problem. If anyone can> explain this behavior it would be appreciated, otherwise Wolfram> Research should be made aware of this feature of the function when it> is called as: BinCounts[{x1, x2, ...}, {xmin, xmax, dx}]A developer of Mathematica's Standard Packages has requested that thisresponse be posted to the forum:[begin developer's comments]Note that if you don't apply N when computing datBinWidth, you will alwaysget the expected number of bins; i.e., datBinWidth = (datMax -datMin)/datBins (assuming datMax and datMin are also exact numbers).Given input {xmin, xmax, dx}, BinCounts determines the number of bins tobe computed via Ceiling[(xmax - xmin)/dx]. For numericalized values, it'spossible for dx to end up such that the Ceiling forces \ an additional binto be added; presumably, it's better to have \ too many rather than too fewbins -- for example, if the dx was deliberately given such that the xmaxis not at an integer bin boundary... If you use exact values for binbounds and increment, then there will be no problem.[end developer's comments]--User Interface Programmer paulh@wolfram.comWolfram Research, Inc. ==== =I would like to create a 3D chart from an ASCII \file using Mathematica3.0. Can anyone give me some help? ==== =You might want to tell us how to \find A.10.Anyway, it's easier to simply go to Floor in the help browser (inversion 4.2, anyway).Bobby Treat-----Original Message-----David ==== =I doubt there's any money to be made here. Lots of people have createdvery valuable additions to Mathematica, but they're all being givenaway, so far as I \ can tell. It's too bad, too.And here we are, giving away our \ time. Sigh...Bobby-----Original Message-----there who's both a TeXpert and a Mathematica guru who can do it. No doubt there's money to be made.Probably just a pipe dream...---Selwyn Hollis ==== =OK, I give up; how would I \find Chapter AdvancedMathematics/Mathematical and Other Notations/Operators in the HelpBrowser?Bobby Treat-----Original Message-----> think not, so then, can it be constructed by hand.> Jack[LeftFloor] and [RightFloor] can be used for this.Look at Chapter Advanced Mathematics/Mathematical and Other Notations/Operators.Yours, Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== => You might want to tell us how to \find A.10.Open your fourth edition of _The Mathematica Book_ to page 1065. That's where part 10 of the Appendix starts. > Anyway, it's easier to simply go to Floor in the help browser (in> version 4.2, anyway).I suppose you're right. But I -- call me old-fashioned if you wish -- prefer to use the book.David ==== =I'll assume you have the information in a matrix like x:TableForm[x = {{1, A }, {1, B }, {2, B}, {3, D}, {4, D}, {5, C}}]First \find the highest actor number (or use what you've inputelsewhere):m = Last[Union[x[[All,1]]]]5De\fine the incidence function:f[x_, a_, b_] /; a == b := 0f[x_, a_, b_] := If[{} $B!b(B Intersection[Cases[x, {a, y_} -> y], Cases[x, {b, y_} -> y]],1, 0]Here's the incidence matrix:Array[f[x, #1, #2] &, {m, m}]{{0, 1, 0, 0, 0}, {1, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}}Once you have the incidence function, the only reason to store theincidence matrix is to avoid computing over again the same answers, andthat can be accomplished in other ways. If you won't have other xmatrices, it's convenient to de\fine f this \ way:f[a_, b_] /; a == b := f[a, b] = 0f[a_, b_] /; a < b := f[a, b] = If[{} $B!b(B Intersection[Cases[x, {a, y_} -> y], Cases[x, {b, y_} ->y]], 1, 0]f[a_, b_] := f[b, a]Array[f, {m, m}]{{0, 1, 0, 0, 0}, {1, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 1, 0, 0}, {0,0, 0, 0, 0}}Whenever you would want the {j,k} element of the adjacency matrix, justuse f[j,k] instead. Each pair is computed only once. In this version,I've taken advantage of the symmetry of the problem, too, to cut thework in half.Bobby Treat-----Original Message-----. .. .m nWhere 1 to m represent actors and A to n represent events. My goal is tohave an (m x m) matrix where cell i,j equals 1 if two actors areincident to the same event (in the sample above, 1 and 2 are bothincident to B) and 0 otherwise (w/ zeros on the diagonal).I'm new to Mathmatica, and so I'm on \ the steep part of the learningcurve ... All I've been able to \ \figure out so far is how to get myincidence list into the program using Import[\filename.txt]. But thenwhat? How do I convert to the adjacency matrix? I've found theToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can'tseem to get it to work ...Tom**********************************************Thomas P. MoliternoGraduate School of ManagementUniversity of California, Irvinetmoliter@uci.edu*************************************** ******* ==== =Well, I don't know how fast, but it is fairly simple, anyway. Suppose youhave a series of values s for which you wish to obtain the edf.In[1]:=s = Table[Random[Integer, {0, 3}], {10}]Out[1]={2,2,1,2,0,0,1,1,1,3}If no speci\fication is made about their position on the x-axis, we assumethat they correspond to the integers from 1 to 10. What we have then is thecollection of pairsIn[2]:=porig = Transpose[{Range[10], s}]Out[2]={{1, 2}, {2, 2}, {3, 1}, {4, 2}, {5, 0}, {6, 0}, {7, 1}, {8, 1}, {9, 1}, {10, 3}}The edf gives, for each x, the proportion of points in s that are less thanor equal to x, for all x. We obtain these proportions through the cumulativesumsIn[3]:=N[CumulativeSums[s]/Plus @@ s]Out[3]={ 0.153846,0.307692,0.384615,0.538462,0.538462,0.538462,0.615385 ,0.692308,0.769231,1.}so that for each of the pairs (x, y) below, y gives the proportion of pointsin s that are less than or equal to x:In[4]:=cumporig = Transpose[{Range[10], N[CumulativeSums[s]/Plus @@ s]}]Out[4]={{1, 0.15384615384615385}, {2, 0.3076923076923077}, {3, 0.38461538461538464}, {4, 0.5384615384615384}, {5, 0.5384615384615384}, {6, 0.5384615384615384}, {7, 0.6153846153846154}, {8, 0.6923076923076923}, {9, 0.7692307692307693}, {10, 1.}}Now shift the x values one unit to the left, by dropping the last value andprepending 0 to them:In[5]:=ps = Transpose[{Prepend[Drop[Range[1, 10], -1], 0], CumulativeSums[s]/Plus @@ s}]Out[5]={{0, 2/13}, {1, 4/13}, {2, 5/13}, {3, 7/13}, {4, 7/13}, {5, 7/13}, {6, 8/13}, {7, 9/13}, {8, 10/13}, {9, 1}}Then use Interpolation on this shifted set of points:In[6]:=ips=Interpolation[ps,InterpolationOrder[Rule]0] Out[6]=InterpolatingFunction[{{0,9}},<>]ips[x-1] is the edf you are looking for, as you may check by plotting it anddisplaying in the same graph together with the ListPlot of cumporig above.Tomas GarzaMexico City----- Original Message -----> and f is continuous from the right. When the number of observations is large, the Which statement> evaluates fairly slowly (even if it has been Compiled). Since> InterpolationFunction evaluates so much faster in general, I've tried> to use Interpolation with InterpolationOrder -> 0. The problem is that> the resulting InterpolatingFunction doesn't behave the way (I think)> it ought to. For example, let g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder - 0] Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.> In addition, g is continuous from the left rather than from the right. Obviously I am not aware of the considerations that went into> determining the behavior of InterpolationFunction when> InterpolationOrder -> 0. So I have two questions: (1) Does anyone have any opinions about how InterpolatingFunction> ought to behave with InterpolationOrder -> 0? (2) Does anyone have a faster way to evaluate an empirical CDF than a> compiled Which function? By the way, here's my current version: CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] :=> Block[{x}, Compile[{{x, _Real}}, Evaluate[> Which @@ Flatten[> Append[> Transpose[{> Thread[x < Sort[list]],> Range[0, 1 - 1/#, 1/#] & @ Length[list]> }],> {True, 1}]]> ]]] --Mark ==== =I have no opinion on the behavior associated with InterpolationOrder->0,except that it should be DOCUMENTED, but isn't.Meanwhile, try this:lst = {{1, 1/3}, {2, 2/3}, {3, 1}}; ClearAll[empiricalCDF]empiricalCDF[{x_List, y_List}] := Compile[ {{z, _Real}}, Evaluate[ Which @@ Flatten[ Transpose[ {(z < #1 & ) /@ x, y}]]]]empiricalCDF[v:{{_, _}..}] := empiricalCDF[v] = empiricalCDF[ ({Join[#1[[1]], {In\finity}], Join[{0}, #1[[ 2]]]} & )[Transpose[ lst]]]empiricalCDF[lst]Plot[empiricalCDF[lst][x], {x, 1, 3}];I split the work into two de\finitions for readability. If you evaluate:?empiricalCDFafter doing the plot above, you'll see that empiricalCDF[{{1, 1/3}, {2,2/3}, {3, 1}}] has been compiled and saved for later use, and that ittakes precedence over the SetDelayed rules listed after it. Hence, thecompilation only occurs once for each list.As written, your CompileEmpiricalCDF would be compiled all over againevery time it's used -- for each and every point you plot -- so ofcourse it's slow. There are other problems, \ too. For instance, thepatternlist_?(VectorQ[#, NumericQ] &)makes no sense at all. Maybe you meantlist_?And[VectorQ[#],NumericQ[#]]&Bobby Treat-----Original Message-----evaluates fairly slowly (even if it has been Compiled). SinceInterpolationFunction evaluates so much faster in general, I've triedto use Interpolation with InterpolationOrder -> 0. The problem is thatthe resulting InterpolatingFunction doesn't behave the way (I think)it ought to. For example, letg = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder ->0]Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.In addition, g is continuous from the left rather than from the right.Obviously I am not aware of the considerations that went intodetermining the behavior of InterpolationFunction whenInterpolationOrder -> 0.So I have two questions: (1) Does anyone have any opinions about how InterpolatingFunctionought to behave with InterpolationOrder -> 0?(2) Does anyone have a faster way to evaluate an empirical CDF than acompiled Which function?By the way, here's my current version:CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] := Block[{x}, Compile[{{x, _Real}}, Evaluate[ Which @@ Flatten[ Append[ Transpose[{ Thread[x < Sort[list]], Range[0, 1 - 1/#, 1/#] & @ Length[list] }], {True, 1}]] ]]]--Mark ==== =Try deleting ...Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb> Your machine information and OS EXACTLY matches mine (except that mypage\file> is NOT on a separate physical drive -- perhaps this is a clue as to whereto start),> and I had no problem building the help \file. Hence, as you say, thismust> be a problem for Wolfram to address. Perhaps, someone from WRI willenlighten> us via this newsgroup.> ....Terry I too have been unable to get the help browser functioning. I have> exactly the same problem. When trying to open the help browser it gets> to the point where it says scanning index \file and freezes. I tried> all the suggestions in the faq and the links provided here to no> avail. I'm running Winows 2000 with service pack 3. I have 512mb of> memory with a 768mb page\file on a separate drive, so I don't think> \ that's an issue. Mathematica 4.1 ran just \fine on this setup, so> judging by the number of other people affected by this, I'd say it's> some kind of bug with 4.2. Hopefully Wolfram will address this with> either a link that will provide a \fix that actually works, or a patch. >What is your operating system? How much memory do you have in yourmachine?>Also, how big is your page\file? Sounds to me like the rebuild ran out>of room to do its thing in. I just installed Mathematica 4.2, and had no problem rebuildingthe help index.>Subsequently, I ahd no problem using the Help browser either.>Hope that helps!>....Terry>I'd start with the following FAQ.>>http://support.wolfram.com/mathematica/interface/ helpbrowser/howrebuildindex.html>-Dale> Sorry that i failed say it immediately in a \first place, but ofcourse> i did try it FAQ at \first, and both tried to delete cache and rebuild> index, but results where the same - whenever i try to invoke help> browser (or rebuild index, for that matter), mathematica stops> responding (i did read your answer to the same question asked> a week ago before - actually that is why i turned to the FAQ).> ==== =>Try deleting ...>Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb > ==== =Simplify:5nth sqrt (3)/sqrt (6)5nth Sqrt(3)------------ Sqrt(6)1st.. is this the correct notation for use on a computer2nd.. how is the solution solved, step by step please.Reply-To: kuska@informatik.uni-leipzig.de ==== => Simplify:> 5nth sqrt (3)/sqrt (6)> 5nth Sqrt(3)> ------------> Sqrt(6)> 1st.. is this the correct notation for use on a computerNo. May be you mean3^(1/5)/Sqrt[6]??> 2nd.. how is the solution solved, step by step please.3^(1/5)/Sqrt[6] // FullSimplify Jens ==== =I want to make a list of all symbols in the Global context, as inNames[Global`*]and compute a ByteCount for each symbol's OwnValues -- withoutevaluating the symbols.It seems possible in principle, but I haven't found a way.Bobby TreatReply-To: kuska@informatik.uni-leipzig.de ==== =whats wrong withToExpression[#, StandardForm, Hold] & /@ Names[Global`*] /. Hold[a_] :> ByteCount[OwnValues[a]] Jens> I want to make a list of all symbols in the Global context, as in> Names[Global`*]> and compute a ByteCount for each symbol's OwnValues -- without> evaluating the symbols.> It seems possible in principle, but I haven't found a way.> Bobby Treat ==== =with the following Java comands you can execute any Mathematica commands:ml.putFunction(EnterTextPacket, 1);ml.put(string);See JLinkUserGuide p. 164.Hermann Schmitt----- Original Message ----- > I've checked the documentation on Wolfram, but did not \find the \ Ôhook' > for ReadList from java. Any help would be appreciated. thanks.> Pete> ==== =I want to use the capability of mathematica from java. This is what I want to do:I want to read a data set and use ReadList to structure it into an array and then plot that data set with the output as a .gif. Any ideas?I've checked the documentation on Wolfram, but did not \find the \ Ôhook' for ReadList from java. Any help would be appreciated. thanks.Pete ==== =Dear Mark,I suggest trying the following code before you putfurther energy in speeding up your functions. Mycode is very short and seems to be fast in my \firsttest with a random array of 100000 integers.cdf[li_List]:= FoldList[#1+Length[#2]&, 0.0, Split[Sort[li]]]/Length[li]t=Table[Random[Integer,{1,1000}],{ 100000}];Timing[cdf[t];]{0.44 Second,Null}Probably the speed could be increased further generatinga compiled version. But this would require additionalprogramming effort. Then you had to write a function whichcounts the number ofequal data Ôby hand' while scanning through the data list. Johannes> \ I'm trying to write a fast empirical cummulative distribution function> (CDF). Empirical CDFs are step functions that can be expressed in> terms of a Which statement. For example, given the list of> observations {1, 2, 3},> f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]&> is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1}> and f is continuous from the right.> When the number of observations is large, the Which statement> evaluates fairly slowly (even if it has been Compiled). Since> InterpolationFunction evaluates so much faster in general, I've tried> to use Interpolation with InterpolationOrder -> 0. The problem is that> the resulting InterpolatingFunction doesn't behave the way (I think)> it ought to. For example, let> g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder - 0]> Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.> In addition, g is continuous from the left rather than from the right.> Obviously I am not aware of the considerations that went into> determining the behavior of InterpolationFunction when> InterpolationOrder -> 0.> So I have two questions: > (1) Does anyone have any opinions about how InterpolatingFunction> ought to behave with InterpolationOrder -> 0?> (2) Does anyone have a faster way to evaluate an empirical CDF than a> compiled Which function?> By the way, here's my current version:> CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] :=> Block[{x}, Compile[{{x, _Real}}, Evaluate[> Which @@ Flatten[> Append[> Transpose[{> Thread[x < Sort[list]],> Range[0, 1 - 1/#, 1/#] & @ Length[list]> }],> {True, 1}]]> ]]]> --Mark> <><><><><><><><><><><><>Johannes LudsteckEconomics DepartmentUniversity of RegensburgUniversitaetsstrasse 3193053 Regensburg ==== =>-----Original Message----->Sent: Wednesday, September 11, 2002 7:28 PM>Dear MathGroup,>>To plot FrameTicks outward with the same style as the Frame, I use>ExtendGraphics in the following way.>>Needs[ExtendGraphics`Ticks`];>>tf[min_,max_] := TickFunction[min, max, MajorStyle ->{Thickness[0.003]},> MajorLength - > {0, 0.01}, MinorStyle -> {Thickness[0.003]},>MinorLength -> {0, 0.005}]>>Plot [-2.4 (x+6) (x-8), {x, -6.2, 9.2}, FrameTicks -> {tf, tf, >None, None},>AspectRatio -> 18/25, Frame -> True, DefaultFont ->{Helvetica-Bold, 12},>Axes -> None,>FrameStyle -> Thickness[0.003], FrameLabel -> {x, y, None, None},>PlotStyle -> Thickness[0.006],>ImageSize -> 504];(instead of the same Plot statement with FrameTicks -> {Automatic,>Automatic, None, None})>>This arrangement of major and minor ticks is clearly unacceptable. The>minor ticks do not divide> intervals of adjacent labelled major ticks into equal parts.>>Are there other solutions? I have noticed that some major statistical>(plotting) programs don't do minor ticks \ at all.>>Tom Aldenberg>RIVM>Bilthoven>NetherlandsSeveral alternatives (if the default ticks of Plot, Show that is, wouldn'tdo):(1) generate the ticks explicitly (to get \ control over supplied min, maxvalues for TickFunction):yticks = tf[-40., 120.]xticks = tf[-6.2, 9.2]Plot[-2.4 (x + 6) (x - 8), {x, -6.2, 9.2}, FrameTicks -> {xticks, yticks, None, None}, ...](2) try the Option TickNumbers, e.g.tf[min_, max_] := TickFunction[min, max, MajorStyle -> {Thickness[0.005]}, MajorLength -> {0, 0.01}, MinorStyle -> {Thickness[0.003]}, MinorLength -> {0, 0.005}, TickNumbers -> {5, 25}]gives an acceptable result, or TickNumbers -> {6, 18};with TickNumbers -> {8, 8} you'll have no minor ticks.(3) \ rede\fine the tick function's helperBegin[ExtendGraphics`Ticks`Private`]?? TickPositionTickPosition[ min, max, num] returns a list of at most num nicely roundedpositions between min and max. These can be used for tick mark positions.TickPosition[x0_Real, x1_Real, (num_Integer)?Positive] := Block[{dist, scale, min, max, i, delta, space}, space = {1., 2., 2.5, 5., 10.}; dist = (x1 - x0)/num; scale = 10.^Floor[Log[10, dist]]; dist = dist/scale; If[dist < 1., dist *= 10.; scale /= 10.]; If[dist >= 10., dist /= 10.; scale *= 10.]; delta = First[Select[space, #1 >= dist & ]]*scale; min = Ceiling[x0/delta]*delta; Table[Floor[x/delta + 0.5]*delta, {x, min, x1, delta}]]End[]There are some things to play with: space, scale, the de\finition for delta,to get at more nicely rounded positions; or rewrite completely.(4) for best control, de\fine the ticks all by yourself, e.g. yticks1 = Table[{t, t, {0, 0.01`}, {Thickness[0.003`]}} , {t, -25, 100, 25}]yticks2 = DeleteCases[ Table[{t, , {0, 0.005`}, {Thickness[0.003`]}} , {t, -25, 100, 12.5}], {t_, __} /; Mod[t, 25] == 0]xticks = Join[xticks1, xticks2]xticks1 = Table[{t, t, {0, 0.01`}, {Thickness[0.003`]}} , {t, -5, 7.5, 2.5}]xticks2 = DeleteCases[ Table[{t, , {0, 0.005`}, {Thickness[0.003`]}} , {t, -7.5, 8.5, 1.25}], {t_, __} /; Mod[t, 2.5] == 0]yticks = Join[yticks1, yticks2]--Hartmut Wolf ==== => I need to create an adjacency matrix from my data, which is currently in> the form of a .txt \file and is basically a two column incidence list.> For example: > 1 A > 1 B > 2 B > 3 C > . . > . . > . . > m n Past the following notebook into Mathematica.Tom BurtonNotebook[{Cell[CellGroupData[{Cell[Preparing an adjacency matrix,Section],Cell[,Text],Cell[CellGroupData[{Cell[Introduction,Subsection], Cell[, Text]}, Open]],Cell[CellGroupData[{Cell[The structure of a graph,Subsection],Cell[, Text],Cell[BoxData[ (<, Text],Cell[BoxData[ (bb = Graph[{{{1, 2}}},{{{(-1. ), 0}}, {{1. , 0}}}])], Input],Cell[BoxData[(ToAdjacencyMatrix[aa])], Input],Cell[BoxData[(ToAdjacencyMatrix[bb])], Input]}, Open]],Cell[CellGroupData[{Cell[Example of a list of actor-event pairs,Subsection],Cell[BoxData[ (data = {{1, }, {4, }, {3,}, {1, }, {1, }, {3, }, {2, }, {2,}})], Input],Cell[,Text],Cell[BoxData[ (d = Max[data[([All, 1])]])], Input]},Open ]],Cell[CellGroupData[{Cell[Getting the list of edges,Subsection],Cell[TextData[{ Given the list of actors and actions,this is most of the work. I'll do it in baby steps, as I would like to seewere I new to , StyleBox[Mathematica, FontSlant->Italic], . Itcould be done more directly.}], Text],Cell[Put events \first.,Text],Cell[BoxData[ (data2 = Reverse /@ data)],Input],Cell[Group by event, with increasing actors within each event.,Text],Cell[BoxData[ (data3 = Sort[data2])],Input],Cell[BoxData[ (data4 = Split[data3, First[#1] == First[#2]&])], Input],Cell[Remove isolated pairs., Text],Cell[BoxData[(data5 = DeleteCases[data4, {{_, _}}])], Input],Cell[Drop theactions., Text],Cell[BoxData[ (data6 = data5[LeftDoubleBracket]All, All, 2[RightDoubleBracket])],Input],Cell[, Text],Cell[BoxData[ (data7 = (KSubsets[#, 2]&) /@ data6)], Input],Cell[Collect edges into one list,Text],Cell[BoxData[ (data8 = Flatten[data7, 1])],Input],Cell[and remove duplicates, Text],Cell[BoxData[(onedir = Union[data8])], Input]}, Open]],Cell[CellGroupData[{Cell[Adjacency matrix via a list of edges usingMapAt, Subsection],Cell[Convert to directed edges,Text],Cell[BoxData[ (bothdir = Join[onedir, Reverse /@ onedir])],Input],Cell[,Text],Cell[BoxData[ (emptymat = Table[0, {d}, {d}])],Input],Cell[BoxData[ (adjmat = MapAt[1 &, emptymat, bothdir])],Input]}, Open ]],Cell[CellGroupData[{Cell[Adjacency matric viaToAdjacencyMatrix, Subsection],Cell[Construct a set of vertices fordisplay, Text],Cell[BoxData[ (verts = Table[{Cos[2 [Pi]j/d], Sin[2 [Pi] j/d]}, {j, d}])],Input],Cell[, Text],Cell[BoxData[ (g = Graph[List /@ onedir,N[List /@ verts]])], Input],Cell[Check our handiwork:,Text],Cell[BoxData[ (InputForm[g])], Input],Cell[BoxData[((ShowGraph[g];))], Input],Cell[BoxData[(ToAdjacencyMatrix[g])], Input]}, Open ]]}, Open]]},ScreenRectangle->{{43, 1152},{0, 746}},WindowSize->{565, 624},WindowMargins->{{243, Automatic}, {48,Automatic}}] ==== =I have a notebook that will become a web page. I want to have a logo GIF atthe top.My \first thought was that I could drag and drop a GIF into a cell in thenotebook, but that does not work.I can Import a GIF and Show it. This creates an input cell, the GIF, and anoutput cell. I don't want the input cell and the output cell to \ show whenthe HTML code is created.How can I do this?Tom Compton ==== =Instead of using Legend in plots with multiple series is there a wayto have arrows with a text at the end identifying the differentseries? The reason I'd like this is that the legend is a bit Ôbulky'looking and \ I'd want something tidier.I know there is an Arrow package but I think you'd need to manuallyenter each start and end point of each arrow - is there a simplecommand to do this?Also - is there a way to adjust the legend font size? I.e. make itsmall so that it doesn't interfere with data series. _ | thankyouReply-To: kuska@informatik.uni-leipzig.de ==== =Needs[Graphics`Arrow`]Plot [{Sin[x], Cos[x]}, {x, 0, 2Pi}, Epilog -> {{GrayLevel[0.9], Rectangle[{3.75, 0.25}, {5.2, 0.9}]}, Arrow[{4, 0.75}, {2, Sin[2]}], Text[Sin[x], {4, 0.75}, {-1, 0}], Arrow[{4, 0.5}, {2, Cos[2]}], Text[Cos[x], {4, 0.5}, {-1, 0}]}] Jens> Instead of using Legend in plots with multiple series is there a way> to have arrows with a text at the end identifying the different> series? The reason I'd like this is that the legend is a bit Ôbulky'> looking and \ I'd want something tidier.> I know there is an Arrow package but I think you'd need to manually> enter each start and end point of each arrow - is there a simple> command to do this?> Also - is there a way to adjust the legend font size? I.e. make it> small so that it doesn't interfere with data series.> _> |> \ > > > > thankyou ==== =>-----Original Message----->I'm trying to write a fast empirical cummulative distribution function>(CDF). Empirical CDFs are step functions that can be expressed in>terms of a Which statement. For example, given the list of>observations {1, 2, 3},>>f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]&>>is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1}>and f is continuous from the right.>>When the number of observations is large, the Which statement>evaluates fairly slowly (even if it has been Compiled). Since>InterpolationFunction evaluates so much faster in general, I've tried>to use Interpolation with InterpolationOrder -> 0. The problem is that>the resulting InterpolatingFunction doesn't behave the way (I think)>it ought to. For example, let>>g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder -0]>>Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.>In addition, g is continuous from the left rather than from the right.>>Obviously I am not aware of the considerations that went into>determining the behavior of InterpolationFunction when>InterpolationOrder -> 0.>>So I have two questions: (1) Does anyone have any opinions about how InterpolatingFunction>ought to behave with InterpolationOrder -> 0?(2) Does anyone have a faster way to evaluate an empirical CDF than a>compiled Which function?>>By the way, here's my current version:>>CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] :=> Block[{x}, Compile[{{x, _Real}}, Evaluate[> Which @@ Flatten[> Append[> Transpose[{> Thread[x < Sort[list]],> Range[0, 1 - 1/#, 1/#] & @ Length[list]> }],> {True, 1}]]> ]]]--Mark>Mark,as to (1) I don't know, but following your observation, and regarding ff = CompileEmpiricalCDF[{1, 2, 3}]Plot[ff[x], {x, 0, 4}, PlotRange -> {All, {0, 1}}]as a correct CDF, we get something quite similar withobs = {1, 2, 3}t = With[{n = Length[obs]}, Transpose[{Append[obs, Last[obs] + 1], Range[0, 1, 1/n]}]]g = Interpolation[t, InterpolationOrder -> 0]Off[InterpolatingFunction::dmval]Plot[g[x], {x, -1, 5}, PlotRange -> All]See that all values are shifted by one place, zero must be de\fined and onepoint added to the right.Now, comparingff /@ ({0, 1, 2, 3, 4}){0., 0.333333, 0.666667, 1., 1.}g /@ ({0, 1, 2, 3, 4}){0, 1/3, 1/3, 2/3, 1}We get something wrong for g, but forg /@ ({0, 1, 2, 3, 4} + 2$MachineEpsilon){0, 1/3, 2/3, 1, 1}obviously is all right. So we ran into problems of numerical precision. Now,what is the sense of the CDF at the point of jump? None I'd say, at somepoint above the jump it must count for the fraction of all events below inrespect to over all. And this is done within the limits of numericalprecision. Conceptionally the CDF is function used to integrate as aStieltjes Integral, so only interpretations in this contex are possible, andyou have to look at the limit from above (within the con\fines of numericalprecision), all ok, I think.To dig up a bigger sample:<< Statistics`ContinuousDistributions`gdist = GammaDistribution[3, 1]cdfunction = CDF[gdist, x]pTheory = Plot[cdfunction, {x, 0, 10}, PlotStyle -> Hue[.7]]data = RandomArray[gdist, 1000];t = With[{n = Length[data], obs = Sort[data]}, Transpose[{Append[obs, Last[obs] + 1], Range[0, 1, 1/n]}]];g = Interpolation[t, InterpolationOrder -> 0]pExperiment = Plot[g[x], {x, 0, 10}, PlotPoints -> 200]Show[pExperiment, pTheory]Nice comparison!ff = CompileEmpiricalCDF[Sort[data]];pExperiment2 = Plot[ff[x], {x, 0, 10}, PlotStyle -> {Hue[.4, 1, .5], Thickness[.003]}, PlotPoints -> 200]Show[pTheory, pExperiment2, pExperiment]I couldn't see any differences between pExperiment and pExperiment2enlarged.Timings:rx = Table[Random[Real, {0, 10}], {10000}];(s1 = g /@ rx); // Timing{1.082 Second, Null}(s2 = ff /@ rx); // Timing{28.39 Second, Null}s1 == s2True So, I think, with deliberate use, your observation can be well exploited as(2)!--Hartmut Wolf ==== =First of all, Import is not really meant for this sort of situation; it is better to use ReadList. Suppose your \file is:1 A1 B2 B3 C4 B5 D5 E6 F7 Aand its name is adj.txt. Here is one way you can deal with this case. First, read in the \file:In[1]:=ss=ReadList[adj.txt,{Number,Word}]Out[1]={{1,A},{1 ,B},{2,B},{3,C},{4,B},{5,D},{5,E},{6,F},{7,A}}Next, \find how many actors there are:In[2]:=l=Length[Union[First[Transpose[ss]]]]Out[2]= 7Construct the adjacency matrix:In[3]:=Table[If[Intersection[Cases[ss,{i,x_}->x,{1}], Cases[ss,{j,x_}->x,{1}]]=!={},1,0](1-KroneckerDelta[i,j]),{i, l},{j,l}]//MatrixFormOut[3]//MatrixForm=0 1 0 1 0 0 11 0 0 1 0 0 00 0 0 0 0 0 01 1 0 0 0 0 00 0 0 0 0 0 00 0 0 0 0 0 01 0 0 0 0 0 0The function ToAdjacencyMatrix form the Combinatorica package constructs the adjacency matrix from a graph, so it has no direct application to your problem.Andrzej KozlowskiToyama International UniversityJAPAN> I need to create an adjacency matrix from my data, which is currently > in> the form of a .txt \file and is basically a two column incidence list.> For example: 1 A> 1 B> 2 B> 3 C> . .> . .> . .> m n Where 1 to m represent actors and A to n represent events. My goal is > to> have an (m x m) matrix where cell i,j equals 1 if two actors are> incident to the same event (in the sample above, 1 and 2 are both> incident to B) and 0 otherwise (w/ zeros on the diagonal). I'm new to Mathmatica, and so I'm on the steep part of the learning> curve ... All I've been able to \figure out so far is how to \ get my> incidence list into the program using Import[\filename.txt]. But then> what? How do I convert to the adjacency matrix? I've found the> ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't> seem to get it to work ...> Tom **********************************************> Thomas P. Moliterno> Graduate School of Management> University of California, Irvine> tmoliter@uci.edu> **********************************************> ==== =When I click on The Mathematica Book, I see no chapters, no chapteralready fully expanded and there were chapter numbers next to thechapter names.Anyway, what is Floor doing in a chapter on Advanced Mathematics? Whyisn't there a chapter on notation? I suppose that's why an unexpandedIf you Go To notation or notations, there's no link to Mathematicaland Other Notations. notation and notations yield different links,too. Very strange.As for looking for LeftFloor -- that makes sense only if you alreadyknow about LeftFloor. (Now I do.) Links from Floor to LeftFloor andRightFloor would make a lot of sense, but that's probably why \ they'renot there.very kindly helping to make up for it.Bobby Treat-----Original Message-----I'm reaching it by clicking on The Mathematica Book and then clickingdie chapter and subchapters as mentioned above. It's chapter 3.10.4 (inYou can also \ \find it by looking for [LeftFloor] in the Master index.Yours, Alexander Dreyer-- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== =One can make my original code (below) much faster by adding an auxiliary function and using dynamic programming:In[1]:=ss=ReadList[adj.txt,{Number,Word}]Out[1]={ {1,A},{1,B},{2,B},{3,C},{4,B},{5,D},{5,E},{6,F},{7,A}}In[2]:= l=Length[Union[First[Transpose[ss]]]]Out[2]=7a[i_] := a[i] = Cases[ss, {i, x_} -> x, {1}]In[4]:=Table[If[Intersection[a[i],a[j]]=!={},1,0](1- KroneckerDelta[i,j]),{i,l},{j, l}]//MatrixFormOut[4]//MatrixForm=0 1 0 1 0 0 11 0 0 1 0 0 00 0 0 0 0 0 01 1 0 0 0 0 00 0 0 0 0 0 00 0 0 0 0 0 01 0 0 0 0 0 0For large lists you will see a large difference in speed.Andrzej KozlowskiToyama International UniversityJAPAN> First of all, Import is not really meant for this sort of situation; > it is better to use ReadList. Suppose your \file is: 1 A> 1 B> 2 B> 3 C> 4 B> 5 D> 5 E> 6 F> 7 A and its name is adj.txt. Here is one way you can deal with this > case. First, read in the \file:> In[1]:=> ss=ReadList[adj.txt,{Number,Word}] Out[1]=> {{1,A},{1,B},{2,B},{3,C},{4,B},{5,D},{5,E},{6,F},{7,A}} Next, \find how many actors there are: In[2]:=> l=Length[Union[First[Transpose[ss]]]] Out[2]=> 7 Construct the adjacency matrix: In[3]:=> Table[If[Intersection[Cases[ss,{i,x_}->x,{1}],> > Cases[ss,{j,x_}->x,{1}]]=!={},1,0](1-KroneckerDelta[i,j]),{i, > l},{j,l}]//MatrixForm Out[3]//MatrixForm=> 0 1 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 The function ToAdjacencyMatrix form the Combinatorica package > constructs the adjacency matrix from a graph, so it has no direct > application to your problem. Andrzej Kozlowski> Toyama International University> JAPAN> I need to create an adjacency matrix from my data, which is currently > in> the form of a .txt \file and is basically a two column incidence list.> For example:> 1 A> 1 B> 2 B> 3 C> . .> . .> . .> m n> Where 1 to m represent actors and A to n represent events. My goal is > to> have an (m x m) matrix where cell i,j equals 1 if two actors are> incident to the same event (in the sample above, 1 and 2 are both> incident to B) and 0 otherwise (w/ zeros on the diagonal).> I'm new \ to Mathmatica, and so I'm on the steep part of the learning> curve ... All I've been able to \figure out so \ far is how to get my> incidence list into the program using Import[\filename.txt]. But then> what? How do I convert to the adjacency matrix? I've found the> ToAdjacencyMatrix[] \ command in DiscreteMath`Combinatorica`, but I > can't> seem to get \ it to work ...> Tom> **********************************************> Thomas P. Moliterno> Graduate School of Management> University of California, Irvine> tmoliter@uci.edu> ********************************************** ==== = script.Unfortunately when I start Mathreader I get the error message No \file exists for resource 318 while the programme is initialising the text resource manager. It is not possible to click this message away.Can anybody help me with this problem? The only hint I found was the which I didn't \ \find very useful.Best,M. ==== =I have written the following in a JLink program:drawArea=JavaNew[com.wolfram.jlink.MathCanvas];then I perform an analysis of some data with output of this form....plot = DisplayTogether[ListPlot[],ListPlot[].etc...];Unfortunately, at this point I dont know how to associate \ Ôplot' withdrawArea so that draw.Area@RepaintNow[]; repaints the math screen to show the plots \ I'vecomputed...I've tried draw.Area@update[plot] and draw.Area@setImage[plot] but thesedont work........how to \fix?.........thanks.....jerry blimbaum NSWC panama city, ß ==== =Somehow, we at WRI seem to have completely neglected to make any slide shows with internal hyperlinks (probably because slide show content, by its very nature, is just less likely to need internal hyperlinks), and so we never saw this problem.We'll \ \fix it in a future version of Mathematica, but in the mean time, \ here's a workaround. The workaround is not exactly perfect...it can cause ßashing on screen and may not put the scrollbar in exactly the right place...but it does work.With the slide show you're editing open, perform the following steps:* Format->Edit Style Sheet... Choose Import Private Copy (unless you want to modify the global style sheet, which I wouldn't recommend unless you need this in a lot of notebooks).* In the stylesheet, open the Hyperlinks group. Open the group for the Hyperlink style with that.* Place the cell insertion point after the prototype for the Hyperlink style and copy/paste the following in (pressing Yes when asked whether to interpret the cell):Cell[StyleData[Hyperlink, SlideShow], ButtonBoxOptions->{ButtonFunction:>(FrontEndExecute[ { CompoundExpression[ FrontEnd`SetOptions[ FrontEnd`ButtonNotebook[ ], ScrollingOptions -> { PagewiseDisplay -> False}], FrontEnd`NotebookLocate[ #2], FrontEnd`SetOptions[ FrontEnd`ButtonNotebook[ ], ScrollingOptions -> { PagewiseDisplay -> Inherited}]]}]&)}]* Close the style sheet, then save your slideshow notebook. Internal hyperlinks should now work.Sincerely,John Fultzjfultz@wolfram.comUser Interface GroupWolfram Research, Inc.>I am interested in creating a slide presentation using slide view>mode in Mathematica 4.2. I would like to have hyperlinks between>different slides ( e.g., a hyperlink in say slide 6 takes me back to>slide 3).>>I have no dif\ficulty in creating such a hyperlink (using tags) when>I am in the author mode. But the hyperlink does not work when a>revert back to slide view mode.>>I guess it has somthing to do with the fact that in author view>mode your slides are a subset of a single notebook but in slide view>mode each slide becomes a distinct notebook.>>So my question: Is there a way to reference the individual slides>using the hyperlink command?>Brian ==== =BRIEFMathematica seems to support 3 levels of nesting:section, subsection, and subsubsection.Q: how can I obtain more levels of nesting?I typically go 6-7 levels deep.DETAIL= Con\fig =I am using Mathematica 4 on a Sun Sparc at work.= Good Style or Not =I *know*, good style guides say that you should nevergo more than 3 levels of section deep. I disagree, anddon't care. After editting my documents may \ only endup with three levels of subsection nesting, but whileI am editting, moving stuff around, I frequently want more.(Often, I move a whole subtree of the document around,so that all sections become subsubsections, subsectionsbecome subsubsections, etc.) E.g. HTML originally had only H1, H2, H3,but now it goes all the way up to H10.= How are Sections Indicated? =I had hoped to de\fine my own styles, section, subsection, sub2section, sub3section, etc.(ideally, section(level) if styles can be parameterized).But, I cannot see how to indicate how deeply nested a style is.In particular, I want to use the folding or hidingfeature, so that after I have de\fined sub6section, etc.I can hide everything below a sub4section.== Nesting Level or Bracket? ==It appears that Mathematica's sections have the level hardwiredinto them. section is at level 0 subsection at level 1 subsubsection at level 2This means that the next section at the same level terminatesa nesting group.The alternative implementation is to use brackets, e.g. XML
level 1
level 2
level3
level 2
level 1
This does not require the section level to be hardwired into the style.Obviously, Mathematica supports the \first, hardwired or explicit levelscheme. But, I cannot \figure out how to extend it to multiple levels.I woulds be especially happy if the second approach were available,but, again, do not know how to create a Mathematica notebook stylethat accomplishes \ it.APOLOGIESI'm sorry if this is a frequently asked question. I have searched the FAQand the MathGroup archives to no avail. I did \find \ stuff on section numbering,which is related - I usually like Dewey decimal section numbers extended to the samearbitrary depth - but none on deeper nesting than subsubsection. ==== =Perhaps, it is a stupid question, but somehow, I was not able to \find any help on the following:I have a notebook, which does some calculations and saves results onto disk. All I need is to execute this notebook somewhere within another notebook. Sometimes it is nice to keep some parts of the code separated in different notebook \files, which depending on the circumstances could be run manually via FrontEnd or within an automated loop from a notebook.To a certain extent this philosophy resembles, for example, what they have for scripts in another system.Please, reply directly to akolzine@uiuc.eduSincerely,Alexei. ==== =Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2, however after workingwith this program for more than a month, trying every possible permutation andmanipulation, and having it still crash, I am still worried that upgrading to 4.2won't solve \ my problem. Can anyone else with 4.2 try running this program for me agood number of times, say 3 or 4, and see if they get similar good results?Bernard GressDear Group,I have a program to take the local polynomial non parametric regressionof two variables. It uses Compile, unfortunately, and regularly, butinconsistently, causes Mathematica to crash (in Win2K, with I forgetwhat error, and in Win98/Mathematica4.0 with an invalid memory access fromMathDLL.dll). I am running Mathematica 4.1, and have this problem consistentlyon 4 different machines.Here is the code, if it doesn't crash the \first time, it will the secondor third:(*w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real,0}, {nn, _Integer, 0}, {ord, _Integer, 0}},First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q,1], {q, 0, ord}],Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0,ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] .Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])*E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]];*)(*!(tt = MemoryInUse[]; ListPlot[Table[{((i + 1))^2, (Timing[ nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i,nn}]; testX = Table[i* .3 - Random[]*2, {i, nn}]; testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; Map[w[#, testX, testY, .1 + Random[], nn, 0] &, testX];])[([1])]/Second}, {i, 15}], PlotJoined ->True, PlotLabel -> ]; MemoryInUse[] - tt)*) ==== =I ran it 10 times on 4.2 with no crashes.> Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2,however after working> with this program for more than a month, trying every possible permutationand> manipulation, and having it still crash, I am still worried that upgradingto 4.2> won't solve my problem. Can anyone \ else with 4.2 try running this programfor me a> good number of times, say 3 or 4, and see if they get similar goodresults?> Bernard Gress Dear Group, I have a program to take the local polynomial non parametric regression> of two variables. It uses Compile, unfortunately, and regularly, but> inconsistently, causes Mathematica to crash (in Win2K, with I forget> what error, and in Win98/Mathematica4.0 with an invalid memory access from> MathDLL.dll). I am running Mathematica 4.1, and have this problemconsistently> on 4 different machines. Here is the code, if it doesn't crash \ the \first time, it will the second> or third: (*> w = \ Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real,> 0},> {nn, _Integer, 0}, {ord, _Integer, 0}},> First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q,> 1], {q, 0, ord}],> Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0,> ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] .> Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])*> E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]];> *) (*> !(tt = MemoryInUse[];> ListPlot[Table[{((i + 1))^2, (Timing[> nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i,> nn}];> testX = Table[i* .3 - Random[]*2, {i, nn}];> testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon];> Map[w[#, testX, testY, .1 + Random[], nn, 0] &,> testX];])[([1])]/Second}, {i, 15}], PlotJoined - True,> PlotLabel -> ];> MemoryInUse[] - tt)> *)>Reply-To: kuska@informatik.uni-leipzig.de ==== =my Mathematica 4.2 does not crash and you may upgradeyour version. Jens> Dear Group,> I have a program to take the local polynomial non parametric regression> of two variables. It uses Compile, unfortunately, and regularly, but> inconsistently, causes Mathematica to crash (in Win2K, with I forget> what error, and in Win98/Mathematica4.0 with an invalid memory access from> MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently> on 4 different machines.> Here is the code, if it doesn't crash the \first time, it \ will the second> or third:> (*> w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real,> 0},> {nn, _Integer, 0}, {ord, _Integer, 0}},> First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q,> 1], {q, 0, ord}],> Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0,> ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] .> Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])*> E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]];> *)> (*> !(tt = MemoryInUse[];> ListPlot[Table[{((i + 1))^2, (Timing[> nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i,> nn}];> testX = Table[i* .3 - Random[]*2, {i, nn}];> testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon];> Map[w[#, testX, testY, .1 + Random[], nn, 0] &,> testX];])[([1])]/Second}, {i, 15}], PlotJoined - True,> PlotLabel -> ];> MemoryInUse[] - tt)> *)> I have followed Ted Ersek's tips \ and tricks> (http://www.verbeia.com/mathematica/tips/tip_index.html) about Compile,> and have tried changing all variable names (works sometimes), removing> any hidden spaces, restructuring the formulas, changing all 0's to 0. Ôs> and all \ 1's to 1. Ôs, etcetera etcetera, but I still can't comprehend> what the problem might be. Doing w[[-2]] shows a list of op-code> numbers, and one function name, Inverse[#1]&, so it seems to me that> there are no problems with the use of Compile here. Would anyone have> any thoughts???> Bernard Gress> burnthebiscuit@netscape.net ==== =Mr Kuska,4.2, I thought I had solved this problem so many times and still it would suddenlystart crashing again our of the blue, after 20 or 30 executions.Bernard my Mathematica 4.2 does not crash and you may upgrade> your version.> ==== =>Is it possible to con\figure a style sheet so that functions or data shown in>graphs are coloured (colored :)) in working but black in printing...without>actually re-executing the function that created the graphics?>>thanks>>MikeThere is no way do this, but with a couple of tricks you can create the same effect.First, we generate 2 graphics. One is the normal graphic. The other uses all black colors. This process is automated by changing $DisplayFunction.$DisplayFunction = ( (* \first the normal graphic *) Display[$Display, #1]; (* then a new B&W graphic *) CellPrint[ Cell[GraphicsData[PostScript, DisplayString[#1 /. {_RGBColor | _CMYKColor -> GrayLevel[0]}]], GraphicsPrintout]]; #1 ) &;If you set this and do a plot you will see the two graphics. The second graphic will look strange because it's in a different cell style. We're going to use the cell styles to control which graphic is shown.Next, open the style sheet (menu item Format>Edit Style Sheet). Replace the Graphics/Printout style with the following cell.Cell[StyleData[Graphics, Printout], ShowCellBracket->False, CellMargins->{{0, 0}, {0, 0}}, CellElementSpacings->{CellMinHeight->0}, CellGroupingRules->NormalGrouping, CellFrameMargins->False, CellSize->{Inherited, 0}, Background->None]It hides the colored cell in the Printout environment. Then, add the following styles.Cell[StyleData[GraphicsPrintout], CellMargins->{{4, Inherited}, {Inherited, Inherited}}, CellGroupingRules->GraphicsGrouping, CellHorizontalScrolling->True, PageBreakWithin->False, GeneratedCell->True, CellAutoOverwrite->True, ShowCellLabel->False, DefaultFormatType->DefaultOutputFormatType, LanguageCategory->None, FormatType->InputForm, ImageMargins->{{43, Inherited}, {Inherited, 0}}, StyleMenuListing->None, FontFamily->Courier, FontSize->10]Cell[StyleData[GraphicsPrintout, Printout], ImageMargins->{{30, Inherited}, {Inherited, 0}}, Magni\fication->0.8]Cell[StyleData[GraphicsPrintout, Working], ShowCellBracket->False, CellMargins->{{0, 0}, {0, 0}}, CellElementSpacings->{CellMinHeight->0}, CellGroupingRules->NormalGrouping, CellFrameMargins->False, CellSize->{Inherited, 0}, Background->None]It hides the B&W cell in the Working environment and shows the cell in the Printout environment.Finally, try it out.Plot[x, {x, 0, 1}, PlotStyle -> RGBColor[1, 0, 0], TextStyle -> {FontColor -> RGBColor[0, 0, 1]}]--------------------------------------------------------- -----Omega ConsultingThe \final answer to your Mathematica needsSpend less time searching and more time \finding.http://www.wz.com/internet/Mathematica.html ==== =I was completely wrong about the pattern list_?(VectorQ[#, NumericQ] &).I had forgotten about that notation and didn't think to look it up.Sorry!Bobby-----Original Message-----evaluates fairly slowly (even if it has been Compiled). SinceInterpolationFunction evaluates so much faster in general, I've triedto use Interpolation with InterpolationOrder -> 0. The problem is thatthe resulting InterpolatingFunction doesn't behave the way (I think)it ought to. For example, letg = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder ->0]Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.In addition, g is continuous from the left rather than from the right.Obviously I am not aware of the considerations that went intodetermining the behavior of InterpolationFunction whenInterpolationOrder -> 0.So I have two questions: (1) Does anyone have any opinions about how InterpolatingFunctionought to behave with InterpolationOrder -> 0?(2) Does anyone have a faster way to evaluate an empirical CDF than acompiled Which function?By the way, here's my current version:CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] := Block[{x}, Compile[{{x, _Real}}, Evaluate[ Which @@ Flatten[ Append[ Transpose[{ Thread[x < Sort[list]], Range[0, 1 - 1/#, 1/#] & @ Length[list] }], {True, 1}]] ]]] ==== =I was wondering if a way exists to move the main menu bar of the front end.I am talking about the bar that occupies the top of the screen and extends,by default, from the left end of the screen to the right. It has a lot ofblank space to the right of the menus. Making it narrower frees up someimportant screen real estate, if you want to reach icons under it. How couldI make Mathematica do that automatically? I cannot seem to \find it in thePreferences or in the sections on manipulating notebooks.Nicholas ==== =The various Intro/Mathematica Programming books I've seen (e.g. Gray:Mastering Mathematica -- now out of print but have a copy on order) andMathematical Navigator and other books \ I've seen are based on V3. Is thereany Intro/Programming book based on V4 (or even updated for 4.2) that isavailable besides the on-line book?Does someone have notes that update the V3 books? ==== =I puzzled over this and came up with an explanation. The phenomenonsomebody noticed is that the fractional part of(Sqrt[3] + Sqrt[2])^(2*n)approaches 1 from below as n (integer) gets large. Hence, for instance,Mod[ N[(Sqrt[2] + Sqrt[3])^2002, 2000], 100]has a string of 996 nines after the decimal point. Well, here's thereason for that.Let x and y be the square roots of any integers and let n be an eveninteger power. Then (x + y)^n == Sum[Binomial[n, m]*y^m*x^(n - m), {m, 0, n}];and (x - y)^n == Sum[(-1)^m*Binomial[n, m]*y^m*x^(n - m), {m, 0, n}];so, adding the two equations, we have (x + y)^n + (x - y)^n == Sum[Binomial[n, m]*y^m*x^(n - m)* (1 + (-1)^m), {m, 0, n}];1 + (-1)^m is 0 when m is odd and 2 when m is even, so (x + y)^n + (x - y)^n == 2*Sum[Binomial[n, 2*k]*y^(2*k)*x^(n - 2*k), {k, 0, n/2}];Since n is even, all powers of x and of y are even in this expression.Since x and y are the square roots of integers, it follows that all theterms are integers. Hence(x + y)^n + (x - y)^nis integer. Now we assume, in addition to our other conditions, that0 < x - y < 1In that case, (x - y)^n approaches 0 from above as n gets large, andFractionalPart[(x + y)^n] == 1 - (x - y)^nwhich approaches one from below as n gets large. The number of ninesafter the decimal point can be calculated asFloor[(-n)*Log[10, Sqrt[3] - Sqrt[2]]]For n=2002 (the example we started with, this is indeed)Floor[-2002*Log[10, Sqrt[3] - Sqrt[2]]]996Bobby Treat-----Original Message-----> \finally take the result modulo 10^n.> Mod[Floor[ N[(Sqrt[2] + Sqrt[3])^2002 , 1000]], 10^2]> results in 9, so the last two digits before the decimal point are 09.> With a slight modi\fication we can \ \find the \first n digits after thedecimal> point. Simply \find the last n digits before the decimal point of 10^ntimes> the number.> Mod[Floor[ N[10^2 (Sqrt[2] + Sqrt[3])^2002 , 1000]], 10^2]> results in 99, so these are the digits you are interested in.> But there is something curious about this number.> Mod[Floor[N[10^1000 (Sqrt[2] + Sqrt[3])^2002 , 2000]], 10^1000]> results in 996 digits 9 followed by 7405.> You can also play with the following command, resulting in the digitsaround> the decimal point:> Mod[ N[(Sqrt[2] + Sqrt[3])^2002, 2300], 10^6]> The decimal expansion of (Sqrt[2]+Sqrt[3])^2002 contains a sequence of> 997 consecutive digits 9. Do you have any idea why?Not unusual. Try other even exponents and there should be large blocks of 9s . Smaller number for small exponents. Some kind of propagation of 9s as the exponent grows. Try other odd values for 3 and the same thinghappens for some values. Also for other values for 2.Larry> Fred Simons> Eindhoven University of Technology> ==== =>I have written the following in a JLink program:>drawArea=JavaNew[com.wolfram.jlink.MathCanvas];>> then I perform an analysis of some data with output of this form....>>plot = DisplayTogether[ListPlot[],ListPlot[].etc...];>Unfortunately, at this point I dont know how to associate \ Ôplot' with>drawArea so that>>draw.Area@RepaintNow[]; repaints the math screen to show the plots \ I've>computed...>I've tried draw.Area@update[plot] and draw.Area@setImage[plot] but these>dont work........how to \fix?.........thanks.....Jerry,You use the MathCanvas.setMathCommand() method to specify the Mathematica command that is used to generate the image to display: drawArea.setMathCommand(plot);You will \find a very simple example of this in section 1.2.8.2 of the J/Link User Guide (in the Help Browser hierarchy, this is found at JLink/Part 1. Installable Java/Drawing and Displaying Images in Java Windows/Showing Graphics and Typeset Expressions).You do not need to use the repaintNow() method unless you are updating the image continuously in response to a user action, like dragging a slider.Todd GayleyWolfram Research ==== =try:(((((3^(1/2))^(1/2))^(1/2))^(1/2))^(1/2))/(6^ (1/2))Out:1/(Sqrt[2]*3^(15/32))You can see what happened:1st: 6^(1/2) = 2^(1/2)*3^(1/2);2nd: subtraction of the 3's exponents (1/2)^5 - 1/2 = 1/32 - 16/32 = -15/32.MATHEMATICA does these straightforward simpli\fications without you having toinvoke Simplify[].Matthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de-----Ursprí.b9ngliche Nachricht-----Gesendet: Freitag, 13. September 2002 07:14An: mathgroup@smc.vnet.netBetreff: nth rootsSimplify:5nth sqrt (3)/sqrt (6)5nth Sqrt(3)------------ Sqrt(6)1st.. is this the correct notation for use on a computer2nd.. how is the solution solved, step by step please. ==== =Dear all,I want to include some Mathematica code in some lecture notes I am writing.For that purpose, I use the LaTeX style provided with Mathematica. It seemsto be working \fine when I produce a document that is just Mathematica code.The problem - as expected - is that when I include the Mathematica code asa part of a larger document, there are (1) clashes with existing packages(2) some LaTeX elements, such as the equations, start to use theMathematica fonts too. My objective would be to typeset a document instandard LaTeX, where only the Mathematica code has the Mathematica feeling.Does anyone know of any style available that is completely seperated fromall other LaTeX de\finitions?BestKyriakos_____+**+____+**+___+**+__+**+_ Kyriakos ChourdakisLecturer in Financial EconomicsURL: http://www.qmw.ac.uk/~te9001tel: (++44) (+20) 7882 5086Dept of EconomicsUniversity of London, QMLondon E1 4NSU.K.Reply-To: kuska@informatik.uni-leipzig.de ==== =a) you must change the fonts, because the Mathematica symbols are designed to \fit to Times/Helvetica/Courier and not to Computer Modern ! Mixing Computer Modern and the Mathematica fonts look not very nice because Comuter Modern has smaler strokes. You need atleast wrisym.sty, i.e. usepackage[monospacemath]{wrisym} but this will switch the main document font to Times and the mono-space font to courier. With Mathematica 4.2 you can use Adobe-Garamond and Janson as document fonts too, with usepackage[monospacemath,garamond]{wrisym} but this are commercial fonts and you have to buy it from Adobe.b) If you like the narrow monotype fonts similar to Computer Modern you can use the CMTT fonts, now included in Mathematica 4.2 Just use the package option usepackage[cmtt]{wrisym}c) I have a TeX frontend that use only the wrisym package and a preprocessor. It run \fine with the most style \ \files But you have to use TeX notebooks that are essential TeX \files with mathinput environments. The TeX frontend send the contents of the mathinput environments to the kernel and paste the output into the \final TeX \file. It also does some fancy \ formating with the Mathematica input and replace -> with Rule, :> with RuleDelayed .. You can have the program and the style \files if you like. Jens> Dear all,> I want to include some Mathematica code in some lecture notes I am writing.> For that purpose, I use the LaTeX style provided with Mathematica. It seems> to be working \fine when I produce a document that is just \ Mathematica code.> The problem - as expected - is that when I include the Mathematica code as> a part of a larger document, there are> (1) clashes with existing packages> (2) some LaTeX elements, such as the equations, start to use the> Mathematica fonts too. My objective would be to typeset a document in> standard LaTeX, where only the Mathematica code has the Mathematica feeling.> Does anyone know of any style available that is completely seperated from> all other LaTeX de\finitions?> Best> Kyriakos> _____+**+____+**+___+**+__+**+_> Kyriakos Chourdakis> Lecturer in Financial Economics> URL: http://www.qmw.ac.uk/~te9001> tel: (++44) (+20) 7882 5086> Dept of Economics> University of London, QM> London E1 4NS> U.K.