A60 == I have a set of vectors eg{{12,21,22},{21,24,87},{-16,3,5}..........}} Iwill like to plot the stereographic projections of these. can anyone help?Reply-To: majort@cox-internet.com ==== It seems to me that using a pattern like _?z makes no sense (at all) if z will never evaluate to True, as in this case. As a result, those two rules for a can never result in an evaluation. Nothing can possibly match. but Mathematica must do something with the right hand side of > RuleDelayed[] otherwise> how become you rule a member of DownValues[] ??>> Since Catch[] and Throw[] are non-local operations,> a Throw[] can not protected by the processing> of the right hand side. Just use>> Clear[a, z];> Catch[> z[x_Integer] := 2;> z[x_] := Throw[11];> a[i_, iUp_?z] := 3;> a[i_Integer, iUp_?z] := 5;> ]> Jens> Why does the following code cause and exception? I thought that the>> left hand side of := was not evaluated.>> Clear[a, z];>> z[x_Integer] := 2;>> z[x_] := Throw[11];>> a[i_, iUp_?z] := 3;>> a[i_Integer, iUp_?z] := 5;>> Hein>>-- majort@cox-internet.comBobby R. Treat ==== is it posible to get the value of Q ifQ = ax^2 + by^2Q = cx^2 + dy^2|||Q = gx^2 + hy^2where a..h is a contants valuecan i get the maximum value of Q from those equation???thank You. ==== Hi,I am looking for an efficient (read fast) way to generate the set of all combinations of na elements drawn with replacement from a set of nr distinct elements. The number of these, of course isIn[53]:=numcombs[na_,nr_]:=((nr+1)+na-1)!/(na!*((nr+1)-1)!) In[106]:=numcombs[3,4]Out[106]=35Just for illustration, here's a super-inefficient example that generates all subsets of the right size, then pares them down to just the unique combinations. I'm assuming that the set of elements is {0,1,2,...,nr-1}, and using the KSubsets function from the Combinatorica package.In[111]:=tcombs[na_,nr_]:=KSubsets[Flatten[Table[ Range[0,nr],{na}]],na]In[112]:=temp1=tcombs[3,4];temp2=Union[ Map[Sort[#]&,temp1]]Length[temp2]Out[113]={{0,0,0},{0,0,1},{ 0,0,2},{0,0,3},{0,0,4},{0,1,1},{0,1,2},{0,1,3},{ 0,1,4},{0,2,2},{0,2,3},{0,2,4},{0,3,3},{0,3,4},{0,4,4},{1,1,1 },{ 1,1,2},{1,1,3},{1,1,4},{1,2,2},{1,2,3},{1,2,4},{1,3,3},{1,3,4 },{ 1,4,4},{2,2,2},{2,2,3},{2,2,4},{2,3,3},{2,3,4},{2,4,4},{3,3,3 },{ 3,3,4},{3,4,4},{4,4,4}}Out[114]=35This gets highly unwieldy as na and nr increase. Any suggestions?Gareth RussellColumbia University ==== One solution:g[x_] := 0 /; x <=0g[x_] := 3 /; x >=3g[x_]:=First[Select[Range[3],(#-1 I am definihg step-like function>> Clear[h]> h[x_] := 0/;x<0> h[x_] := 1/;0<=x<=1> h[x_] := 2/;1<=x<=2> h[x_] := 3/;2<=x<=3> h[x_] := 4/;x>3>> It works fine:>> Table[h[x],{x,-1,4,.5}]> {0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>> As I may need more steps, I am trying to do the same in loop:>> Clear[g]> g[x_] := 0/;x<0> Do[g[x_] := i/;i-1<=x<=i, {i,3}]> g[x_] := 4/;x>3>> This time no luck:>> Table[g[x],{x,-1,4,.5}]> {0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}> {0, 0, g[0.], g[0.5], g[1.], g[1.5], g[2.], g[2.5], g[3.], 4, 4}>> How to do this?>> Vadim.>> ==== Use Map instead of Do:In[1]:=Clear[g]g[x_]:=0/;x<0Map[(g[x_]:=#/;#-1ç.8cxç .8c#)&, Range[3]];g[x_]:=4/;x>3In[5]:=Table[g[x],{x,-1,4,.5}]Out[5]={ 0,0,1,1,1,2,2,3,3,4,4}The reason why your code does not work is that inside the Do loop the right hand side of g[x_] := i/;i-1<=x<=i is not evaluated so your i's do not acquire any numerical values. Replacing := by = also won't work because of the HoldAll attribute of Condition.> I am definihg step-like function>> Clear[h]> h[x_] := 0/;x<0> h[x_] := 1/;0<=x<=1> h[x_] := 2/;1<=x<=2> h[x_] := 3/;2<=x<=3> h[x_] := 4/;x>3>> It works fine:>> Table[h[x],{x,-1,4,.5}]> {0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>> As I may need more steps, I am trying to do the same in loop:>> Clear[g]> g[x_] := 0/;x<0> Do[g[x_] := i/;i-1<=x<=i, {i,3}]> g[x_] := 4/;x>3>> This time no luck:>> Table[g[x],{x,-1,4,.5}]> {0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}> {0, 0, g[0.], g[0.5], g[1.], g[1.5], g[2.], g[2.5], g[3.], 4, 4}>> How to do this?>> Vadim.>Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/ ==== Clear[g];g[x_]:=0/;x<0;Do[ is =ToString[i]; ToExpression[ g[x_]:=<>is<>/;<>ToString[i-1]<> <=x<=<>is],{i,3}];g[x_]:=4/;x>3;Or more simplyClear[g];g[x_] := Evaluate[Sum[UnitStep[x-i], {i,0,3}]];Bob Hanlon<< It works fine:Table[h[x],{x,-1,4,.5}]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}As I may need more steps, I am trying to do the same in loop:Clear[g]g[x_] := 0/;x<0Do[g[x_] := i/;i-1<=x<=i, {i,3}]g[x_] := 4/;x>3This time no luck:Table[g[x],{x,-1,4,.5}]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}{0, 0, g[0.], g[0.5], g[1.], g[1.5], g[2.], g[2.5], g[3.], 4, 4}How to do this?Vadim. >>

==== It works!Vadim>One solution:>>g[x_] := 0 /; x <=0>g[x_] := 3 /; x >=3>g[x_]:=First[Select[Range[3],(#-1g[#]& /@ Table[i,{i, -1,3,0.5}]>{0,0,0,1,1,2,2,3,3}>>Phaul> >I am definihg step-like function>>Clear[h]>>h[x_] := 0/;x<0>>h[x_] := 1/;0<=x<=1>>h[x_] := 2/;1<=x<=2>>h[x_] := 3/;2<=x<=3>>h[x_] := 4/;x>3>>It works fine:>>Table[h[x],{x,-1,4,.5}]>>{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>>As I may need more steps, I am trying to do the same in loop:>>Clear[g]>>g[x_] := 0/;x<0>>Do[g[x_] := i/;i-1<=x<=i, {i,3}]>>g[x_] := 4/;x>3>>This time no luck:>>Table[g[x],{x,-1,4,.5}]>>{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>>{0, 0, g[0.], g[0.5], g[1.], g[1.5], g[2.], g[2.5], g[3.], 4, 4}>>How to do this?>>Vadim.>> ==== >-----Original Message----->Sent: Friday, April 04, 2003 8:27 AM>To: mathgroup@smc.vnet.net>I am definihg step-like function>>Clear[h]>h[x_] := 0/;x<0>h[x_] := 1/;0<=x<=1>h[x_] := 2/;1<=x<=2>h[x_] := 3/;2<=x<=3>h[x_] := 4/;x>3>>It works fine:>>Table[h[x],{x,-1,4,.5}]>{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>>As I may need more steps, I am trying to do the same in loop:>>Clear[g]>g[x_] := 0/;x<0>Do[g[x_] := i/;i-1<=x<=i, {i,3}]>g[x_] := 4/;x>3>>This time no luck:>>Table[g[x],{x,-1,4,.5}]>{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>{0, 0, g[0.], g[0.5], g[1.], g[1.5], g[2.], g[2.5], g[3.], 4, 4}>>How to do this?>>Vadim.>Vadim,regard the result of yout attempted definition:In[12]:= ?gGlobal`gg[x_] := 0 /; x < 0g[x_] := i /; i - 1 <= x <= ig[x_] := 4 /; x > 3as you see the running varable i has not been evaluated at the rhs of setdelayed!A logical step would be to force evaluation:In[15]:= x = NonsenseOut[15]= Nonsense In[16]:= Clear[g] g[x_] := 0 /; x < 0 Do[g[x_] := Evaluate[i /; Evaluate[i - 1 <= Unevaluated[x] <= i]], {i,3}] g[x_] := 4 /; x > 3In[21]:= Table[g[x], {x, -1, 4, .5}]Out[21]={0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}Simply Evaluate at rhs would not do since Condition has the HoldAllattribute, so we have to wrap Evaluate at the rhs of Condition. Now asCondition will be evaluated, the result now is the condition with evaluatedlhs and rhs with i put in (and the arithmetic done). To protect x from anaccidential value (Nonsense in our case, we wrap it with Unevaluated). Tomy surprise this wrapper isn't stripped here, but is later, when thedefinition is executed. So this works.Alternatively we might have tried to use Set instead of SetDelayed, but,alas, then we must attach the Condition to the lhs, such we have similarwork:In[22]:= Clear[g] g[x_] := 0 /; x < 0 Do[Evaluate[g[x_] /; Evaluate[i - 1 <= Unevaluated[x] <= i]] = i, {i, 3}] g[x_] := 4 /; x > 3In[27]:= Table[g[x], {x, -1, 4, .5}]Out[27]={0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}The recommended way however is different: substitute i into the expression,before it is evaluated:In[28]:= Clear[g]In[29]:= g[x_] := 0 /; x < 0 Do[With[{i = i}, g[x_] := i /; i - 1 <= x <= i], {i, 3}] g[x_] := 4 /; x > 3In[33]:= Table[g[x], {x, -1, 4, .5}]Out[33]={0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}Or In[34]:= Clear[g]In[35]:= g[x_] := 0 /; x < 0 Scan[(g[x_] := # /; # - 1 <= x <= #) &, Range[3]] g[x_] := 4 /; x > 3In[39]:= Table[g[x], {x, -1, 4, .5}]Out[39]={0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}Or In[94]:= Clear[g]In[95]:= g[x_] := 0 /; x < 0 Do[Unevaluated[g[x_] := i /; i - 1 <= x <= i] /. HoldPattern[i] -> i, {i,3}] g[x_] := 4 /; x > 3In[99]:= Table[g[x], {x, -1, 4, .5}]Out[99]={0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}--Hartmut Wolf ==== Use:Table[With[{i=i},g[x_] := i/;i-1<=x<=i],{i,3}]OrestisYour definitions> I am definihg step-like function> Clear[h]> h[x_] := 0/;x<0> h[x_] := 1/;0<=x<=1> h[x_] := 2/;1<=x<=2> h[x_] := 3/;2<=x<=3> h[x_] := 4/;x>3> It works fine:> Table[h[x],{x,-1,4,.5}]> {0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}> As I may need more steps, I am trying to do the same in loop:> Clear[g]> g[x_] := 0/;x<0> Do[g[x_] := i/;i-1<=x<=i, {i,3}]> g[x_] := 4/;x>3> This time no luck:> Table[g[x],{x,-1,4,.5}]> {0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}> {0, 0, g[0.], g[0.5], g[1.], g[1.5], g[2.], g[2.5], g[3.], 4, 4}> How to do this?> Vadim. ==== >>Clear[h] h[x_] := 0/;x<0 h[x_] := 1/;0<=x<=1h[x_] := 2/;1<=x<=2h[x_] := 3/;2<=x<=3 h[x_] := 4/;x>3>It works fine:>Table[h[x],{x,-1,4,.5}] >{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4}>As I may need more steps, I am trying to do the same in loop:While I am sure there is a way to do it in a loop this is certainly not the easiest wayTryf[x_, n_]:= Sum[UnitStep[x-k], {k,0,n}]Table[f[x,3], {x,-1,4,0.5}]{0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4}Reply-To: majort@cox-internet.com ==== This works (and some of the changes weren't necessary):test[f_, {vars__}] := Block[{dummy, dummy2, vPat = Sequence @@ (Pattern[#, Blank[]] & /@ {vars})}, Clear[temp]; dummy[temp[vPat], dummy2[temp[vars], f[vars]]] /. {dummy -> SetDelayed, dummy2 -> Set} ]test[Sin, {x}]?? temptemp[x_] := temp[x] = Sin[x]test[g, {x, y}]?? temptemp[x_, y_] := temp[x, y] = g[x, y]Bobby> Hi MathGroup,>> I'm trying to figure out how to create a function that remembers its > values inside a function definition (I want the temporary function to > stay hidden in a package eventually. I've tried the following>> test[f_, vars_List] :=> Module[{v, vPat},> Clear[temp];> vPat = Sequence @@ (Pattern[#, Blank[]] & /@ vars);> v = Sequence @@ vars;> temp[vPat] := temp[v] = f[v];> ]>> When I evaluate> test[Sin, {x}]>> I find that the definition of temp isn't what I want>> ?temp>> temp[x_] := temp[v$97] = Sin[v$97]>> What I'd like to get instead is>> temp[x_] := temp[x] = Sin[x]>> I've tried putting ReleaseHold around various parts of the assignment but > so far haven't found a way to do what I want.>> Any help will be appreciated.>> Ken-- majort@cox-internet.comBobby R. Treat ==== >-----Original Message----->Sent: Friday, April 04, 2003 8:24 AM>To: mathgroup@smc.vnet.net>Hi MathGroup,>>I'm trying to figure out how to create a function that remembers its >values inside a function definition (I want the temporary function to >stay hidden in a package eventually. I've tried the following>>test[f_, vars_List] :=> Module[{v, vPat},> Clear[temp];> vPat = Sequence @@ (Pattern[#, Blank[]] & /@ vars);> v = Sequence @@ vars;> temp[vPat] := temp[v] = f[v];> ]>>When I evaluate>test[Sin, {x}]>>I find that the definition of temp isn't what I want>>?temp>>temp[x_] := temp[v$97] = Sin[v$97]>>What I'd like to get instead is>>temp[x_] := temp[x] = Sin[x]>>I've tried putting ReleaseHold around various parts of the assignment >but so far haven't found a way to do what I want.>>Any help will be appreciated.>>Ken>-- >Ken Sale>Group Leader / Physicist>Radiation Technology Group>Lawrence Livermore National Laboratory>(925) 423-0686>Ken,the problem is that for SetDelayed the rhs isn't evaluated such the variablev$97 prevailes. But we cannot just evaluate the rhs, dent Set woulddisappear. Insted we have to introduce the evaluated variableIn[12]:=test[f_, vars_List] := Module[{v, vPat}, Clear[temp]; vPat = Sequence @@ (Pattern[#, Blank[]] & /@ vars); v = Sequence @@ vars; Unevaluated[temp[vPat] := temp[v] = f[v]] /. HoldPattern[v] -> v;]In[28]:= test[ArcTan, {x, y}]In[31]:= temp[4, 5]Out[31]= ArcTan[5/4]In[32]:= ?tempGlobal`temptemp[4, 5] = ArcTan[5/4]temp[x_, y_] := temp[Sequence[x, y]] = ArcTan[Sequence[x, y]]Or else:In[34]:= Clear[temp]In[35]:=test[f_, vars_List] := Block[{}, With[ {vPat = Sequence @@ (Pattern[#, Blank[]] & /@ vars), v = Sequence @@ vars}, temp[vPat] := temp[v] = f[v]]]and later put temp into the braces of Block.I don't know what you finally want to achieve, but be cautious with thevariable names; you cannot (or should not refer to them withinModule/Block). Such you need only to specify the number of parameters, andbetter generate the symbols anonymously within.--Hartmut Wolf ==== This is a general question.Functions like DSolve will solve an equation, say, DSolve[{y''[x] == -2*y[x], y[0] == 0, y'[0] == 1}, y, x] for y or y[x]. However, in my few months of use of Mathematica, it is very perplexing how it works with y, y[x], interpolating functions, substitution. It is not clear how to use the results of things. When to substitute with the /. operator, when not, when to use Evaluate, when not, how to use the output as an ordinary function... I have had limited success understanding these issues with the mathematica book. Does anyone know a source of information explaining these topics so that when I get an output from for instance an NDSolve function there's no confusion about how to use it in various circumstances like Plotting and such? It's perplexing.thanks,Steve Story ==== For anyone who has the most recent DrawGraphics, cdj's plot may be made withthe following code.Needs[DrawGraphics`DrawingMaster`]f[x_] := (x - 3)^2 - 1I want to plot only over the domain that gives the displayed range. Thatmakes it easier to attach arrows at both ends of the curve.Solve[f[x] == 10]{{x -> 3 - Sqrt[11]}, {x -> 3 + Sqrt[11]}}xyticks := CustomTicks[Identity, {-10, 10, 1, 1}]plot1 = Module[{g, greverse}, g = Draw[f[x], {x, 3 - Sqrt[11], 3 + Sqrt[11]}]; greverse = g /. Line[a_] :> Line[Reverse[a]]; Draw2D[ {VenetianRed, g, ArrowCurve[g, 1, HeadCenter -> 1/2, HeadLength -> 0.03], ArrowCurve[greverse, 1, HeadCenter -> 1/2, HeadLength -> 0.03], Black, AbsoluteThickness[1], Arrow[{0, 0}, #, HeadCenter -> 1/2, HeadLength -> 0.03] & /@ {{0, 10}, {0, -10}, {10, 0}, {-10, 0}}, CirclePoint[#, 4, Black, White] & /@ {{0, 8}, {2, 0}, {3, -1}, {4, 0}, {6, 8}}}, AspectRatio -> Automatic, PlotRange -> {{-1, 1}, {-1, 1}}10.02, Axes -> True, AxesStyle -> White, AxesLabel -> {x, y}, Ticks -> {xyticks, xyticks}, PlotLabel -> Book Plotnn, ImageSize -> 600]];David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ substantially darker than the rest of the grid.(c) Both x and y axes are numbered at the units: 0, +-1, ..., +-10.The numbers should be to the left of the y axis, and below the x axis.The origin doesn't have to be labelled, if it's ugly, or too hard.(d) The y axis is labelled y at the top of the graph, x axis islabelled x on the right.(e) Puts little arrows on the 4 tips of the axes (signifying that theycontinue arbitrarily far).(f) The following points are explicitly represented withreasonable-sized dots: (0,8), (2, 0), (3,-1), (4,0), and (6,8).(g) It would be nice, but not essential, if the tips of the parabolaitself had little arrows (again signifying that it continues upwardwith increasing abs(x) values.Sorry for all the conditions - just trying to be somewhat preciseabout what I meant by graphs like those in textbooks. Once I get thecode for this, I'm sure I can modify it to other similar tasks...Can all these desiderata be obtained in *one* Mathematica graph? Or isthere another graphics/graphing program that is better-suited to suchtasks?cdj ==== >Take, for example, f(x)= (x-3)^2 - 1>I'd greatly appreciate seeing the Mathematica code that does the>following:>(a) Plots the parabola itself (duh). >(b) Does so on a a gridded piece of graph paper, with the axes>substantially darker than the rest of the grid. >(c) Both x and y axes are numbered at the units: 0, +-1, ..., +-10.>The numbers should be to the left of the y axis, and below the x axis.>The origin doesn't have to be labelled, if it's ugly, or too hard. >(d) The y axis is labelled y at the top of the graph, x axis is>labelled x on the right. >(e) Puts little arrows on the 4 tips of the axes (signifying that they>continue arbitrarily far). >(f) The following points are explicitly represented with>reasonable-sized dots: (0,8), (2, 0), (3,-1), (4,0), and (6,8). >(g) It would be nice, but not essential, if the tips of the parabola>itself had little arrows (again signifying that it continues upward>with increasing abs(x) values.The following code does most of what you listed above<< Graphics`Arrow`;Plot[(x - 3)^2 - 1, {x, -1, 10}, PlotRange -> {{-1, 7}, {-1, 10}}, AxesStyle -> {Thickness[ .005]}, Ticks -> {Range[-1,7], Range[-1, 10]}, AspectRatio -> 1, PlotPoints -> 50, AxesLabel -> {x, y}, Epilog -> {PointSize[ .015], Point/@ {{0, 8}, {2, 0}, {3, -1}, {4, 0}, {6, 8}}, Arrow[{6, 0}, {7, 0}], Arrow[{0, 0}, {-1, 0}], Arrow[{0, 0}, {0, -1}], Arrow[{0, 9}, {0, 10}]}]; Visually, I think the following code produces a much better plot.(Plot[(x - 3)^2 - 1, {x, -1, 10}, PlotRange -> {{-1,7}, {-1, 10}}, AxesLabel -> {, }, Ticks -> {Range[-1, 7], Range[(-1), 10]}, AspectRatio -> 1, PlotPoints -> 50, AxesOrigin -> {-1, -1}, Epilog -> {PointSize[ .015], Point /@ {{0, 8}, {2, 0}, {3, -1}, {4, 0}, {6, 8}}}]; Which is better obviously depends on your taste and purpose. In any case a good reference on creating graphics in Mathematica is The Mathematica Graphics Guidebook by Cameron Smith and Nance Blachman This reference is somewhat dated since it only covers Mathematica version 2 and earlier. Despite this I still think it is one of the best guides to Mathematica graphics that has been written.An excellent general guide to displaying graphic information isThe Visual Display of Quantitative Information written by Edward TufteThis reference shows many examples of very bad and very good graphic displays. Tufte also give general guidelines for creating good graphics. Adding emphasis to the axes by making it darker and adding arrows is definitely inconsistent with the guidelines Tufte gives. Adding emphasis to the axes draws attention to the axes and away from the data (parabola and plotted points). Since the only reason for producing a graph is to display the data, other elements of the graph should help clarify the data, not draw attention away from the data.Reply-To: majort@cox-internet.com ==== I used David Park's drawing package for this, which you can get athttp://home.earthlink.net/~djmp/First, load the package.Needs[DrawGraphics`DrawingMaster`]Here's a routine for building the graph paper gridlines.Block[{ySpan, xGrid, yGrid, xGridFine, yGridFine, xGranularity, yGranularity}, xGranularity = Round[xSpan.{-1, 1}/20]; xGridFine = Range[Sequence @@ Inner[#1@#2 &, {Floor, Ceiling}, xSpan, List], xGranularity]; xGrid = Select[xGridFine, Mod[#, 5xGranularity] == 0 &]; ySpan = {Min@#, Max@#} &[f /@ Join[xGridFine, xSpan]]; yGranularity = Round[ySpan.{-1, 1}/20]; yGridFine = Range[Sequence @@ Inner[#1@#2 &, {Ceiling, Floor}, ySpan, List], yGranularity]; yGrid = Select[yGridFine, Mod[#, 5yGranularity] == 0 &]; {Join[{#, {Blue}} & /@ xGrid, {#, {PowderBlue}} & /@ xGridFine], Join[{#, {Blue}} & /@ yGrid, {#, {PowderBlue}} & /@ yGridFine]} ]Here's a routine for the plot. It supplies some options, but also allows them to be overridden or supplemented. It also allows graphics to be inserted along with the main function plot.niceDraw[f_, graphicsPrimitives___, xSpan : {_Integer | _Real, _Integer | _Real}, opts___] := Draw2D[{Draw[f@x, Evaluate@{x, Sequence @@ span}], graphicsPrimitives}, opts, PlotRange -> All, Frame -> True, Axes -> True, AspectRatio -> 1, ImageSize -> 400, AxesStyle -> {Black, Thickness[0.005]}, FrameLabel -> {x, y}, RotateLabel -> False];Here's an example:f[x_] := (x - 3)^2 - 1niceDraw[f, AbsolutePointSize[5], Point /@ {{0, 8}, {2, 0}, {3, -1}, {4, 0}, {6, 8}}, {-5, 15}, AspectRatio -> 0.7];Bobby> Hi,>> I'm sure that questions like this have been asked/answered before, but> I'm not sure what keywords to search on to find them... some obvious> candidates didn't get me anywhere...>> Take, for example, f(x)= (x-3)^2 - 1>> I'd greatly appreciate seeing the Mathematica code that does the> following:>> (a) Plots the parabola itself (duh).> (b) Does so on a a gridded piece of graph paper, with the axes> substantially darker than the rest of the grid.> (c) Both x and y axes are numbered at the units: 0, +-1, ..., +-10.> The numbers should be to the left of the y axis, and below the x axis.> The origin doesn't have to be labelled, if it's ugly, or too hard.> (d) The y axis is labelled y at the top of the graph, x axis is> labelled x on the right.> (e) Puts little arrows on the 4 tips of the axes (signifying that they> continue arbitrarily far).> (f) The following points are explicitly represented with> reasonable-sized dots: (0,8), (2, 0), (3,-1), (4,0), and (6,8).> (g) It would be nice, but not essential, if the tips of the parabola> itself had little arrows (again signifying that it continues upward> with increasing abs(x) values.>> Sorry for all the conditions - just trying to be somewhat precise> about what I meant by graphs like those in textbooks. Once I get the> code for this, I'm sure I can modify it to other similar tasks...>> Can all these desiderata be obtained in *one* Mathematica graph? Or is> there another graphics/graphing program that is better-suited to such> tasks?> cdj>>-- majort@cox-internet.comBobby R. TreatReply-To: majort@cox-internet.com ==== Oops. I had a small bug there (span where I should have had xSpan), so I'm too.Block[{ySpan, xGrid, yGrid, xGridFine, yGridFine, xGranularity, yGranularity}, xGranularity = Round[xSpan.{-1, 1}/20]; xGridFine = Range[Sequence @@ Inner[#1@#2 &, {Floor, Ceiling}, xSpan, List], xGranularity]; xGrid = Select[xGridFine, Mod[#, 5xGranularity] == 0 &]; ySpan = {Min@#, Max@#} &[f /@ Join[xGridFine, xSpan]]; yGranularity = Round[ySpan.{-1, 1}/20]; yGridFine = Range[Sequence @@ Inner[#1@#2 &, {Ceiling, Floor}, ySpan, List], yGranularity]; yGrid = Select[yGridFine, Mod[#, 5yGranularity] == 0 &]; {Join[{#, {Blue}} & /@ xGrid, {#, {PowderBlue}} & /@ xGridFine], Join[{#, {Blue}} & /@ yGrid, {#, {PowderBlue}} & /@ yGridFine]} ]f[x_] := (x - 3)^2 - 1niceDraw[f, Red, AbsolutePointSize[7], Point@{#,f@#} & /@ {0, 2, 3, 4, 6}, {-5, 15}, AspectRatio -> 0.7];Bobbyof (easy) functions like those in textbooks?Reply-To: majort@cox- I used David Park's drawing package for this, which you can get athttp://home.earthlink.net/~djmp/First, load the package.Needs[DrawGraphics`DrawingMaster`]Here's a routine for building the graph paper gridlines.Block[{ySpan, xGrid, yGrid, xGridFine, yGridFine, xGranularity, yGranularity}, xGranularity = Round[xSpan.{-1, 1}/20]; xGridFine = Range[Sequence @@ Inner[#1@#2 &, {Floor, Ceiling}, xSpan, List], xGranularity]; xGrid = Select[xGridFine, Mod[#, 5xGranularity] == 0 &]; ySpan = {Min@#, Max@#} &[f /@ Join[xGridFine, xSpan]]; yGranularity = Round[ySpan.{-1, 1}/20]; yGridFine = Range[Sequence @@ Inner[#1@#2 &, {Ceiling, Floor}, ySpan, List], yGranularity]; yGrid = Select[yGridFine, Mod[#, 5yGranularity] == 0 &]; {Join[{#, {Blue}} & /@ xGrid, {#, {PowderBlue}} & /@ xGridFine], Join[{#, {Blue}} & /@ yGrid, {#, {PowderBlue}} & /@ yGridFine]} ]Here's a routine for the plot. It supplies some options, but also allows them to be overridden or supplemented. It also allows graphics to be inserted along with the main function plot.niceDraw[f_, graphicsPrimitives___, xSpan : {_Integer | _Real, _Integer | _Real}, opts___] := Draw2D[{Draw[f@x, Evaluate@{x, Sequence @@ span}], graphicsPrimitives}, opts, PlotRange -> All, Frame -> True, Axes -> True, AspectRatio -> 1, ImageSize -> 400, AxesStyle -> {Black, Thickness[0.005]}, FrameLabel -> {x, y}, RotateLabel -> False];Here's an example:f[x_] := (x - 3)^2 - 1niceDraw[f, AbsolutePointSize[5], Point /@ {{0, 8}, {2, 0}, {3, -1}, {4, 0}, {6, 8}}, {-5, 15}, AspectRatio -> 0.7];BobbyHi,I'm sure that questions like this have been asked/answered before, butI'm not sure what keywords to search on to find them... some obviouscandidates didn't get me anywhere...Take, for example, f(x)= (x-3)^2 - 1I'd greatly appreciate seeing the Mathematica code that does thefollowing:(a) Plots the parabola itself (duh).(b) Does so on a a gridded piece of graph paper, with the axessubstantially darker than the rest of the grid.(c) Both x and y axes are numbered at the units: 0, +-1, ..., +-10.The numbers should be to the left of the y axis, and below the x axis.The origin doesn't have to be labelled, if it's ugly, or too hard.(d) The y axis is labelled y at the top of the graph, x axis islabelled x on the right.(e) Puts little arrows on the 4 tips of the axes (signifying that theycontinue arbitrarily far).(f) The following points are explicitly represented withreasonable-sized dots: (0,8), (2, 0), (3,-1), (4,0), and (6,8).(g) It would be nice, but not essential, if the tips of the parabolaitself had little arrows (again signifying that it continues upwardwith increasing abs(x) values.Sorry for all the conditions - just trying to be somewhat preciseabout what I meant by graphs like those in textbooks. Once I get thecode for this, I'm sure I can modify it to other similar tasks...Can all these desiderata be obtained in *one* Mathematica graph? Or isthere another graphics/graphing program that is better-suited to suchtasks?cdj-- majort@cox-internet.comBobby R. Treat ==== I tried RSolve on this system of coupled recurence equations withnot so good result, maybe there are some tricks?eqs = { r[1][p + 1] == 0.3628 r[1][p] + 0.1360 r[3][p] + 0.59648 r[4][p]+ 2.4838 r[5][p] + 5.4 r[6][p], r[2][p + 1] == 0.2763 r[1][p] + 0.3332 r[2][p] + 0.0529 r[3][p]+ 0.23196 r[4][p] + 0.96592 r[5][p] + 2.1 r[6][p], r[3][p + 1] == 0.0607 r[1][p] + 0.3124 r[2][p] + 0.3937r[3][p], r[4][p + 1] == 0.0542 r[2][p] + 0.266 r[3][p] + 0.4150 r[4][p], r[5][p + 1] == 0.0402 r[3][p] + 0.225 r[4][p] + 0.2778 r[5][p], r[6][p + 1] == 0.05957 r[4][p] + 0.1631 r[5][p]};start values e.g.:{ r[1][0] ==800, r[2][0] == 200, r[3][0] == 500, r[4][0] ==1200, r[5][0] ==400, r[6][0] == 400}This is what I plugged into RSolve (I tried startvalues: numerical, asundetermined constants (as below), and no staringvalues at all).RSolve seems to determine the system RowReduce::luc: Result forRowReduce of badly conditioned matrix etc....sol = RSolve[Flatten[Join[eqs, { r[1][0] == c1, r[2][0] == c2, r[3][0] == c3, r[4][0] == c4, r[5][0] == c5, r[6][0] == c6}]], {r[1], r[2], r[3], r[4], r[5], r[6]}, p]With no starting values I got some result that not seem to agree withstep by step calculation of the system.The reason I look for closed solution is that I want to estabish thesymptotic behavior for the system for different numerical coefs. in eqs. ==== I have a plot of three dimensional points, and I would like to rotate by sixdegrees around the y axis. I have found a command ImageRotate(img, angle)that should provide the wanted rotation. However, I am using mathematica3.0, and this command does not seem to be recognized. Is there any otherway to get the desired result??Ellen Tolonenentolonen@utep.edu ==== >lost a word in question 2: 2.Are the two types Word& Record have>different meanings?Yes, Word and Record are different.With the default settings, Words are any sequence of characters separated by either a tab or space. Records are any sequence of characters separated by newlines.For example suppose I had the following in a fileaaa bb ccaaa ddd ccaaa ff ccReadList[file, Word]{aaa, bb, cc, aaa, ddd, cc, aaa, ff, cc}ReadList[file,Record]{aaa bb cc, aaa ddd cc, aaa ff cc}Also, you can specify both the left and right record separators. For example,ReadList[file,Record,RecordSeparators->{{aa},{cn}}]{a bb c, a ddd c, a ff c}It is also possible to set the options so that a record is identical to a word.For example,ReadList[file,Word]==ReadList[file,Record, RecordSeparators->{n, }]TrueBut while this is possible it is hard to imagine a case where it would be a good idea. Setting options to make record become the same as word or vice versa will almost certainly lead to confusion later. ==== I need an information: I need a function for computing the minimum directed (source or sink) spanning tree of a directed weighted graph. In the package Combinatorica (the one in Mathematica 4.0) there is only de undirected version of this function. Someone knows whether exists some othere package of graph algorithms around?Many thanks - Gianluca ==== > Everytime I type parethesis [] or {} I get a:>> You used a Command or Control key combination that is not defined to doanything.>> The parethesis are printed tough.> Maybe that is because I use a german keyboard layout?> I have to use ctrl-alt or alt gr to get the parethesis.> What can I do?>> (Win2000, Mathematica 4)I posted here the same question before, and got no useful answer. One (ugly)way to circumvent the problem is to disable beep-ing and displaying thoselayout (which works fine) and remember positions of [, ] and othercharacters on the keyboard.Marko ==== =========================================== ==== =============Sevareid's Law: The chief cause of problems is solutions. ==== =============================================== ==== =========Author-Address: areiner tph tuwien ac at ==== > Actually, this is a pretty serious problem. We've been trying to make > Mathematica a standard language for our engineering firm, but I've > struggled for years with developing good documentation standards. The ...You might be interested in literate programming - any system shouldnoweb , BTW); thereis also a system specific for Mathematica, viz. TeX/Mathematica, which presupposesa working emacs installation. I have no idea how well it would work onnon-Unix systems, though....> methods difficult. I'm tempted to ban prefix and postfix notation in > packages because they can make for very opaque code. Many years ago, ...Conversely, I feel that they make for very readable code: expr // f1 // f2shows me the expression I start from, and tells me that the functionsare applied in some sequence that (hopefully) makes sense; and the @character in /@, @@, etc. is such a nice dark blotch on the screenthat it stands out visually much more prominently than square brackets(I hardly use ~f~ - usually the precedence doesn't fit for me.)Albert.. ==== showing my test results on the Parallel Toolkit. In short, the ParallelMap[ ] function and others like it are gawdawful slow, and it is better for you to to decompose the problem yourself and use RemoteEvaluate[ ] to call them.> Dear All,> I appreciate any response on the following problem:> It appears that ParrallelDot function, which is a> part of Parallel Kit, works two orders of magnitude> slower on my two processor machine than Dot. ==== > Hi,> parallel commands are usualy slower than serial ones,> because you have the overhead for process communication.Have you used the Parallel Toolkit? My experience shows there are some gross inefficiencies in their implementation of the ParallelMap[ ] functions.In general, the toolkit is useful if you can decompose your problem coarsely. Don't use the ParallelMap[ ] function or similar, develop yuor own analogs based on RemoteEvaluate[ ]. ==== True, but in case you put people off ever using a parallel set-up, let me point out where it is useful and easy: simulations and related programming. If I want to run the same simulation 1000 times, returning 1000 values, and that takes an hour, I can distribute the task to ten machines that do 100 each, and that will take just a little over 6 minutes. And all by putting the function that represents the simulation into ParallelTable.Gareth RussellColumbia University> Hi,> parallel commands are usualy slower than serial ones,> because you have the overhead for process communication.> For your parallel dot command you have to transfer two> doubles (16 Byte) to do a multiplication and a addition> with double speed. I don't know you CPU type and speed. > I would expect, that you CPU can do> an addition and a multiplication in 2-4 CPU-cylces> and this will need much less time than the transfer> of 16 Byte via MathLink. > Since the time for sending the data is much larger than> the speed gain by the parallel execution, your parallel> command must be much slower than the serial version.> General it is very difficult to design an> algorithm that is faster executed parallel than on a> serial machine. The critical question is how fast can the> comunicatione be and how can I reduce the data exchange> because a communication via shared memory, pipes or TCP/IP> is typical 100-10000 slower than the data exchange on the> system bus on the mainboard.> To get a speed gain, you have to increase the operation> count that every CPU does on the data. It must > be much lager than a simple addition/multiplication.> Say 5000-10000 CPU cycles per byte - than and only than you will> see a speed gain.> Don't expect, that any of your parallel commands> is faster than the serial execution. It is a> fairy-tale that parallel computing is faster> than serial execution. The exceptions of this> rule need special algorithms and very carefull > programming.> Jens>>> Dear All,>>> I appreciate any response on the following problem:>>> It appears that ParrallelDot function, which is a>> part of Parallel Kit, works two orders of magnitude>> slower on my two processor machine than Dot. Below>> is the commands used to evaluate dot product in pa->> rallel. I am not sure that the command>>> ExportEnvironment[TestMtrx];>>> is necessary in that case (though it doesn't do any>> harm). It takes 6 seconds to evaluate>>> Dot[TestMtrx,TestMtrx]>>> and about half an hour to evaluate>>> ParallelDot[TestMtrx,TestMtrx]>>> Needs[Parallel`Parallel`]>>> Needs[Parallel`Commands`]>>> ProcIDTable = Table[LaunchSlave[localhost,$mathkernel],{2}];>>> TestMtrx = Table[Random[Real,{-1,1}],{1000},{1000}];>>> ExportEnvironment[TestMtrx];>>> TestDot = ParallelDot[TestMtrx,TestMtrx]>>> I have plenty of RAM (4GB), thus this problem can't>> be caused by kernels competing for memory space...>>>> -->>> Denis Areshkin>> (919) 513-2424 (office)>> (919) 835-1650 (home)> ==== does a command or module exist which can test a list of values and determineif it is a super-increasing list?A super-increasing list satifies the conditions:a. the list is in increasing orderb. each element of the list is greater than the sum of it's previouselementsExample:list = {2, 3, 7, 15, 31}So check:a. It is in increasing order andb. 3 > 2, 7 > 3+ 2, 15 > 7 + 3 + 2 and 31 > 15 + 7 + 3 + 2,hence the list is super-increasing. ==== here is the function that grows on unit interval in 12 steps:n=12;Map[(g[x_]:=#/n/;(#-1)/n<=x<=#/n)&,Range[n]];Plot[ g[x], {x,0,1}]Now, changing n in the first line we can get different number ofsteps.Instead, I would like to make n the function parameter: g[x_,n_] anddefine it when plotting, likePlot[{g[x,3],g[x,7],g[x,12]}, {x,0,1}]How to to this?Vadim. ==== Why does the following code cause and exception? I thought that theleft hand side of := was not evaluated.Clear[a, z];z[x_Integer] := 2;z[x_] := Throw[11];a[i_, iUp_?z] := 3;a[i_Integer, iUp_?z] := 5;Hein ==== I am wondering if there is a way to take multiple derivatives of afunction with several arguments.For examplef_0_0_0_... = f(t_1, t_2, t_3,.....) = (t_1)^5 * (t_2)^5 + (t_1)^5 *(t_3)^5+ (t_1)^5 * (t_4)^5 + (t_1)^5 * (t_5)^5 + ...f_1_0_0_...= D[f(t_1, t_2, t_3,.....), t_1])=5(t_1)^4 * (t_2)^5+ 5(t_1)^4 * (t_3)^5 + 5(t_1)^4 * (t_4)^5 + 5(t_1)^4 * (t_5)^5 + ...f_1_1_0_...= D[f_1_0_0_... , t_2])=5(t_1)^4 * 5(t_2)^4f_1_2_0_...= D[f_1_1_0_... , t_2])=5(t_1)^4 * 20(t_2)^3f_2_2_0_...= D[f_1_2_0_... , t_1])=20(t_1)^3 * 20(t_2)^3I would like to be able to find terms like f_2_2_0_4_0_5 , and f_3_0_0_0_1_5 considerinig they exsist.ChrisReply-To: kuska@informatik.uni-leipzig.de ==== Hi,Table[ Plot[Sin[x], {x, 0, Pi}, Evaluate[ImageSize -> i]], {i, 50, 600, 50}]orSetOptions[Plot,ImageSize->100000] Jens> NATIONAL AEROSPACE LABORATORIES,> BANGALORE, INDIA> Hi mathgroup,> Whenever a graphic command is executed in a notebook> the graph is drawn in an area of fixed dimensions.> this area is a little too small for a good view,> especially when you have a number of plots with> varying parameters, as in the case of solution of> differential equations. Is there a way of enlarging> the graph? I would appreciate if DAVID PARK also> responds to this.> __________________________________________________> Do you Yahoo!?> Yahoo! Tax Center - File online, calculators, forms, and more> http://platinum.yahoo.com ==== In the graphics use the option ImageSize or under Mathematica preferences setthe global preference for ImageSize.Bob Hanlon<< Whenever a graphic command is executed in a notebookthe graph is drawn in an area of fixed dimensions.this area is a little too small for a good view,especially when you have a number of plots withvarying parameters, as in the case of solution ofdifferential equations. Is there a way of enlargingthe graph? I would appreciate if DAVID PARK alsoresponds to this. >>

==== KY,There are a number of methods for solving this problem. First, you can clickon the graphic with the mouse, than grab one of the handles and drag thegraphic to a larger size. If you change and reevaluate the graphic code itwill still use the larger size. If you delete the output graphics orevaluate in a fresh notebook it will revert to the smaller default graphicsize.You can use the graphics option ImageSize -> 500, say, in your Plotstatement and then Mathematica will always use the specified size.If you are making a lot of plots, say with the Plot statement, then youcould redefine it to always include the ImageSize option, and whatever otheroptions you wish to use.myPlot[args__, opts___?OptionQ] := Plot[args, opts, ImageSize -> 500, Frame -> True]Needs[Graphics`Colors`]myPlot[Sin[x], {x, 0, 2Pi}, PlotLabel -> Sin[x], Background -> Linen];That saves typing the ImageSize and Frame options each time you make a plot.You could also change ImageSize or Frame just by including them in themyPlot statement. The only trouble is that if you are using a number ofdifferent plot types you will have to make a definition for each plot type.If you are using the DrawGraphics package and paradigm, then you can makeone definition for all your 2D graphics and a second definition for all your3D graphics, if needed.For example, right now I am trying to learn some complex analysis usingTristan Needham's Visual Complex Analysis book. I found that I was alwaystyping the same options into my graphics statements so I made thedefinition:ComplexGraphics[primitives : {___}, opts___] := Draw2D[primitives, opts, AspectRatio -> Automatic, Frame -> True, FrameTicks -> False, Axes -> True, AxesOrigin -> {0, 0}, AxesStyle -> Gray, ImageSize -> 500 ]That saves a lot of typing with each piece of graphics.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ differential equations. Is there a way of enlargingthe graph? I would appreciate if DAVID PARK alsoresponds to this.__________________________________________________Do you Yahoo!?Yahoo! Tax Center - File online, calculators, forms, and morehttp://platinum.yahoo.com ==== KY,I forgot. There is also another method.Go to the OptionInspectorGraphics OptionsImage Bounding BoxImage Size andset the size you wish to use. That should change the default size for all ofyour plots.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ differential equations. Is there a way of enlargingthe graph? I would appreciate if DAVID PARK alsoresponds to this. ==== Click on plot to get 8 points ( 4 corners and 4 mid-points of sides).Point to any of these eight. Click drag mouse outwards to get plot ofenlarged size. HTH ; Narasimham > NATIONAL AEROSPACE LABORATORIES,> BANGALORE, INDIA> > Hi mathgroup,> Whenever a graphic command is executed in a notebook> the graph is drawn in an area of fixed dimensions.> this area is a little too small for a good view,> especially when you have a number of plots with> varying parameters, as in the case of solution of> differential equations. Is there a way of enlarging> the graph? I would appreciate if DAVID PARK also> responds to this.> __________________________________________________> Do you Yahoo!?> Yahoo! Tax Center - File online, calculators, forms, and more> http://platinum.yahoo.com-- To contact in private, remove ==== Click anywhere inside the graph and a frame with small handles will appear.Place your cursor on any of the handles and drag out till you get thedesired size. Or, use the Option Inspector and change the settings inGraphics Options|Image Size to use a permanent image size either in thepresent notebook or forever.Tomas GarzaMexico City----- Original Message -----> this area is a little too small for a good view,> especially when you have a number of plots with> varying parameters, as in the case of solution of> differential equations. Is there a way of enlarging> the graph? I would appreciate if DAVID PARK also> responds to this.> __________________________________________________> Do you Yahoo!?> Yahoo! Tax Center - File online, calculators, forms, and more> http://platinum.yahoo.com>> ==== Hi,Look up the option ImageSize for graphics.ImageSize->500Yas> To: mathgroup@smc.vnet.net> NATIONAL AEROSPACE LABORATORIES,> BANGALORE, INDIA>> Hi mathgroup,> Whenever a graphic command is executed in a notebook> the graph is drawn in an area of fixed dimensions.> this area is a little too small for a good view,> especially when you have a number of plots with> varying parameters, as in the case of solution of> differential equations. Is there a way of enlarging> the graph? I would appreciate if DAVID PARK also> responds to this.> __________________________________________________> Do you Yahoo!?> Yahoo! Tax Center - File online, calculators, forms, and more> http://platinum.yahoo.com>> ==== Hi,what is the way to export graphics to eps files with embedding the characters?I heard this is now finaly possible in Mathematica 4.2.1.Daniel Nettels ==== >1. What's the difference between Import[ ] & ReadList?Basically, Import is pre-programmed to understand a lot of specific file formats and ReadList isn't. The built in knowledge of Import about certain file types makes it much simpler to read the data from these files into Mathematica than would otherwise be the case. But there is a performance cost associated with Import.To give a specific example, suppose you had a spreadsheet file save as a tab deliminated file that contained a mixture of both numeric and non-numeric data. ThenImport[filename, Table] would read all of the data in correctly maintaining the data structure. Numeric data would be read in as numbers ready to use in further computation. OTOH, ReadList[filename, Number, RecordLists->True] would generate errors and fail when the non-numeric data was encountered. The errors could be avoided withReadList[filename, Word, RecordLists->True]but now all of the data would be type String and would not be ready for further computations without additional programming.If the file had the same format but contained only numeric data,Import[filename,Table] andReadList[filename, Number, RecordLists->True]would have identical results but ReadList would execute faster.>2.Are the two types Word and have different meanings?Not as far as I know.Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,no because for the good pictures (say the 4.x Logo)you need a fast machine with a huge amount of memoryand the most creators will not give it away ..May be one Michael Trott's books will help you Jens> Is there a place where I can get Mathematica notebooks that demonstrate 3-D> graphics? I am running Mathmatica 4.0 and wanted to see an entire range of> surfaces, 3-D Art, etc.> ==== TracyHave you checked out the 3D Graphics in the Help Browser ? Look underGetting Started/Demos then under Graphics Gallery. After that, checkout the WRI site, they usually have some 3d graphics knocking about,Graphica and Artlandia are two keywords which spring to mind. Then it'son to Tom Wickham-Jones' book.Mark Westwood> Is there a place where I can get Mathematica notebooks that demonstrate 3-D> graphics? I am running Mathmatica 4.0 and wanted to see an entire range of> surfaces, 3-D Art, etc.> ==== >I've not used a newsgroup before so I'm not sure how to get in to post >questions,> but I need help with a problem in mathematica.> (If questions regarding mathematica are sent,> please could you post this question so I might get a>reply?)>>Problem:>In mathematica I want to create two or more buttons within>a cell.>When I press the first button I want some text (eg correct) to appear ,>(if possibly in same cell next to the buttons,if not in new>cell immediately below)>when i press another button i want the text to be written over> with another piece of text (eg wrong)>How do I set the buttons up?>>Cheryl Tucker>>--------------------------------------->TUCKER C.YIt just so happens that we recently released a package that does just this. You can get a full-featured demo athttp://omegaconsultinggroup.com/Products/form/demo.htmlOnce you've installed the package, you can do the following:< I'd like to throw this out as a challenge to the group: What's the most> efficient way to implement in Mathematica an explicit multistep> iterative method such as, say, the 4-step Adams-Bashforth method for> solving y' = f(t,y):>> y[k+1]:= y[k] + (h/24)*(55*f[k] - 59*f[k-1] + 37*f[k-2] - 9*f[k-3])>> where y[0], y[1], y[2], y[3] are given, and f[i] denotes f[t0 +i*h,> y[i]]. The desired output would be the list>> {y[0], y[1], y[2], ... , y[n]}.>> A suitable toy problem is>> y' = -2t*y^2, y(0) = 1,>> with h = 0.01, n = 1000 (?), and the starting values taken from the> exact solution y = 1/(1+t^2):>> y[0]=1, y[1] = 0.9999, y[2] = 0.9996, y[3] = .999101.> -------> Selwyn Hollis>> ==== >I'd like to throw this out as a challenge to the group: What's the most>efficient way to implement in Mathematica an explicit multistep>iterative method such as, say, the 4-step Adams-Bashforth method for>solving y' = f(t,y):>>y[k+1]:= y[k] + (h/24)*(55*f[k] - 59*f[k-1] + 37*f[k-2] - 9*f[k-3])>>where y[0], y[1], y[2], y[3] are given, and f[i] denotes f[t0 +i*h,>y[i]]. The desired output would be the list>>{y[0], y[1], y[2], ... , y[n]}.>>A suitable toy problem is>>y' = -2t*y^2, y(0) = 1,>>with h = 0.01, n = 1000 (?), and the starting values taken from the>exact solution y = 1/(1+t^2):>>y[0]=1, y[1] = 0.9999, y[2] = 0.9996, y[3] = .999101.>------->Selwyn HollisI don't know about most efficient, but this does the trick.In[1]:= h=.01;Here is a function definition that uses caching. When it encounters a new y[k] it calculates the value and then saves it. When you reuse the value, it doesn't get recalculated. That makes it faster but it uses more memory.In[2]:= y[k_] := y[k] = y[k-1]+(h/24)*(55*f[k-1]-59*f[k-2]+37*f[k-3]-9*f[k-4])In[3]:= f[k_] := -2 h k y[k]^2In[4]:=y[0]=1;y[1]=.9999;y[2]=.9996;y[3]=.999101;In[8]: = Timing[lst=Table[y[k],{k,1000}];]Out[8]= {0.15 Second,Null}Compare the values:In[9]:= y[1000]Out[9]=0.00990099In[10]:=1./(1+(h 1000)^2)Out[10]=0.00990099----------------------------------- ---------------------------Omega ConsultingThe final answer to your Mathematica needshttp://omegaconsultinggroup.com ==== Everytime I type parethesis [] or {} I get a:You used a Command or Control key combination that is not defined to do anything.The parethesis are printed tough.Maybe that is because I use a german keyboard layout?I have to use ctrl-alt or alt gr to get the parethesis.What can I do?(Win2000, Mathematica 4) ==== Dear All,I appreciate any response on the following problem:It appears that ParrallelDot function, which is apart of Parallel Kit, works two orders of magnitudeslower on my two processor machine than Dot. Belowis the commands used to evaluate dot product in pa-rallel. I am not sure that the commandExportEnvironment[TestMtrx];is necessary in that case (though it doesn't do anyharm). It takes 6 seconds to evaluateDot[TestMtrx,TestMtrx]and about half an hour to evaluateParallelDot[TestMtrx,TestMtrx]Needs[Parallel`Parallel `]Needs[Parallel`Commands`]ProcIDTable = Table[LaunchSlave[localhost,$mathkernel],{2}];TestMtrx = Table[Random[Real,{-1,1}],{1000},{1000}];ExportEnvironment[ TestMtrx];TestDot = ParallelDot[TestMtrx,TestMtrx]I have plenty of RAM (4GB), thus this problem can'tbe caused by kernels competing for memory space...--Denis Areshkin(919) 513-2424 (office)(919) 835-1650 (home)Reply-To: wlopez@uninorte.edu.co ==== Hi,I am a new user of Mathematica and I have currently encountered aproblem. In fact, I plotted a graph which contains arrows ( for this Icalled up on the =0When I try to plot the function:Plot[h[x],{x,-1,1}]I see that it's defined as h[x_]:=x on all values, not only positive ones.What am I missing here?Vadim.Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,Plot[f[x],{x,0,Xo}, Epilog->(Point /@ data)]orBlock[{$DisplayFunction=Identity}, g1=ListPlot[data]; g2=Plot[f[x],{x,0,Xo}]; ]Show[g1,g2]orShow[ ListPlot[data,DisplayFunction->Identity], Plot[f[x],{x,0,Xo},DisplayFunction->Identity], DisplayFunction->$DisplayFunction ]orNeeds[Graphics`Graphics`]DisplayTogether[ ListPlot[data],Plot[f[x],{x,0,Xo}] ] Jens> The list operations have been very useful.> Here's a pet peeve. Often when I combine several graphics objects with> the show command I get a bunch of extraneous plots. Suppose I have a list> of {x,y} pairs (named data) and a fit function f[x] and I want to show> them together. The easiest way to do this is with the command,> Show[ListPlot[data],Plot[f[x],{x,0,Xo}]> When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and> then the tro combined. How can I have the front end suppress the first> two plots? (this error is especially annoying when I'm plotting 7 or 8> lists together)> Nathan Moore ==== Look at on-line help for DisplayFunction and DisplayTogether.Bob Hanlon<< The list operations have been very useful.Here's a pet peeve. Often when I combine several graphics objects withthe show command I get a bunch of extraneous plots. Suppose I have a listof {x,y} pairs (named data) and a fit function f[x] and I want to showthem together. The easiest way to do this is with the command,Show[ListPlot[data],Plot[f[x],{x,0,Xo}]When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], andthen the tro combined. How can I have the front end suppress the firsttwo plots? (this error is especially annoying when I'm plotting 7 or 8lists together) >>

==== Nathan,You can surpress the printout of plots by setting the DisplayFunction option to Identity. Recall the default setting in the Show-command with $Displayfunction as in below.data =Table[{x,x^2 + Random[Real, {- .4, .4}]}, {x, -2, 2, .2}];fitfun = Fit[data, {1, x, x^2}, x];plota = ListPlot[data, PlotStyle -> PointSize[ .02], DisplayFunction -> Identity];plotb = Plot[fitfun, {x, -2, 2}, DisplayFunction -> Identity];Show[{plota, plotb}, DisplayFunction -> $DisplayFunction];Or just use DisplayTogetherDisplayTogether[{ListPlot[data, PlotStyle -> PointSize[.02]], Plot[fitfun, {x, -2, 2}]}];/HelgeChalmers University of TechnologySweden>The list operations have been very useful.>>Here's a pet peeve. Often when I combine several graphics objects with>the show command I get a bunch of extraneous plots. Suppose I have a list>of {x,y} pairs (named data) and a fit function f[x] and I want to show>them together. The easiest way to do this is with the command,>>Show[ListPlot[data],Plot[f[x],{x,0,Xo}]>>When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and>then the tro combined. How can I have the front end suppress the first>two plots? (this error is especially annoying when I'm plotting 7 or 8>lists together)>>Nathan Moore ==== Nathan,Here are some examples.data = Table[{x, Sin[x] + Random[Real, {-0.2, 0.2}]}, {x, 0, 2Pi, 2Pi/20}];The basic method is to use the DisplayFunction option to turn the displayoff or on. You may wish to lookup DisplayFunction in Help.plot1 = ListPlot[data, DisplayFunction -> Identity];plot2 = Plot[Sin[x], {x, 0, 2Pi}, DisplayFunction -> Identity];Show[plot1, plot2, DisplayFunction -> $DisplayFunction, Prolog -> AbsolutePointSize[5]];A shorter method is to use a Block statement and temporarily reset thesystem DisplayFunction.Block[{$DisplayFunction = Identity}, plot1 = ListPlot[data]; plot2 = Plot[Sin[x], {x, 0, 2Pi}];]Show[plot1, plot2, Prolog -> AbsolutePointSize[5]];An even shorter method is to uses the DisplayTogether command from theGraphics`Graphics` package.Needs[Graphics`Graphics`]DisplayTogether[ ListPlot[data, Prolog -> AbsolutePointSize[5]], Plot[Sin[x], {x, 0, 2Pi}]];The only trouble with some of these methods is that it is sometimesdifficult to control how options are picked up. Basically Mathematica picksorder you would lose the AbsolutePointSize option.DisplayTogether[ Plot[Sin[x], {x, 0, 2Pi}], ListPlot[data, Prolog -> AbsolutePointSize[5]]];If you were trying to set options in both plots you would be out of luck.The DrawGraphics package at my web site was basically designed to overcomethese problems and provide a more natural paradigm for combining plots. Oneuses Draw statements to replace Plot statements. The Draw statements extractthe graphic primitives of a plot without producing a side display. Hence theoutput of a Draw statement is on the same level as the other graphicprimitives such as Point, Line etc. You can also freely mix in graphicsdirectives. So the above plot, with the curve plotted in Blue, would begiven asNeeds[DrawGraphics`DrawingMaster`]Draw2D[ {AbsolutePointSize[5], ListDraw[data], Blue, Draw[Sin[x], {x, 0, 2Pi}]}, Axes -> True];I've come to think that ListPlot and MultipleListPlot are often thedifficult way to do things. It is often easier to just Map Point onto thedata list to plot the points or wrap the data list in Line to plot the line.Here is an example, plotting the data points as points and as a Red line.Draw2D[ {AbsolutePointSize[5], Point /@ data, Red, Line[data], Blue, Draw[Sin[x], {x, 0, 2Pi}]}, Axes -> True];You can add as many other elements to the graphic as you wish, just bystacking them up. You could. for example, add a curve produced byParametricPlot just by writing it is ParametricDraw, or a curve produced byImplicitPlot, just by writing it as ImplicitDraw.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/lists together)Nathan MooreReply-To: murray@math.umass.edu ==== This sort of question must surely rank as one of the most-often asked!You need to turn off normal display for the individual graphics objects, then turn in back on for the combined object using the DisplayFunction option. For example: f[x_] := x data = Table[{n, n + Random[]}, {n, 0, 20}]; pts = ListPlot[data, DisplayFunction -> Identity]; (* no display is produced *) model = Plot[f[x], {x, 0, 20}, DisplayFunction -> Identity]; (* no display is produced *) Show[pts, model, DisplayFunction -> $DisplayFunction];Of course you can do all that in a single expression ... Show[ListPlot[data, DisplayFunction -> Identity], Plot[f[x], {x, 0, 20}, DisplayFunction -> Identity], DisplayFunction -> $DisplayFunction];... but that gets a bit hard to read.> The list operations have been very useful.> Here's a pet peeve. Often when I combine several graphics objects with> the show command I get a bunch of extraneous plots. Suppose I have a list> of {x,y} pairs (named data) and a fit function f[x] and I want to show> them together. The easiest way to do this is with the command,> Show[ListPlot[data],Plot[f[x],{x,0,Xo}]> When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and> then the tro combined. How can I have the front end suppress the first> two plots? (this error is especially annoying when I'm plotting 7 or 8> lists together)> Nathan Moore> -- Murray Eisenberg murray@math.umass.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375 ==== Use the option DisplayFunction->Identity in each of the plots you want tosupress, and then DisplayFunction->$DisplayFunction in the Show command.Tomas GarzaMexico City----- Original Message ----->> When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and> then the tro combined. How can I have the front end suppress the first> two plots? (this error is especially annoying when I'm plotting 7 or 8> lists together)>> Nathan Moore> ==== Hi Nathan,> Here's a pet peeve. Often when I combine several graphics > objects with> the show command I get a bunch of extraneous plots. Suppose > I have a list> of {x,y} pairs (named data) and a fit function f[x] and I > want to show> them together. The easiest way to do this is with the command,> Show[ListPlot[data],Plot[f[x],{x,0,Xo}]> When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and> then the tro combined. How can I have the front end suppress > the first> two plots? (this error is especially annoying when I'm > plotting 7 or 8> lists together)Why not try p1 = ListPlot[dta, DisplayFunction->Identity]; p2 = Plot[f[x], DisplayFunction->Identity]; p3 = Show[p1, p2, DisplayFunction->$DisplayFunction];You might also want to try looking at the help for DisplayTogether andDisplayTogetherArray ...Dave. ==== ====================================== Dr. David Annetts EM Modelling Analyst Australia David.Annetts@csiro.au ==== =================================== ==== ====>The list operations have been very useful.>>Here's a pet peeve. Often when I combine several graphics objects>with the show command I get a bunch of extraneous plots. Suppose I>have a list of {x,y} pairs (named data) and a fit function f[x] and>I want to show them together. The easiest way to do this is with the>command,>>Show[ListPlot[data],Plot[f[x],{x,0,Xo}]>>When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and>then the tro combined. How can I have the front end suppress the>first two plots? Use the DisplayFunction option. Setting DisplayFunction->Identity suppresses display of the plots. For your specific exampleShow[ ListPlot[data,DisplayFunction->Identity], Plot[f[x],{x,0,X0},DisplayFunction->Identity], DisplayFunction->$DisplayFunction]will display the one combined plot you are interested in ==== G'day,Use DisplayFunction -> Identity to suppress the graphic display ofListPlot and Plot.e.g. ListPlot[data, DisplayFunction -> Identity]Then use DisplayFunction -> $DisplayFunction in Show to show the combinedgraphic on screen.Yas> The list operations have been very useful.>> Here's a pet peeve. Often when I combine several graphics objects with> the show command I get a bunch of extraneous plots. Suppose I have a list> of {x,y} pairs (named data) and a fit function f[x] and I want to show> them together. The easiest way to do this is with the command,>> Show[ListPlot[data],Plot[f[x],{x,0,Xo}]>> When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and> then the tro combined. How can I have the front end suppress the first> two plots? (this error is especially annoying when I'm plotting 7 or 8> lists together)>> Nathan Moore> ==== howdy,Is it possible, to either - open and use a socket from Mathematica or - use HTTP as a client;I would like to write some way to upload a file using HTTP fromMathematica (with a custom CGI app on the server);Using Mathlink or J/Link is not an option;murpheeReply-To: kuska@informatik.uni-leipzig.de ==== Hi,it run fine with Mandrake 9.0with Mandrake 9.1 I can wait until the nVidia driveris updated Jens> I am having segmentation fault at startup with Mathematica 4.2.1 (and 4.2)> start just the kernel. It occurs with both the statically and the> dynamically linked versions. The same install works fine when I boot> up using Red Hat 8.0.> Mathematica 4.1 runs but the display seem to have a big font encoding mess.> At last one other Mandrake user reports font issues with 4.1.> Anybody else is experiencing these issues?> Minh. ==== The segmentation fault was solved by using the dynamically linkedMinh.Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,and what hat this to do with Mathematica ?If you Import[] the bitmap into MathematicaImport[SomeImage.bmp][[1,1]]will give you the matrix with gray values orrgb triples Jens> I am trying to obtain the raw information of a picture BMP (array of> numbers) and import it to excel spreadsheet to calculate some things.> Do you guys have any idea how can I do that?> thanks in advance,> Victor ==== VictorThe function Import returns a graphics object - which includes the RGB(or other colour function) coordinates of each pixel. A littleexperimentation will show you how to extract the numbers from the restof the graphics info. I suggest that you start with very small imagesuntil you are confident in handling the raw data.I imagine you could then export the data to an Excel spreadsheet but Icannot for the life of me understand why, having imported it intoMathematica in the first place, you would want to do so.Hope this helps with the first step at leastMark Westwood> I am trying to obtain the raw information of a picture BMP (array of> numbers) and import it to excel spreadsheet to calculate some things.> Do you guys have any idea how can I do that?> thanks in advance,> Victor ==== Hi,If you have taken the trouble to import the data into Mathematica, thenwhy not do the calculations in Mathematica. Use RasterArray orListDensityPlot with the Mesh turned off to view your results after thecalculation. Recently there has been a discussion on working with Listsmg[40326] and threads. You will find some of that discussion useful forprocessing your images.Yas> I am trying to obtain the raw information of a picture BMP (array of> numbers) and import it to excel spreadsheet to calculate some things.>> Do you guys have any idea how can I do that?>> thanks in advance,>> Victor>>I have a difficult problem:Given a constant integer X (which may be very large) , you no need to find the value of XandX mod 8 = n1X mod 16 = n2the problem is that find n2 if n1 is know? ==== >It ought to be simple, I just don't know where to find it: I want to>do a (linear, least square) fit but instead of functions in a variable>I want to use lists of the same length as the data list.Is this what you have in mindIn[1]:=listA=Table[Random[],{10}];listB=Table[Random[],{ 10}];Fit[Transpose[{listA,listB}],{1,x},x]Out[3]= 0.7560816265287248 - 0.26693573953881305*xReply-To: majort@cox-internet.com ==== Here are a couple of ways to do it. In either case, Regress can be replaced with Fit.Known values:n = 10;knowns = Sin@Range@n;Predictor variable lists:a = Array[Random[] &, n];b = Range@n;c = b^2;The simplest thing:Regress[Transpose@{a, b, c, knowns}, {1, x, y, z}, {x, y, z}]A more ßexible method:f = Interpolation[a];g = Interpolation[b];h = Interpolation[c];Regress[knowns, {1, f@x, g@x, h@x}, x]The second method can be easily modified to include other predictor functions:Regress[knowns, {1, f@x, g@x, h@x, Cos@x}, x]BobbyOn Sat, 29 Mar 2003 05:20:26 -0500 (EST), Martin It ought to be simple, I just don't know where to find it:> I want to do a (linear, least square) fit but instead of functions in> a variable I want to use lists of the same length as the data list.>> And by the way, I am still running 4.0>-- majort@cox-internet.comBobby R. Treat ==== I am a researcher in Artificial Intelligence and I have a question aboutgenerating random permutation of a set of numbers. More formal definition:Given a set of N numbers S = {n1, ., nn} how to efficiently and accurately generate P(S) = random_permutation(S)Ex: S = {3,4,12}, P(S) should have a probability equals to 1/3! = 1/6 toreturnone of the following permutations:{(3,4,12)(3,12,4)(4,3,12)(4,12,3)(12,3,4)(12,4,3) }and a complexity equals to O(N). and how to efficiently generate an iterator on the numbers which will bereturned by P(S) ?Ex: S = {3,4,12} P(S) can return any of the permutations describedbelow, butwhat we want here is to get an iterator on the future numbers withoutcreating the full permutation Do you know any algorithm performing this task which is very efficientin terms of quality (each permutationhas the same probability to be generated) and in terms of complexity(minimal number of operationsis necessary to perform this operation n2, n, log n, etc.). If you have any clue or web links where I can find this information, this would be very much appreciated. ==== >I'm wondering whether there's a smart way to do map projections with>mathematica.>I know that mathematica comes along with the package `WorldPlot. So is>there anyway to access the data they're using there? They even got>some different projections options but the point is that I want to do>in on my own.>Has anyone got experience in this?Have you opened the file WorldPlot.m that comes with Mathematica using a text editor or something else that can display ASCII? If you do this you will find you can review the code used to implement each of the functions. Additionally, there is information regarding the sources used to develop this package.As far as accessing the data used, the first line of code after the comments isBeginPackage[Miscellaneous`WorldPlot`,Miscellaneous` WorldNames`, Miscellaneous`WorldData`,Utilities`FilterOptions`]suggesting the file WorldData.m contains the data of interest. And that file contains the comment(* :Source: These data are derived from what was originally a CIA database, released into the public domain by the Freedom of Information Act. I acquired a copy of these data, and rearranged them to the form below. The copy I found was from the Amiga Fish disks, a public-domain distribution of software for the Amiga computer, under the name WorldDataBank. Note that these data (in the original format) are available at higher resolution from this source.*)Looking at the packages that were distributed with Mathematica is a very good way to learn by example many useful techniques. ==== f[s_?VectorQ] := Module[{n=0}, Fold[Append[#1,n-Count[Take[s, n++],#2]]&, {},s]];s={a,b,b,a,a,a,b,a,b,a,a};g={0,1,1,2,2,2,4,3,5,4,4};f[ s] == gTrues=Table[{a,b,c}[[Random[Integer, {1,3}]]], {15}]{a,b,a,c,b,b,a,c,a,b,a,b,a,a,c}f[s]{ 0,1,1,3,3,3,4,6,5,6,6,7,7,7,12}Bob Hanlon<< this particular calculation is used. The current application is anunusual conjecture in geometry. >>

==== Here is one (nice?) way of doing this that does not depend on how many different values s contains:f1[s_List] := MapIndexed[Length[DeleteCases[Take[s, First[#2]], #1]] &, s]and here is another one that works only (as it stands) with just two distinct values:f2[l_List] := Module[{mult = Length /@ Split[l], list1, list2, values}, list1 = Rest[FoldList[Plus, 0, Table[mult[[i]], {i, 1, Length[mult], 2}]]]; list2 = FoldList[Plus, 0, Table[mult[[i]], {i, 2, 2( Floor[(Length[mult] + 1)/2]) - 1, 2}]]; values = Take[Flatten[Transpose[{list2, list1}]], Length[mult]]; Flatten[Table[Table[values[[i]], { mult[[i]]}], {i, 1, Length[mult]}]]]The second function is a lot more complex and may not satisfy your criteria of niceness but it is also a lot more efficient.Let's first make sure they both work correctly with your original s:In[3]:=s={a,b,b,a,a,a,b,a,b,a,a};In[4]:=f1[s]Out[4]={ 0,1,1,2,2,2,4,3,5,4,4}In[5]:=f2[s]Out[5]={ 0,1,1,2,2,2,4,3,5,4,4}Now let's try something bigger:In[6]:=s=Table[If[Random[Integer]==1,a,b],{10^3}];In[7 ]:=a=f1[s];//TimingOut[7]={1.37 Second,Null}In[8]:=b=f2[s];//TimingOut[8]={0.04 Second,Null}In[9]:=a==bOut[9]=TrueSo niceness doesn't always pays, it seems.Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> Given a list consisting of only two distinct values, such as> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position> 1<=p<=Length[s], look at list s and set g[[p]] to the number of> elements in s to the left of p which are not equal to s[[p]].> In a more general version, which I do not need now, s would> not be restricted to only two distinct values.>> this particular calculation is used. The current application is an> unusual conjecture in geometry.>> ==== First rename a->1 b->2 (with s/.{a->1, b->2})and try this (a Ômore general version')In[]:=s = {1, 2, 2, 1, 1, 1, 2, 1, 2, 1, 1};In[]:=t = Table[0, {Max[s]}];sumt = 0;g = (sumt++ - t[[#]]++) & /@ s Mihajlo Vanevic mvane@EUnet.yu 2003-03-29*************************************************** ************ At 2003-03-29, 05:19:00 ************************************************************* *> Given a list consisting of only two distinct values, such as>s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length>g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position>1<=p<=Length[s], look at list s and set g[[p]] to the number of>elements in s to the left of p which are not equal to s[[p]].> In a more general version, which I do not need now, s would>not be restricted to only two distinct values.>>this particular calculation is used. The current application is an>unusual conjecture in geometry.**************************************************** ********** ==== Here's my attempt:Different[s_List] := Module[{types, i}, types = Union[s]; Thread[(i /@ types) == 0] /. Equal -> Set; (i[#]++; Tr[i /@ DeleteCases[types, #]]) & /@ s ]--Mark> Given a list consisting of only two distinct values, such as> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position> 1<=p<=Length[s], look at list s and set g[[p]] to the number of> elements in s to the left of p which are not equal to s[[p]].> In a more general version, which I do not need now, s would> not be restricted to only two distinct values.> this particular calculation is used. The current application is an> unusual conjecture in geometry.> ==== >Given a list consisting of only two distinct values, such as>s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length>g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position>1<=p<=Length[s], look at list s and set g[[p]] to the number of>elements in s to the left of p which are not equal to s[[p]]. Here is something that will do the trickMapThread[(Length[Take[s, #2]] - Length[Position[ Take[s, #2], #1]]) &, {s, Range[Length[s]]}] ==== Steve,Nice problem. The following seems to work pretty well (and on the more general problem): countdiffs[s_List] := Module[{members, totals, g}, members = Union[s]; totals = Count[s, #] & /@ members; g = {}; Scan[ Module[{i}, i = First@First@Position[members, #]; PrependTo[g, Plus @@ totals - totals[[i]]]; totals[[i]]--]&, Reverse[s] ]; g ] s = Table[Random[Integer, {1, 9}], {10}] {3, 4, 4, 9, 9, 4, 1, 6, 1, 3} countdiffs[s] {0, 1, 1, 3, 3, 3, 6, 7, 7, 8}Since this will probably become a speed contest :) ... s = Table[Random[Integer, {1, 9}], {5000}]; First@Timing[countdiffs[s];] 1.53 Second(4.1.5, Mac OS X, 1GHz DP)-----Selwyn Hollishttp://www.math.armstrong.edu/faculty/hollis> Given a list consisting of only two distinct values, such as> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position> 1<=p<=Length[s], look at list s and set g[[p]] to the number of> elements in s to the left of p which are not equal to s[[p]].> In a more general version, which I do not need now, s would> not be restricted to only two distinct values.>> this particular calculation is used. The current application is an> unusual conjecture in geometry.> ==== Oops, that timing was wrong. Should have beens = Table[Random[Integer, {1, 9}], {5000}];First@Timing[countdiffs[s];]2.36 Second-- SH> Steve,>> Nice problem. The following seems to work pretty well (and on the more > general problem):>> countdiffs[s_List] := Module[{members, totals, g},> members = Union[s];> totals = Count[s, #] & /@ members;> g = {};> Scan[ Module[{i}, i = First@First@Position[members, #];> PrependTo[g, Plus @@ totals - totals[[i]]];> totals[[i]]--]&,> Reverse[s] ];> g ]>> s = Table[Random[Integer, {1, 9}], {10}]>> {3, 4, 4, 9, 9, 4, 1, 6, 1, 3}>> countdiffs[s]>> {0, 1, 1, 3, 3, 3, 6, 7, 7, 8}>> Since this will probably become a speed contest :) ...>> s = Table[Random[Integer, {1, 9}], {5000}];> First@Timing[countdiffs[s];]>> 1.53 Second>> (4.1.5, Mac OS X, 1GHz DP)> -----> Selwyn Hollis> http://www.math.armstrong.edu/faculty/hollis> Given a list consisting of only two distinct values, such as>> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length>> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position>> 1<=p<=Length[s], look at list s and set g[[p]] to the number of>> elements in s to the left of p which are not equal to s[[p]].>> In a more general version, which I do not need now, s would>> not be restricted to only two distinct values.>> this particular calculation is used. The current application is an>> unusual conjecture in geometry.>Reply-To: majort@cox-internet.com ==== leftCount[s_List] := Block[{count}, count[any_] := 0; Range@Length@s - Rest@FoldList[++count[#2] &, s, s]]leftCount[s]{0, 1, 1, 2, 2, 2, 4, 3, 5, 4, 4}orleftCount[s_List] := Block[{count, n = 0}, count[any_] := 0; Rest@FoldList[++n - (++count[#2]) &, s, s]]leftCount[s]{0, 1, 1, 2, 2, 2, 4, 3, 5, 4, 4}BobbyOn Sat, 29 Mar 2003 05:19:39 -0500 (EST), Steve Gray Given a list consisting of only two distinct values, such as> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position> 1<=p<=Length[s], look at list s and set g[[p]] to the number of> elements in s to the left of p which are not equal to s[[p]].> In a more general version, which I do not need now, s would> not be restricted to only two distinct values.>> this particular calculation is used. The current application is an> unusual conjecture in geometry.>-- majort@cox-internet.comBobby R. Treat ==== Here's two plots, one linear and one not so linear ;)Plot[ {3x+5, x^2}, {x, -10, 10} ]And I want to know the intersection points of the two expressions.Is there a simple way to do this, and is it extensible to three or fourexpressions? ==== Here another, perhaps surprising solution, which works, if the the elementsof the list are symbols (as in Steve's example):In[236]:=s = With[{syms = Table[Unique[s], {100}]}, Table[syms[LeftDoubleBracket] Random[Integer, {1, 100}][RightDoubleBracket], {10000}]]; In[237]:=(bob4 = Block[{count}, count[any_] := 0; Range@Length@s - Map[++count[#] &, s]]); // TimingOut[237]= {0.541 Second, Null} In[238]:=(hw6 = Block[#2, Scan[(#1 = 0) &, #2]; Range[0, Length[#1] - 1] - Function[{sym}, sym++, {HoldFirst}] /@ Unevaluated[#1] ] &[s, Union[s]]); // TimingOut[238]= {0.23 Second, Null}In[239]:= hw6 === bob4Out[239]= True--Hartmut Wolf-----Urspr.9fngliche Nachricht-----Gesendet: Samstag, 29. M.8arz 2003 11:20An: mathgroup@smc.vnet.netBetreff: Need a nice way to do this Given a list consisting of only two distinct values, such ass={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal lengthg={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position1<=p<=Length[s], look at list s and set g[[p]] to the number ofelements in s to the left of p which are not equal to s[[p]]. In a more general version, which I do not need now, s wouldnot be restricted to only two distinct values.this particular calculation is used. The current application is anunusual conjecture in geometry. ==== I sincerely appreciate past comments I have receivedregarding my last post.( thank you Dr. Hollis) Frankly though, myself being a biology grad student,this task, which might take a mathematician or aprogrammer a day's work, has taken large part of pastthree weeks. So I would like to share with you all a problem Ihave. and hopefully some of you will be helpful tosuggest the next course of action. Please do consider with me, the diffusion equation inthe form of D[u, t] == D[u, x, x]( from the helpbrowser).Now also consider the following solution that is givenwhich does wonderfully to plot and show the behaviourthat particular equation over the range of x and tgiven. In[143]:=Clear[c, x, t, u, xmax, xmin, nbins, npoints, dx];u = y[x, t];v6 = NDSolve[{D[u, t] == D[u, x, x], y[x, 0] == If[Abs[x] < 2.99, E^(-x^2), 0],y[-10, t] == 0, y[10, t] == 0}, y, {x, -10, 10}, {t, 0, 20}]Plot3D[ Evaluate[y[x, t] /. v6 [[1]]], {x, -10, 10},{t, 0, 20}, PlotPoints -> 30, PlotRange -> {0, 1}]which gives the correct output along with a plot, Out[145]={{y -> InterpolatingFunction[{{-10., 10.}, {0., 20.}},<>]}}now please consider my attempt( and incorrectapparently) at the discretization of the second orderspatial derivative as follows... In[226]:=Clear[c, x, t, u, xmax, xmin, nbins, npoints, dx];c = .1;eq1 = D[u, t] == D[u, x, x];xmin = -3; xmax = 3; nbins = 2; npoints = nbins + 1;dx = Abs[(xmax - xmin)/(nbins)];eq2 = Table[ D[y[i][t], t] == (y[i + 1][t] - 2y[i][t] + y[i -1][t])/(dx^2) + c y[i][t]^2 - c y[i][t], {i, 1, nbins}];ic = Table[ y[i][0] == N[E^(-x^2) /. {x -> xmin + (i -1)(xmax - xmin)/nbins}], {i, 1, nbins}];vbls = Table[y[i][t], {i, 1, nbins}];list = Join[eq2, ic];NDSolve[list, vbls, {t, 0, 20}]which then gives the errorneous output of, going on. And not much good that has done. If anyone out there has a way or an idea to try inorder for me to get a plot that is similar to theoriginal solution that is given in the help browser, Iwould be most appreciative in hearing about it. any and all comments are welcome. thank you all very much in advance, (I didn't want tochoice. ) john __________________________________________________Do you Yahoo!?Yahoo! Tax Center - File online, calculators, forms, and morehttp://platinum.yahoo.com ==== >-----Original Message----->Sent: Sunday, March 30, 2003 11:08 AM>To: mathgroup@smc.vnet.net>>I am a researcher in Artificial Intelligence and I have a >question about>generating random permutation of a set of numbers.>More formal definition:>Given a set of N numbers S = {n1, ., nn}>how to efficiently and accurately generate P(S) = random_permutation(S)>Ex: S = {3,4,12}, P(S) should have a probability equals to >1/3! = 1/6 to>return one of the following permutations:>{(3,4,12)(3,12,4)(4,3,12)(4,12,3)(12,3,4)( 12,4,3)}>and a complexity equals to O(N).>and>how to efficiently generate an iterator on the numbers which will be>returned by P(S) ?>Ex: S = {3,4,12} P(S) can return any of the permutations described>below, but what we want here is to get an iterator on the >future numbers >without creating the full permutation >Do you know any algorithm performing this task which is very efficient>in terms of quality (each permutation has the same probability to be >generated) and in terms of complexity (minimal number of operations>is necessary to perform this operation n2, n, log n, etc.).>If you have any clue or web links where I can find this information, >this would be very much appreciated.>The problem with that question are the conßicting goals of correctness,performance and asymptotc behavior. The right answer depends on what youwant to do.In Mathematica there are two packages:In[1]:= << DiscreteMath`Permutations`In[2]:= RandomPermutation[13070]; // TimingOut[2]= {0.501 Second, Null}In[3]:= Quit[]And also In[1]:= << DiscreteMath`Combinatorica`In[2]:= RandomPermutation1[13070]; // TimingOut[2]= {0.42 Second, Null}In[3]:= RandomPermutation2[13070]; // TimingOut[3]= {1.132 Second, Null}In[6]:= Quit[]The fastest algorithm, I know of is this:In[1]:=permutation[n_Integer?NonNegative] := Ordering[Array[Random[] &, {n}]]In[2]:= permutation[13070]; // TimingOut[2]= {0.04 Second, Null}In[3]:= Quit[]Depending on your problem, you may be happy with this. It is howeversomewhat ßawed, as well as RandomPermutation and RandomPermutation1: If thesame random reals are hit twice (improbable, though possible) the Sort orOrdering will not give these two in random order. Now it depends on what ismore important: this rather seldom incidence or performance. You may try toeliminate the problem, by checking e.g. with Split. A penalty has to bepaid, of course:In[1]:= permutation2[n_Integer?NonNegative] := Block[{ra = Array[Random[] &, {n}], ord}, If[Times @@ Length /@ Split[ra[[ord = Ordering[ra]]]] === 1, ord, permutation2[n]]]In[2]:= permutation2[13070]; // TimingOut[2]= {0.18 Second, Null}In[3]:= Quit[](Of course this discussion also questions the quality of the random numbergenerator behind, such that this improvement may become nonsense for otherreasons.)The asymptotic behaviour of these algorithms is O[n log n], i.e. good forall practical purposes.Another point is whether is is senseful to have an iterator to spit out theelements of the random permutation one by one. Im Mathematica I'd say no,list operation is faster, however (and depending on your real problem) inC++ things might become different. Here is an iterator for Mathematica: In[1]:=makeRPI /: Set[lhs_, makeRPI[n_]] := (lhs = makeRPI0[n];)In[2]:= makeRPI0[n_Integer?Positive] := Module[{r = Range[n], nr = n, x}, If[nr === 0, {}, {x, r} = Through[{Part, Delete}[r, Random[Integer, {1, nr--}]]]; x]&]In[3]:= it = makeRPI[5]In[4]:= Table[it[], {6}]Out[4]= {1, 5, 4, 2, 3, {}}In[5]:=(it2 = makeRPI[13070]; Table[it2[], {13070}];) // TimingOut[5]= {68.819 Second, Null}In[6]:= Quit[]This algorithm for each step draws at random from a bag of Integers. TheProblem with this one is the Delete-ing of the integer drawn: this makes itsbehaviour as O[n^2].Instead of deleting, we just loose the integer drawn out of sight from thewindow of interest, our bag now just being the rest of an initial list ofintegers to be mapped over (the integer not drawn is moved into the positionof the integer drawn):In[1]:=randperm2[n_] := Module[{deck = Range[n], s, j}, MapIndexed[(s = deck[[j = #1 + First[#2] - 1]]; deck[[j]] = deck[[First[#2]]]; s) &, Reverse[Table[Random[Integer, {1, i}], {i, n}]]]]In[2]:= randperm2[5]Out[2]= {2, 5, 3, 4, 1}In[3]:= randperm2[13070]; // TimingOut[3]= {1.252 Second, Null}In[4]:= Quit[]community by Daniel Lichtblau (search the archive), which can be compiled: In[1]:=randperm = Compile[{{n, _Integer}}, Module[ {deck = Range[n], newj}, Do[ newj = Random[Integer, {j, n}]; deck[[{j, newj}]] = deck[[{newj, j}]], {j, n - 1}]; deck ]] ;In[2]:= randperm[5]Out[2]= {4, 3, 2, 1, 5}In[3]:= randperm[13070]; // TimingOut[3]= {0.21 Second, Null}(RandomPermutation2 from the Package DiscreteMath`Combinatorica` is quitesimilar, however not coded as effectively and not compiled.)--Hartmut Wolf ==== Can anyone have a Mathematic-a program which can solve the Cubic Spline?I have no time to solve this by myself.URGENT!!!kusan@EUnet.yuReply-To: kuska@informatik.uni-leipzig.de ==== Hi,<< Graphics`PlotField`PlotVectorField[ {x, Sin[x - y]}, {x, -5, 5}, {y, -5, 5}, PlotPoints -> 30, ColorFunction -> Hue, ScaleFunction -> (.25# &), ScaleFactor -> None ] Jens> Hi, I am trying to plot a directional field plot for the DE> y'=sin(x-y). The question suggests using a viewing window such as> -10=x=10, -10=y=10 I have spent hours and hours trying to get this to> work, but I must be doing something wrong. Can anyone please, please> help me with typing the right commands? ==== Seehttp://forums.wolfram.com/mathgroup/archive/ 2003/Mar/msg00518.html-----Selwyn Hollishttp://www.math.armstrong.edu/faculty/hollis> Hi, I am trying to plot a directional field plot for the DE> y'=sin(x-y). The question suggests using a viewing window such as> -10=x=10, -10=y=10 I have spent hours and hours trying to get this to> work, but I must be doing something wrong. Can anyone please, please> help me with typing the right commands?>> ==== Freddy,We have dy/dx == Sin[x-y] or dy == Sin[x-y]dx. So our slope field is {dx,dy}== {dx,Sin[x-y]dx} == dx{1,Sin[x-y]}. Take dx == 1 and the vector fieldis...field[x_, y_] := {1, Sin[x - y]}We can then plot with...Needs[Graphics`PlotField`]Needs[Graphics`Colors`] PlotVectorField[field[x, y], {x, -Pi, Pi}, {y, -Pi, Pi}, Frame -> True, FrameLabel -> {x, y}, PlotLabel -> y'[x] == Sin[x - y], Axes -> True, AxesStyle -> LightBlue, Background -> Linen, ImageSize -> 500];David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== The replies have been beautiful!suppose I have a list of n {x,y}pairs. I'd like to cull the list into asmaller list for which the condition xYo is true. If the list was1-D I could simply use Select, how do I access the data points in pairs?Nathan MooreUniversoty of Minnesota Physics ==== I'd like to throw this out as a challenge to the group: What's the most efficient way to implement in Mathematica an explicit multistep iterative method such as, say, the 4-step Adams-Bashforth method for solving y' = f(t,y):y[k+1]:= y[k] + (h/24)*(55*f[k] - 59*f[k-1] + 37*f[k-2] - 9*f[k-3])where y[0], y[1], y[2], y[3] are given, and f[i] denotes f[t0 +i*h, y[i]]. The desired output would be the list{y[0], y[1], y[2], ... , y[n]}.A suitable toy problem isy' = -2t*y^2, y(0) = 1,with h = 0.01, n = 1000 (?), and the starting values taken from the exact solution y = 1/(1+t^2):y[0]=1, y[1] = 0.9999, y[2] = 0.9996, y[3] = .999101.-------Selwyn HollisReply-To: majort@cox-internet.com ==== Here's a timing for that:n = 10000;test = Array[Random[Integer] &, n];Timing[drbob[test];]Timing[drbob2[test];]Timing[drbob3[ test];]Timing[drbob4[test];]Timing[andrzej2[test];]Timing[ deLouis[test];]{0.0779999999999994*Second, Null}{0.125*Second, Null}{0.125*Second, Null}{0.0940000000000003*Second, Null}{0.06299999999999972*Second, Null}{0.8120000000000003*Second, Null}and another:n = 10000;test = Array[Round[20Random[]] &, n];Timing[drbob[test];]Timing[drbob2[test];]Timing[drbob3[ test];]Timing[drbob4[test];]Timing[deLouis[test];]{ 0.07800000000000029*Second, Null}{0.125*Second, Null}{0.14000000000000057*Second, Null}{0.0940000000000003*Second, Null}{0.391*Second, Null}BobbyOn Mon, 31 Mar 2003 04:01:08 -0500 (EST), Dana DeLouis > I'm new at this, but I'll take a shot:>> s = {a, b, b, a, a, a, b, a, b, a, a};>> Table[j - Count[Take[s, j], s[[j]]], {j, Length[s]}]>> {0, 1, 1, 2, 2, 2, 4, 3, 5, 4, 4}>-- majort@cox-internet.comBobby R. TreatReply-To: majort@cox-internet.com ==== Here are timings for that, with a slight modification:kuska2[lst_] := Module[{l, i, symbs = Union@lst}, Map[(i = 0; l[#1] = Map[Function[{x}, If[x =!= #1, i++, i]], lst]) &, symbs]; MapIndexed[l[#][[First[#2]]] &, lst]]n = 10000;test = Array[Random[Integer] &, n];Timing[drbob[test];]Timing[drbob2[test];]Timing[drbob3[ test];]Timing[drbob4[test];]Timing[andrzej2[test];]Timing[ kuska2[test];]{0.078 Second,Null}{0.141 Second,Null}{0.141 Second,Null}{0.078 Second,Null}{0.047 Second,Null}{0.141 Second,Null}n = 10000;test = Array[Round[20Random[]] &, n];Timing[drbob[test];]Timing[drbob2[test];]Timing[drbob3[ test];]Timing[drbob4[test];]Timing[kuska2[test];]{0.063 Second,Null}{0.156 Second,Null}{0.141 Second,Null}{0.062 Second,Null}{1.219 Second,Null}n = 10000;test = Array[Round[99Random[]] &, n];Timing[fisher[test];]Timing[selwyn2[test];]Timing[drbob[ test];]Timing[drbob2[test];]Timing[drbob3[test];]Timing[ drbob4[test];]Timing[kuska2[test];]{2.188 Second,Null}{0.703 Second,Null}{0.109 Second,Null}{0.157 Second,Null}{0.156 Second,Null}{0.094 Second,Null}{5.64 Second,Null}BobbyOn Mon, 31 Mar 2003 04:01:23 -0500 (EST), Jens-Peer Kuska > Hi,>> UnequalLeft[lst_, symbs_] := Module[{l, i},> Map[> (i = 0; l[#1] = Map[Function[{x}, If[x =!= #1, i++, i]] , lst]) &, > symbs];> MapIndexed[l[#][[First[#2]]] &, lst]> ]>> and call it with>> UnequalLeft[s, {a, b}]>> Jens> Given a list consisting of only two distinct values, such as>> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length>> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position>> 1<=p<=Length[s], look at list s and set g[[p]] to the number of>> elements in s to the left of p which are not equal to s[[p]].>> In a more general version, which I do not need now, s would>> not be restricted to only two distinct values.>> this particular calculation is used. The current application is an>> unusual conjecture in geometry.>>-- majort@cox-internet.comBobby R. TreatReply-To: kuska@informatik.uni-leipzig.de ==== Hi,> But to be honest: Isn't it a torture trying to understand the how does it> work of a oneliner written by some else?If it was hard to program, it should be hard to understand ...> Is it useful to use //TreeForm to visualize the inner structure of a> oneliner (where is the inner beginning)No, it is useful to split up the nested function calls an to seewhat every step does.> The vast majority of oneliners presented here lack on comments.A one-liner with comments is longer than one line and is nota one-liner any more.> Despite of> the wonderful constructs, is this good programming style?hmmReal Programmers don't need comments-- the code is obvious.it is stil an open task to rewrite http://www.pbm.com/~lindahl/real.programmers.htmlfor Mathematica programmers.It is a question of you personal style, how many commentsyou need to understand the code in 2-3 years.In the most cases the authors have no idea how skilled isthe questioner. If the questioner does not understand theanswer, he can ask again or he can try to understand thesolution by its own and learn a lot ...If you look on the threads with one-liners, it is seldom,that the questioner ask back for an explanation.In the most cases the regulars in the group start adiscussion how can the code be optimized orwhich one-liner is the faster. So, it seems, thatthere is a little need for larger comments. Jens ==== As to ... no comments .... I believe this might trace to a Mathematica culturethat the code itself is a direct statement of what it does, and so inmost cases comments wouldn't really clarify things unless you can't readthe Mathematica directly. Wolfram himself mentions this in NKS, and themathematica book says it someplace too, I believe.So, the only comments you'd tend to find is where the behavior of thealgorithm wasn't clear even when the Mathematica code was completely understood. One liners tend to not have that property.For example, you wouldn't find a comment like Iterate over the listselecting each element greater than 5 then sum the selected elements inthe Mathematica culture.> Hallo dear community,> I don't know whether this topic has been discussed ever since before.> I like those socalled Oneliners to solve this or that problem. It shows> up, how elegant and effective the Mathematica language can be.> But to be honest: Isn't it a torture trying to understand the how does it> work of a oneliner written by some else?> Is it useful to use //TreeForm to visualize the inner structure of a> oneliner (where is the inner beginning)> The vast majority of oneliners presented here lack on comments. Despite of> the wonderful constructs, is this good programming style?> I'm looking forward to the next oneliner !> Oliver Friedrich ==== This is what I tried:ani = Table[ plottrees1[har, 80, {{15}, {14}, {12}, {10}, {9}, {8}}],{har, 0.005, 0.14,0.01}]; plottrees1[] is a module that produces a plot as you might expect, thegraphics array ani was produced in good orderthen I did:Export[D:trees.gif, ani, ConversionOptions -> {Loop -> True,AnimationDisplayTime -> .1}];Export:: type : ({Null, Null, Null, Null, Null, Null, Null, Null, Null,Null}) cannot be exported to the GIF format.What is the probable cause for this? I suspect that I have e.g. an emptyline somewhere I can not find it and it does not appear while plotting.Is there something else that one might expect to cause this?Peter W ==== Steve,You're not alone. The things you're asking about are the kind of voodoo that most of us have experienced while reaching a beneficial working relationship with the beast. Mathematica does do seemingly strange and nonsensical things at times; however there is almost always a simple cause/explanation, *if* you can manage to isolate the problem sufficiently. (That's the hard part, and often it's not worth the trouble.) I've found that you just have to be persistent and use good trouble-shooting methods, and unfortunately the documentation doesn't help much with the gory details.Re your questions/observations,1. Remove Options-Recursive is indispensable and can often bail you out of a mess... but sometimes it doesn't work. Occasionally a stubborn option just won't go away. At this point beware; save your work, because if you select and try to delete the stubborn expression, you're likely to crash. A fall-back plan is to use Show Expression and try to make sense of the underlying code. Once you get fairly good at that, you can sometimes edit your way out of a mess.2. I wish I knew, too.3. Are you viewing in the PrintOut Screen Style Environment? (See the Format menu.)4. The only way to get a better handle on it is to use it to do real work. Catch-22?5. A book about publishing with the Mathematica front end is much needed. But until there is one, we have MathGroup :)-----Selwyn Hollishttp://www.math.armstrong.edu/faculty/hollis>> I have some questions.>> 1. I found that certain cells were not editable even though> Cell > Edit was true. Someone who knows far more than I suggested> doing Format > Remove Options > Recursive. This worked, to my relief,> but where was I supposed to find this obscure fix? There doesn't seem> to be anything in the Big Book index under Cell that's relevant. (And> many thanks to whoever suggested that.)>> 2. When I do Copy/Paste, sometimes the expression (which is> usually output from a calculation) is pasted in with the pure ASCII> form, having lots of slashes and quotes, and sometimes it pastes in> just like it looked when I copied it. The latter is what I want. What> makes it vary this way and how do I always get the proper-looking> format?>> 3. I rarely print from Mathematica, but today when I printed a page of> output that had been copied and pasted, some of the print came out a> different size from other print, where they looked identical on the> screen. When I changed the point size of the cells, the printout was> unaffected. This surprised me and right now I don't know how to get> proper printing (looking exactly like it does on the screen).>> 4. Observation 1: I find the mathematical part of Mathematica much> easier to deal with, and much more predicatble, than the parts having> to do with formats, printing, copying/pasting, etc. Unless I get a> better handle on this, I would never use it for final printing or> presentation.>> 5. Observation 2: I frequently can't find answers to my> questions in the documentation. For example, the above questions seem> to have no answers in the material I have. (I have the usual Wolfram> material but only one small third-party book. Is there one that would> help a lot?)> Steve Gray>> ==== I am given a set of four ordered pairs of formulae of six variables (thisis displayed as version 3 Mathematica text, so copy and pasteit to StandardForm for a better display) as follows (you may or may notprefer to look at the 4 ordered pairs using MatrixForm):!(ListForm[{{{{(((((-b) g + f h)) ((a b - h^2)) (((-a) +b + @(((a - b))^2 + 4 h^2))) + @2 @((-(((-a) b h + h^3))^2) ((a (((-b) c + f^2)) + b g^2 + h (((-2) f g + c h))))(((-a) + b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b +h^2))^2 (((-a) + b + @(((a - b))^2 + 4 h^2)))))}, {(a f - g h)/((-a) b + h^2) + @((-(((-a) b h + h^3))^2) ((a(((-b) c + f^2)) + b g^2 + h (((-2) f g + c h)))) (((-a) + b +@(((a - b))^2 + 4 h^2))))/(@2 h (((-a) b +h^2))^2)}}}, {{{(((-((b g - f h))) ((a b - h^2)) (((-a) + b + @(((a -b))^2 + 4 h^2))) - @2 @((-(((-a) b h + h^3))^2) ((a(((-b) c + f^2)) + b g^2 + h (((-2) f g + c h)))) (((-a)+ b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b + h^2))^2(((-a) + b + @(((a - b))^2 + 4 h^2)))))}, {(-((2 h (((-a) f +g h)) (((-a) b + h^2)) + @2 @((-(((-a) b h + h^3))^2)((a (((-b) c + f^2)) + b g^2 + h (((-2) f g + c h)))) (((-a) + b + @(((a - b))^2 + 4 h^2)))))/(2 h (((-a) b + h^2))^2)))}}}, {{{(((-((b g - f h))) ((a b - h^2)) ((a - b + @(((a - b))^2 + 4 h^2))) - @2 @((((-a) b h + h^3))^2((a (((-b) c + f^2)) + b g^2 + h (((-2) f g + c h))))((a - b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b + h^2))^2((a - b + @(((a - b))^2 + 4 h^2)))))}, {(a f - g h)/((-a)b + h^2) + @((((-a) b h + h^3))^2 ((a (((-b) c + f^2)) +b g^2 + h (((-2) f g + c h)))) ((a - b + @(((a - b))^2 + 4h^2))))/(@2 h (((-a) b + h^2))^2)}}}, {{{(((((-b) g + f h)) ((a b - h^2)) ((a - b + @(((a - b))^2 + 4 h^2))) + @2 @((((-a) b h + h^3))^2 ((a (((-b) c + f^2)) + b g^2+ h (((-2) f g + c h)))) ((a - b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b + h^2))^2 ((a - b + @(((a - b))^2 + 4 h^2)))))}, {(-((2 h (((-a) f + g h)) (((-a) b + h^2)) + @2 @((((-a) b h + h^3))^2 ((a (((-b) c + f^2)) + b g^2+ h (((-2) f g + c h)))) ((a - b + @(((a - b))^2 + 4 h^2)))))/(2 h (((-a) b + h^2))^2)))}}}}])I refer to the six variables as a (complex valued) sectuple, withinteresting cases usually occurring with real values, and such that eachof:i) hh-ab=/=0 (Cases interested in: replace Ô=/=' with Ô<', Ô>',respectively),ii) (abc-2fgh-aff-bgg-chh)/(ab-hh)=/=0 (Cases interested in: replace Ô=/='with Ô<', Ô>', respectively),and,iii) a=/=b (Cases interested in: replace Ô=/=' with Ô<', Ô>', respectively)occur (ie, cases i, ii, iii hold simultaneously, but the subcases can (andmight need to) be broken down further).I would like to get the equations into the following form, but alsorespecting the complex-valued arithmetic (so that when I laterdefine the second as a general sectuple function, it should produce somereal and some complex values when assigned real-valued sectuples):!(* RowBox[{(, GridBox[{ { TagBox[ RowBox[{(, GridBox[{ {(@(Abs[[Zeta]]/2) @Abs[((a - b + Abs[@(((a- b))^2 + 4 h^2)]))]/((a b - h^2)) + [Alpha])}, {((@(Abs[[Zeta]]/2)) @Abs[((b - a +Abs[@(((a - b))^2 + 4 h^2)]))]/((a b - h^2)) + [Beta])} }], )}], (MatrixForm[ #]&)]}, { TagBox[ RowBox[{(, GridBox[{ {((@(Abs[[Zeta]]/2) @Abs[((a - b + Abs[@(((a -b))^2 + 4 h^2)]))])/(((-a) b + h^2)) + [Alpha])}, {((-((@(Abs[[Zeta]]/2) @Abs[((b - a + Abs[@(((a - b))^2 + 4 h^2)]))])/(((-a) b + h^2)))) -[Beta])} }], )}], (MatrixForm[ #]&)]}, { TagBox[ RowBox[{(, GridBox[{ {((-@((Abs[[Zeta]] )/2)) @Abs[(((-a) + b +Abs[@(((a - b))^2 + 4 h^2)]))]/(((-a) b + h^2)) +[Alpha])}, {(@((Abs[[Zeta]] )/2) @Abs[(-((a - b + Abs[@(((a - b))^2 + 4 h^2)])))]/(((-a) b + h^2)) + [Beta])} }], )}], (MatrixForm[ #]&)]}, { TagBox[ RowBox[{(, GridBox[{ {((@(Abs[[Zeta]]/2)) @Abs[(-(((-a) + b + Abs[@(((a - b))^2 + 4 h^2)])))]/(((-a) b + h^2)) + [Alpha])}, {((-@((Abs[[Zeta]] )/2)) @Abs[(-((a - b +Abs[@(((a - b))^2 + 4 h^2)])))]/(((-a) b + h^2)) - [Beta])} }], )}], (MatrixForm[ #]&)]} }], )}])In some cases, when multiplying across square roots, absolute valuearithmetic need be enforced (I would prefer to not introduce trig and exparithmetic rules using exptotrig and trigtoexp). In fact, when running afew tests on these equations, I had found that by changing a few Abssigns on sqrts, that I could reproduce identical results between the twoformulae.So, the main question is then: if Mathematica's root command likes to takea certain parity in computing the nth root (n integer) of value^k, 0k?)? I don'tfully understand how all of the abbreviating rules of Hold, etc can workfor me, and would rather not have to override operator definitions to makethem look too concise - means: be thorough; I don't use pattern matchingrules too often if I can get away with it, mainly since I find this partof the Mathematica book harder to understand. ]I would like to generate a more effecient coding scheme than just writinga few nested for(j,k,l=1 to 2 do (-1^j,k,l)) loops to switch the signswhenever I come across a new formula possibility.The following idea for complex numbers scaled to the unit circle wouldwork in a similar fashion, but for my formulae (but for unscaled numbers):!((tFor[k = 1, k < 30, {a_k := FullSimplify[@(((((1 + I))/@2))^(k/2))%3 ((((-I) - @3)/2))^3], Print[a_k]}, (++k)]))System specifics: Pentium II 350 Mhz, 64 Meg Ram, Window 98, Mathematica3.0, and sometimes get Out of Memory. Exiting. returns when trying tofurther manipulate these and similar formulae. Upgrade ofsoftware/hardware is not an option for me at this time.Kai G. Gauer ==== Hi,DiscreteMath`RSolve` solves univariate recurrence relations.Is there anything equivalent for bivariate recurrence relations?For example, is there a Mathematica package that can deducefrom the equationsf[n,k] == f[n-1,k] + f[n-1,k-1]f[0,0] == 0that f[n,k] -> Binomial[n,k] , for 0<=k<=n ?UriReply-To: rolf@mertig.com ==== Is this what you want?Copyright 1988-2002 Wolfram Research, Inc. -- Motif graphics initialized --In[1]:= !!tayt[n_,p_,q_] := Block[{f, res = 1}, f[i_] = (E^(z*p*(q)^(i - 1)) - 1)*u + 1 + O[z]^(n + 1); Do[res = Expand[Normal[res*f[j]]] + O[z]^(n + 1), {j, 1, n}]; SeriesCoefficient[res, n]];Table[Print[n = ,j, time = , ti[j]=First[Timing[r[j]=t[j,1/2,1/2]]]];ti[j]/Second,{j, 10,50,10}]In[1]:= < Hi,> I have the following function from which I would like to extract the > coefficient of z^{50}, and then expand the result as a series in u:> f[z_,u_] := Product[1 + u (Exp(zpq^{i - 1}) - 1), {i,50}]> where p=q=1/2.> The product from i=1 to 10 can be done in a reasonable amount of time, but > anything larger takes far too long.> Does anyone have an idea of how to expand f[z,u] as a series quickly, or even > to extract the coefficient of z^{50} some other way?> M. Archibald> University of the Witwatersrand ==== > Hi,> I have the following function from which I would like to extract the> coefficient of z^{50}, and then expand the result as a series in u:> f[z_,u_] := Product[1 + u (Exp(zpq^{i - 1}) - 1), {i,50}]> where p=q=1/2.> The product from i=1 to 10 can be done in a reasonable amount of time, but> anything larger takes far too long.> Does anyone have an idea of how to expand f[z,u] as a series quickly, or even> to extract the coefficient of z^{50} some other way?> M. Archibald> University of the WitwatersrandOne method would be to expand by hand subject to a rule that powers ofz higher than 50 get discarded. We employ a few other tactics along theway to reduce the computation time.p = q = 1/2;You did not use Mathematica syntax so I assume the function below iswhat you had in mind.f[z_,u_] := Product[1 + u*(Exp[z*p*q^(i-1)] - 1), {i,50}]We make a list of the factors, and take a power series of each.ll = Apply[List,f[z,u]];ll2 = Series[ll,{z,0,50}];Now we remove the denominator from each series, and convert each to apolynomial. We also record the product of the denominators.denoms = Map[LCM[Apply[Sequence,Denominator[#[[3]]]]]&, ll2];ll3 = ll2 * denoms;ll4 = Normal[ll3];denom = Apply[Times,denoms];We set up a rule that forces powers of z larger than 50 to disappear.z^m_ /; m>50 ^= 0;We are now prepared to expand the product of these polynomials.In[10]:= Timing[poly = Fold[Expand[#1*#2]&, 1, ll4];]Out[10]= {433. Second, Null}The desired coefficient is simplycoeff = Last[CoefficientList[poly,z]] / denomIt is a polynomial in u of degree 50.There may be faster ways to do all this but the approach above seemsreasonable given the size of numbers that appear in the polynomials.Daniel LichtblauWolfram ResearchReply-To: kuska@informatik.uni-leipzig.de ==== Hi,what is withWaitForExternalFile[command_, filename_String, maxCount_Integer, pattern_:*.txt] := Module[{i = 0, found = False}, Run[command]; While[i++ < maxCount, Pause[10]; (* look if the file is created *) found = MemberQ[FileNames[pattern], filename]; If[found, Break[]]; ]; found ]and something likeWaitForExternalFile[EMFIELD.EXE -p1 -p2,Results.txt,10000]should work.Possibly you get a timing problem, when the programhas not finished the file but Mathematica tryto read from an open file.The best way would be to write a MathLink programthat return the result to the kernel. Jens> Hi,> I'd like to use Mathematica to run an extermal program,> let me say EMFIELD.EXE with some parameters p1 , p2 :> Run[EMFIELD.EXE -p1 -p2]> The external program put results in the ascii file Results.txt> (a filename that I can change every time).> Then I read results from it with> ReadList[Results.txt, Number,...]> After an analysis of them inside the same session of Mathematica,> I modify the parameters p1, p2 and run again the external program.> And so on for many times until analysis is OK.> Since EMFIELD may take seconds or hours to generate the results,> depending on the complexity of the problem and the values of parameters,> how can I tell Mathematica to wait until the Results.txt file is> created or updated? Pause[n] would be fine if I knew n, but this is> not the case and putting a guessed large n is a poor solution> (offending Mathematica lovers!).> Many thanks, Roberto> Roberto Brambilla> CESI> Via Rubattino 54> 20134 Milano> tel +39.02.2125.5875> fax +39.02.2125.5492> rlbrambilla@cesi.it ==== when the file is created or modified the While ends and your commands areexecuted. If the file is not ready you can use a TimeConstrained Pause torelease your CPU while it waits. These are just a few hints, I have solveda similar problem in this way so I know you can find a way around yourproblem by heading this directions.-----Original Message-----After an analysis of them inside the same session of Mathematica,I modify the parameters p1, p2 and run again the external program.And so on for many times until analysis is OK.Since EMFIELD may take seconds or hours to generate the results,depending on the complexity of the problem and the values of parameters,how can I tell Mathematica to wait until the Results.txt file iscreated or updated? Pause[n] would be fine if I knew n, but this isnot the case and putting a guessed large n is a poor solution(offending Mathematica lovers!).Many thanks, RobertoRoberto BrambillaCESIVia Rubattino 5420134 Milanotel +39.02.2125.5875fax +39.02.2125.5492rlbrambilla@cesi.it ==== Begin by setting the proper directory:SetDirectory[C:mydir]Then evaluate the following:If[FileNames[Results.txt]==={}, (* if the file initially does not exist, check whether it exists *) check:=FileNames[Results.txt]==={}, (* otherwise, check whether the modification date has changed *) ]];Run[EMFIELD.EXE -p1 -p2];(* check every 30 sec whether the file is ready *)While[check,Pause[30]];The While loop will exit when the job is done.Adjust the 30 seconds interval to appropriate value.Orestis> Hi,> I'd like to use Mathematica to run an extermal program,> let me say EMFIELD.EXE with some parameters p1 , p2 :> Run[EMFIELD.EXE -p1 -p2]> The external program put results in the ascii file Results.txt> (a filename that I can change every time).> Then I read results from it with > ReadList[Results.txt, Number,...]> After an analysis of them inside the same session of Mathematica,> I modify the parameters p1, p2 and run again the external program.> And so on for many times until analysis is OK.> Since EMFIELD may take seconds or hours to generate the results,> depending on the complexity of the problem and the values of parameters,> how can I tell Mathematica to wait until the Results.txt file is> created or updated? Pause[n] would be fine if I knew n, but this is> not the case and putting a guessed large n is a poor solution> (offending Mathematica lovers!).> Many thanks, Roberto> Roberto Brambilla> CESI> Via Rubattino 54> 20134 Milano> tel +39.02.2125.5875> fax +39.02.2125.5492> rlbrambilla@cesi.it ==== Steve,You're not alone. The things you're asking about are the kind of voodoo that most of us have experienced while reaching a beneficial working relationship with the beast. Mathematica does do seemingly strange and nonsensical things at times; however there is almost always a simple cause/explanation, *if* you can manage to isolate the problem sufficiently. (That's the hard part, and often it's not worth the trouble.) I've found that you just have to be persistent and use good trouble-shooting methods, and unfortunately the documentation doesn't help much with the gory details.Re your questions/observations,1. Remove Options-Recursive is indispensable and can often bail you out of a mess... but sometimes it doesn't work. Occasionally a stubborn option just won't go away. At this point beware; save your work, because if you select and try to delete the stubborn expression, you're likely to crash. A fall-back plan is to use Show Expression and try to make sense of the underlying code. Once you get fairly good at that, you can sometimes edit your way out of a mess.2. I wish I knew, too.3. Are you viewing in the PrintOut Screen Style Environment? (See the Format menu.)4. The only way to get a better handle on it is to use it to do real work. Catch-22?5. A book about publishing with the Mathematica front end is much needed. But until there is one, we have MathGroup :)-----Selwyn Hollishttp://www.math.armstrong.edu/faculty/hollis>> I have some questions.>> 1. I found that certain cells were not editable even though> Cell > Edit was true. Someone who knows far more than I suggested> doing Format > Remove Options > Recursive. This worked, to my relief,> but where was I supposed to find this obscure fix? There doesn't seem> to be anything in the Big Book index under Cell that's relevant. (And> many thanks to whoever suggested that.)>> 2. When I do Copy/Paste, sometimes the expression (which is> usually output from a calculation) is pasted in with the pure ASCII> form, having lots of slashes and quotes, and sometimes it pastes in> just like it looked when I copied it. The latter is what I want. What> makes it vary this way and how do I always get the proper-looking> format?>> 3. I rarely print from Mathematica, but today when I printed a page of> output that had been copied and pasted, some of the print came out a> different size from other print, where they looked identical on the> screen. When I changed the point size of the cells, the printout was> unaffected. This surprised me and right now I don't know how to get> proper printing (looking exactly like it does on the screen).>> 4. Observation 1: I find the mathematical part of Mathematica much> easier to deal with, and much more predicatble, than the parts having> to do with formats, printing, copying/pasting, etc. Unless I get a> better handle on this, I would never use it for final printing or> presentation.>> 5. Observation 2: I frequently can't find answers to my> questions in the documentation. For example, the above questions seem> to have no answers in the material I have. (I have the usual Wolfram> material but only one small third-party book. Is there one that would> help a lot?)> Steve Gray>> ==== I am given a set of four ordered pairs of formulae of six variables (thisis displayed as version 3 Mathematica text, so copy and pasteit to StandardForm for a better display) as follows (you may or may notprefer to look at the 4 ordered pairs using MatrixForm):!(ListForm[{{{{(((((-b) g + f h)) ((a b - h^2)) (((-a) +b + @(((a - b))^2 + 4 h^2))) + @2 @((-(((-a) b h + h^3))^2) ((a (((-b) c + f^2)) + b g^2 + h (((-2) f g + c h))))(((-a) + b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b +h^2))^2 (((-a) + b + @(((a - b))^2 + 4 h^2)))))}, {(a f - g h)/((-a) b + h^2) + @((-(((-a) b h + h^3))^2) ((a(((-b) c + f^2)) + b g^2 + h (((-2) f g + c h)))) (((-a) + b +@(((a - b))^2 + 4 h^2))))/(@2 h (((-a) b +h^2))^2)}}}, {{{(((-((b g - f h))) ((a b - h^2)) (((-a) + b + @(((a -b))^2 + 4 h^2))) - @2 @((-(((-a) b h + h^3))^2) ((a(((-b) c + f^2)) + b g^2 + h (((-2) f g + c h)))) (((-a)+ b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b + h^2))^2(((-a) + b + @(((a - b))^2 + 4 h^2)))))}, {(-((2 h (((-a) f +g h)) (((-a) b + h^2)) + @2 @((-(((-a) b h + h^3))^2)((a (((-b) c + f^2)) + b g^2 + h (((-2) f g + c h)))) (((-a) + b + @(((a - b))^2 + 4 h^2)))))/(2 h (((-a) b + h^2))^2)))}}}, {{{(((-((b g - f h))) ((a b - h^2)) ((a - b + @(((a - b))^2 + 4 h^2))) - @2 @((((-a) b h + h^3))^2((a (((-b) c + f^2)) + b g^2 + h (((-2) f g + c h))))((a - b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b + h^2))^2((a - b + @(((a - b))^2 + 4 h^2)))))}, {(a f - g h)/((-a)b + h^2) + @((((-a) b h + h^3))^2 ((a (((-b) c + f^2)) +b g^2 + h (((-2) f g + c h)))) ((a - b + @(((a - b))^2 + 4h^2))))/(@2 h (((-a) b + h^2))^2)}}}, {{{(((((-b) g + f h)) ((a b - h^2)) ((a - b + @(((a - b))^2 + 4 h^2))) + @2 @((((-a) b h + h^3))^2 ((a (((-b) c + f^2)) + b g^2+ h (((-2) f g + c h)))) ((a - b + @(((a - b))^2 + 4 h^2))))))/(((((-a) b + h^2))^2 ((a - b + @(((a - b))^2 + 4 h^2)))))}, {(-((2 h (((-a) f + g h)) (((-a) b + h^2)) + @2 @((((-a) b h + h^3))^2 ((a (((-b) c + f^2)) + b g^2+ h (((-2) f g + c h)))) ((a - b + @(((a - b))^2 + 4 h^2)))))/(2 h (((-a) b + h^2))^2)))}}}}])I refer to the six variables as a (complex valued) sectuple, withinteresting cases usually occurring with real values, and such that eachof:i) hh-ab=/=0 (Cases interested in: replace Ô=/=' with Ô<', Ô>',respectively),ii) (abc-2fgh-aff-bgg-chh)/(ab-hh)=/=0 (Cases interested in: replace Ô=/='with Ô<', Ô>', respectively),and,iii) a=/=b (Cases interested in: replace Ô=/=' with Ô<', Ô>', respectively)occur (ie, cases i, ii, iii hold simultaneously, but the subcases can (andmight need to) be broken down further).I would like to get the equations into the following form, but alsorespecting the complex-valued arithmetic (so that when I laterdefine the second as a general sectuple function, it should produce somereal and some complex values when assigned real-valued sectuples):!(* RowBox[{(, GridBox[{ { TagBox[ RowBox[{(, GridBox[{ {(@(Abs[[Zeta]]/2) @Abs[((a - b + Abs[@(((a- b))^2 + 4 h^2)]))]/((a b - h^2)) + [Alpha])}, {((@(Abs[[Zeta]]/2)) @Abs[((b - a +Abs[@(((a - b))^2 + 4 h^2)]))]/((a b - h^2)) + [Beta])} }], )}], (MatrixForm[ #]&)]}, { TagBox[ RowBox[{(, GridBox[{ {((@(Abs[[Zeta]]/2) @Abs[((a - b + Abs[@(((a -b))^2 + 4 h^2)]))])/(((-a) b + h^2)) + [Alpha])}, {((-((@(Abs[[Zeta]]/2) @Abs[((b - a + Abs[@(((a - b))^2 + 4 h^2)]))])/(((-a) b + h^2)))) -[Beta])} }], )}], (MatrixForm[ #]&)]}, { TagBox[ RowBox[{(, GridBox[{ {((-@((Abs[[Zeta]] )/2)) @Abs[(((-a) + b +Abs[@(((a - b))^2 + 4 h^2)]))]/(((-a) b + h^2)) +[Alpha])}, {(@((Abs[[Zeta]] )/2) @Abs[(-((a - b + Abs[@(((a - b))^2 + 4 h^2)])))]/(((-a) b + h^2)) + [Beta])} }], )}], (MatrixForm[ #]&)]}, { TagBox[ RowBox[{(, GridBox[{ {((@(Abs[[Zeta]]/2)) @Abs[(-(((-a) + b + Abs[@(((a - b))^2 + 4 h^2)])))]/(((-a) b + h^2)) + [Alpha])}, {((-@((Abs[[Zeta]] )/2)) @Abs[(-((a - b +Abs[@(((a - b))^2 + 4 h^2)])))]/(((-a) b + h^2)) - [Beta])} }], )}], (MatrixForm[ #]&)]} }], )}])In some cases, when multiplying across square roots, absolute valuearithmetic need be enforced (I would prefer to not introduce trig and exparithmetic rules using exptotrig and trigtoexp). In fact, when running afew tests on these equations, I had found that by changing a few Abssigns on sqrts, that I could reproduce identical results between the twoformulae.So, the main question is then: if Mathematica's root command likes to takea certain parity in computing the nth root (n integer) of value^k, 0k?)? I don'tfully understand how all of the abbreviating rules of Hold, etc can workfor me, and would rather not have to override operator definitions to makethem look too concise - means: be thorough; I don't use pattern matchingrules too often if I can get away with it, mainly since I find this partof the Mathematica book harder to understand. ]I would like to generate a more effecient coding scheme than just writinga few nested for(j,k,l=1 to 2 do (-1^j,k,l)) loops to switch the signswhenever I come across a new formula possibility.The following idea for complex numbers scaled to the unit circle wouldwork in a similar fashion, but for my formulae (but for unscaled numbers):!((tFor[k = 1, k < 30, {a_k := FullSimplify[@(((((1 + I))/@2))^(k/2))%3 ((((-I) - @3)/2))^3], Print[a_k]}, (++k)]))System specifics: Pentium II 350 Mhz, 64 Meg Ram, Window 98, Mathematica3.0, and sometimes get Out of Memory. Exiting. returns when trying tofurther manipulate these and similar formulae. Upgrade ofsoftware/hardware is not an option for me at this time.Kai G. Gauer ==== Hi,DiscreteMath`RSolve` solves univariate recurrence relations.Is there anything equivalent for bivariate recurrence relations?For example, is there a Mathematica package that can deducefrom the equationsf[n,k] == f[n-1,k] + f[n-1,k-1]f[0,0] == 0that f[n,k] -> Binomial[n,k] , for 0<=k<=n ?UriReply-To: rolf@mertig.com ==== Is this what you want?Copyright 1988-2002 Wolfram Research, Inc. -- Motif graphics initialized --In[1]:= !!tayt[n_,p_,q_] := Block[{f, res = 1}, f[i_] = (E^(z*p*(q)^(i - 1)) - 1)*u + 1 + O[z]^(n + 1); Do[res = Expand[Normal[res*f[j]]] + O[z]^(n + 1), {j, 1, n}]; SeriesCoefficient[res, n]];Table[Print[n = ,j, time = , ti[j]=First[Timing[r[j]=t[j,1/2,1/2]]]];ti[j]/Second,{j, 10,50,10}]In[1]:= < Hi,> I have the following function from which I would like to extract the > coefficient of z^{50}, and then expand the result as a series in u:> f[z_,u_] := Product[1 + u (Exp(zpq^{i - 1}) - 1), {i,50}]> where p=q=1/2.> The product from i=1 to 10 can be done in a reasonable amount of time, but > anything larger takes far too long.> Does anyone have an idea of how to expand f[z,u] as a series quickly, or even > to extract the coefficient of z^{50} some other way?> M. Archibald> University of the Witwatersrand ==== > Hi,> I have the following function from which I would like to extract the> coefficient of z^{50}, and then expand the result as a series in u:> f[z_,u_] := Product[1 + u (Exp(zpq^{i - 1}) - 1), {i,50}]> where p=q=1/2.> The product from i=1 to 10 can be done in a reasonable amount of time, but> anything larger takes far too long.> Does anyone have an idea of how to expand f[z,u] as a series quickly, or even> to extract the coefficient of z^{50} some other way?> M. Archibald> University of the WitwatersrandOne method would be to expand by hand subject to a rule that powers ofz higher than 50 get discarded. We employ a few other tactics along theway to reduce the computation time.p = q = 1/2;You did not use Mathematica syntax so I assume the function below iswhat you had in mind.f[z_,u_] := Product[1 + u*(Exp[z*p*q^(i-1)] - 1), {i,50}]We make a list of the factors, and take a power series of each.ll = Apply[List,f[z,u]];ll2 = Series[ll,{z,0,50}];Now we remove the denominator from each series, and convert each to apolynomial. We also record the product of the denominators.denoms = Map[LCM[Apply[Sequence,Denominator[#[[3]]]]]&, ll2];ll3 = ll2 * denoms;ll4 = Normal[ll3];denom = Apply[Times,denoms];We set up a rule that forces powers of z larger than 50 to disappear.z^m_ /; m>50 ^= 0;We are now prepared to expand the product of these polynomials.In[10]:= Timing[poly = Fold[Expand[#1*#2]&, 1, ll4];]Out[10]= {433. Second, Null}The desired coefficient is simplycoeff = Last[CoefficientList[poly,z]] / denomIt is a polynomial in u of degree 50.There may be faster ways to do all this but the approach above seemsreasonable given the size of numbers that appear in the polynomials.Daniel LichtblauWolfram ResearchReply-To: kuska@informatik.uni-leipzig.de ==== Hi,what is withWaitForExternalFile[command_, filename_String, maxCount_Integer, pattern_:*.txt] := Module[{i = 0, found = False}, Run[command]; While[i++ < maxCount, Pause[10]; (* look if the file is created *) found = MemberQ[FileNames[pattern], filename]; If[found, Break[]]; ]; found ]and something likeWaitForExternalFile[EMFIELD.EXE -p1 -p2,Results.txt,10000]should work.Possibly you get a timing problem, when the programhas not finished the file but Mathematica tryto read from an open file.The best way would be to write a MathLink programthat return the result to the kernel. Jens> Hi,> I'd like to use Mathematica to run an extermal program,> let me say EMFIELD.EXE with some parameters p1 , p2 :> Run[EMFIELD.EXE -p1 -p2]> The external program put results in the ascii file Results.txt> (a filename that I can change every time).> Then I read results from it with> ReadList[Results.txt, Number,...]> After an analysis of them inside the same session of Mathematica,> I modify the parameters p1, p2 and run again the external program.> And so on for many times until analysis is OK.> Since EMFIELD may take seconds or hours to generate the results,> depending on the complexity of the problem and the values of parameters,> how can I tell Mathematica to wait until the Results.txt file is> created or updated? Pause[n] would be fine if I knew n, but this is> not the case and putting a guessed large n is a poor solution> (offending Mathematica lovers!).> Many thanks, Roberto> Roberto Brambilla> CESI> Via Rubattino 54> 20134 Milano> tel +39.02.2125.5875> fax +39.02.2125.5492> rlbrambilla@cesi.it ==== when the file is created or modified the While ends and your commands areexecuted. If the file is not ready you can use a TimeConstrained Pause torelease your CPU while it waits. These are just a few hints, I have solveda similar problem in this way so I know you can find a way around yourproblem by heading this directions.-----Original Message-----After an analysis of them inside the same session of Mathematica,I modify the parameters p1, p2 and run again the external program.And so on for many times until analysis is OK.Since EMFIELD may take seconds or hours to generate the results,depending on the complexity of the problem and the values of parameters,how can I tell Mathematica to wait until the Results.txt file iscreated or updated? Pause[n] would be fine if I knew n, but this isnot the case and putting a guessed large n is a poor solution(offending Mathematica lovers!).Many thanks, RobertoRoberto BrambillaCESIVia Rubattino 5420134 Milanotel +39.02.2125.5875fax +39.02.2125.5492rlbrambilla@cesi.it ==== Begin by setting the proper directory:SetDirectory[C:mydir]Then evaluate the following:If[FileNames[Results.txt]==={}, (* if the file initially does not exist, check whether it exists *) check:=FileNames[Results.txt]==={}, (* otherwise, check whether the modification date has changed *) ]];Run[EMFIELD.EXE -p1 -p2];(* check every 30 sec whether the file is ready *)While[check,Pause[30]];The While loop will exit when the job is done.Adjust the 30 seconds interval to appropriate value.Orestis> Hi,> I'd like to use Mathematica to run an extermal program,> let me say EMFIELD.EXE with some parameters p1 , p2 :> Run[EMFIELD.EXE -p1 -p2]> The external program put results in the ascii file Results.txt> (a filename that I can change every time).> Then I read results from it with > ReadList[Results.txt, Number,...]> After an analysis of them inside the same session of Mathematica,> I modify the parameters p1, p2 and run again the external program.> And so on for many times until analysis is OK.> Since EMFIELD may take seconds or hours to generate the results,> depending on the complexity of the problem and the values of parameters,> how can I tell Mathematica to wait until the Results.txt file is> created or updated? Pause[n] would be fine if I knew n, but this is> not the case and putting a guessed large n is a poor solution> (offending Mathematica lovers!).> Many thanks, Roberto> Roberto Brambilla> CESI> Via Rubattino 54> 20134 Milano> tel +39.02.2125.5875> fax +39.02.2125.5492> rlbrambilla@cesi.itJason, You can do all this very comfortably within a Mathematica notebook.Without knowing the details of your problem, here is a schematic:First go to the appropriate directory and get the names of the data files ina list. I assume they have file extension .dat:SetDirectory[ ...]dataFiles=FileNames[*.dat]Define a function to all the work on one file and save the result in a filewith a different extensionprocessDataFile[fn_String]:=Module[{ result }, result=yourAnalysis[fn]; Save[StringReplace[fn,.dat->.out],result]]Then treat all the filesScan[processDataFile,dataFiles]This assumes that the result is some kind of Mathematica expression and youwould be happy to get that expresssion saved in a file. I suspect youmight want a notebook for each input file, containing plots, tables, etc.That is also possible - see functions like NotebookPut, SelectionEvaluate,.... I'm sorry I don't have time to think through the details.John Jowett> Dear Mathematica Gurus. I am working with a student (undergraduate math major) who is using> Wavelet Explorer to process numerous datasets using a multiresolution> analysis with various parameter settings. We would like to know how> we might create a notebook that would> (1) read in a datafile from a list of files in a local> directory (or in a hardcoded array),> (2) run a multiresolution analysis on the file (this analysis> is already coded),> (3) save the results (e.g., in the form of a mathematica notebook), and> (4) do the same in turn for each of the datasets in a local> directory, as described in (1).> Having a way to create such a Ôloop' would save us much time, but> we're don't know how to direct Mathematica to save the results of> each analysis. Can anybody tell us how we might do this, or if it's a reasonable thing todo?> Jason> --> Jason Miller, Ph.D.> Division of Mathematics and Computer Science> Truman State University> 100 East Normal St.> Kirksville, MO 63501> http://vh216801.truman.edu/millerj> 660.785.7430>Reply-To: murray@math.umass.edu ==== I had no problem running that command in Mathematica 4.2.1.0 under Windows XP. You didn't say what platform yo