mm-539 ==== Subject: can anyone solve this equation? Can anyone solve the following equation (for theta_4)? The assumptions are in this cell (use ctrl+shift+e, paste it into the notebook, and then use ctrl+shift+e again): Cell[< $Assumptions=Flatten[Append[{True},{(#1>=0&)/@{[Alpha]}, (#1>0&)/@{r,numcyl,Displacement[UnderBracket]Base,SBRatio,P[UnderBracket ]0,P [UnderBracket]7,T[UnderBracket]Intake,T[UnderBracket]7}, (#1>1&)/@{R[UnderBracket]ConRodCrankArm,CR[UnderBracket]Base,k[UnderBr acket]Air [UnderBracket]c,k[UnderBracket]Air[UnderBracket]e}}]]; >,Input] The equation is in the cell below (I need the solution for theta underbracket four): Cell[< (1/(2*(-1+CR[UnderBracket]Base)*numcyl))*(Displacement[UnderBracket]Base *(1+CR [UnderBracket]Base-R[UnderBracket]ConRodCrankArm+ CR[UnderBracket]Base*R[UnderBracket]ConRodCrankArm+Cos[[Theta][Under Bracket]4]-CR [UnderBracket]Base*Cos[[Theta][UnderBracket]4]+ Sqrt[R[UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]4]^2]- CR[UnderBracket]Base*Sqrt[R[UnderBracket]ConRodCrankArm^2-Sin[[Theta] [UnderBracket]4]^2]))== (Displacement[UnderBracket]Base*(2^k[UnderBracket]Air[UnderBracket]c*( -1+ CR[UnderBracket]Base)*(P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k [UnderBracket]Air [UnderBracket]c)*q[UnderBracket]LHV* (c[UnderBracket]P[UnderBracket]e+c[UnderBracket]v[UnderBracket]e*[ Alpha])*Cos[[Theta] [UnderBracket]1]+2^k[UnderBracket]Air[UnderBracket]c*c[UnderBracket] v[UnderBracket]e*q [UnderBracket]LHV*[Alpha]* (2-(P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k[UnderBracket]Air [UnderBracket]c)+(P [UnderBracket]Intake/P[UnderBracket]Exit)^(1/k[UnderBracket]Air[Unde rBracket]c)* R[UnderBracket]ConRodCrankArm-(P[UnderBracket]Intake/P[UnderBracket]Ex it)^(1/k [UnderBracket]Air[UnderBracket]c)* Sqrt[R[UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]1]^2]+ CR[UnderBracket]Base*(P[UnderBracket]Intake/P[UnderBracket]Exit)^ (1/k[UnderBracket]Air[UnderBracket]c)*(-1-R[UnderBracket]ConRodCrankAr m+Sqrt[R [UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]1]^2]))+ c[UnderBracket]P[UnderBracket]e*(-2*(1+ AF)*c[UnderBracket]v[UnderBracket]e*(P[UnderBracket]Intake/P[UnderBr acket]Exit)^(1/k[UnderBracket] Air[UnderBracket]c)*T[UnderBracket]Intake*(1+[Alpha])* (1+CR[UnderBracket]Base-R[UnderBracket]ConRodCrankArm+CR[UnderBracket] Base*R [UnderBracket]ConRodCrankArm+Cos[[Theta][UnderBracket]1]- CR[UnderBracket]Base*Cos[[Theta][UnderBracket]1]+Sqrt[R[UnderBracket ]ConRodCrankArm^2- Sin[[Theta][UnderBracket]1]^2]- CR[UnderBracket]Base*Sqrt[R[UnderBracket]ConRodCrankArm^2- Sin[[Theta][UnderBracket]1]^2])^k[UnderBracket]Air[UnderBracket]c+ 2^k[UnderBracket]Air[UnderBracket]c*q[UnderBracket]LHV*(2-(P[UnderBr acket]Intake/P [UnderBracket]Exit)^(1/k[UnderBracket]Air[UnderBracket]c)+ (P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k[UnderBracket]Air[Un derBracket]c)*R [UnderBracket]ConRodCrankArm- (P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k[UnderBracket]Air[Un derBracket]c)*Sqrt[R [UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]1]^2]+ CR[UnderBracket]Base*(P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k [UnderBracket]Air [UnderBracket]c)*(-1-R[UnderBracket]ConRodCrankArm+ Sqrt[R[UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]1]^2]))) ))/((-1+CR [UnderBracket]Base)*c[UnderBracket]P[UnderBracket]e*numcyl* (2^k[UnderBracket]Air[UnderBracket]c*(-1+CR[UnderBracket]Base)*(P[Un derBracket]Intake/P [UnderBracket]Exit)^(1/k[UnderBracket]Air[UnderBracket]c)*q[UnderBra cket]LHV*Cos[[Theta] [UnderBracket]1]- 2*(1+AF)*c[UnderBracket]v[UnderBracket]e*(P[UnderBracket]Intake/P[Un derBracket]Exit)^(1/k [UnderBracket]Air[UnderBracket]c)*T[UnderBracket]Intake*(1+[Alpha])* (1+CR[UnderBracket]Base-R[UnderBracket]ConRodCrankArm+CR[UnderBracket] Base*R [UnderBracket]ConRodCrankArm+Cos[[Theta][UnderBracket]1]- CR[UnderBracket]Base*Cos[[Theta][UnderBracket]1]+Sqrt[R[UnderBracket ]ConRodCrankArm^2- Sin[[Theta][UnderBracket]1]^2]- CR[UnderBracket]Base*Sqrt[R[UnderBracket]ConRodCrankArm^2- Sin[[Theta][UnderBracket]1]^2])^k[UnderBracket]Air[UnderBracket]c+ 2^k[UnderBracket]Air[UnderBracket]c*q[UnderBracket]LHV*(2-(P[UnderBr acket]Intake/P [UnderBracket]Exit)^(1/k[UnderBracket]Air[UnderBracket]c)+ (P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k[UnderBracket]Air[Un derBracket]c)*R [UnderBracket]ConRodCrankArm- (P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k[UnderBracket]Air[Un derBracket]c)*Sqrt[R [UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]1]^2]+ CR[UnderBracket]Base*(P[UnderBracket]Intake/P[UnderBracket]Exit)^(1/k [UnderBracket]Air [UnderBracket]c)*(-1-R[UnderBracket]ConRodCrankArm+ Sqrt[R[UnderBracket]ConRodCrankArm^2-Sin[[Theta][UnderBracket]1]^2]))) ) >,Output, CellLabel->Out[40]=] -- Chris Chiasson http://chrischiasson.com/ 1 (810) 265-3161 ==== Subject: Re: List operations Hi Anton, to get the words: We extract the structure: t = Map[0 &, lst, {3}] then we mark the positions: t = MapAt[1 &, t, {{2, 2, 2}, {5, 1, 2}}] // Flatten then we get the position number t = Position[t, 1] // Flatten and finally we calculate the distance: t[[2]] - t[[1]] + 1 all together for words: t = Map[0 &, lst, {3}] t = MapAt[1 &, t, {{2, 2, 2}, {5, 1, 2}}] // Flatten t = Position[t, 1] // Flatten t[[2]] - t[[1]] + 1 analogously for sentences: t = Map[0 &, lst, {2}] t = MapAt[1 &, t, {{2, 2}, {5, 1}}] // Flatten t = Position[t, 1] // Flatten t[[2]] - t[[1]] + 1 number of chapters can be calculated directly from the positions: 5-2+1 sincerely, Daniel Huber > suppose i have a list containing a whole book, the list will contain > words, sentences, chapters; as an example: > lst={{{abc,def},{as,red}},{{fat,qqq,qqq}, > {asd,asd,vbn}},{{zz,zz}},{{zz,wtt,wtt}},{{r ed,zz}, > {sd,ed},{er,to}},{{ww,ww,dff},{as,end}}} please check sometimes some servers may insert the false - letter > in the above lst. here is the book lst contains six chapters, 11 sentences, > the question is: what are the general methods wich could be used to > know how many words, and how many sentences and how many chapters > between an arbitrary two words in the book such as an example: > between the word number 2 in sentence 2 in chapter 2 > and the word number 2 in sentence 1 in chapter 5 ie: > wrd1=lst[[2]][[2]][[2]] > wrd2=lst[[5]][[1]][[2]] the results will be: if we count the 2 words and their own sentences > and chapters: > 9 words, 4 sentences, 4 chapters. > reards. > Anton > ==== Subject: Zero Padding and ColumnAlignments in Version 5.1 I am trying to print a table of numbers with a large range. I would like 4 place accuracy and to have columns aligned on the decimal point. I tried TableForm, which does most of this, the option ColumnAlignments->{.,.} is referred to in the documentation for 5.1, but seems to have no effect. Neither does ColumnAlignments->Right or Left. Any help would be appreciated. I have looked for a solution to this in the archive, but only found reference to the problem, not a solution. Kevin ==== Subject: Re: How to rotate a PolarPlot? Hi Paul, Rotate2D from:Geometry`Rotations` will do the trick: < Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None] MapAt[Rotate2D[#, .2] & /@ # &, g, {1, 2, 1, 1}] // Show sincerely, Daniel > Hi All, Would appreciate some help with this. I would like to know how I can > rotate the following plot to an arbitrary angle: PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -> Red, > PlotRange -> All, AspectRatio -> Automatic, Ticks -> None] Paul > ==== Subject: Re: How to rotate a PolarPlot? Needs[Graphics`Graphics`] pp = PolarPlot[Exp[0.2t], {t, 0, 8Pi}, PlotStyle -> Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None]; Show[pp /. Line[pnts_] :> With[{alpha = Pi/4}, Line[{{Cos[alpha], Sin[alpha]}, {-Sin[alpha], Cos[alpha]}}.# & /@ pnts] ] ] ?? Jens schrieb im Newsbeitrag > Hi All, Would appreciate some help with this. I would > like to know how I can > rotate the following plot to an arbitrary angle: PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -Red, > PlotRange -> All, AspectRatio -> Automatic, > Ticks -> None] Paul > ==== Subject: Re: How to rotate a PolarPlot? Just use rotation matrix ! For example : << Graphics`Graphics` des = PolarPlot[Exp[0.2*t], {t, 0, 8*Pi}, PlotStyle -> Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None]; Create a rotation function : rot[draw_, ë±_] := Show[draw /. {(x_)?NumericQ, y_} -> {{Cos[ë±], -Sin[ë±]}, {Sin[ë±], Cos[ë±]}} . {x, y}] Try it : rot[des, Pi/2]; F.Jaccard -----Message d'origine----- DeåÊ: paul@selfreferral.com [mailto:paul@selfreferral.com] EnvoyÌ©åÊ: mercredi, 15. juin 2005 11:58 Ì¥åÊ: mathgroup@smc.vnet.net ObjetåÊ: How to rotate a PolarPlot? Hi All, Would appreciate some help with this. I would like to know how I can rotate the following plot to an arbitrary angle: PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -> Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None] Paul ==== Subject: Re: Plot difficulties Eric, It is just what it says. Your function is not real over the plot domain. (One has to wonder why your plot domain involves such small numbers.) You can only plot real values so you have to investigate your function, maybe exploring it with Table, and decide what is is you really want to plot. If your function is truly a complex function then maybe you want to us Re and Im to plot the real and imaginary parts, or Abs to plot the absolute value. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I have a question regarding Plot. Here is a snip of my code: Plot[function1, {EE,0 ,2.9*1.6 10^-19}, PlotLabel->function1]; Plot:: plnr : function1 is not a machine-sized real number at EE = 6.652531793826348`*^-21 ... function1 evalutates to 0. + 0.00195313i at this point. In fact, at every point the plot command gives an error the evaluation is completly imaginary. Function1 is composed as follows: Sqrt[1/(k1 Rc)] Sqrt[1/(k2i Rs)] (k2i m1 Rc Cos[k2i (Rc - Rs)] Sin[k1 Rc] - (k1 m2 Rc Cos[k1 Rc] + (m1 - m2) Sin[k1 Rc]) Sin[k2i (Rc - Rs)])/ (m1 (Sqrt[1/(k2i Rc)] * Sqrt[k1 Rc] Sqrt[k2i Rc] Sqrt[k2i Rs]) Where k2i is completely imaginary, m1>m2, and Rs>Rc Any Suggestions? Eric ==== Subject: Re: For Loop and Array related I don't understand that. Switching to a simpler Do statement, note that the following does not work. Lattice = Table[0, {n, 100}]; Do[Lattice[[Random[Integer, {1, 100}]]]++, {16000}] Total[Lattice] 16229 But if we calculate the index location first it does work. Lattice = Table[0, {n, 100}]; Do[i = Random[Integer, {1, 100}]; Lattice[[i]]++, {16000}] Total[Lattice] 16000 If we do a Trace on the increment statement in the first construction we obtain the following... Lattice = Table[0, {n, 5}]; Trace[Lattice[[Random[Integer, {1, 5}]]]++] Lattice {HoldForm[Lattice[[Random[Integer, {1, 5}]]]++], {{HoldForm[Lattice], HoldForm[{0, 0, 0, 0, 0}]}, {HoldForm[Random[Integer, {1, 5}]], HoldForm[3]}, HoldForm[{0, 0, 0, 0, 0}[[3]]], HoldForm[0]}, {HoldForm[Lattice[[Random[Integer, {1, 5}]]] = 1], HoldForm[1]}, HoldForm[0]} {0, 0, 0, 1, 0} which I do not follow, but it appears that Mathematica is calculating the random index twice. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi All, I have an array with 100 elements, all set to zero initially. Then I want to randomly choose one element and increase its value by one, and repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should get 16000 (I use Total[Lattice] to get the sum of the list). But this doesn't happen, and strangely, each time I run this, the sum of the list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code like it were C++ and I think i've fallen into this trap as well. So is there a different (more Mathematica) way which I can implement the above? ==== Subject: Re: Plot difficulties David, of v2 increases, the first part of the function becomes imaginary. It is a plot of energy levels within a quantum dot well. Well, it will be when I have the command working right that is. I tried to plot the function using Re and Im, but the graphs that I got for each one were completely unusable. There should be very few zeros in the plot range and the results from using Re and Im showed hundreds. Is there a way that I can block any value that is completely imaginary, leaving only the values that are completely real, or that have a real and imaginary part? Eric -----Original Message----- ==== Subject: Re: Plot difficulties Eric, It is just what it says. Your function is not real over the plot domain. (One has to wonder why your plot domain involves such small numbers.) You can only plot real values so you have to investigate your function, maybe exploring it with Table, and decide what is is you really want to plot. If your function is truly a complex function then maybe you want to us Re and Im to plot the real and imaginary parts, or Abs to plot the absolute value. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I have a question regarding Plot. Here is a snip of my code: Plot[function1, {EE,0 ,2.9*1.6 10^-19}, PlotLabel->function1]; Plot:: plnr : function1 is not a machine-sized real number at EE = 6.652531793826348`*^-21 ... function1 evalutates to 0. + 0.00195313i at this point. In fact, at every point the plot command gives an error the evaluation is completly imaginary. Function1 is composed as follows: Sqrt[1/(k1 Rc)] Sqrt[1/(k2i Rs)] (k2i m1 Rc Cos[k2i (Rc - Rs)] Sin[k1 Rc] - (k1 m2 Rc Cos[k1 Rc] + (m1 - m2) Sin[k1 Rc]) Sin[k2i (Rc - Rs)])/ (m1 (Sqrt[1/(k2i Rc)] * Sqrt[k1 Rc] Sqrt[k2i Rc] Sqrt[k2i Rs]) Where k2i is completely imaginary, m1>m2, and Rs>Rc Any Suggestions? Eric ==== Subject: Mathematica program generating sequence of points stalls for no apparent reason. The following program is a slight variation of a program found in: http://www.research.att.com/cgi-http://www.research.att.com/cgi-bin /access.cgi/as/njas/sequences/eisA.cgi?Anum=A065978 f[n_] := For[p=n/2,True,p--,If[PrimeQ[p]&&PrimeQ[n-p],Return[(n/2)-p]]]; For[n=4; max=-1, True,n+=2,If[f[n]>max,Print[{n,f[n]}]; max=f[n]]] After generating the points: {{4,0},{8,1},{16,3},{44,9},{92,15},{242,18},{256,21},{272,27},{292,33}, {476,39},{530,42},{572,45},{682,48},{688,75},{1052,87},{1808,93}, {2228,117},{3382,120},{3472,135},{3502,138},{3562,168},{4952,183}, {6194,210},{7102,228},{10262,300},{17008,333},{20684,369},{37052,393}, {45128,453},{49552,525},{80144,621},{137414,720},{251806,810}, {349826,846},{362534,1086},{742856,1281},{1655152,1305},{1872236,1515}, {2108282,1590},{2319728,1617},{2707118,1722},{5182214,1794}, {7518328,1833},{10908124,1851},{11939162,2010},{12727966,2064}, {13279472,2085},{13583338,2112},{14366372,2217},{18245438,2352}, {21572990,2754}} I'm attempting to obtain points higher than {21572990,2754} via: f[n_] := For[p=n/2,True,p--,If[PrimeQ[p]&&PrimeQ[n-p],Return[(n/2)-p]]]; For[n=115978712; max=-1, True, n+=2, If[f[n]>max, Print[{n, f[n]}]; max=f[n]]] I'm running the program for a period of (say) one day, but the program lingers at the 9928 K's level of PC memory, without producing any other points. I know that my PC is not running out of memory, because (if this was the case then) Mathematica would give the message: No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. My question is: Why is this happening? ==== Subject: Problem defining assumptions on a set of variables Hi all, I have encountered two problems using Mathematica v5.0 with parameters for which no value is defined but for which some assumptions are defined. I do not understand why each of the following statements return -1. Assuming[q[Element]Reals&&q>0&&q<1, If[q > 3, 1, 0, -1]] Refine[If[q > 3, 1, 0, -1],q[Element]Reals&&q>0&&q<1] I would expect to get 0 as return value. What am I missing here ? In addition I would like to define a fairly large matrix (e.g. 100x100) in which each entry consists of a variable of unknown value. Something like: [ p11 p12 p13, p14, ... , p1100 ] [ p21 p22 p23, p24, ... , p2100 ] ... [ p1001 p1002 p1003, p1004, ... , p100100 ] with pij the variable on row i column j. Any ideas on how to define such a matrix without defining any values for the pij but with the added assumption that 0 <= pij <= 1 for all the pij's ? I want to use this matrix for computations in which I will provide values for some of the variables and not provide values for the remaining variables so that the result is expressed in terms of the undefined variables. However the sets of defined / undefined variables will not be fixed so I'm looking for a flexible solution. Any help will be greatly appreciated. Erik Koffijberg. ==== Subject: Re: Write/WriteString -- writing delimited txt to a stream? Situation: > - I am reading data in from a stream (the file is too big to import) > and processing it chunk by chunk. > - The proesssed data looks something like data = {{100, 1.5, -10}, > {200,3.2, 10},...etc} > - I have opened an output stream to write the data using s = > OpenWrite[file, FormatType -> OutPutForm]; > - I want to write the data in tab or comma separated format with one row > per line. Problem: > - No matter what I've tried, I always get either > (i) output with rows enclosed in brackets, or > (ii) delimited text output, but with Mathematica automatically adding a line > break if a line exceeds what seems to be the default width for output format > - I've tried using Write and WriteString -- nothing seems to work. > - I also tried generating an exact string for each line using a function > that inserts tabs between list items and adds a newline at the end of > the list. > As Stephan Linnik pointed out (msg 57980), you can pass an OutputStream to Export and take advantage of its formatting capabilities. As far as team (ii) from above, you have to set the option PageWidth when writing to an OutputStream to Infinity if you don't want the line wrapping. > ExpressionToTSV[list_] := Module[{temp}, > temp = ToString@Rest@(ToString /@ Flatten@({t, #} & /@ list)); > StringReplace[temp, {{ -> , } -> , , -> }]; > StringInsert[temp, n, -1] > ]; > Not as easy as using Export, but if for some reason you really wanted to use WriteString, then you could do this: In[110]:= data={{123,2.123,123},{123,2.123,123},{123,2.123,123}}; In[112]:= strm=OpenWrite[c:test.txt]; In[113]:= (WriteString[strm, StringReplace[ToString[Flatten[#1]], {{ -> , } -> , , -> ,}], n] & ) /@ data; In[114]:= Close[strm]; In[115]:= !!c:test.txt 123,2.123,123 123,2.123,123 123,2.123,123 -- Igor Antonio Wolfram Research, Inc. http://www.wolfram.com To email me personally, remove the dash. ==== Subject: Re: plot3D over a triangular domain you can try to multiply the function by a boolean (or UnitStep) to set the values to zero outside the triangle that is Plot3D[Boole[-1 < x < 1 && -0.5 + 0.5x < y < 0.5 - 0.5x]*func, {x, -1, 1}, {y, -2, 2}, PlotPoints -> 75, Mesh -> False] If you set func as 1 you will see the triangle alone yehuda Hi All, I would like to plot a function over a isosceles triangular domain. > I mean Plot3D[function, {x,-1,1},{y, -0.5+0.5x, 0.5-0.5x}]. But I got > message that the limit must be real number. Anyone can help me? > Tun Myint Aung > Graduate Student > National University of Singapore > E1A #02-18 > E-mail g0202015@nus.edu.sg > ==== Subject: Re: plot3D over a triangular domain Tun Myint, The DrawGraphics package at my web site below has two methods for making plots over triangular, or many other, domains. Needs[DrawGraphics`DrawingMaster`] f[x_, y_] := Sin[2x]Cos[2y] The first method uses IteratorSubstitution to substitute a new variable w for y and then reparametrize the function so that w has fixed limits. IteratorSubstitution[{x, y, f[x, y]}, {y, (1/2)*(x - 1), (1/2)*(1 - x)}]//Simplify {{x, (-(1/2))*(-1 + 2*w)*(-1 + x), Cos[(-1 + 2*w)*(-1 + x)]* Sin[2*x]}, {w, 0, 1}} Notice that I obtained an expression for {x, y, f[x,y]}. We can then use ParametricPlot3D to directly plot the surface. ParametricPlot3D[{x, (-(1/2))*(-1 + 2*w)*(-1 + x), Cos[(-1 + 2*w)*(-1 + x)]*Sin[2*x]}, {x, -1, 1}, {w, 0, 1}, PlotPoints -> {25, 15}, ViewPoint -> {-0.836, -2.556, 2.054}, AxesLabel -> {x, y, }, ImageSize -> 450]; The following does the same plot using the DrawGraphics routines Draw3DItems, ParametricDraw3D, ColorMix and NeutralLighting. This allows us to color the surface and subdue the 'mesh' lines. Draw3DItems[{SurfaceColor[LightSteelBlue], EdgeForm[ColorMix[LightSteelBlue, Black][0.5]], ParametricDraw3D[{x, (-(1/2))*(-1 + 2*w)*(-1 + x), Cos[(-1 + 2*w)*(-1 + x)]*Sin[2*x]}, {x, -1, 1}, {w, 0, 1}, PlotPoints -> {25, 15}]}, ViewPoint -> {-2.278, -2.142, 1.294}, NeutralLighting[0.3, 0.5, 0.1, 5*Degree], BoxRatios -> {1, 1, 1}, BoxStyle -> Gray, PlotLabel -> f[x, y], Background -> Linen, ImageSize -> 450]; The second method is to use what I call a HollisGrid, devised by Selwyn Hollis. It will divide up any star-like or convex region into more or less equal area polygons. The region can be defined by vertices or by a curve. Here we use vertices that define your triangular region. I plot the grid so we can see what it looks like. vertices = {{-1, -1}, {1, 0}, {-1, 1}}; grid = HollisGrid[vertices, GridExtraSmoothing -> True]; Draw2D[ {Line /@ grid}, AspectRatio -> Automatic, Frame -> True, PlotRange -> {{-1, 1}, {-1, 1}}, Background -> Linen, ImageSize -> 350]; We can then raise the grid to a 3D surface. Draw3DItems[{SurfaceColor[Melon], EdgeForm[ColorMix[Melon, Black][0.4]], RaiseTo3D[f][Polygon /@ grid]}, NeutralLighting[0.3, 0.5, 0.1, 85*Degree], BoxRatios -> {1, 1, 1/2}, BoxStyle -> Gray, ViewPoint -> {-1.014, -2.149, 2.409}, PlotLabel -> f[x, y], Background -> ColorMix[Peacock, White][0.8], ImageSize -> 450]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi All, I would like to plot a function over a isosceles triangular domain. I mean Plot3D[function, {x,-1,1},{y, -0.5+0.5x, 0.5-0.5x}]. But I got message that the limit must be real number. Anyone can help me? Tun Myint Aung Graduate Student National University of Singapore E1A #02-18 E-mail g0202015@nus.edu.sg ==== Subject: Re: How to rotate a PolarPlot? The iterator of Polar plot determines the angle while the function determines the radius. So if you want to shift in angle, all you need is to start the angle from a different initial value , i.e. PolarPlot[Exp[0.2 (t-t0)],{t,t0,t1}] where t0 is the initial value, and t1 is the final value for the angles. Note that t-t0 makes your function to compute the values for 0<=t<=t2-t1 (which I assume that you wanted this behavior) yehuda > Hi All, Would appreciate some help with this. I would like to know how I can > rotate the following plot to an arbitrary angle: PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -> Red, > PlotRange -> All, AspectRatio -> Automatic, Ticks -> None] Paul > > ==== Subject: Re: How to rotate a PolarPlot? > Hi All, Would appreciate some help with this. I would like to know how I can > rotate the following plot to an arbitrary angle: PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -> Red, > PlotRange -> All, AspectRatio -> Automatic, Ticks -> None] Paul > Paul, First define the rotation matrix, corresponding to ccw rotations through Euler angles psi, phi, theta around the z, x, and z axes, respectively: rot[psi_, phi_, theta_] = {{Cos[theta], -Sin[theta], 0}, {Sin[theta], Cos[theta], 0}, {0, 0, 1}}. {{1, 0, 0}, {0, Cos[phi], -Sin[phi]}, {0, Sin[phi], Cos[phi]}}. {{Cos[psi], -Sin[psi], 0}, {Sin[psi], Cos[psi], 0}, {0, 0, 1}} Now define show3DRot[plot2D_, {psi_, phi_, theta_}, opts___] := Show[ Graphics3D[ First[ plot2D /. {{x_Real, y_Real} -> rot[theta, phi, psi].{x, y, 0}} ] ], opts] Then, for example, grf = PolarPlot[Exp[.2t], {t, 0, 8Pi}, PlotStyle -> Red] show3DRot[ grf, {Pi/2, Pi/3, Pi/4}, PlotRange -> All] ---------------- Selwyn Hollis http://www.appliedsymbols.com ==== Subject: Re: How to rotate a PolarPlot? Paul, You have to change the iterator range and compensate in the radial expression. Let ang be the angle of rotation. ang = Pi; PolarPlot[Exp[(t - ang)/5], {t, ang, 8Pi + ang}, PlotStyle -> Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None]; Or you could use ParametricPlot. ang = Pi; ParametricPlot[Exp[t/5]{Cos[t + ang], Sin[t + ang]}, {t, 0, 8 Pi}, PlotStyle -> Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None]; Or you could plot this as a complex curve using the Cardano3 package from my web site. Needs[Cardano3`ComplexGraphics`] ang = Pi; Draw2D[ {Red, ComplexCurve[Exp[t/5 + I t]Exp[I ang], {t, 0, 8 Pi}]}, AspectRatio -> Automatic, Axes -> True, Ticks -> None, PlotRange -> All]; Or you could use the DrawPolarR routine and DrawingTransform from the underlying DrawGraphics package. ang = Pi/2; Draw2D[ {Red, DrawPolarR[Exp[t/5], {t, 0, 8Pi}] /. DrawingTransform[#1Cos[ang] - #2Sin[ang] &, #1Sin[ang] + #2Cos[ ang] &]}, AspectRatio -> Automatic, Axes -> True, Ticks -> None, PlotRange -> All]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi All, Would appreciate some help with this. I would like to know how I can rotate the following plot to an arbitrary angle: PolarPlot[Exp[.2t], {t, 0, 8p}, PlotStyle -> Red, PlotRange -> All, AspectRatio -> Automatic, Ticks -> None] Paul ==== Subject: Re: spotlight escape sequences hm ... Needs[Combinatorica`] with the surround-quotes doesn't seem to work for me. i did install the wolfram notebook indexer plugin some days ago after an announcement came out over email ... but here's a question: is there a way that i can check to make sure that installation was successful? maybe i didn't install after all? trevor. ==== Subject: Re: Re: spotlight escape sequences > os x only: >> how do you type: >> Needs[Combinatorica`] >> into apple's os x spotlight and get back what you expect? > > Surrounding the whole thing in quotes (with no escaping on the inner > quotes) seems to work for me: Needs[Combinatorica`] Doesn't work for me. Have you installed the Wolfram Notebook Indexer plugin for Spotlight > ? This is an > example of a search that will not work without it. Yes. -Rob (author of Wolfram Notebook Indexer plugin for Spotlight) Garry Helzer gah@math.umd.edu ==== Subject: Re: spotlight escape sequences The Wolfram Notebook Indexer plugin for Spotlight indexes the textual contents of notebook files. Do you have reason to believe it is not working properly for you? There's no way for Spotlight to show you the textual contents, but if you search for text you know to be in the contents Spotlight should find it. -Rob ==== Subject: Re: Interrupt[] without confirmation So, is there a command to end evalution of a notebook/input cell totally, i.e. a command that once reached Mathematica kernel stops evaluating anything below this command? ==== Subject: Plot3D over a triangular domain I would like to plot a function over a isosceles triangular domain. I mean Plot3D[function, {x,-1,1},{y, -0.5+0.5x, 0.5-0.5x}]. But I got message that the limit must be real number. Anyone can help me? I did this using the UnitStep function. Try Plot3D[UnitStep[y-(-.5+.5x),0.5-0.5x-y]*function,{x,-1,1},{y,-1,1}]; If something does not work I can send you the Notebook. Sergio Terrazas University of Juarez Mexico ==== Subject: Kernel shuts down due to lack of memory when solving the system of 10 polynomial equations with FindRoot, after 5 minutes of running I get No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry.. Is there a way to bypass this problem? My old laptop never has this problem although it keeps solving and solving forever. ==== Subject: New Mathematica visualization website I've created a website for my own visualizations with Mathematica. Just wanted to share with the rest of the Mathematica community. http://members.wri.com/jeffb/visualization/ If any one has other interesting graphics they've created and wish to share, feel free to contact me and I will consider adding it to the site, giving the author credit of course. -Jeff ==== Subject: Real time analysis of data. I have a piece of test equipment running, with a computer interface. Data is being collected every 100ms or so, although I might well reduce the rate. Is it possible to feed the real-time data into Mathematica with a plot that continuously updates? (I have Mathematica 5.1 for UNIX running on a Sun Ultra 80 under Solaris 9). I guess Labview might well be a more appropriate tool for this sort of task, but can Mathematica do it? ==== Subject: Re: For Loop and Array related >I have an array with 100 elements, all set to zero initially. Then >I want to randomly choose one element and increase its value by >one, and repeat this 16000 times. Here is my code: >Lattice = Table[0, {n, 100}]; For[i = 1, i = 16000, i++, >Lattice[[Random[Integer, {1, 100}]]]++] >So now if I add all the elements in the list Lattice together, I >should get 16000 (I use Total[Lattice] to get the sum of the list). > But this doesn't happen, and strangely, each time I run this, the >sum of the list is different! What am I doing wrong? >Also I'm aware that a lot of Mathematica newbies try and write code >like it were C++ and I think i've fallen into this trap as well. >So is there a different (more Mathematica) way which I can >implement the above? I don't see why your code above isn't giving the result you expect. OTOH, I do know how to get the result you want without using a For loop. Specifically, lattice=Length/@Split[Sort@Table[Random[Integer,{1,100}],{16000}]]; Will do what you want An alternative solution would be lattice=Count[Table[Random[Integer, {1,100}],{1600}],#]&/@Range@100; I did a bit of quick testing which indicates the alternative I show is slower by a factor of 2-3. But it may be preferable since it can result in some values in lattice being zero while the faster method will never give a zero value. For your stated conditions (16000 random integers between 1 and 100) it is very unlikely not to have at least one occurance of every interger from 1 to 100. And as long as every integer occurs, the two methods yield identical results. -- To reply via email subtract one hundred and four ==== Subject: Re: Randomness Test >Okay, I have a sequence of numbers as below. When i do a scatter >plot, there seems to be a bias toward positive numbers. Although >when I run some tests like runs test, it shows me that the >numbers are random. If that is the case, then when i plot the >numbers on a scatter plot, should'nt they be equally divided up and >below the x axis? My goal is to prove that that there is a >significant bias towards positive numbers. Since you list contained 9 negative numbers 6 zeros 26 positive numbers There is a clear bias toward positive numbers. A runs test looks for a sequence of the same number and isn't the right test to use to look for a preponderence of positive numbers. The sequence of positive integers is clearly not random but will have no runs and pass a runs test. -- To reply via email subtract one hundred and four ==== Subject: Re: Help with the User Interface in Mathematica 5.1.1 > Create the file given by: ToFileName[{$UserAddOnsDirectory, Autoload, My, FrontEnd}, > init.m] Put the following command: SetOptions[InputNotebook[], > WindowMargins->{{0,0},{0,0}}, > WindowSize->{Automatic,Automatic} > ] This will resize the startup nb to fill the screen. ---------------------------------------------- > Omega Consulting > The final answer to your Mathematica needs. > http://omegaconsultinggroup.com > Perfect! I changed WindowSize to reflect the pixel dimensions I wanted, James ==== Subject: Re: For Loop and Array related While I've no idea exactly why your code fails (although i = 16000 should be i <= 16000, but that's not the problem) I found that assigning the random integer value to a variable solves this problem. Using the code: Lattice = Table[0, {n, 100}]; For[i = 1, i <= 16000, i++, r = Random[Integer, {1, 100}]; Lattice[[r]]++]; Total[Lattice] always returns exactly 16000. I've programmed in C++ a lot but I guess this is not a Mathematica syntax problem but some internal Mathematica issue. Anybody else knows what's going on here ? Erik Koffijberg. -----Original Message----- ==== Subject: For Loop and Array related Hi All, I have an array with 100 elements, all set to zero initially. Then I want to randomly choose one element and increase its value by one, and repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should get 16000 (I use Total[Lattice] to get the sum of the list). But this doesn't happen, and strangely, each time I run this, the sum of the list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code like it were C++ and I think i've fallen into this trap as well. So is there a different (more Mathematica) way which I can implement the above? ==== Subject: splitting sublists hi how to split the sublists inside a bigger list wherever we find x letter {{3,1,4,x,1,5,9,2,x},{6,5,x,3,5,x,8,9,x}} the results will be: {{{3,1,4},{1,5,9,2}},{{6,5},{3,5},{8,9}}} anton ==== Subject: Re: splitting sublists > hi > how to split the sublists inside a bigger list wherever we find x > letter > {{3,1,4,x,1,5,9,2,x},{6,5,x,3,5,x,8,9,x}} > the results will be: {{{3,1,4},{1,5,9,2}},{{6,5},{3,5},{8,9}}} anton DeleteCases[Split[#,#1=!=x&=!=x&]&/@{{3,1,4,x,1,5,9,2,x}, {6,5,x,3,5,x, 8,9,x}},{x},Infinity] {{{3, 1, 4}, {1, 5, 9, 2}}, {{6, 5}, {3, 5}, {8, 9}}} Andrzej Kozlowski Chiba, Japan ==== Subject: Re: splitting sublists lst = {{3, 1, 4, x, 1, 5, 9, 2, x}, {6, 5, x, 3, 5, x, 8, 9, x}}; lst //. {a___, x, b___} :> {{a}, b} //. {lst_List, iseq__Integer} :> Sequence @@ {lst, {iseq}} Jens schrieb im Newsbeitrag > hi > how to split the sublists inside a bigger list > wherever we find x > letter > {{3,1,4,x,1,5,9,2,x},{6,5,x,3,5,x,8,9,x}} > the results will be: {{{3,1,4},{1,5,9,2}},{{6,5},{3,5},{8,9}}} anton > ==== Subject: field line with NDSolve Hi everybody! I am trying to obtain a magnetic field line in 3d, i.e. z(x{y),y). So I have magnetic induction vector B = (Bx, By, Bz), where Bi=Bi(x,y,z), i={x,y,z}. By the definition I set an unit vector in direction y: b = B / Abs[By] = (bx, by, bz) and replace coordinates x and z with functions x[y], z[y]. The final step is to integrate the set of 2 equations: x'[y] = bx z'[y] = bz In version 4.0 of Mathematica I was able to solve that with the code below, but in 5.1 I am not anymore. I suppose the conflict exists in passing arguments as symbolic, since B depends on z through InterpolatingFunction(s) and after replacing z -> z[y], I got InterpolatingFunction[{{0., 1000.}}, <>][z[y]]. But I am not sure how to manage this ... B = {Bx, By, Bz}; b = B/Abs[By] /. {x -> x[y], z -> z[y]}; r = {x[y], z[y]}; eqn_b = {D[r[[1]], y] == b[[1]], D[r[[2]], y] == b[[3]]} bnd_con = {x[ymin] == xmax/2, z[ymin] == zmax/10}; eqn_bnd = Join[eqn_b, bnd_con]; B_line = NDSolve[eqn_bnd, r, {y, ymin, ymax}]; The error I get is: NDSSolve::nlnum : The function value {...a large expression...} is not a list of numbers with dimmensions {2} at y={...a value...} Any hints, please. Ragards Rafal Kosinski -- Promocja! Format 15x20 tylko 99gr! Zam.97w odbitki cyfrowe online - odbierz za darmo w EMPiK-u lub wy.a6lemy Ci je poczt± http://gazeta.empikfoto.pl ==== Subject: Re: problem with InverseLaplaceTransform > I'm pretty new to Mathematica and am having difficulty trying to derive > an inverse laplace transform using Mathematica. When I run the code, > Mathematica starts to run (says running...), but then just continues > to remain like that and doesn't give an answer....as if it has crashed > or something. Do you really, really, really, want to compute this expression in closed form? It is possible, but messy. And what do you plan to do with this closed-form expression once you have it? > The code I`m trying to run is below (layout messed up, > but if you copy and paste it back into Mathemtica it`s fine): Some comments: [1] Note that the first argument to InverseLaplaceTransform is enclosed in {{}}. These brackets are not required, but will not cause a problem. Perhaps you obtained this expression from a matrix? [2] It is possible to use subscripted greek variables to make your expression easier to read. Alternatively, I've used m1 for muone and la3 for lambdathree, etc. [3] Using Together and Simplify on the expression to be inverted I obtain (m1 (la2 + m2 + s) (la3 + m3 + s) (m4 + s) + la1 (m2 (la3 + m3 + s) (m4 + s) + la2 (la3 m4 + m3 (m4 + s))))/ (s^2 ((la2 + m2 + s) (la3 + m3 + s) (m4 + s) + la1 ((la3 + m3 + s) (m4 + s) + la2 (la3 + m4 + s)))) By collecting together powers of s in the Denominator and Numerator separately, one sees that this expression is of the form lp = (a s^3 + b s^2 + c s + d)/(s^2 (e s^3 + f s^2 + g s + h)) where a - h are polynomials in your lambda and mu variables, independent of s. Now, Mathematica can quite quickly and easily compute the InverseLaplaceTransform of this expression: InverseLaplaceTransform[lp, s, t] The result is a horrendous collection of Root objects -- for a discussion of what these are, and why Mathematica uses this representation, see a number of earlier postings by Dan Lichtblau on this topic. Each Root object is an indexed root of the cubic in the denominator of lp. If you determine the a through h a polynomials in your lambda and mu variables and substitute this into the computed InverseLaplaceTransform, you have the result you requested -- but I doubt that it will be of any practical use to you. The only useful cases are likely to be where the cubics in the numerator and denominator factor. For example, writing lp = (s-a)(s-b)(s-c)/(s^2 (s-d)(s-e)(s-f)) (where a - f are now _different_ constant factors to those in lp above), then the InverseLaplaceTransform has a simple closed form. Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul http://InternationalMathematicaSymposium.org/IMS2005/ ==== Subject: Re: problem with InverseLaplaceTransform I'm afraid that you're asking a bit too much of Mathematica. The transform you're trying to invert has an almost general cubic factor in its denominator. (Look at Simplify[ExpandDenominator [yourexpression]].) Even with specific instances of the seven parameters in it, Mathematica typically gives the inverse transform in terms of a slew of Root[] expressions (representing roots of cubic equations). By the way, Mathematica probably isn't crashing on you; it's just working. You can (usually) stop it with Abort Evaluation in the Kernel menu. Selwyn Hollis http://www.appliedsymbols.com > I'm pretty new to Mathematica and am having difficulty trying to > derive > an inverse laplace transform using Mathematica. When I run the code, > Mathematica starts to run (says running...), but then just continues > to remain like that and doesn't give an answer....as if it has crashed > or something. The code I`m trying to run is below (layout messed up, > but if you copy and paste it back into Mathemtica it`s fine): InverseLaplaceTransform[{{(muone (mufour + s) (lambdathree + muthree + s) (lambdatwo + mutwo + s) + lambdaone (lambdathree (lambdatwo mufour + mutwo (mufour + s)) + (mufour + s) (lambdatwo muthree + mutwo (muthree + s))))/(s (mufour + s) > (lambdaone + muone + s) (lambdathree + muthree + s) (lambdatwo + > mutwo + s) (1 - (muone (mufour + s) (lambdathree + muthree + s) (lambdatwo + mutwo + s) + lambdaone (lambdathree (lambdatwo mufour + mutwo (mufour + s)) + (mufour + s) (lambdatwo muthree + mutwo (muthree + s))))/((mufour + s) (lambdaone + muone + s) (lambdathree + > muthree + s) (lambdatwo + mutwo + s))))}}, s, t] Can anybody explain my problem? > Barry ==== Subject: Re: problem with InverseLaplaceTransform and you have taken into account that { and } is used for lists and not for algebraic brakets ? Jens Barry Shaw schrieb im > I'm pretty new to Mathematica and am having > difficulty trying to derive > an inverse laplace transform using Mathematica. > When I run the code, > Mathematica starts to run (says running...), > but then just continues > to remain like that and doesn't give an > answer....as if it has crashed > or something. The code I`m trying to run is > below (layout messed up, > but if you copy and paste it back into > Mathemtica it`s fine): InverseLaplaceTransform[{{(muone (mufour + s) > (lambdathree + muthree + s) (lambdatwo + mutwo + s) + lambdaone (lambdathree (lambdatwo > mufour + mutwo (mufour + s)) + > (mufour + s) (lambdatwo muthree + mutwo (muthree + s))))/(s > (mufour + s) > (lambdaone + muone + s) (lambdathree + muthree > + s) (lambdatwo + > mutwo + s) (1 - (muone (mufour + s) > (lambdathree + muthree + s) (lambdatwo + mutwo > + s) + lambdaone (lambdathree > (lambdatwo mufour + mutwo (mufour + > s)) + (mufour + s) (lambdatwo > muthree + mutwo (muthree > + s))))/((mufour + s) (lambdaone + muone + > s) (lambdathree + > muthree + s) (lambdatwo + mutwo + > s))))}}, s, t] Can anybody explain my problem? > Barry > ==== Subject: Re: Randomness Test > Okay, I have a sequence of numbers as below. When i do a scatter plot, there seems to be a bias toward positive numbers. Although when I run some tests like runs test, it shows me that the numbers are random. If that is the case, then when i plot the numbers on a scatter plot, should'nt they be equally divided up and below the x axis? My goal is to prove that that there is a significant bias towards positive numbers. > -0.164971751 > 1.137014315 > 0.622389791 > 0.048958333 > 1.232944503 > 0.3241877 > 0.1015 > 0.075538717 > 0.265537849 > -0.175252257 > 0.279807692 > -0.409979424 > 0.628232355 > -0.137667494 > 0.210711568 > -0.984059857 > -0.016778523 > 0.384063745 > 0.079707844 > -0.183936235 > -0.567394095 > 0 > 0.277777778 > 0.785185185 > 0.267555556 > 0.078717201 > 0.344352617 > 0 > 0.442245021 > 0.310665658 > 0.788764045 > 0.015850552 > -0.054098361 > 0 > 0 > 0.929482371 > 0.278787879 > 0.123773346 > 0.125175809 > 0 > 0 > Dave, try the following: x={you list goes here} ListPlot[Abs[Fourier[x]]] Sequences of gaussian distributed numbers (mu=0) have a flat frequency spectrum. Your data shows a significant peak at the first Fourier coefficient, which (spoken in terms of electrical engineering) refers to the DC level. Your data seems to be biased, around Mean[x]=0.182068. Torsten ==== Subject: Re: Randomness Test The Random' property that you are looking for is not well defined. You may be looking for a practical proof for a UNIFORM distribution around zero for this specific set of numbers, and under this context, there is a sense to look at the bias to determine if the numbers are uniformly distributed (with zero mean). An immediate test would be (say that you already stored your numbers in a list called l) Mean[l]. For the specific example here you get 0.182068. Both results show that there is a bias towards positive numbers, but, to my opinion, the set of numbers given here is not sufficiently large. We all assume that the random number generator of Mathematica is accurate (well, at least I assume that) and if you check the running mean you will probably will not ever get an accurate zero for the mean. Try this one for example ListPlot[Rest[FoldList[Plus, 0, Table[Random[Real, {-1, 1}], {100000}]]]/Range[100000]] and you will see what I mean. yehuda p.s. Regarding my first remark, if you are looking for a different distribution, you need to state so explicitly yehuda > Okay, I have a sequence of numbers as below. When i do a scatter plot, there seems to be a bias toward positive numbers. Although when I run some tests like runs test, it shows me that the numbers are random. If that is the case, then when i plot the numbers on a scatter plot, should'nt they be equally divided up and below the x axis? My goal is to prove that that there is a significant bias towards positive numbers. > -0.164971751 > 1.137014315 > 0.622389791 > 0.048958333 > 1.232944503 > 0.3241877 > 0.1015 > 0.075538717 > 0.265537849 > -0.175252257 > 0.279807692 > -0.409979424 > 0.628232355 > -0.137667494 > 0.210711568 > -0.984059857 > -0.016778523 > 0.384063745 > 0.079707844 > -0.183936235 > -0.567394095 > 0 > 0.277777778 > 0.785185185 > 0.267555556 > 0.078717201 > 0.344352617 > 0 > 0.442245021 > 0.310665658 > 0.788764045 > 0.015850552 > -0.054098361 > 0 > 0 > 0.929482371 > 0.278787879 > 0.123773346 > 0.125175809 > 0 > 0 > > ==== Subject: Re: Randomness Test Hi Dave, why do you not simply calculate the mean: Mean[data] If you are only interessted in the sign and the values do not matter you could calculate how many more positives than negatives there are by: Total[Sign/@ data] sincerely, Daniel > Okay, I have a sequence of numbers as below. When i do a scatter plot, there seems to be a bias toward positive numbers. Although when I run some tests like runs test, it shows me that the numbers are random. If that is the case, then when i plot the numbers on a scatter plot, should'nt they be equally divided up and below the x axis? My goal is to prove that that there is a significant bias towards positive numbers. > -0.164971751 > 1.137014315 > 0.622389791 > 0.048958333 > 1.232944503 > 0.3241877 > 0.1015 > 0.075538717 > 0.265537849 > -0.175252257 > 0.279807692 > -0.409979424 > 0.628232355 > -0.137667494 > 0.210711568 > -0.984059857 > -0.016778523 > 0.384063745 > 0.079707844 > -0.183936235 > -0.567394095 > 0 > 0.277777778 > 0.785185185 > 0.267555556 > 0.078717201 > 0.344352617 > 0 > 0.442245021 > 0.310665658 > 0.788764045 > 0.015850552 > -0.054098361 > 0 > 0 > 0.929482371 > 0.278787879 > 0.123773346 > 0.125175809 > 0 > 0 > ==== Subject: Re: For Loop and Array related Hi You could try: Lattice = RandomComposition[16000, 100] which strikes me as a suitably Mathematica-type way of getting the list you would like. As for performance, my Mathematica is currently defunct so I haven't been able to check it. RandomComposition[] is a function from the Combinatorica package. Mark Westwood ==== Subject: Re: For Loop and Array related > I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? A syntax error (use of == vs. =) and a subtlety. Here is the modified code: Lattice = Table[0, {n, 100}]; SeedRandom[1]; Module[{t}, For[i = 1, i <= 16000, i++, t = Random[Integer, {1, 100}]; Lattice[[t]]++]]; Lattice I've included SeedRandom[1]; so that we get a repeatable random sequence. Note the use of the local variable t. If you write Lattice[[Random[Integer, {1, 100}]]]++ then, essentially, you are evaluating Lattice[[Random[Integer, {1, 100}]]] = Lattice[[Random[Integer, {1, 100}]]] + 1 which involves two _different_ random numbers. > Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. So is > there a different (more Mathematica) way which I can implement the > above? First compute a list of 16000 numbers: SeedRandom[1]; t = Table[Random[Integer, {1, 100}], {16000}]; Here are three ways to compute Lattice: [1] Count[t, #]& /@ Range[100] [2] << Statistics`; BinCounts[t, {0, 100}] [3] Length /@ Split[Sort[t]] These 3 codes give the same result as above. The last code will not work with short lists because it does not return any zero counts. Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul http://InternationalMathematicaSymposium.org/IMS2005/ ==== Subject: Re: For Loop and Array related > Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. So is > there a different (more Mathematica) way which I can implement the > above? Increment[x] internally evaluates x = x + 1 (and returns the old value of x then). Therefore, L[[Random[...]]]++ becomes L[[Random[...]]] = L[[Random[...]]] + 1, where Random is evaluated twice and gives two different indices. Perhaps it would be better if Increment, AddTo and other assignment functions evaluated the arguments of the left-hand side once; that is, in pos=1;L[[pos++]]++ the argument pos++ should be evaluated once and then the expression should be transformed into L[[1]] = L[[1]] + 1. This way we get the desired behaviour: pos now has the value 2 and the first element of L is incremented. Otherwise Increment just confuses the programmer into thinking that it will work like in C. This still wouldn't get rid of side effects, though, as x = x + 1 still evaluates x on the right-hand side of Set. Your example can be rewritten as Lattice[[#]]++& /@ Table[Random[Integer, {1, 100}], {16000}] For further speed-up, this can be compiled: Lattice = Compile[{}, Module[{Lattice}, Lattice = Table[0, {100}]; Lattice[[#]]++& /@ Table[Random[Integer, {1, 100}], {16000}]; Lattice ]][]; Sow and Reap give comparable performance: Lattice = Last@ Reap[ Sow[0, Range@ 100]; Sow[0, Table[Random[Integer, {1, 100}], {16000}]], _, Length@ #2 - 1&]; If the number of tries is much larger than 16000, then the compiled version takes several times less memory than uncompiled, most likely due to the use of packed arrays. Maxim Rytin m.r@inbox.ru ==== Subject: Re: For Loop and Array related Try this: For[i = 1, i <= 100, i++, n = Random[Integer, {1, 10}]; Lattice[[n]]++; Print[{n, Total[Lattice], Lattice}]] Two things: It should be i <= 16000 (a comparison), not i = 16000 (an assignment) in your For statement. Also, after playing with this for a minute or two, I'm guessing that ++ is implemented internally as expr = expr + 1 But Random is a non-referentially transparent operation: Imagine expanding the ++ in your original form to ... Lattice[[ Random[...] ]] = Lattice[[ Random[...] ]] + 1 and you can see that it replaces one random element of the lattice by another random element plus one, hence the goofy behavior. So to get around this, you have to compute the random number and save it somewhere. Good luck, -- Garrett Mitchener ==== Subject: Re: For Loop and Array related The format of the For[] function is For[Init, condition, increment, body]; You have a problem at the part of the condition. I'm sure you ment For[i = 1, i <= 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] Otherwise i will be set to 16000 and the loop wil not be executed yehuda p.s. it is better to use the Do loop in this case, that is Lattice= Table[0, {n, 100}]; Do[Lattice[[Random[Integer, {1, 100}]]]++, {16000}]. This way you probably will avoide some of these errors in the future yehuda > Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. So is > there a different (more Mathematica) way which I can implement the > above? > ==== Subject: Re: For Loop and Array related > Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I > should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. > So is > there a different (more Mathematica) way which I can implement the > above? Looks to me that the Increment operator has problems here. I modified your program for a While. In[152]:= i = 0; n = 100; s = 160; lattice = Table[0, {j, n}]; While[i++ <= s, lattice[[Random[Integer, {1, 100}]]]++; Print[i]; Print[ Total[lattice]]; Print[Tr[lattice]]; Print[Sum[lattice[[k]], {k, 1, n}]]; Print[i - Tr[lattice]]; Print[-----]; ]; When I run this, the Total, Tr and Sum all agree. However Print[i - Tr[lattice]]; clearly show that sometimes no increment takes place and sometimes it is incremented with more than just one. If I re-write the lattice[[Random[Integer, {1, 100}]]]++; the old fashion way: r = Random[Integer, {1, 100}]; lr = lattice[[r]]; lr = lr + 1; lattice[[r]] = lr; than it works fine. J.87nos In[171]:= $Version Out[171]= 5.1 for Mac OS X (October -------------------------------------------- ==== Subject: Re: For Loop and Array related > Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. So is > there a different (more Mathematica) way which I can implement the > above? > I think the one-line (two lines if you count loading the Statistics`DataManipulation package, which you need to use the CategoryCounts function) method below is easier to implement what you want. The idea is that for your problem, you just need to generate a 16,000 element list giving the locations in the 100 element list that are augmented at each step. The number of times a location appears in the 16,000-member list is the final value of that location in the 100-member list, since everything starts at zero. You don't need to use For loops, which I always find confusing in Mathematica. In[1]:= << Statistics`DataManipulation` In[2]:= ans = CategoryCounts[Table[Random[Integer, {1, 100}], {16000}], Range[100]]; In[3]:= ans Out[3]= {16, 12, 20, 15, 20, 18, 15, 17, 16, 19, 14, 14, 15, 17, 20, 11, 13, 18, 13, 16, 14, 12, 17, 16, 13, 19, 13, 17, 10, 15, 22, 12, 20, 23, 18, 18, 21, 21, 20, 17, 16, 12, 18, 9, 16, 17, 12, 13, 16, 22, 16, 16, 17, 16, 23, 22, 16, 20, 8, 15, 16, 9, 11, 20, 10, 14, 14, 17, 14, 11, 13, 14, 13, 22, 21, 18, 19, 15, 13, 15, 19, 21, 17, 16, 12, 18, 17, 14, 12, 15, 12, 14, 10, 14, 16, 15, 18, 28, 10, 26} In[4]:= Plus @@ ans Out[4]= 16000 ==== Subject: Re: For Loop and Array related > Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. So is > there a different (more Mathematica) way which I can implement the > above? Here's how I would approach this. Create a table of your random integers: data = Table[Random[Integer, {1, 100}], {16000}]; Then, the following function will create your lattice: rand[d_] := Normal[SparseArray[#[[All, 1]] -> Length /@ #, 100]] &[Split@Sort@d] Apply the function rand to your data: lattice=rand[data]; Check: In[20]:= Total[lattice] Dimensions[lattice] Out[20]= 16000 Out[21]= {100} Carl Woll Wolfram Research ==== Subject: Re: For Loop and Array related > Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I > should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? > Using ++ (Increment) with the expression lattice[[Random[Integer, {1,100}]]] is part of your problem. Increment appears to evaluate its argument in a very odd way, you can see this if you use trace. Random effectively gets called twice and the assigned value is indeterminate. For example: In[146]:= a=Table[0,{3}]; Trace[a[[Random[Integer,{1,3}]]]++] a Out[147]= {a[[Random[Integer,{1,3}]]]]++,{{a,{0,0, 0}},{Random[Integer,{1,3}], 3},{0,0,0}[[3]], 0},{a[[Random[Integer,{1,3}]]]=1, 1},0} Out[148]= {0,1,0} You can see that Random was evaluated once resulting in a value of 3, then the third element of the list was extracted, resulting in a 0, then that value was incremented resulting in a 1, and now the important part: Random is called again (for some reason Trace doesn't show that but the expression a[[Random[Integer,{1,3}]]]=1 necessarily means that Random is evaluated again, in this case resulting in a value of 2 (we can infer that from the result), then the result of the incremented value from the first call to Random is assigned to the element at the second call of Random. I wish I could explain the logic more plainly, but I can't imagine how, I hope you can follow. Anyway the moral of this lesson is not to call Random in expressions that use Increment because the result is probably not what you intended. > Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. > So is > there a different (more Mathematica) way which I can implement the > above? Basically your problem is you're fighting with the Mathematica evaluator, and you're right; your expectations based on languages like C are incorrect in this case. The structure you are searching for is called a composition, and you can generate those using the Combinatorica function RandomComposition eg. < Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. So is > there a different (more Mathematica) way which I can implement the > above? Using the *Random* function directly within an assignment where the indices are supposed to be the same on both side might not be a good idea! You will find below the same function written in a slightly more Mathematica way: a *Do* loop is used since the index is not used in the body of the program and the index is first computed and saved in a variable before being used by the following instruction that increments the value of the corresponding element. Also, avoid defining symbol names that begin by a capital letter. In[1]:= data = Table[0, {n, 100}]; Do[index = Random[Integer, {1, 100}]; data[[index]]++, {16000}]; Total[data] Out[3]= 16000 /J.M. ==== Subject: Re: For Loop and Array related try Lattice = Table[0, {100}]; For[i = 1, i < 1601, i++, k = Random[Integer, {1, 100}]; Lattice[[k]]++ ] Jens schrieb im Newsbeitrag > Hi All, I have an array with 100 elements, all set to > zero initially. Then I > want to randomly choose one element and increase > its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, > Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list > Lattice together, I should > get 16000 (I use Total[Lattice] to get the sum > of the list). But this > doesn't happen, and strangely, each time I run > this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies > try and write code > like it were C++ and I think i've fallen into > this trap as well. So is > there a different (more Mathematica) way which I > can implement the > above? ==== Subject: Re: For Loop and Array related Hi All, I have an array with 100 elements, all set to zero initially. Then I > want to randomly choose one element and increase its value by one, and > repeat this 16000 times. Here is my code: Lattice = Table[0, {n, 100}]; > For[i = 1, i = 16000, i++, Lattice[[Random[Integer, {1, 100}]]]++] So now if I add all the elements in the list Lattice together, I > should > get 16000 (I use Total[Lattice] to get the sum of the list). But this > doesn't happen, and strangely, each time I run this, the sum of the > list is different! What am I doing wrong? Also I'm aware that a lot of Mathematica newbies try and write code > like it were C++ and I think i've fallen into this trap as well. > So is > there a different (more Mathematica) way which I can implement the > above? > The reason why your code does not work is that Lattice[[Random [Integer, {1, 100}]]]++ actually calls Random[Integer, {1, 100}] twice and the two values you get are not the same (unlike what you intended). As for a more Mathematica like code, load in the discrete Math packages In[1]:= << discretemath` we initialize your lattice In[2]:= Lattice = Table[0, {n, 100}]; And now we do the random increasing In[3]:= Timing[p = With[{s = Prepend[Table[0, {99}], 1]}, Nest[#1 + RandomPermutation[s] & , Lattice, 1600]]; ] Out[3]= {0.7715100000000001*Second, Null} The total sum is indeed 1600: In[4]:= Total[p] Out[4]= 1600 We look at the first 20 entries to see what happened to them: In[5]:= Take[p, 20] Out[5]= {16, 14, 13, 15, 18, 14, 15, 19, 17, 10, 22, 16, 12, 17, 12, 14, 11, 23, 15, 22} One more thing. I have no idea why << discretemath` loads all discrete math packages. I noticed Maxim doing so I tried it and it worked this but I don't think it is a documented feature. Does anyone know? Of course what really is needed above is only the Combinatorica package and the normal, documented way of reading it in is < I spend a lot of time using Input > Create Automatic Numbering > Object . . . to create references of the form : Proposition 3.7.9. > The relevant part of the cell expression is something like TextData[{ > Propostion[NonBreakingSpace], CounterBox[Title, foo], > ., CounterBox[Section, foo], > ., CounterBox[Proposition, foo] > }] Here foo is a cell label and Proposition is a defined cell style. I would like a more efficient way to do this. What I have in mind is > something like a function propref[foo] which when evaluated in > place changes to Proposition 3.7.9, or a button, or a palette, or > something. Any suggestions of the best way to go about this? Garry Helzer > gah@math.umd.edu > This question is a bit vague, but I think you might find CellPrint useful - you can create a cell with any structure you like. David Bailey http://www.dbaileyconsultancy.co.uk ==== Subject: Re: fitting multiple datasets (no idea about the second question, but I'd like to hear an answer) > 2) About the first, obviously... Frank -- Frank K.9fster Inst. f. Biochemie der Univ. Z.9frich Debian Developer ==== Subject: Re: fitting multiple datasets Hi Nate, Question1: You could e.g. add an additional first coordinate x0 to your data points, that indicates the data set, and define f (I call the known parameters a and b and the unknown p1,p2,p3): f[x0_,x_,p1_,p2_,p3_]:=Which[ x0==1, f[x,a1,b1,p1,p2,p3], x0==2, f[x,a2,b2,p1,p2,p3], x0==3, f[x,a3,b3,p1,p2,p3], x0==4, f[x,a4,b4,p1,p2,p3], x0==5, f[x,a5,b5,p1,p2,p3] ] Then you would call FindFit: FindFit[data,f[x0,x,x2,x3,x4,x5],{p1,p2,p3},{x0,x}] Question2: for contstrained optimization you could use NMinimize sincerely, Daniel > I have two questions, > 1) I have multiple datasets, and one function that depend on multiple > parameters, of which I would like to find a global best fit to three of the > parameters. However, within each dataset, I need to specify slightly > different parameters within the function. For example (not actual function > and will not make sense), > f(a_,b_,c_,d_,e_) = a*x^5 + b*x^4 + c*x^3 + d*x^2 + e*x > In datasets 1-5, I would like to specify different a and b values (for > each dataset), while finding the best single fit (global) for c, d, and > e in the function using all datasets. I see that using FindFit one can enter multiple points of the same > dataset, and minimize the parameters of a function to best fit one dataset, > but is it possible to enter multiple datasets and find a global minimum for > multiple parameters in a function? Or do I need to write my own loop in > Mathematica? > 2) When I am doing a minimization using FindFit how do I tell the > minimization routine that I am only interested in solutions (assuming they > exist as local minima) that satisfy a certain range. For example, a > solution to a parameter that is only within the range {a,b}. Nate ==== Subject: Re: fitting multiple datasets (no idea about the second question, but I'd like to hear an answer) > 2) When I am doing a minimization using FindFit how do I tell the > minimization routine that I am only interested in solutions (assuming they > exist as local minima) that satisfy a certain range. For example, a > solution to a parameter that is only within the range {a,b}. You can use NMinimize and give it some constraints in form of inequalities (or even equalities). -- Frank K.9fster Inst. f. Biochemie der Univ. Z.9frich Debian Developer ==== Subject: Transformation rule problem Hi there, I'm stuck with a problem concerning transformation rules and was wondering whether somebody could give me a hint on this. I wouldn't mind a complete solution either ;-) Here's the problem: In a sum like for example a^2 b^4 + a^3 b + a^5 + a^5 b I'd like to replace every instance of the product (a b) by a different expression, let's call it d. Thus my result should look like d^2 b^2 + a^2 d + a^5 + a^4 d This replacement is required to work for arbitrary a and b (especially when they're functions). I've already tried some simple transformation rules but they couldn't do the job. Cheerio, Oliver ==== Subject: Mathematica 5.1 Cumulative Normal Definition (normalcdf[x_] := 1/2 Erf[x^2] + 1/2; ?[x_] := D[normalcdf[x1],x1] /. x1 -> x // ?[x] [ExponentialE]-(x^2/2)/Sqrt(2 ?) I am using this definition of the Cumulative Normal Function which produces a nice clean derivative. When I start using complicated functions the 1/2 from the definition makes for messy solutions. Can anyone suggest a better way to define the cumulative normal distribution? I am only interested in Frank