A20 ==== How can I run mathematica program in background? Is there any way similar to fortran or c where one can runs his program in the background? ==== math <> someresults.m & ??? BTW this is a problem of your operating system and not of Mathematica. Jens > How can I run mathematica program in background? Is there any way > similar to fortran or c where one can runs his program in the > background? Please suggest. Raj ==== First define the functions z[x_] := x^2 + 4; y1[x_] := 4 - x^2; y2[x_] := 3x; Figure out where the y limits coincide: Solve[y1[x] == y2[x], x] {{x -> -4}, {x -> 1}} Which is bigger in between? y1[0] - y2[0] 4 y1 is. Confirm that with a plot. (y2 is linear): Plot[{y1[x], y2[x]}, {x, -5, 5}] Next figure out where z is zero: Solve[z[x] == 0, x] {{x -> -2*I}, {x -> 2*I}} It's never zero for real x, but is it positive, or negative? z[0] 4 Look at the plot, just for fun: Plot[{z[x]}, {x, -4, 1}] z is positive for all x (but only the interval [-4,1] MATTERS). The volume you want, therefore, is Integrate[z[x]*(y1[x] - y2[x]), {x, -4, 1}] 625/4 or: g[x_] = Integrate[z[x]*(y1[x] - y2[x]), x] g[1] - g[-4] 16*x - 6*x^2 - (3*x^4)/4 - x^5/5 625/4 Bobby Treat -----Original Message----- Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: kuska@informatik.uni-leipzig.de ==== you mean: In[]:=Needs[Calculus`Integration`] Integrate[Boole[x^2 + 4 - z > 0 && 4 - x^2 - y > 0 && 3 - x - y < 0 && z > 0], {x, -1, 2}, {y, 1, 5}, {z, -1, 10}]] Out[]=(15*Sqrt[5])/4 and to plot the volume: In[]:=Get[MathGL3d`OpenGLViewer`] In[]:=MVContourPlot3D[ If[1 == Boole[x^2 + 4 - z > 0 && 4 - x^2 - y > 0 && 3 - x - y < 0 && z > 0], 1., -1.], {x, -1, 2}, {y, 1, 5}, {z, -0.1, 7}, Contours -> {0.}, PlotPoints -> 64, MVNewScene -> True] Jens First of all, I would like to thanks to all for trying to help. > Sorry, I must have something missing in my previous description. I need to find out the volumn of a 3D object which form by the equation : > z=x^2 +4 (as bottom surface) > and on the xy plane which bounded by a parabola y=4-x^2 and y=3x line. How would I use Mathematica to plot out this 3D object or find out its volumn > with only the equation given? Shz Shz ==== ========================================================================= ==== = of the individual or entity to which they are addressed. Any disclosure, copying, > distribution and diversion contrary to the applicable export control laws \ and > regulations including US Export Administration Regulations is strictly prohibited. and do not disclose it to others. Please notify the postmaster@hitachi.com.my > of the delivery error by replying to this message and then delete it from \ your ==== = Constantine, If you break your problem up into two cases, even n and odd n, then Mathematica can sum up your problem and get results, albeit with hypergeometric functions. Consider the following (make sure you look at this with a fixed font): In[21]:= evenans = Sum[Binomial[2*n, k]*p^(2*n - k)*(1 - p)^k, {k, 0, n - 1}]; In[22]:= PowerExpand[FunctionExpand[FullSimplify[evenans, n [Element] Integers]]] Out[22]= 2 n n n 1 p - 1 2 (1 - p) p Gamma[n + -] Hypergeometric2F1[1, -n, n + 1, -----] 2 p 1 - -------------------------------------------------------------------- Sqrt[Pi] Gamma[n + 1] In[23]:= oddans = Sum[Binomial[2*n + 1, k]*p^(2*n + 1 - k)*(1 - p)^k, {k, 0, n - 1}]; In[24]:= PowerExpand[FunctionExpand[FullSimplify[oddans, n [Element] Integers]]] Out[24]= 2 n + 1 n n + 1 3 p - 1 2 (1 - p) p Gamma[n + -] Hypergeometric2F1[1, -n - 1, n + 1, -----] 2 p 1 - ------------------------------------------------------------------------ -------- Sqrt[Pi] Gamma[n + 2] Is this what you were looking for? Carl Woll Physics Dept U of Washington > I want to get some F and R such that: > > F[n,p] + R[n,p] = Sum[Binomial[n,k] p^(n-k) (1-p)^k, {k, 0, Floor[n/2] - 1}], > when F[n,p] is an approximation to the sum and the R is the remaining error. > > Constantine. > > > > >>I'm looking for a way of finding the approximation for partitial binomial >>sum. >>I'll be pleasant for any hint.. > > >Use the standard add-on package Statistics`NonlinearFit` to do a >NonlinearFit to whatever model you want to use for the approximation. > > >Bob Hanlon >Chantilly, VA USA > > Constantine Elster > Computer Science Dept. > Technion I.I.T. > Office: Taub 411 > > ==== Can someone provide me more information on how ListIntegrate works than what is contained in the version 4 manual ? Is there a website perhaps or tutorial ? I would like to know how the beginning and end of a list of {x,y} pairs that is being integrated is dealt with by ListIntegrate. I know a series of polynomials is somehow used but how ? Do these overlap ? Are they piecewise continuous ? Are these polynomials available for inspection ? How do they change as a function of k ? optimum k value for a given list ? For any given list, will accuracy monotonically increase with increasing values of k ? Is there anything in the Option Inspector that could cause unexpected behaivor with ListIntegrate ? Are there any good rules of thumb or procedures that will help ensure a reasonable answer is produced ? Is there a way of estimating the error or accuracy of integration performed by ListIntegrate ? ==== Be sure to note the following and what comes after it near the end of the Help Browser info on ListIntegrate: ``This package has been included for compatibility with previous versions of Mathematica. The functionality of this package has been superseded by improvements made to InterpolatingFunction. In other words, ListIntegrate is a dinosaur that you don't need at all! To integrate a list of data with Mathematica, one can proceed in either of two ways: (1) Construct an interpolating function and use NIntegrate (or, better, NIntegrateInterpolatingFunction) on that (which is what ListIntegrate apparently does); or (2) apply a simple routine that implements the trapezoidal rule, Simpson's rule, or maybe some higher order method. Assuming you've chosen to take path #1, you need to realize the following: (a) NIntegrate[Interpolation[data, InterpolationOrder->1][x], {x,a,b}] is equivalent to the trapezoidal rule; (b) NIntegrate[Interpolation[data, InterpolationOrder->2][x], {x,a,b}] is *not* equivalent to Simpson's rule (because of the peculiar way that Interpolation works); (c) Interpolation[data, InterpolationOrder->k] generally does not return a smooth function unless you set InterpolationOrder->n-1, where n is the number of data points, which is the case where a single polynomial of degree n-1 fits the data points. (d) If you want to integrate a smooth interpolant, you can do this: <k][x], {x, 0, 5}, PlotRange -> All], {k, 1, 6}] (The last of those plots will give a warning message.) Having said all that, you really should consider path #2 instead. Here are a couple of links to a MathGroup discussion of last July (somehow the thread got split up): http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00490.html http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00519.html I hope all this helps some. ---- Selwyn Hollis > Can someone provide me more information on how ListIntegrate works > than what is contained in the version 4 manual ? Is there a website > perhaps or tutorial ? > > I would like to know how the beginning and end of a list of {x,y} > pairs that is being integrated is dealt with by ListIntegrate. > > I know a series of polynomials is somehow used but how ? Do these > overlap ? Are they piecewise continuous ? > > Are these polynomials available for inspection ? How do they change as > a function of k ? > > optimum k value for a given list ? For any given list, will accuracy > monotonically increase with increasing values of k ? Is there > anything in the Option Inspector that could cause unexpected behaivor > with ListIntegrate ? > > Are there any good rules of thumb or procedures that will help ensure > a reasonable answer is produced ? > > Is there a way of estimating the error or accuracy of integration > performed by ListIntegrate ? > > > > ==== I timed Daniel's three solutions and Gary's one (plus a couple of my own a little later): perps1[v_] := If[v[[1]] == v[[2]] == 0, {{1, 0, 0}, {0, 1, 0}}, {{v[[2]], -v[[ 1]], 0}, Cross[v, {v[[2]], -v[[1]], 0}]}] perps2[v_] := With[{vecs = NullSpace[{v}]}, {vecs[[ 1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]}] perps2C = Compile[{{v, _Real, 1}}, Module[{vecs = NullSpace[{v}]}, { vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]}]] helzer[v : {a1_, a2_, a3_}] := With[{w = First[Sort[{{a2, -a1, 0}, {a3, 0, -a1}, {0, a3, -a2}}, OrderedQ[{Plus @@ Abs[#2], Plus @@ Abs[#1]}] &]]}, {w, Cross[v, w]}] vecs = Table[Random[], {10000}, {3}]; Timing[perps1 /@ vecs; ] Timing[perps2 /@ vecs; ] Timing[perps2c /@ vecs; ] Timing[helzer /@ vecs; ] {1.7350000000000012*Second, Null} {0.5619999999999994*Second, Null} {0.219 Second, Null} {2.7349999999999994*Second, Null} I made a small change to Daniel's perps1, and got a solution as fast as perps2c, WITHOUT compiling. Compiling tripled the speed again, so treatC is the fastest solution I've seen so far. treat[{a_, b_, c_}] := If[a == b == 0, {{1, 0, 0}, {0, 1, 0}}, {{b, -a, 0}, {a*c, b*c, -a^2 - b^2}}] treatC = Compile[{{v, _Real, 1}}, If[v[[1]] == v[[2]] == 0, {{1, 0, 0}, {0, 1, 0}}, {{v[[2]], -v[[1]], 0}, {v[[1]]*v[[3]], v[[2]]*v[[3]], -v[[1]]^2 - v[[2]]^2}}]] vecs = Table[Random[], {10000}, {3}]; Timing[perps2c /@ vecs; ] Timing[helzer /@ vecs; ] Timing[treat /@ vecs; ] Timing[treatC /@ vecs;] {0.2190000000000083*Second, Null} {2.7339999999999947*Second, Null} {0.25*Second, Null} {0.07800000000000296*Second, Null} None of these solutions reliably return normalized vectors. Bobby Treat -----Original Message----- > pose the problem to MathGroup. Who has the most elegant Mathematica > routine... OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will return > two unit vectors orthogonal to each other and to v. You can assume that v is nonzero. David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ Some possibilities: perps1[v_] := If [v[[1]]==v[[2]]==0, {{1,0,0},{0,1,0}}, {{v[[2]],-v[[1]],0}, Cross[v,{v[[2]],-v[[1]],0}]} ] perps2[v_] := With[{vecs=NullSpace[{v}]}, {vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]} ] This appears to be 2-3 times faster than perps1 for vectors of machine reals. I get another factor of 2 using Compile, which is appropriate for e.g. graphics use. perps2C = Compile[{{v,_Real,1}}, Module[{vecs=NullSpace[{v}]}, {vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]} ]] In[61]:= vecs = Table[Random[], {10000}, {3}]; In[62]:= Timing[p2 = Map[perps1C,vecs];] Out[62]= {0.49 Second, Null} This is on a 1.5 GHz processor. Daniel Lichtblau Wolfram Research ==== >I was wondering if there is a method for resizing Raster graphics >(resizing the actual matrix of pixels, not just the display size). I >am processing a large number of JPEG images, and we sometimes need to >reduce the image size to allow data processing algorithms to function >without running out of memory. In the past we simply used a program >such as Photoshop to resize them before importing them into >Mathematica. Due to the number of images we are processing now this >is very inconvenient and it would be very useful if there was a method >for accomplishing it in Mathematica, but I can't find one. I also >thought about doing something simple like sampling every few pixels or >averaging, but I thought there might be a method with more efficacy >than this. I also tried exporting the graphics with the Export command >as new JPEGs and manipulating the ImageResolution and ImageSize >options but this seemed to have no effect. Any help would be much >appreciated. >Aaron Urbas In 4.2, the following should work (as long as you define newsize). in = Import[file.jpg]; Export[newfile.jpg, in, ImageSize->newsize] In 4.1 and earlier, this will not work because an optimization interferes with the ImageSize and rasters are written out with the raster size, not the ImageSize. There is a ConversionOption to force the behavior you want. in = Import[file.jpg]; Export[newfile.jpg, Show[in, ImageSize->newsize], ConversionOptions->{RasterExport->Graphics} ] -Dale ==== Borrowing liberally from Daniel, I like the following: ClearAll[sumBin, sumBinOdd, sumBinEven, index] sumBinOdd = Sum[Binomial[2index + 1, k]*p^(2index + 1 - k)*(1 - p)^k, { k, 0, index - 1}]; sumBinEven = Sum[Binomial[2index, k]* p^(2index - k)*(1 - p)^k, {k, 0, index - 1}]; sumBin[n_, Odd] = sumBinOdd /. {index -> (n - 1)/2}; sumBin[n_, Even] = sumBinEven /. {index -> n/2}; sumBin[n_?EvenQ] = sumBin[n, Even]; sumBin[n_?OddQ] = sumBin[n, Odd]; It allows you to see the solution symbolically for both odd and even n, and also to calculate it when n is a known integer. We also have the opportunity, for instance, to assume that 3x is even and calculate sumBin[3x, Even] p^(3*x)*((1/p)^(3*x) - ((-4 + 4/p)^((3*x)/2)* Gamma[1/2 + (3*x)/2]*Hypergeometric2F1[1, -((3*x)/2), 1 + (3*x)/2, (-1 + p)/p])/(Sqrt[Pi]*Gamma[1 + (3*x)/2])) or assume 3x is odd and calculate sumBin[3*x, Odd] p^(3*x)*((1/p)^(3*x) - (2^(3*x)*(-1 + 1/p)^((1/2)*(-1 + 3*x))* Gamma[3/2 + (1/2)*(-1 + 3*x)]*Hypergeometric2F1[1, -1 + (1/2)*(1 - 3*x), 1 + (1/2)*(-1 + 3*x), (-1 + p)/p])/(Sqrt[Pi]* Gamma[2 + (1/2)*(-1 + 3*x)])) Bobby Treat -----Original Message----- > when F[n,p] is an approximation to the sum and the R is the remaining error. Constantine. >In a message dated 8/28/02 4:44:13 AM, celster@cs.technion.ac.il > > >>I'm looking for a way of finding the approximation for partitial binomial >>sum. >>I'll be pleasant for any hint.. > [...] > Office: Taub 411 You can get a closed form in terms of special functions if you split into two cases depending on whether n is even or odd. In[39]:= n = 2*m; In[40]:= InputForm[Sum[Binomial[n,k]*p^(n-k)*(1-p)^k, {k,0,m-1}]] Out[40]//InputForm= p^(2*m)*((p^(-1))^(2*m) - ((-4 + 4/p)^m*Gamma[1/2 + m]* Hypergeometric2F1[1, -m, 1 + m, (-1 + p)/p])/(Sqrt[Pi]*Gamma[1 + m])) In[41]:= n = 2*m+1; In[42]:= InputForm[Sum[Binomial[n,k]*p^(n-k)*(1-p)^k, {k,0,m-1}]] Out[42]//InputForm= p^(1 + 2*m)*((p^(-1))^(1 + 2*m) - (2^(1 + 2*m)*(-1 + p^(-1))^m*Gamma[3/2 + m]* Hypergeometric2F1[1, -1 - m, 1 + m, (-1 + p)/p])/(Sqrt[Pi]*Gamma[2 + m])) Daniel Lichtblau Wolfram Research ==== I've found that Mathematica 4.2 takes too long to finish to generate first time help browser. Is this normal? How many time should it take? Calimero ==== Please excuse me if this has been discussed before; I haven't been monitoring the group very much. A long time ago I posted to this group as well as to Wolfram about the errors in many or all functions involving Fourier transforms when values of FourierParameters other than the default values are used. The group responded that indeed there was a problem so I'm wondering if it was ever fixed. My version (then and now) is 4.0.1 for Macintosh. Jerry ==== Could you help me? I'm to solve heat conductivity equation (Laplas equation) - partial differential equation. Are there any ready-to-use packages that will help me do the job? Standard function DSolve cannot! And so do functions from package Calculus`DSolveIntegrals`. More info: the space where the equation is to be solved is cylindre (not infinite). Andrew. ==== When I multiply an expression with 0 it is giving 0.expression which is creating problem in the further calculation. eg. In[1]:=func1[r_]:=Exp[-r/2] In[2]:coeff[[1,1]]=0.0; ; ; In[34]:=func1[r]coeff[[1,1]] Out[34]:=0.Exp[-r/2] I want anything to be multiply by zero must be zero. How can I do that? Your suggestion will be highly appreciated. Raj ==== > When I multiply an expression with 0 it is giving 0.expression which > is creating problem in the further calculation. No. Your trouble comes when you multiply an expression by the floating-point number 0.0, rather than by the precise symbolic 0 (having no decimal point). Merely make the coefficient 0 (rather than 0.0) and everything should work as you wish. David > eg. > > In[1]:=func1[r_]:=Exp[-r/2] > In[2]:coeff[[1,1]]=0.0; > ; > ; > In[34]:=func1[r]coeff[[1,1]] > > Out[34]:=0.Exp[-r/2] > > I want anything to be multiply by zero must be zero. > > How can I do that? -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service Reply-To: kuska@informatik.uni-leipzig.de ==== Unprotect[Times] Times[0., __] := 0 Protect[Times] Jens > When I multiply an expression with 0 it is giving 0.expression which > is creating problem in the further calculation. eg. In[1]:=func1[r_]:=Exp[-r/2] > In[2]:coeff[[1,1]]=0.0; > ; > ; > In[34]:=func1[r]coeff[[1,1]] Out[34]:=0.Exp[-r/2] I want anything to be multiply by zero must be zero. How can I do that? > Your suggestion will be highly appreciated. > Raj ==== Now I'm trying to calculate this formula: Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] eq has this form a x^2 + b x + c But there is a problem with the x^0 coefficient! How can I overcome that? CeZaR Reply-To: kuska@informatik.uni-leipzig.de ==== and Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x,2] Coefficient[eq, x,0] does what you want. Because the Help-Browser say: Coefficient[expr, form, 0] picks out terms that are not proportional to form. Jens > Now I'm trying to calculate this formula: Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] eq has this form a x^2 + b x + c But there is a problem with the x^0 coefficient! > How can I overcome that? > CeZaR ==== I need to fill the space between two contour lines, C1 and C2, with red color, and leave the other place white. What trick I have to use? Any suggestion and advice will be appreciated. Jun Lin Reply-To: kuska@informatik.uni-leipzig.de ==== gr = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, Contours -> {0.2, 0.4}, ColorFunction -> (If[# >= 0.2 && # <= 0.4, RGBColor[1, 0, 0], RGBColor[1, 1, 1]] &), ColorFunctionScaling -> False ] Jens I need to fill the space between two contour lines, C1 and C2, with > red color, and leave the other place white. What trick I have to use? > Any suggestion and advice will be appreciated. Jun Lin ==== I am trying to find an example that will demonstrate the difference between $PrePrint and $Post. I found an old thread in this news group where a user wanted to display all matrices using MatrixForm. Some users suggested the following: In[1]:= $Post=(#/.mtrx_?MatrixQ:>MatrixForm[mtrx]&); Then Dave Withoff said it's better to assign this to $PrePrint since the objective here is to adjust the display rather than the result of the calculation. With the assignment to $Post you could, for example, get unexpected results from calculations using %, since matrices will be wrapped in MatrixForm. -------- However, if we use $Post above, the next input will compute the inverse the matrix. I did verify that Inverse can't take a matrix wrapped in MatrixForm. Can somebody give an example where doing this with $PrePrint instead of $Post gives a different result. In[2]:= m={{2,3},{0,1}}; Inverse[%] Out[3]= (* Inverse of (m) in MatrixForm, not shown. *) ------ Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html Reply-To: kuska@informatik.uni-leipzig.de ==== yo can just try In[]:=$Post = (# /. mtrx_?MatrixQ :> AnyHead[mtrx] &); In[]:=m = {{2, 3}, {0, 1}} In[]:=q=%; In[]:=Head[q] and In[]:=$PrePost = (# /. mtrx_?MatrixQ :> AnyHead[mtrx] &); In[]:=m = {{2, 3}, {0, 1}} In[]:=q=%; In[]:=Head[q] But you are right -- the behaviour of MatrixForm[] in your example is strange. Jens I am trying to find an example that will demonstrate the difference between > $PrePrint and $Post. I found an old thread in this news group where a > user wanted to display all matrices using MatrixForm. Some users suggested > the following: In[1]:= $Post=(#/.mtrx_?MatrixQ:>MatrixForm[mtrx]&); Then Dave Withoff said it's better to assign this to $PrePrint since the > objective here is to adjust the display rather than the result of the > calculation. With the assignment to $Post you could, for example, get > unexpected results from calculations using %, since matrices will be wrapped > in MatrixForm. > -------- However, if we use $Post above, the next input will compute the inverse > the matrix. I did verify that Inverse can't take a matrix wrapped in > MatrixForm. Can somebody give an example where doing this with $PrePrint > instead of $Post gives a different result. In[2]:= m={{2,3},{0,1}}; > Inverse[%] Out[3]= (* Inverse of (m) in MatrixForm, not shown. *) ------ > Ted Ersek > Get Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html ==== myArray is a list of triplets which look like {n,k,p}, where n and k are integers and p is real number. repetitions in n and k are allowed but no two triplets ar the same. I define a function, myfunc[n_,pthreshold_] as follows. myfunc[n_,pthreshold_] := Module[{t}, t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; If[t>=0,t,-1]] It prints the largest k for which p is greater than pthreshold for a given n and -1 if there is no such k. The function does its job fine. My problem is as follows. I would like to plot a collection of plots, myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the following does not work as desired. Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] because the Table gets evaluated to numeric value (-1) before Plot is invoked. ==== I made a mistake in the definition of the question. The function is correctly defined as myfunc[n_,pthreshold_] := Module[{t}, t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> k, 2]]; If[t>=0,t,-1]] Please note that inserting Evaluate before Table does not work correctly either, because evaluating myfunc[n,p] when p is not a number, gives -1. > Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] because the Table gets evaluated to numeric value (-1) before Plot is > invoked. Reply-To: kuska@informatik.uni-leipzig.de ==== could you supply a complete example next time ? Try myfunc[] with a more restrictive pattern and it works: myArray = Flatten[Table[{n, 1, Random[]}, {15}, {n, 1, 21}], 1]; myfunc[n_, pthreshold_?NumericQ] := Module[{t}, t = Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; If[t >= 0, t, -1]] Plot[Evaluate[Table[myfunc[n, p], {n, 1, 21}]], {p, 0.0, 1.0}] Jens myArray is a list of triplets which look like {n,k,p}, where n and k > are integers and p is real number. repetitions in n and k are allowed > but no two triplets ar the same. I define a function, myfunc[n_,pthreshold_] as follows. myfunc[n_,pthreshold_] := Module[{t}, > t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; > If[t>=0,t,-1]] It prints the largest k for which p is greater than pthreshold for a > given n and > -1 if there is no such k. The function does its job fine. My problem is as follows. I would like to plot a collection of plots, > myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the > following does not work as desired. Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] because the Table gets evaluated to numeric value (-1) before Plot is > invoked. ==== For my PDE class we have been calculating Fourier transforms. The instructor arrived today with a printout of two plots of a certain Fourier transform, done with a different CAS. The first plot was to 30 terms, the second was to 120 terms. Curious, I translated the functions into Mathematica (4.0 on Windows2000 on a PIII 700) to see how much time this required to process. I was Staggered at how much time it took. Here's the code: L = 2; f[x_] := UnitStep[x - 1]; b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] Out[23]= {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} In this case the number of terms is 30. The time required per number of terms seems to fit the following polynomial: y = 0.3926x^2 + 2.2379x This is a large amount of time. I understand that the code is not optimized, and was more or less copied from the code in the other CAS, but is this a reasonable amount of time, or is something going wrong? I don't use Mathematica because of the speed, but should it be this slow? Just curious, Steve Story ==== > I don't use Mathematica > because of the speed, but should it be this slow? Mathematica has become more competitive in the speed department in recent years. See for example the attached comparison (not sent to newsgroup) by Stephan Steinhaus (steinhaus-net.de). So when Mathematica takes a very long time, you should investigate. In this case inserting Evaluate[] in two places In[91]:=b[n_] := Evaluate[(2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; .... In[104]:=Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]] Out[104]={0.18 Second,[SkeletonIndicator]Graphics[SkeletonIndicator]} speeds the process enormously (18 milliseconds to plot 120 terms on my feeble old 500MHz PowerBook). Why was it so slow before? When I switch from an ordinary numerical language to Mathematica, I enter into an implicit bargain with Mathematica: the software will go the extra mile to get me a good answer, including (1) using exra precision (sometimes without being asked) and (2) carrying around unevaluated mathematical expressions (usually without being asked) that could possibly be evaluated more appropriately at a later time. Most tools cannot do either of these things, so I don't have to worry about it, except for the bad answers that result now and then. But I need to take care that Mathematica does not burden itself unnecessarily. That's my side of the bargain. Number (2) is the issue here. Your definition of b[n] is written so that Mathematica analytically evaluates b separately for each n. But you know in this case that the integration can be done safely once for all n. So do it! The huge difference, though, comes from pre-evaluating the argument to Plot. Read the on-line help! You should pre-evaluate where possible. In some cases, the most common of which involve branching within the definition of function to plot, you cannot pre-evaluate so, in keeping with the bargain, Mathematica goes the extra mile and holds back just in case. You need to steer it into the shortcut when it's OK. Hope this helps, Tom Burton -- Reply-To: kuska@informatik.uni-leipzig.de ==== with your code you compute the expansion coefficents every time when FS[] is evaluated. Store the values for b[n] with L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] and you need only a 1-3 seconds (depending on your machine) Jens For my PDE class we have been calculating Fourier transforms. The instructor > arrived today with a printout of two plots of a certain Fourier transform, > done with a different CAS. The first plot was to 30 terms, the second was \ to > 120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 > on a PIII 700) to see how much time this required to process. I was > Staggered at how much time it took. Here's the code: L = 2; > f[x_] := UnitStep[x - 1]; > b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] Out[23]= > {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} In this case the number of terms is 30. The time required per number of terms seems to fit the following polynomial: y = 0.3926x^2 + 2.2379x This is a large amount of time. I understand that the code is not optimized, > and was more or less copied from the code in the other CAS, but is this a > reasonable amount of time, or is something going wrong? I don't use Mathematica > because of the speed, but should it be this slow? Just curious, Steve Story ==== I would like to use mathematica type papers for my math courses, but I'm having trouble formatting documents. Despite searching, I've been unable to find a complete guide to word processing with mathematica. Does anyone know where such a document could be found? ==== Look at in the Help browser or in the Mathematica Book Style Sheet Also, you have the documentation included for package Author Tools (only in Mathematica 4.2). Guillermo Sanchez > I would like to use mathematica type papers for my math courses, but > I'm having trouble formatting documents. Despite searching, I've been > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== Kenny, Sympathy but no solution. I too have been trying to use Mathematica (v4.2 most recently) to type maths papers and the like but I'm not ready to ditch LaTeX yet. There are just too many cases where I cannot figure out how to achieve what I want in Mathematica, things like: - left brackets spanning multiple lines for defining hybrid functions; - vertical alignment of equals signs in multi-line equations or derivations; - setting typefaces in tables of material. I figure most of this is do-able, but I don't have the time, or patience, to spend too much time on it. So, I'll be the first customer when you write the guide to math publishing in Mathematica - I just hope you won't have to use LaTeX to write it. Mark Westwood I would like to use mathematica type papers for my math courses, but > I'm having trouble formatting documents. Despite searching, I've been > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== OrthogonalUnitVectors that I sent a few minutes ago doesn't do what I thought it would. After making either definition below I get the following: In[2]:= s1=OrthogonalUnitVectors[{1,0,1/2,1,0},{0,1,-1,1/2,2}] Out[2]= {{0, -2/Sqrt[5], 0, 0, 1/Sqrt[5]}, {-2/3, -1/3, 0, 2/3, 0}, {-1/3, 2/3, 2/3, 0, 0}} The dot products below aren't zero, so the vectors aren't orthogonal. What went wrong? In[3]:= Part[s1,1].Part[s1,2] Out[3]= 2/(3*Sqrt[5]) In[4]:= Part[s1,1].Part[s1,3] Out[3]= -4/(3*Sqrt[5]) -------------- > Hugh Goyder and David Park gave a most elegant function to find two > vectors that are orthogonal to one vector in 3D. The key to coming up > with the elegant solution is an understanding of Mathematica's NullSpace > function. We can easily make the version from Hugh and David much more > general with the version below. > ------------- > OrthogonalUnitVectors[vect__?VectorQ]:= > #/Sqrt[#.#]&/@NullSpace[{vect}] ------------- > The version above will give a set of unit orthogonal vectors if given any > number of vectors in any dimension. > So besides giving it a 3D vector we can give it the following: > OrthogonalUnitVectors[{2,1,0,-1,1}] > or > OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] ------------ > But the short version above isn't very robust. > (1) Clear[x,y,z];NullSpace[{{x,y,z}}] > returns two vectors orthogonal to {x,y,z}, but the two vectors > NullSpace returns aren't orthogonal to each other. > So (OrthogonalUnitVectors) should only work with numeric vectors. (2) We should ensure all the vectors have the same dimension and length >1. I give a less concise version below that corrects these problems. > ------------ OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; > (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= > #/Sqrt[#.#]&/@NullSpace[{vect}] -------------- > Ted Ersek > Get Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html > ==== Daniel Lichtblau has pointed out that NullSpace does not generally give orthogonal vectors. Therefore the routines that depended upon that were in error. He says that it does give orthogonal vectors when the input vector contains approximate numbers. For graphical purposes this will be good enough for me. Therefore I modify Ted's routine to OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] and the short version for 3D vectors OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ NullSpace[{v//N}] For exact vectors I might use for 3D OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ {temp = First[NullSpace[{v}]], v[Cross]temp} I'm still looking for something that is easy to remember. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ The version above will give a set of unit orthogonal vectors if given any number of vectors in any dimension. So besides giving it a 3D vector we can give it the following: OrthogonalUnitVectors[{2,1,0,-1,1}] or OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] ------------ But the short version above isn't very robust. (1) Clear[x,y,z];NullSpace[{{x,y,z}}] returns two vectors orthogonal to {x,y,z}, but the two vectors NullSpace returns aren't orthogonal to each other. So (OrthogonalUnitVectors) should only work with numeric vectors. (2) We should ensure all the vectors have the same dimension and length >1. I give a less concise version below that corrects these problems. ------------ OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= #/Sqrt[#.#]&/@NullSpace[{vect}] -------------- Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html ==== I am unsure if my messages are making it through to the usegroup so \ I will try again. I have several differential equations I would like to plot in Mathematica. I would like to plot the Slope Fields of them though. Can anyone lead me in the right direction? I can solve the equations trivially but I want to display the slope fields. An example follows : y' + 2y = 3 -John ==== John, You can do it from scratch with PlotVectorField from the Graphics`PlotField` package, but you make make your life easier (and get prettier plots) by using my DEGraphics package, which can be found at MathSource (it's part of the DiffEqs suite of packages) or here: http://www.math.armstrong.edu/faculty/hollis/mmade/DiffEqs --- Selwyn Hollis > I am unsure if my messages are making it through to the usegroup so \ I > will try again. I have several differential equations I would like to > plot in Mathematica. I would like to plot the Slope Fields of them > though. Can anyone lead me in the right direction? I can solve the > equations trivially but I want to display the slope fields. An example > follows : y' + 2y = 3 -John > Reply-To: kuska@informatik.uni-leipzig.de ==== Needs[Graphics`PlotField`] PlotVectorField[{x, 3 - 2 y}, {x, 0, 4}, {y, -1, 4}, Axes -> True] ??? Jens I am unsure if my messages are making it through to the usegroup so I > will try again. I have several differential equations I would like to > plot in Mathematica. I would like to plot the Slope Fields of them > though. Can anyone lead me in the right direction? I can solve the > equations trivially but I want to display the slope fields. An example > follows : y' + 2y = 3 > -John ==== You can proceed like this : delta[poly2_, var_] := Coefficient[poly2, var, 1]^2 - 4*Coefficient[poly2, var, 0]*Coefficient[poly2, var, 2] Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : ven., 6. septembre 2002 09:17 è : mathgroup@smc.vnet.net Objet : Coefficient problem Now I'm trying to calculate this formula: Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] eq has this form a x^2 + b x + c But there is a problem with the x^0 coefficient! How can I overcome that? CeZaR ==== This works: eq = a x^2 + b x + c discriminant[eq_, x_] := Coefficient[eq, x]^2 - 4 Coefficient[eq, x, 2] Coefficient[eq, x, 0] discriminant[eq, x] x^0 is reduced to 1 and the Coefficient of 1 doesn't make sense to Mathematica, because it depends on what the variable is (a, b, c, or x?). So, the other form of the Coefficient call is needed. I used it for the second power too, but that wasn't necessary. I think that form is best, though, since it allows no ambiguity. I renamed the function because that's what the quantity is often called, for a quadratic. Bobby Treat -----Original Message----- CeZaR ==== >-----Original Message----- >Sent: Friday, September 06, 2002 9:17 AM > > >myArray is a list of triplets which look like {n,k,p}, where n and k >are integers and p is real number. repetitions in n and k are allowed >but no two triplets ar the same. > >I define a function, myfunc[n_,pthreshold_] as follows. > >myfunc[n_,pthreshold_] := Module[{t}, >t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; >If[t>=0,t,-1]] > >It prints the largest k for which p is greater than pthreshold for a >given n and >-1 if there is no such k. The function does its job fine. > >My problem is as follows. I would like to plot a collection of plots, >myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the >following does not work as desired. > >Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] > >because the Table gets evaluated to numeric value (-1) before Plot is >invoked. > The problem with your calculation indented is (1) to evaluate Table (within Plot), which gives {myfunc[1, p], ..., myfunc[21, p]} but (2) *then* to prevent further evaluation of myfunc[.., p] to -1. There are several tricks to do so, e.g. ... Hold[Plot[toPlot, {p, 0, 1}]] /. toPlot -> Table[headPlaceholder[n, p], {n, 3}] /. headPlaceholder -> myfunc // ReleaseHold ...but in your case just simply prevent evaluation of myfunc[.., p] with p being a Symbol by defining: myfunc2[n_, pthreshold_?NumericQ] := ... now... Plot[Evaluate[Table[myfunc2[n, p], {n, 21}]], {p, 0, 1}] ...works as expected. BTW, what do you want to read off the plot, that you didn't know from Table[myfunc[n, 0], {n, 21}] ? -- Hartmut Wolf ==== >-----Original Message----- >Sent: Friday, September 06, 2002 9:17 AM > > > > When I multiply an expression with 0 it is giving 0.expression which >is creating problem in the further calculation. > >eg. > >In[1]:=func1[r_]:=Exp[-r/2] >In[2]:coeff[[1,1]]=0.0; >; >; >In[34]:=func1[r]coeff[[1,1]] > >Out[34]:=0.Exp[-r/2] > >I want anything to be multiply by zero must be zero. > > How can I do that? >Your suggestion will be highly appreciated. > > > Raj > Raj, this simply is, because 0. Exp[-r/2] is not always zero! func1[-Infinity]coeff[[1, 1]] Infinity::indet: Indeterminate expression 0. Infinity encountered. Out[90]= Indeterminate -- Hartmut Wolf ==== I have a mathematica notebook showing using the alternating direction implicit method for solving heat conduction in 2D via finite difference methods. Moving from 2D to 3D is pretty simple although I can't find my notebook on this anymore :( . The 3D method is sometimes called Brian's method. http://mid-ohio.mse.berkeley.edu/scott/projects/index.html Scott > Could you help me? > I'm to solve heat conductivity equation (Laplas > equation) - partial differential equation. Are there > any ready-to-use packages that will help me do the job? > Standard function DSolve cannot! And so do functions > from package Calculus`DSolveIntegrals`. More info: the space where the equation is to be > solved is cylindre (not infinite). Andrew. > ==== I am working with Mathematica 4.0, and I would like pass my data to do one graphic in Origin 5.0. How can I do this in more simple manner? ==== > I need to fill the space between two contour lines, C1 and C2, with > red color, and leave the other place white. What trick I have to use? > Any suggestion and advice will be appreciated. Over the years I have alighted upon the following scheme. Suppose I want to color only between contour levels 1 and 2: In[84]:=Needs[Graphics`Colors`] In[88]:=ContourPlot[x, {x, -1, 3}, {y, 0, 1}, Contours -> {0, 1, 2, 3, 4}, ColorFunction -> (If[1 < # < 2, Red, White] & ), ColorFunctionScaling -> False]; 1. Specify the specific contour levels instead of specifying only the count. 2. Disable ColorFunctionScaling so the argument to ColorFunction corresponds to the contour levels. Hope this helps, Tom Burton ==== David Park replied with ---------------- Daniel Lichtblau has pointed out that NullSpace does not generally give orthogonal vectors. Therefore the routines that depended upon that were in error. He says that it does give orthogonal vectors when the input vector contains approximate numbers. For graphical purposes this will be good enough for me. Therefore I modify Ted's routine to OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] ---------------- Lets see what NullSpace does with approximate complex vectors. In[1]:= v1 = {1.0 I, 0.0, 0.5 I, 0.0, 1.0}; v2 = {0.0, 2.0, 1.0 I, 2.0, 0.5}; {v3,v4,v5} = NullSpace[{v1,v2}] Out[3]= {{-0.730153 + 0.*I, 0. - 0.138254*I, 0.250585 + 0.*I, 0. - 0.138254*I, 0. + 0.60486*I}, {0. + 0.*I, -0.515861 + 0.*I, 0. + 0.457321*I, 0.687357 + 0.*I, 0.22866 + 0.*I}, {0. + 0.*I, 0.510406 + 0.*I, 0. + 0.740442*I, -0.23274 + 0.*I, 0.370221 + 0.*I}} -------- In the next line we see NullSpace returned vectors that are orthogonal to the vectors we gave NullSpace. In[4]:= {v1.v3, v1.v4, v1.v5, v2.v3, v2.v4, v2.v5}//Chop Out[4]= {0, 0, 0, 0, 0, 0} ---------- However, the vectors returned aren't orthogonal to each other. In[5]:= {v3.v4, v3.v5, v4.v5}//Chop Out[5]= {0.229195*I, 0.371087*I, -0.677239} --------- I suppose an OrthogonalUnitVectors function that uses NullSpace should (1) Only accept real valued vectors. (2) Ensure NullSpace is given approximate vectors. ------ Ted Ersek ==== >OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; > (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := > #/Sqrt[#.#] & /@ NullSpace[{vect}// N] > >Lets see what NullSpace does with approximate complex vectors. > >In[1]:= > v1 = {1.0 I, 0.0, 0.5 I, 0.0, 1.0}; > v2 = {0.0, 2.0, 1.0 I, 2.0, 0.5}; > {v3,v4,v5} = NullSpace[{v1,v2}] > >Out[3]= > {{-0.730153 + 0.*I, 0. - 0.138254*I, 0.250585 + 0.*I, 0. - 0.138254*I, >0. >+ 0.60486*I}, > {0. + 0.*I, -0.515861 + 0.*I, 0. + 0.457321*I, 0.687357 + 0.*I, 0.22866 >+ 0.*I}, > {0. + 0.*I, 0.510406 + 0.*I, 0. + 0.740442*I, -0.23274 + 0.*I, 0.370221 >+ 0.*I}} > >-------- >In the next line we see NullSpace returned vectors that are orthogonal to >the vectors we gave NullSpace. > >In[4]:= > {v1.v3, v1.v4, v1.v5, v2.v3, v2.v4, v2.v5}//Chop > >Out[4]= > {0, 0, 0, 0, 0, 0} > >---------- >However, the vectors returned aren't orthogonal to each other. > >In[5]:= > {v3.v4, v3.v5, v4.v5}//Chop > >Out[5]= > {0.229195*I, 0.371087*I, -0.677239} > >--------- >I suppose an OrthogonalUnitVectors function that uses NullSpace should > (1) Only accept real valued vectors. > (2) Ensure NullSpace is given approximate vectors. > >------ > Ted Ersek I think you will find that the output vectors are orthogonal if you use the complex conjugate. for example v4.Conjugate[v5] is zero. Dennis Wangsness ==== >I need to fill the space between two contour lines, C1 and C2, with >red color, and leave the other place white. What trick I have to use? >Any suggestion and advice will be appreciated. Needs[Graphics`FilledPlot`]; Needs[Graphics`Colors`]; FilledPlot[{4 - x^2, 3x}, {x, -4, 1}, Fills -> Red]; Bob Hanlon ==== >For my PDE class we have been calculating Fourier transforms. The instructor >arrived today with a printout of two plots of a certain Fourier transform, >done with a different CAS. The first plot was to 30 terms, the second was >to >120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 >on a PIII 700) to see how much time this required to process. I was >Staggered at how much time it took. Here's the code: > >L = 2; >f[x_] := UnitStep[x - 1]; >b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; > >FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; > >Timing[Plot[FS[30, x], {x, 0, 2}]] > >Out[23]= >{419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} > >In this case the number of terms is 30. > >The time required per number of terms seems to fit the following polynomial: > >y = 0.3926x^2 + 2.2379x > >This is a large amount of time. I understand that the code is not optimized, >and was more or less copied from the code in the other CAS, but is this >a >reasonable amount of time, or is something going wrong? I don't use Mathematica >because of the speed, but should it be this slow? > >Just curious, Your definition of b recalculates the integral for every call. To evaluate \ the integral once include Evaluate. Clear[f, b, FS]; L = 2; f[x_] := UnitStep[x - 1]; b[n_] := Evaluate[ (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; In the case of FS it is best to wait for an integer value of N prior to performing the Sum. FS[N_Integer, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Now Evaluate the argument of the Plot to cause the Sum to be done once. Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]][[1]] 0.366667 Second While my computer may be faster than yours, this result for N=120 is 1000 times faster than your result for N=30. Bob Hanlon ==== > Now I'm trying to calculate this formula: Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] eq has this form a x^2 + b x + c But there is a problem with the x^0 coefficient! > How can I overcome that? > CeZaR Coefficient cannot figure out who is and is not a variable when a variable of 1 is specified. To work around this you might instead do delta1[poly_, x_] := Coefficient[poly,x]^2 - 4*Coefficient[poly,x,2]*Coefficient[poly,x,0] I prefer instead to use CoefficientList: delta2[poly_, x_] := (#[[2]]^2 - 4*#[[1]]*#[[3]])& [CoefficientList[poly,x]] In[25]:= poly = a*x^2+b*x+c; In[26]:= delta1[poly,x] === delta2[poly,x] Out[26]= True Daniel Lichtblau Wolfram Research ==== > >Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, >x^0] > >eq has this form a x^2 + b x + c > >But there is a problem with the x^0 coefficient! >How can I overcome that? see on-line help for Coefficient delta[eq_, x_] := Coefficient[eq, x, 1]^2 - 4 *Coefficient[eq, x, 2] *Coefficient[eq, x, 0]; eq = a*x^2 + b*x + c; delta[eq, x] b^2 - 4*a*c Bob Hanlon ==== Would someone with a very fast machine and lots of memory be willing to try \ this Solve for me? It is the inverse of the 20 node quadratic hexahedral mapping used in finite element analysis. None of my computers can handle this - they run out of memory (using (*Hex20 Node definition in global coordinates *) Clear[ x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20, z20]; (* local coordinates *) Clear[u, v, w]; (* Global co-ordinates *) Clear[x, y, z]; (* corner nodes *) N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; (* to u nodes *) N2= (1-u^2)*(1-v)*(1-w)/4; N6= (1-u^2)*(1+v)*(1-w)/4; N14=(1-u^2)*(1-v)*(1+w)/4; N18=(1-u^2)*(1+v)*(1+w)/4; (* to v nodes *) N4= (1+u)*(1-v^2)*(1-w)/4; N8= (1-u)*(1-v^2)*(1-w)/4; N16=(1+u)*(1-v^2)*(1+w)/4; N20=(1-u)*(1-v^2)*(1+w)/4; (* to w nodes *) N9= (1-u)*(1-v)*(1-w^2)/4; N10=(1+u)*(1-v)*(1-w^2)/4; N11=(1+u)*(1+v)*(1-w^2)/4; N12=(1-u)*(1-v)*(1-w^2)/4; (* solve the inverse transform *) Solve[{ x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19+x20*\ N20-x==0, y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19+y20*\ N20-y==0, z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19+z20*\ N20-z==0}, {u,v,w}] Christopher J. Purcell Defence R&D Canada \.9a Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== Needs[Graphics`Colors`]; ContourPlot[Sin[x y], {x, -5, 5}, {y, -5, 5}, ColorFunction -> (If[0.5 < # < 0.7, Red, White] &)]; Bob Hanlon >ContourPlot? > > >Jun Lin > >> In a message dated 9/6/02 3:53:58 AM, >>I need to fill the space between two contour lines, >> C1 and C2, with >>red color, and leave the other place white. What >> trick I have to use? >>Any suggestion and advice will be appreciated. >> Needs[Graphics`FilledPlot`]; >> Needs[Graphics`Colors`]; >> FilledPlot[{4 - x^2, 3x}, {x, -4, 1}, Fills -> Red]; ==== Jun Lin, Here is an example. Needs[Graphics`Colors`] Let's make a contour plot of this function. f[x_, y_] := Sin[x]Sin[2y] Let's specify the exact contours to use. I got rid of the 0. contour because it is difficult to obtain in this plot. contourvalues = Complement[Range[-1, 1, 0.2], {0.}] {-1, -0.8, -0.6, -0.4, -0.2, 0.2, 0.4, 0.6, 0.8, 1.} Now we define a ColorFunction for the plot. I actually colored two different bands to show how you can make a general color function to give each band a desired color. cfun[z_] := Which[ -0.6 < z < -0.42, RoyalBlue, 0.4 < z < 0.6, Red, True, White] ContourPlot[f[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30, ColorFunctionScaling -> False, ColorFunction -> cfun, Contours -> contourvalues]; Using the option ColorFunctionScaling -> False says that the z value will be the actual value of f[x,y]. Otherwise, in general, it will be scaled between 0 and 1. It is easier to write a color function when z is the actual value of the function. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: ==== I checked again the six solutions I had previously timed, and they DO give orthogonal results. (None of them depend on NullSpace for that.) By the way, I reused my combinations function (from a recent problem on adding fractions to get 1) to check for orthogonality: ClearAll[orthogonalQ] orthogonalQ[v : {__?VectorQ}] := And @@ (Chop@( Dot @@ #) == 0 & /@ combinations[v, {2}]) << DiscreteMath`Combinatorica`; ClearAll[combinations]; r = Range[1, 9]; combinations::usage = combinations[list,n:{__Integer}] lists the combinations of list taken n at a time; combinations[r_List, n_Integer, {}] := If[n > Length@r, {}, DiscreteMath`Combinatorica`KSubsets[r, n]]; combinations[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@ DiscreteMath`Combinatorica`KSubsets[Complement[r, e], n]; combinations[r_List, n_Integer, e : {__?VectorQ}] := Flatten[ combinations[r, n, #] & /@ e, 1]; combinations[r_List, n : {__Integer}] := Which[Plus @@ n == Length@r, Join[#, Complement[r, #]] & /@ combinations[r, Drop[n, -1]], Plus @@ n > Length@r, {}, True, Fold[ combinations[r, #2, #1] &, {}, n]] Bobby -----Original Message----- (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] and the short version for 3D vectors OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ NullSpace[{v//N}] For exact vectors I might use for 3D OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ {temp = First[NullSpace[{v}]], v[Cross]temp} I'm still looking for something that is easy to remember. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ OrthogonalUnitVectors[vect__?VectorQ]:= #/Sqrt[#.#]&/@NullSpace[{vect}] ------------- The version above will give a set of unit orthogonal vectors if given any number of vectors in any dimension. So besides giving it a 3D vector we can give it the following: OrthogonalUnitVectors[{2,1,0,-1,1}] or OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] ------------ But the short version above isn't very robust. (1) Clear[x,y,z];NullSpace[{{x,y,z}}] returns two vectors orthogonal to {x,y,z}, but the two vectors NullSpace returns aren't orthogonal to each other. So (OrthogonalUnitVectors) should only work with numeric vectors. (2) We should ensure all the vectors have the same dimension and length >1. I give a less concise version below that corrects these problems. ------------ OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= #/Sqrt[#.#]&/@NullSpace[{vect}] -------------- Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html ==== I have substituted the letters SS, CC, X, Y and Z1 and Z2 for some complicated expressions just to illustrate the form of the function. This function works and all the conditions are necessary but I am sure a more elegant programming solution perhaps using While could be found. Any f[{Sa_, Ca_, Aa_, Sb_, Cb_, Ab_, a_, b_}] := {If[Aa == Ab, a Sa + b Sb, If[Ca == 0 || Cb == 0, a Sa + b Sb, SS]], If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== Check out the Help for Coefficient. Coefficient[expr, form, 0] picks out terms that are not proportional to form. Delta[eq_, x_] := Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x, 0] Delta[a x^2 + b x + c, x] b^2 - 4*a*c David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ ==== Dear all, 1.) How to find the General Solution for below's partial differential equation? (y + u) du/dx + y (du/dy) = x - y ** I use d to represent the partial differential symbol. Can it be solved by function NDSolve in mathematica 4.1? How? 2.) I manage to get the roots of complex equation z^5 = i from Solve[z^5 == i, z]. It gave me straight the 5 roots in the output. Is there any way to view the steps in mathematica? Shz Shz ==== ======================================================================== ==== == of the individual or entity to which they are addressed. Any disclosure, copying, distribution and diversion contrary to the applicable export control laws and regulations including US Export Administration Regulations is strictly prohibited. and do not disclose it to others. Please notify the postmaster@hitachi.com.my of the delivery error by replying to this message and then delete it from your ==== ======================================================================== ==== == ==== I have been trying to code Sethian's Fast Marching Method in 2D but Mathematica has been very slow (taking something like 1-2 hours for something that should take much less than a second in C++). I am sure part of the problem my time. I looked at the list archives and there was mention of an profiling package for Mathematica but a)I can't find it & b)It may not work with Mathematica 4.*. My questions: 1. Any general suggestions on how to figure out which functions are taking most of the time? I guess I could manually have each function I am interested in monitoring keep a variable that counts the amount of CPU time that has been spent on it by doing something like: function[args_]:=Module[{},functionTimer+=Timing[ .... My actual function ..... ][[1]]] but it would very cumbersome to do this to all of the functions in my program and I am not sure I will get accurate results anyway. 2. Compiling functions is not always that easy. I did read the on-line docs and the archives and it does take some work to make a function compile usefully. Is there an FAQ or a tutorial somewhere? 3. Am I the only one who finds the lack of a profiler really really annoying ? Mathematica is powerful and it is usually easy to ask it to do what u want. The challenge a lot of times is doing so without taking too long. Husain PS: One more quick one: Why does the front end act funny when I have the Reply-To: jmt@dxdydz.net ==== mathematica -primaryModifierMask etc see man mathematica for other (very useful) options > PS: One more quick one: Why does the front end act funny when I have the Your X server is set up so that the NumLock key is mapped to Mod2. I > learned by accident that Mod2 is actually quite useful. Mod2-click on a > cell selects all cells of that type in the current notebook. This is an > easy way to delete all the graphics cells and output cells in a notebook to > reduce file size. An annoying aspect is that Mod2-click means press > NumLock, click, then press NumLock again to turn it off. You should be able > to map a different key to Mod2 using xmodmap. Remapping modifier keys in \ X > is awfully annoying, though. I recommend xkeycaps > (http://www.jwz.org/xkeycaps/). > Reply-To: kuska@informatik.uni-leipzig.de ==== a Mathematica profiler is described in The Mathematica Journal Volume 5, Issue 3, Summer 1995 The Mathematica Toolbox: A Mathematica Profiler by Todd Gayley The electronic material for this issue isn not on MathSource but it may be that Todd has the code some where and can make is acessible. Jens > I have been trying to code Sethian's Fast Marching Method in 2D but Mathematica > has been very slow (taking something like 1-2 hours for something that > should take much less than a second in C++). I am sure part of the problem > my time. I looked at the list archives and there was mention of an profiling > package for Mathematica but a)I can't find it & b)It may not work with Mathematica 4.*. > My questions: > 1. Any general suggestions on how to figure out which functions are taking > most of the time? I guess I could manually have each function I am > interested in monitoring keep a variable that counts the amount of CPU > time that has been spent on it by doing something like: > function[args_]:=Module[{},functionTimer+=Timing[ .... My actual function > ..... ][[1]]] > but it would very cumbersome to do this to all of the functions in my > program and I am not sure I will get accurate results anyway. > 2. Compiling functions is not always that easy. I did read the on-line > docs and the archives and it does take some work to make a function > compile usefully. Is there an FAQ or a tutorial somewhere? > 3. Am I the only one who finds the lack of a profiler really really > annoying ? Mathematica is powerful and it is usually easy to ask it to do \ what u > want. The challenge a lot of times is doing so without taking too long. Husain > PS: One more quick one: Why does the front end act funny when I have the ==== > PS: One more quick one: Why does the front end act funny when I have the Your X server is set up so that the NumLock key is mapped to Mod2. I learned by accident that Mod2 is actually quite useful. Mod2-click on a cell selects all cells of that type in the current notebook. This is an easy way to delete all the graphics cells and output cells in a notebook to reduce file size. An annoying aspect is that Mod2-click means press NumLock, click, then press NumLock again to turn it off. You should be able to map a different key to Mod2 using xmodmap. Remapping modifier keys in X is awfully annoying, though. I recommend xkeycaps (http://www.jwz.org/xkeycaps/). ==== Caution: the definition b[n_] := Evaluate[(2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; doesn't immediately compute the integral unless f is already defined at this point, and in that case you may as well write b[n_] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; instead. If b will be computed more than once for the same n, its even better to do it THIS way (if f and L do not change): f[x_] = Cos[x] (* for example *) Simplify[Integrate[f[x]*Sin[n*Pi*(x/L)], {x, 0, L}]] (L*((-n)*Pi + n*Pi*Cos[L]*Cos[n*Pi] + L*Sin[L]*Sin[n*Pi]))/ ((L - n*Pi)*(L + n*Pi)) b[n_] := b[n] = (L*((-n)*Pi + n*Pi*Cos[L]*Cos[n*Pi] + L*Sin[L]*Sin[n*Pi]))/ ((L - n*Pi)*(L + n*Pi)) Bobby -----Original Message----- Stephan Steinhaus (steinhaus-net.de). So when Mathematica takes a very long time, you should investigate. In this case inserting Evaluate[] in two places In[91]:=b[n_] := Evaluate[(2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; .... In[104]:=Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]] Out[104]={0.18 Second,[SkeletonIndicator]Graphics[SkeletonIndicator]} speeds the process enormously (18 milliseconds to plot 120 terms on my feeble old 500MHz PowerBook). Why was it so slow before? When I switch from an ordinary numerical language to Mathematica, I enter into an implicit bargain with Mathematica: the software will go the extra mile to get me a good answer, including (1) using exra precision (sometimes without being asked) and (2) carrying around unevaluated mathematical expressions (usually without being asked) that could possibly be evaluated more appropriately at a later time. Most tools cannot do either of these things, so I don't have to worry about it, except for the bad answers that result now and then. But I need to take care that Mathematica does not burden itself unnecessarily. That's my side of the bargain. Number (2) is the issue here. Your definition of b[n] is written so that Mathematica analytically evaluates b separately for each n. But you know in this case that the integration can be done safely once for all n. So do it! The huge difference, though, comes from pre-evaluating the argument to Plot. Read the on-line help! You should pre-evaluate where possible. In some cases, the most common of which involve branching within the definition of function to plot, you cannot pre-evaluate so, in keeping with the bargain, Mathematica goes the extra mile and holds back just in case. You need to steer it into the shortcut when it's OK. Hope this helps, Tom Burton -- ==== With the second method below (mine), the times add up to 40% less than with \ the first method (Jens-Peer's), for what SEEMS to be exactly the same work. \ Go figure! Can anybody explain that? (* Jens-Peer *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.547 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} (* Treat #1 *) Timing[(2/L)*Integrate[f[x]*Sin[n*Pi*(x/L)], {x, 0, L}]] {0.016000000000000014*Second, (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi)} ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi); FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.297 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} Even stranger, it SLOWS the Plot if we precompute b before Timing starts: (* Treat #2 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi); b /@ Range[30]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.328 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} But here's a winner: (* Treat #3 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/ (n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.204 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} Apparently, computing b within the Plot causes machine-precision arithmetic \ to be used, and that saves time. Precomputing b and then converting exact expressions to approximate ones within the Plot seems to take longer. For that to make sense, I think it must be that n is approximate (not Integer) when it is passed to b within Plot. Bobby Treat -----Original Message----- and you need only a 1-3 seconds (depending on your machine) Jens > > For my PDE class we have been calculating Fourier transforms. The instructor > arrived today with a printout of two plots of a certain Fourier transform, > done with a different CAS. The first plot was to 30 terms, the second was \ to > 120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 > on a PIII 700) to see how much time this required to process. I was > Staggered at how much time it took. Here's the code: > > L = 2; > f[x_] := UnitStep[x - 1]; > b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; > > FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; > > Timing[Plot[FS[30, x], {x, 0, 2}]] > > Out[23]= > {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} > > In this case the number of terms is 30. > > The time required per number of terms seems to fit the following polynomial: > > y = 0.3926x^2 + 2.2379x > > This is a large amount of time. I understand that the code is not optimized, > and was more or less copied from the code in the other CAS, but is this a > reasonable amount of time, or is something going wrong? I don't use Mathematica > because of the speed, but should it be this slow? > > Just curious, > > Steve Story ==== Even better -- MUCH better -- add Bob Hanlon's Evaluate to the other tricks: ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[Evaluate[FS[30, x]], {x, 0, 2}]] {0.015 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]] {0.063 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} Bobby Treat -----Original Message----- Timing[Plot[FS[30, x], {x, 0, 2}]] {0.547 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} (* Treat #1 *) Timing[(2/L)*Integrate[f[x]*Sin[n*Pi*(x/L)], {x, 0, L}]] {0.016000000000000014*Second, (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi)} ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi); FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.297 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} Even stranger, it SLOWS the Plot if we precompute b before Timing starts: (* Treat #2 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi); b /@ Range[30]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.328 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} But here's a winner: (* Treat #3 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/ (n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.204 Second, \ .89»¡Graphics.89»\[DownExcla\ mation]} Apparently, computing b within the Plot causes machine-precision arithmetic \ to be used, and that saves time. Precomputing b and then converting exact expressions to approximate ones within the Plot seems to take longer. For that to make sense, I think it must be that n is approximate (not Integer) when it is passed to b within Plot. Bobby Treat -----Original Message----- and you need only a 1-3 seconds (depending on your machine) Jens > > For my PDE class we have been calculating Fourier transforms. The instructor > arrived today with a printout of two plots of a certain Fourier transform, > done with a different CAS. The first plot was to 30 terms, the second was \ to > 120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 > on a PIII 700) to see how much time this required to process. I was > Staggered at how much time it took. Here's the code: > > L = 2; > f[x_] := UnitStep[x - 1]; > b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; > > FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; > > Timing[Plot[FS[30, x], {x, 0, 2}]] > > Out[23]= > {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} > > In this case the number of terms is 30. > > The time required per number of terms seems to fit the following polynomial: > > y = 0.3926x^2 + 2.2379x > > This is a large amount of time. I understand that the code is not optimized, > and was more or less copied from the code in the other CAS, but is this a > reasonable amount of time, or is something going wrong? I don't use Mathematica > because of the speed, but should it be this slow? > > Just curious, > > Steve Story ==== How can I plot with Mathematica two function in the same graphic? I explain better: compare a and b). Reply-To: kuska@informatik.uni-leipzig.de ==== Plot[{x,x^2},{x,-1,1}] may do it. Jens How can I plot with Mathematica two function in the same graphic? > I explain better: > compare a and b). > ==== Other than Plot[{x,x^2},...] you can use Show[] as well. plt1=Plot[x,{x,0,1}]; plt2=Plot[x^2,{x,0,1}]; Show[plt1,plt2] Lawrence > How can I plot with Mathematica two function in the same graphic? > I explain better: > compare a and b). > Mario, Here is a fancy version of your plot. I used Text statements within an > Epilog option to label the two curves. The regular plot statement allows you > to plot a series of functions inclosed in a list. Needs[Graphics`Colors`] > Plot[{x, x^2}, {x, 0, 1}, > PlotStyle -> {Black, Blue}, > Frame -> True, > FrameLabel -> {x, y}, > PlotLabel -> Comparison of Two Functions, > Epilog -> {Text[x, {0.5, 0.55}], Blue, Text[x^2, {0.7, 0.4}]}, > Background -> Linen, > ImageSize -> 500]; David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ How can I plot with Mathematica two function in the same graphic? > I explain better: > compare a and b). > ==== (1) Is there a way in Mathematica 4.2 to put two separate gifs into a single, cell side by side (with some intervening space), without having to combine them in some graphics program first? In particular, I'd like to do that within a text cell. Even in a new Input cell, if I first create a GridBox (via Inut>Create Table/Matrix/Palette) and then try to insert the first gif (via Edit>Insert Object>Create from File ....), Mathematica promptly crashes. (Mathematica 4.2 under Windows 2000.) I just don't see how to get anything other than a single gif into a cell. (2) Is there a way to cause a gif imported into a Mathematica 4.2 notebook to become a hyperlink -- so that when the user clicks on the gif the hyperlink's target is summoned? (My aim in all this is to use Mathematica to create web pages with high mathematical content -- saving the notebook as HTML+MathML -- without having to do any extensive editing of the resulting .xml and related files. That way as the source Mathematica notebook changes, I would need only to re-export without further tinkering with the .xml file, etc.) -- Murray Eisenberg Internet: murray@math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) Reply-To: kuska@informatik.uni-leipzig.de ==== it works with any graphics NotebookWrite[SelectedNotebook[], GridBox[{Cell[GraphicsData[PostScript, DisplayString[#, MPS]], Graphics] & /@ {leftGraphics, rightGraphics}}]] Jens (1) Is there a way in Mathematica 4.2 to put two separate gifs into a > single, cell side by side (with some intervening space), without > having to combine them in some graphics program first? In particular, I'd like to do that within a text cell. Even in a new Input cell, if I first create a GridBox (via Inut>Create > Table/Matrix/Palette) and then try to insert the first gif (via > Edit>Insert Object>Create from File ....), Mathematica promptly > crashes. (Mathematica 4.2 under Windows 2000.) I just don't see how to get anything other than a single gif into a > cell. (2) Is there a way to cause a gif imported into a Mathematica 4.2 > notebook to become a hyperlink -- so that when the user clicks on the > gif the hyperlink's target is summoned? (My aim in all this is to use Mathematica to create web pages with > high mathematical content -- saving the notebook as HTML+MathML -- > without having to do any extensive editing of the resulting .xml and > related files. That way as the source Mathematica notebook changes, I > would need only to re-export without further tinkering with the .xml > file, etc.) -- > Murray Eisenberg Internet: murray@math.umass.edu > Mathematics & Statistics Dept. Voice: 413-545-2859 (W) > University of Massachusetts 413-549-1020 (H) ==== Your method 1), below, does not produce correct results if one then uses menu>Save As Special>HTML+MathML. I view the resulting .xml file in a MathML-enabled browser (e.g., Mozilla with appropriate TrueType fonts installed -- the four BaKoMa cm fonts, the old Mathematica Math1, etc., fonts, and the two MT fonts. Then the everything in the originally multi-line inline cell appears on one line separate by a ?, as do the alignment markers. In the page source, these unrendered symbols have codes #8289 and #63328, respectively. Is there an issue of the encoding used in the browser here? I did try Unicode-7, Unicode-8, and several of the Western encodings available under Mozilla's Default Character Encoding. Or is it something else? Note that I do also have the new Mathematica TrueType fonts (Mathematica1, etc.). P.S. I don't think Mathematica documents this, but if one wants a file exported from Mathematica as HTML+MathML to be rendered correctly by a browser, it seems to require an extension of .xml rather than .html. > >>When writing a series of equations in mathematica (in a text cell) >>is there any way to align the equations at the = similar to >>what can be done in the equation editor made by math type (used >>in word etc.)? > > > Mike, > Two ways > 1) Start an inline cell in your text cell (menu>Edit>Expression Input>Start > Inline Cell) > Type in your equations with the alignment marker (Esc am Esc) in after each > equal sign. > Close the inline cell (menu>Edit>Expression Input>End Inline Cell). > Select the text cell (or the inline cell, though this is a delicate > operation, do it by repeatedly double clicking in it}. > Use menu> Format>Text Alignment>On Alignment Marker. > -- you will find that all single letters are now italic - you can select > individual letters and change this - alternatively you can select the inline > cell and use the option inspector (menu>Format>Option Inspector) to set > SingleLetterItalics->False) > > -- you can put existing text in an inline cell by selcting it and using > menu>Edit>Expression Input>Start Inline Cell, but you may have to adjust > the line breaks after this.... -- Murray Eisenberg Internet: murray@math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) ==== Group, Can anyone help me with the following? I guess this is something trivial for most of you, but I have being struggling with it for weeks. The problem is to construct a taxonomic hierarchy whose structure is hereby \ described by example: << DiscreteMath`Combinatorica` n[1]:= m = 10; (*with the following I get the 1th level (1--element) partition*) in[2]:= ks1 = Partition[Range[m], 1] (*Now the following gives all the 2th-level (?) different partitions that can be set up by joining two elements in the 1-element partition and leaving the rest as they are?*) (*First, these are all possible 'joinings' to generate the two elements 'pieces' from 1th level (1--element) partition*) in[3]:= ks2 = KSubsets[Range[m], 2] (*And this generates all the 2th-level (?) different partitions that can be \ set up by joining two elements in the 1-element partition and leaving the rest as they are.*) in[4]:= p2 = MapThread[Complement[Append[#1, #2], (Sequence @@ {#} & /@ Partition[#2, 1])] &, {Array[ks1&, Length[ks2]], ks2}]; Length[p2] in[5]:= p2[[1]] out[5]:= {{3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2}} in[6]:= p2[[Length[p2]]] out[6]:= {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9, 10}} (*compute in[4] t and see the full output*) (*Now I need to solve the problem of given the ith-level (?) different partitions to set up all the i+1th different partitions by joining two elements in the ith level partition and leaving the rest as they are? *) (*for example given the following 2th-level partition*) {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2} (*we should get*) {{{4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2, 3}}, {{3}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2, 4}}, {{3}, {4}, {6}, {7}, {8}, {9}, {10}, {1, 2, 5}}, {{3}, {4}, {5}, {7}, {8}, {9}, {10}, {1, 2, 6}}, {{3}, {4}, {5}, {6}, {8}, {9}, {10}, {1, 2, 7}}, {{3}, {4}, {5}, {6}, {7}, {9}, {10}, {1, 2, 8}}, {{3}, {4}, {5}, {6}, {7}, {8}, {10}, {1, 2, 9}}, {{3}, {4}, {5}, {6}, {7}, {8}, {9}, {1, 2, 10}}} (*The process would end up to *) {1,{2,3,4,5,6,7,8,9,10}} {2,{1,3,4,5,6,7,8,9,10}} {3,{1,2,4,5,6,7,8,9,10}} {4,{1,2,3,5,6,7,8,9,10}} {5,{1,2,3,4,6,7,8,9,10}} {6,{1,2,3,4,5,7,8,9,10}} {7,{1,2,3,4,5,6,8,9,10}} {8,{1,2,3,4,5,6,7,9,10}} {9,{1,2,3,4,5,6,7,8,10}} {10,{1,2,3,4,5,6,7,8,9}} (* and*) {1,2,3,4,5,6,7,8,9,10} Emilio Martin-Serrano Reply-To: tharter@attglobal.net ==== Your machine information and OS EXACTLY matches mine (except that my pagefile is NOT on a separate physical drive -- perhaps this is a clue as to where to \ start), and I had no problem building the help file. Hence, as you say, this must be a problem for Wolfram to address. Perhaps, someone from WRI will enlighten us via this newsgroup. ....Terry > > I too have been unable to get the help browser functioning. I have > exactly the same problem. When trying to open the help browser it gets > to the point where it says scanning index file and freezes. I tried > all the suggestions in the faq and the links provided here to no > avail. I'm running Winows 2000 with service pack 3. I have 512mb of > memory with a 768mb pagefile on a separate drive, so I don't think > that's an issue. Mathematica 4.1 ran just fine on this setup, so > judging by the number of other people affected by this, I'd say it's > some kind of bug with 4.2. Hopefully Wolfram will address this with > either a link that will provide a fix that actually works, or a patch. > >What is your operating system? How much memory do you have in your machine? >Also, how big is your pagefile? Sounds to me like the rebuild ran out >of room to do its thing in. > > I just installed Mathematica 4.2, and had no problem rebuilding the help index. >Subsequently, I ahd no problem using the Help browser either. >Hope that helps! >....Terry > > >>I'd start with the following FAQ. >> >http://support.wolfram.com/mathematica/interface/helpbrowser/howrebuildinde\ x .html >> >>-Dale >> >> Sorry that i failed say it immediately in a first place, but of course >> i did try it FAQ at first, and both tried to delete cache and rebuild >> index, but results where the same - whenever i try to invoke help >> browser (or rebuild index, for that matter), mathematica stops >> responding (i did read your answer to the same question asked >> a week ago before - actually that is why i turned to the FAQ). > ==== Try deleting ... Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb > Your machine information and OS EXACTLY matches mine (except that my pagefile > is NOT on a separate physical drive -- perhaps this is a clue as to where to start), > and I had no problem building the help file. Hence, as you say, this must > be a problem for Wolfram to address. Perhaps, someone from WRI will enlighten > us via this newsgroup. > ....Terry > > > > I too have been unable to get the help browser functioning. I have > exactly the same problem. When trying to open the help browser it gets > to the point where it says scanning index file and freezes. I tried > all the suggestions in the faq and the links provided here to no > avail. I'm running Winows 2000 with service pack 3. I have 512mb of > memory with a 768mb pagefile on a separate drive, so I don't think > that's an issue. Mathematica 4.1 ran just fine on this setup, so > judging by the number of other people affected by this, I'd say it's > some kind of bug with 4.2. Hopefully Wolfram will address this with > either a link that will provide a fix that actually works, or a patch. > >What is your operating system? How much memory do you have in your machine? >Also, how big is your pagefile? Sounds to me like the rebuild ran out >of room to do its thing in. > > I just installed Mathematica 4.2, and had no problem rebuilding the help index. >Subsequently, I ahd no problem using the Help browser either. >Hope that helps! >....Terry > > >>I'd start with the following FAQ. >> >> >http://support.wolfram.com/mathematica/interface/helpbrowser/howrebuildinde\ x.html >> >>-Dale >> >> Sorry that i failed say it immediately in a first place, but of course >> i did try it FAQ at first, and both tried to delete cache and rebuild >> index, but results where the same - whenever i try to invoke help >> browser (or rebuild index, for that matter), mathematica stops >> responding (i did read your answer to the same question asked >> a week ago before - actually that is why i turned to the FAQ). > > > ==== >Try deleting ... >Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb > > > > ==== > I too have been trying to use Mathematica (v4.2 most recently) to type > maths papers and the like but I'm not ready to ditch LaTeX yet. There > are just too many cases where I cannot figure out how to achieve what I > want in Mathematica, things like: > - left brackets spanning multiple lines for defining hybrid functions; You can accomplish this by doing the following: 1) Put your function braches in the rows of a grid box structure. 2) Add the following options to your cell: ShowAutoStyles -> False SpanMaxSize -> Infinity The following cell snippet demonstrates how this influences the result. To view it, paste the Cell[] expression into a notebook and then click on Yes when you are prompted on whether the front end should interpret the result. Cell[BoxData[ FormBox[ RowBox[{ RowBox[{f, (, x, )}], =, RowBox[{{, GridBox[{ {x, RowBox[{x, , <, 0}]}, { SuperscriptBox[x, 2], RowBox[{0, [LessEqual], x, <, 1}]}, { RowBox[{sin, (, x, )}], RowBox[{1, [LessEqual], x, <, 2}]}, { RowBox[{[CapitalGamma], (, x, )}], RowBox[{x, [GreaterEqual], 2}]} }]}]}], TraditionalForm]], DisplayFormula, ShowAutoStyles->False, SpanMaxSize->Infinity] > - vertical alignment of equals signs in multi-line equations or > derivations; Put your equations in a GridBox and set the ColumnAlignments option to a string containing the equal sign. Cell[BoxData[ FormBox[GridBox[{ { RowBox[{ RowBox[{ RowBox[{3, x}], , +, , RowBox[{4, , y}]}], , =, , 9}]}, { RowBox[{ RowBox[{ RowBox[{2, x}], , -, , RowBox[{7, , y}]}], =, RowBox[{32, , -, , RowBox[{sin, (, x, )}]}]}]} }], TraditionalForm]], DisplayFormula, GridBoxOptions->{ColumnAlignments->{=}}] > - setting typefaces in tables of material. I think the Author Tools material that comes with Mathematica 4.2 might be able to help you do this. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== You have three nonlinear (fourth-order) equations and 23 unknowns. A faster computer won't help any. Bobby -----Original Message----- (*Hex20 Node definition in global coordinates *) Clear[ x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20, z20]; (* local coordinates *) Clear[u, v, w]; (* Global co-ordinates *) Clear[x, y, z]; (* corner nodes *) N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; (* to u nodes *) N2= (1-u^2)*(1-v)*(1-w)/4; N6= (1-u^2)*(1+v)*(1-w)/4; N14=(1-u^2)*(1-v)*(1+w)/4; N18=(1-u^2)*(1+v)*(1+w)/4; (* to v nodes *) N4= (1+u)*(1-v^2)*(1-w)/4; N8= (1-u)*(1-v^2)*(1-w)/4; N16=(1+u)*(1-v^2)*(1+w)/4; N20=(1-u)*(1-v^2)*(1+w)/4; (* to w nodes *) N9= (1-u)*(1-v)*(1-w^2)/4; N10=(1+u)*(1-v)*(1-w^2)/4; N11=(1+u)*(1+v)*(1-w^2)/4; N12=(1-u)*(1-v)*(1-w^2)/4; (* solve the inverse transform *) Solve[{ x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19+ x20*N20-x==0, y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19+ y20*N20-y==0, z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19+ z20*N20-z==0}, {u,v,w}] Christopher J. Purcell Defence R&D Canada - Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== If I haven't missed a step, the following should work nicely -- best done before defining any of the symbols that appear: Attributes[dummyIf] = HoldAll; Attributes[dummyWhich] = HoldAll; expr = {If[Aa == Ab, a Sa + b Sb, If[Ca == 0 || Cb == 0, a Sa + b Sb, SS]], If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[ Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} /. {If -> dummyIf}; rule1 = dummyIf[a_, b_, dummyIf[c_, d_, e_]] -> dummyWhich[a, b, c, d, True, e]; rule2 = dummyIf[a_, dummyIf[ b_, c_, d_], e_] -> dummyWhich[a && b, c, a, d, True, e]; rule3 = dummyIf[a_, dummyIf[b_, c_, d_]] -> dummyWhich[a && b, c, a, d]; rule4 = dummyWhich[a__, b_, dummyIf[c_, d_, e_], f___] -> dummyWhich[a, b && c, d, b, e, f]; rule5 = dummyWhich[a__, b_, dummyWhich[c_, d_, e___], f___] -> dummyWhich[a, b && c, d, b, dummyWhich[e], f]; rule6 = dummyWhich[] :> Null; rule7 = HoldPattern[True && a_] :> a; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7} /. {dummyWhich -> Which The result of that last line is: {Which[Aa == Ab, a Sa + b Sb, Ca == 0 || Cb == 0, a Sa + b Sb, True, SS], Which[Aa == Ab, a Ca + b Cb, Ca == 0 || Cb == 0, a Ca + b Cb, True, CC], Which[Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X]} I've used Null where that would be the result of your original logic -- maybe you want it to be Nil. Or maybe you want to use Null instead of Nil. Your choice. Wherever you see Null, there's possibly a case you haven't covered. Bobby Treat -----Original Message----- If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== Dear Group, I have a program to take the local polynomial non parametric regression of two variables. It uses Compile, unfortunately, and regularly, but inconsistently, causes Mathematica to crash (in Win2K, with I forget what error, and in Win98/Mathematica4.0 with an invalid memory access from MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently on 4 different machines. Here is the code, if it doesn't crash the first time, it will the second or third: (* w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, 0}, {nn, _Integer, 0}, {ord, _Integer, 0}}, First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, 1], {q, 0, ord}], Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; *) (* !(tt = MemoryInUse[]; ListPlot[Table[{((i + 1))^2, (Timing[ nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, nn}]; testX = Table[i* .3 - Random[]*2, {i, nn}]; testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; Map[w[#, testX, testY, .1 + Random[], nn, 0] &, testX];])[([1])]/Second}, {i, 15}], PlotJoined -> True, PlotLabel -> ]; MemoryInUse[] - tt) *) I have followed Ted Ersek's tips and tricks (http://www.verbeia.com/mathematica/tips/tip_index.html) about Compile, and have tried changing all variable names (works sometimes), removing any hidden spaces, restructuring the formulas, changing all 0's to 0. 's and all 1's to 1. 's, etcetera etcetera, but I still can't comprehend what the problem might be. Doing w[[-2]] shows a list of op-code numbers, and one function name, Inverse[#1]&, so it seems to me that there are no problems with the use of Compile here. Would anyone have any thoughts??? Bernard Gress burnthebiscuit@netscape.net ==== Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2, however \ after working with this program for more than a month, trying every possible permutation and manipulation, and having it still crash, I am still worried that upgrading to 4.2 won't solve my problem. Can anyone else with 4.2 try running this program for me a good number of times, say 3 or 4, and see if they get similar good results? Bernard Gress Dear Group, I have a program to take the local polynomial non parametric regression of two variables. It uses Compile, unfortunately, and regularly, but inconsistently, causes Mathematica to crash (in Win2K, with I forget what error, and in Win98/Mathematica4.0 with an invalid memory access from MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently on 4 different machines. Here is the code, if it doesn't crash the first time, it will the second or third: (* w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, 0}, {nn, _Integer, 0}, {ord, _Integer, 0}}, First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, 1], {q, 0, ord}], Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; *) (* !(tt = MemoryInUse[]; ListPlot[Table[{((i + 1))^2, (Timing[ nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, nn}]; testX = Table[i* .3 - Random[]*2, {i, nn}]; testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; Map[w[#, testX, testY, .1 + Random[], nn, 0] &, testX];])[([1])]/Second}, {i, 15}], PlotJoined -> True, PlotLabel -> ]; MemoryInUse[] - tt) *) ==== I ran it 10 times on 4.2 with no crashes. > Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2, however after working > with this program for more than a month, trying every possible permutation and > manipulation, and having it still crash, I am still worried that upgrading to 4.2 > won't solve my problem. Can anyone else with 4.2 try running this program for me a > good number of times, say 3 or 4, and see if they get similar good results? > > > Bernard Gress > > Dear Group, > > I have a program to take the local polynomial non parametric regression > of two variables. It uses Compile, unfortunately, and regularly, but > inconsistently, causes Mathematica to crash (in Win2K, with I forget > what error, and in Win98/Mathematica4.0 with an invalid memory access from > MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently > on 4 different machines. > > Here is the code, if it doesn't crash the first time, it will the second > or third: > > (* > w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, > 0}, > {nn, _Integer, 0}, {ord, _Integer, 0}}, > First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, > 1], {q, 0, ord}], > Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, > ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . > Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* > E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; > *) > > (* > !(tt = MemoryInUse[]; > ListPlot[Table[{((i + 1))^2, (Timing[ > nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, > nn}]; > testX = Table[i* .3 - Random[]*2, {i, nn}]; > testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; > Map[w[#, testX, testY, .1 + Random[], nn, 0] &, > testX];])[([1])]/Second}, {i, 15}], PlotJoined -> > True, > PlotLabel -> ]; > MemoryInUse[] - tt) > *) > > > Reply-To: kuska@informatik.uni-leipzig.de ==== my Mathematica 4.2 does not crash and you may upgrade your version. Jens Dear Group, I have a program to take the local polynomial non parametric regression > of two variables. It uses Compile, unfortunately, and regularly, but > inconsistently, causes Mathematica to crash (in Win2K, with I forget > what error, and in Win98/Mathematica4.0 with an invalid memory access from > MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently > on 4 different machines. Here is the code, if it doesn't crash the first time, it will the second > or third: (* > w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, > 0}, > {nn, _Integer, 0}, {ord, _Integer, 0}}, > First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, > 1], {q, 0, ord}], > Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, > ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . > Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* > E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; > *) (* > !(tt = MemoryInUse[]; > ListPlot[Table[{((i + 1))^2, (Timing[ > nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, > nn}]; > testX = Table[i* .3 - Random[]*2, {i, nn}]; > testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; > Map[w[#, testX, testY, .1 + Random[], nn, 0] &, > testX];])[([1])]/Second}, {i, 15}], PlotJoined -> > True, > PlotLabel -> ]; > MemoryInUse[] - tt) > *) I have followed Ted Ersek's tips and tricks > (http://www.verbeia.com/mathematica/tips/tip_index.html) about Compile, > and have tried changing all variable names (works sometimes), removing > any hidden spaces, restructuring the formulas, changing all 0's to 0. 's > and all 1's to 1. 's, etcetera etcetera, but I still can't comprehend > what the problem might be. Doing w[[-2]] shows a list of op-code > numbers, and one function name, Inverse[#1]&, so it seems to me that > there are no problems with the use of Compile here. Would anyone have > any thoughts??? > Bernard Gress > burnthebiscuit@netscape.net ==== Mr Kuska, 4.2, I thought I had solved this problem so many times and still it would suddenly start crashing again our of the blue, after 20 or 30 executions. Bernard > > my Mathematica 4.2 does not crash and you may upgrade > your version. > ==== Expanding on my earlier simplification of the Moran Research code, I studied the problem a little more and found another useful Rule and a Rule that should help but doesn't. Maybe somebody can explain what I'm doing wrong on that one. My earlier result (after applying rule1, ... rule7) had the following as third element of a List in the definition of f: Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X] Several things occurred to me in terms of simplifying this. The first was that the last six arguments of Which could be replaced with two, as follows: Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True,Mod[X,180]] This probably has no advantage other than clarity, but that's worth the others: rule8 = dummyIf[a_ > b_, a_ - b_, dummyIf[a_ < 0, a_ + b_, a_]] :> Mod[a, b]; but it had no effect on the expression. Apparently there was no match, and I can't see why. The second thing I noticed was that the condition Ca == 0 && Cb == 0 occurs twice in the Which statement. The following rule fixes that kind of situation: rule9 = dummyWhich[a___, b_, c_, d__, b_, e_, f__] /; EvenQ[Length[List[a]]] && EvenQ[Length[List[d]]] && EvenQ[Length[List[f]]] :> dummyWhich[a, b, c, d, f]; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule9} The third thing I noticed was the treatment of Aa and Ab. The expressions If[Aa > 90, Aa - 90, Aa + 90] If[Ab > 90, Ab - 90, Ab + 90] in the original expression may be equivalent (depending on what's known about Aa and Ab a priori) to: Mod[Aa+90,180] Mod[Ab+90,180] If that is a valid assumption in the situation (no way for me to know), the expression is now Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] The next thing I notice is that the sixth condition, Z1==Z2, which results in Null if found True, isn't needed. If Z1==Z2 then one of the first five conditions is also true, so execution wouldn't get that far. Hence we can delete that condition-response pair. Finally, I'm stopping with this: Which[ Ca == 0 == Cb, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] I have no idea what you're actually doing with this code, but it looks weird even AFTER I've simplified it. Bobby Treat -----Original Message----- 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[ Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} /. {If -> dummyIf}; rule1 = dummyIf[a_, b_, dummyIf[c_, d_, e_]] -> dummyWhich[a, b, c, d, True, e]; rule2 = dummyIf[a_, dummyIf[ b_, c_, d_], e_] -> dummyWhich[a && b, c, a, d, True, e]; rule3 = dummyIf[a_, dummyIf[b_, c_, d_]] -> dummyWhich[a && b, c, a, d]; rule4 = dummyWhich[a__, b_, dummyIf[c_, d_, e_], f___] -> dummyWhich[a, b && c, d, b, e, f]; rule5 = dummyWhich[a__, b_, dummyWhich[c_, d_, e___], f___] -> dummyWhich[a, b && c, d, b, dummyWhich[e], f]; rule6 = dummyWhich[] :> Null; rule7 = HoldPattern[True && a_] :> a; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7} /. {dummyWhich -> Which The result of that last line is: {Which[Aa == Ab, a Sa + b Sb, Ca == 0 || Cb == 0, a Sa + b Sb, True, SS], Which[Aa == Ab, a Ca + b Cb, Ca == 0 || Cb == 0, a Ca + b Cb, True, CC], Which[Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X]} I've used Null where that would be the result of your original logic -- maybe you want it to be Nil. Or maybe you want to use Null instead of Nil. Your choice. Wherever you see Null, there's possibly a case you haven't covered. Bobby Treat -----Original Message----- If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== Sorry... ONE MORE simplification: Which[ Ca == 0 == Cb, Nil, Z1 == Z2, Which[Ca < 0, Aa, Cb < 0, Ab, Ca > 0, Mod[Aa + 90, 180], Cb > 0, Mod[Ab + 90, 180]], Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] I didn't like repeating the Z1==Z2 test. Upon noticing this, I thought at first that my rule5 caused this situation to occur, but actually I have to delete both rule 4 AND rule5 to eliminate it, and the resulting expression wouldn't be as easy to understand. Bobby Treat -----Original Message----- Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X] Several things occurred to me in terms of simplifying this. The first was that the last six arguments of Which could be replaced with two, as follows: Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True,Mod[X,180]] This probably has no advantage other than clarity, but that's worth the others: rule8 = dummyIf[a_ > b_, a_ - b_, dummyIf[a_ < 0, a_ + b_, a_]] :> Mod[a, b]; but it had no effect on the expression. Apparently there was no match, and I can't see why. The second thing I noticed was that the condition Ca == 0 && Cb == 0 occurs twice in the Which statement. The following rule fixes that kind of situation: rule9 = dummyWhich[a___, b_, c_, d__, b_, e_, f__] /; EvenQ[Length[List[a]]] && EvenQ[Length[List[d]]] && EvenQ[Length[List[f]]] :> dummyWhich[a, b, c, d, f]; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule9} The third thing I noticed was the treatment of Aa and Ab. The expressions If[Aa > 90, Aa - 90, Aa + 90] If[Ab > 90, Ab - 90, Ab + 90] in the original expression may be equivalent (depending on what's known about Aa and Ab a priori) to: Mod[Aa+90,180] Mod[Ab+90,180] If that is a valid assumption in the situation (no way for me to know), the expression is now Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] The next thing I notice is that the sixth condition, Z1==Z2, which results in Null if found True, isn't needed. If Z1==Z2 then one of the first five conditions is also true, so execution wouldn't get that far. Hence we can delete that condition-response pair. Finally, I'm stopping with this: Which[ Ca == 0 == Cb, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] I have no idea what you're actually doing with this code, but it looks weird even AFTER I've simplified it. Bobby Treat -----Original Message----- 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[ Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} /. {If -> dummyIf}; rule1 = dummyIf[a_, b_, dummyIf[c_, d_, e_]] -> dummyWhich[a, b, c, d, True, e]; rule2 = dummyIf[a_, dummyIf[ b_, c_, d_], e_] -> dummyWhich[a && b, c, a, d, True, e]; rule3 = dummyIf[a_, dummyIf[b_, c_, d_]] -> dummyWhich[a && b, c, a, d]; rule4 = dummyWhich[a__, b_, dummyIf[c_, d_, e_], f___] -> dummyWhich[a, b && c, d, b, e, f]; rule5 = dummyWhich[a__, b_, dummyWhich[c_, d_, e___], f___] -> dummyWhich[a, b && c, d, b, dummyWhich[e], f]; rule6 = dummyWhich[] :> Null; rule7 = HoldPattern[True && a_] :> a; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7} /. {dummyWhich -> Which The result of that last line is: {Which[Aa == Ab, a Sa + b Sb, Ca == 0 || Cb == 0, a Sa + b Sb, True, SS], Which[Aa == Ab, a Ca + b Cb, Ca == 0 || Cb == 0, a Ca + b Cb, True, CC], Which[Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X]} I've used Null where that would be the result of your original logic -- maybe you want it to be Nil. Or maybe you want to use Null instead of Nil. Your choice. Wherever you see Null, there's possibly a case you haven't covered. Bobby Treat -----Original Message----- If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== If x1 through x20 aren't unknowns, you should have told me their values. If you can't, they are UNKNOWN. True, you're not solving for them... but they affect the dimensionality of the problem just as if you WERE solving for them. You have a 20-dimensional space full of contingencies -- solution forms that depend on the values of x1 through x20. The Solve function won't deal with contingencies even if it could, and if it tried, there would be too many. Bobby -----Original Message----- >Bobby > >-----Original Message----- >Sent: Saturday, September 07, 2002 1:54 AM >resend > > >Would someone with a very fast machine and lots of memory be willing to >try >this Solve for me? >It is the inverse of the 20 node quadratic hexahedral mapping used in >finite element analysis. >None of my computers can handle this - they run out of memory (using > >(*Hex20 Node definition in global coordinates *) >Clear[ >x1, y1, z1, >x2, y2, z2, >x3, y3, z3, >x4, y4, z4, >x5, y5, z5, >x6, y6, z6, >x7, y7, z7, >x8, y8, z8, >x9, y9, z9, >x10, y10, z10, >x11, y11, z11, >x12, y12, z12, >x13, y13, z13, >x14, y14, z14, >x15, y15, z15, >x16, y16, z16, >x17, y17, z17, >x18, y18, z18, >x19, y19, z19, >x20, y20, z20]; > >(* local coordinates *) >Clear[u, v, w]; > >(* Global co-ordinates *) >Clear[x, y, z]; > >(* corner nodes *) >N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; >N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; >N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; >N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; >N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; >N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; >N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; >N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; >(* to u nodes *) >N2= (1-u^2)*(1-v)*(1-w)/4; >N6= (1-u^2)*(1+v)*(1-w)/4; >N14=(1-u^2)*(1-v)*(1+w)/4; >N18=(1-u^2)*(1+v)*(1+w)/4; >(* to v nodes *) >N4= (1+u)*(1-v^2)*(1-w)/4; >N8= (1-u)*(1-v^2)*(1-w)/4; >N16=(1+u)*(1-v^2)*(1+w)/4; >N20=(1-u)*(1-v^2)*(1+w)/4; >(* to w nodes *) >N9= (1-u)*(1-v)*(1-w^2)/4; >N10=(1+u)*(1-v)*(1-w^2)/4; >N11=(1+u)*(1+v)*(1-w^2)/4; >N12=(1-u)*(1-v)*(1-w^2)/4; > >(* solve the inverse transform *) >Solve[{ >x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ >x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19 + >x20*N20-x==0, >y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ >y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19 + >y20*N20-y==0, >z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ >z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19 + >z20*N20-z==0}, >{u,v,w}] >Christopher J. Purcell >Defence R&D Canada - Atlantic >9 Grove St., PO Box 1012 >Dartmouth NS Canada B2Y 3Z7 Christopher J. Purcell Defence R&D Canada - Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== If we do think of x1...x20 as constants, it's still fourth-order, with three simultaneous equations. Evaluate this: Solve[a x^4 + b x^3 + c x^2 + d x + e == 0, x] and look at the four solutions found -- for a single variable and one equation! For your problem, I'm thinking there'd be at least 4^3 solutions, each of them even more complicated than these, and an unknown number of contingencies to deal with, depending on values of the xi. Check each radical for a negative argument, and the special cases multiply quickly. For some values of the xi, there'd be no solutions; for other values, many solutions. If you do manage to solve this, I'd love to see the method! Bobby -----Original Message----- many. Bobby -----Original Message----- >Bobby > >-----Original Message----- >Sent: Saturday, September 07, 2002 1:54 AM >resend > > >Would someone with a very fast machine and lots of memory be willing to >try >this Solve for me? >It is the inverse of the 20 node quadratic hexahedral mapping used in >finite element analysis. >None of my computers can handle this - they run out of memory (using > >(*Hex20 Node definition in global coordinates *) >Clear[ >x1, y1, z1, >x2, y2, z2, >x3, y3, z3, >x4, y4, z4, >x5, y5, z5, >x6, y6, z6, >x7, y7, z7, >x8, y8, z8, >x9, y9, z9, >x10, y10, z10, >x11, y11, z11, >x12, y12, z12, >x13, y13, z13, >x14, y14, z14, >x15, y15, z15, >x16, y16, z16, >x17, y17, z17, >x18, y18, z18, >x19, y19, z19, >x20, y20, z20]; > >(* local coordinates *) >Clear[u, v, w]; > >(* Global co-ordinates *) >Clear[x, y, z]; > >(* corner nodes *) >N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; >N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; >N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; >N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; >N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; >N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; >N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; >N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; >(* to u nodes *) >N2= (1-u^2)*(1-v)*(1-w)/4; >N6= (1-u^2)*(1+v)*(1-w)/4; >N14=(1-u^2)*(1-v)*(1+w)/4; >N18=(1-u^2)*(1+v)*(1+w)/4; >(* to v nodes *) >N4= (1+u)*(1-v^2)*(1-w)/4; >N8= (1-u)*(1-v^2)*(1-w)/4; >N16=(1+u)*(1-v^2)*(1+w)/4; >N20=(1-u)*(1-v^2)*(1+w)/4; >(* to w nodes *) >N9= (1-u)*(1-v)*(1-w^2)/4; >N10=(1+u)*(1-v)*(1-w^2)/4; >N11=(1+u)*(1+v)*(1-w^2)/4; >N12=(1-u)*(1-v)*(1-w^2)/4; > >(* solve the inverse transform *) >Solve[{ >x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ >x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19 + >x20*N20-x==0, >y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ >y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19 + >y20*N20-y==0, >z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ >z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19 + >z20*N20-z==0}, >{u,v,w}] >Christopher J. Purcell >Defence R&D Canada - Atlantic >9 Grove St., PO Box 1012 >Dartmouth NS Canada B2Y 3Z7 Christopher J. Purcell Defence R&D Canada - Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== The documentation you're talking about doesn't even deserve to be called documentation. A few hints; that's it. Bobby Treat -----Original Message----- > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== This is a question that's been asked and answered a number of times. One answer, by me, can be found by going to www.wolfram.com and selecting first Resource Library and then MathGroup on the Resource Library page; then search for direction field. You'll find, among many others, the URL: http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00163.html (This is not to chastise you for not first looking there, but to suggest a way for you to find answers more efficiently than waiting for the ou need to load the package, then manufacture a vector field whose plot is the slope field (what you call vector flow diagram). To do the latter, let me separately define the function giving the right-hand side of the ODE; you don't really have to do that, but could instead directly use as the first argument to PlotVectorField the right-hand side of my definition of f. << Graphics`PlotField` f[t_, y_] := {1, 1/y} field = PlotVectorField[f[t, y], {t, 0, 3}, {y, 0.05, 3}]; I gave a name to the graphics result just in order to re-display the field below along with the graph of one solution. First, find a general solution: soln = First @ DSolve[{y'[t] == 1/y[t], y[0] == 1}, y[t], t] {y[t] -> Sqrt[2]*Sqrt[1/2 + t]} grf = Plot[y[t] /. soln, {t, 0, 3}]; Now combine the plot with the field: Show[grf, field]; Note that PlotVectorField does not always give quite the result you might want, since the vector lengths are scaled with respect to the magnitude of the actual vectors. You might want just a direction field in which all arrows have the same length. You can produce such a graphic by using the ScaleFunction and ScaleFactor options to PlotVectorField. For example: field = PlotVectorField[f[t, y], {t, 0, 3}, {y, 0.05, 3}, ScaleFunction -> (1 &), ScaleFactor -> 0.175]; ... I have several differential equations I would like to plot in Mathematica. I would like to plot the Slope Fields of them though. Can anyone lead me in the right direction? I can solve the equations trivially but I want to display the slope fields. An example follows : y' + 2y = 3 ... -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street Amherst, MA 01375 ==== I am trying to implement a very simple sorted tree to quickly store some real numbers I need. I have written an add, delete, minimum, and pop (delete the lowest value) function and they seem to work ok but are very slow. Let's just look @ my implementation of the add part: nums=Null;(*my initial blank Tree) In[326]:= Clear[add] In[327]:= add[Null,x_Real]:=node[x,Null,Null] add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher] In[328]:= add[node[x_Real,lower_,higher_],y_Real]:= If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y]]] In[288]:= add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery_]]:=If[x>y, node[x,add[lowerx,node[y,lowery,highery]],higherx], node[x,lowerx,add[higherx,node[y,lowery,highery]]] ] Now this is my attempt to test how fast my add works: SeedRandom[5]; Do[nums=add[nums,Random[]],{5000}];//Timing Out[333]= {13.279 Second,Null} running on an 1.4GHz Athlon with 1GB of ram). Questions: 1. Is this as fast as I can get my code to run? 2. Am I doing something obviously stupid? 3. would Compiling things help? Husain ==== The vectors that NullSpace gives do not need to be orthogonal to each other. What about the following variant, that adds one vector at a time? It may not be fast enough for serious number crunching. OrthogonalComplement[v__ /; MatrixQ[{v}]] := With[{n = Length[NullSpace[{v}]]}, Take[Nest[Join[{First[NullSpace[#]]}, #] &, {v}, n], n]]; OrthonormalComplement[v__ /; MatrixQ[{v}]] := Map[#/Sqrt[#.#] &, OrthogonalComplement[v]]; When the input of OrthogonalComplement is integer, I expect the output to be integer too: OrthogonalComplement[{1, 2, 3}] {{1, -5, 3}, {-3, 0, 1}} Gianluca Gorni OrthogonalUnitVectors that I sent a few minutes ago doesn't do what I > thought it would. > After making either definition below I get the following: In[2]:= > s1=OrthogonalUnitVectors[{1,0,1/2,1,0},{0,1,-1,1/2,2}] Out[2]= > {{0, -2/Sqrt[5], 0, 0, 1/Sqrt[5]}, {-2/3, -1/3, 0, 2/3, 0}, {-1/3, 2/3, > 2/3, 0, 0}} > The dot products below aren't zero, so the vectors aren't orthogonal. What > went wrong? > In[3]:= > Part[s1,1].Part[s1,2] Out[3]= > 2/(3*Sqrt[5]) > In[4]:= > Part[s1,1].Part[s1,3] Out[3]= > -4/(3*Sqrt[5]) > -------------- >> Hugh Goyder and David Park gave a most elegant function to find two >> vectors that are orthogonal to one vector in 3D. The key to coming up >> with the elegant solution is an understanding of Mathematica's NullSpace >> function. We can easily make the version from Hugh and David much more >> general with the version below. >> ------------- >> OrthogonalUnitVectors[vect__?VectorQ]:= >> #/Sqrt[#.#]&/@NullSpace[{vect}] >> ------------- >> The version above will give a set of unit orthogonal vectors if given any >> number of vectors in any dimension. >> So besides giving it a 3D vector we can give it the following: >> OrthogonalUnitVectors[{2,1,0,-1,1}] >> or >> OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] >> ------------ >> But the short version above isn't very robust. >> (1) Clear[x,y,z];NullSpace[{{x,y,z}}] >> returns two vectors orthogonal to {x,y,z}, but the two vectors >> NullSpace returns aren't orthogonal to each other. >> So (OrthogonalUnitVectors) should only work with numeric vectors. >> (2) We should ensure all the vectors have the same dimension and length > 1. >> I give a less concise version below that corrects these problems. >> ------------ >> OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; >> (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= >> #/Sqrt[#.#]&/@NullSpace[{vect}] >> -------------- >> Ted Ersek >> Get Mathematica tips, tricks from >> http://www.verbeia.com/mathematica/tips/Tricks.html > ==== I am using MultipleListPlot to plot a range of 2D graphs and have found that the last graph, which has a much greater (by a factor of 4) x range than the others does not plot completely but is truncated in the x direction. By removing the Frame, I can see the points where these lie outside the Frame but these are not joined etc. How do I get over this? - Malcolm Woodruff Reply-To: kuska@informatik.uni-leipzig.de ==== set the PlotRange explicit PlotRange->{{0,largeX},Automatic} Jens I am using MultipleListPlot to plot a range of 2D graphs and have found that > the last graph, which has a much greater (by a factor of 4) x range than the > others does not plot completely but is truncated in the x direction. By > removing the Frame, I can see the points where these lie outside the Frame > but these are not joined etc. How do I get over this? > - > Malcolm Woodruff ==== I noticed the same thing when I attempted to plot data with disjoint x-ranges. One way is not to use the MultipleListPlot[] function. You can plot both the lines and the markers by applying Line and Point graphics to your datasets. And use Show[] to display everything on one plot. You can use the PlotSymbol[] function instead of Point. The PlotSymbol function is available in the MultipleListPlot package to get the diamond, star, square, etc. Another way is to modify the MultipleListPlot[] function. I modified the function to do multiple plots on a polar grid. WARNING - I advise you not to change any of the standpackages. Instead, first make a copy then modify it. One of the modifications I made was to change 'pts = First[Transpose[data]]' in the handleset function to 'pts=data'. This seems to work for my application. Hope this helps. Lawrence > I am using MultipleListPlot to plot a range of 2D graphs and have found that > the last graph, which has a much greater (by a factor of 4) x range than the > others does not plot completely but is truncated in the x direction. By > removing the Frame, I can see the points where these lie outside the Frame > but these are not joined etc. How do I get over this? > - > Malcolm Woodruff ==== Group, Sorry for the previous posting. The following solves (to some extent my problem) < (1) Is there a way in Mathematica 4.2 to put two separate gifs into a > single, cell side by side (with some intervening space), without > having to combine them in some graphics program first? > > In particular, I'd like to do that within a text cell. > > Even in a new Input cell, if I first create a GridBox (via Inut>Create > Table/Matrix/Palette) and then try to insert the first gif (via > Edit>Insert Object>Create from File ....), Mathematica promptly > crashes. (Mathematica 4.2 under Windows 2000.) You could do something like this: grlist = Map[Import[#, GIF]&, {, }] celist = Map[Cell[GraphicsData[PostScript, DisplayString[#]]]&, grlist] CellPrint[Cell[BoxData[GridBox[{celist}]], Text]] This embeds the PostScript versions of these graphics each as inline cells in a GridBox[] structure. > (2) Is there a way to cause a gif imported into a Mathematica 4.2 > notebook to become a hyperlink -- so that when the user clicks on the > gif the hyperlink's target is summoned? Again, we embed the PostScript graphic within an inline cell. Here is a function that does what you describe: createGIFHyperlink[gifImage_String, url_String] := NotebookWrite[EvaluationNotebook[], Cell[BoxData[ ButtonBox[ Cell[GraphicsData[PostScript, DisplayString[Import[gifImage, GIF]]]], ButtonStyle -> Hyperlink, ButtonData :> {URL[url], None}]], Text]] -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== > 1.) How to find the General Solution for below's partial differential > equation? > (y + u) du/dx + y (du/dy) = x - y > ** I use d to represent the partial differential symbol. > Can it be solved by function NDSolve in mathematica 4.1? How? It's been a while, but I suspect that the presence of the nonlinear convective term u du/dx alone makes a general solution unlikely. It's easy to get a numerical solution for a particular set of boundary conditions, but you are not guaranteed a solution. For instance, the following choice of a and b are skirting failure, as the diagnostic contour plot shows. Tom Burton Needs[Graphics`Colors`] !((soln = With[{a = (-1), b = 1.27, e = 0.001}, solutions = NDSolve[{((y + u[x, y])) [PartialD]_x u[x, y] + y [PartialD]_y u[x, y] == x - y, u[x, b] == 0, u[a, y] == 0}, u, {x, a, 10}, {y, b, 10}]; [IndentingNewLine]Plot3D[ Evaluate[u[x, y] /. [InvisibleSpace]First[solutions]], {x, a, 10}, {y, b, 10}, PlotPoints [Rule] 50]; [IndentingNewLine]ContourPlot[ Evaluate[y + u[x, y] /. [InvisibleSpace]First[solutions]], {x, a, 10}, {y, b, 10}, PlotPoints [Rule] 50, ColorFunction [Rule] ((If[#1 > e, Green, Red] &))][IndentingNewLine]];)) ==== I'd be happier if I could just control pagination, or if automatic pagination were done sensibly. Yes, I can make a page break where I want one, but I can't eliminate page-breaks that leave tons of white-space at the end of some pages. In some of my notebooks, Mathematica puts the first cell on a page by itself, using less than an inch --- and NOT because the next cell takes a whole page. If I force the first two cells to stay together, the problem just moves to the next page. It's enough to make Mathematica useless as a word processor all by itself. Bobby Treat -----Original Message----- derivations; - setting typefaces in tables of material. I figure most of this is do-able, but I don't have the time, or patience, to spend too much time on it. So, I'll be the first customer when you write the guide to math publishing in Mathematica - I just hope you won't have to use LaTeX to write it. Mark Westwood I would like to use mathematica type papers for my math courses, but > I'm having trouble formatting documents. Despite searching, I've been > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== Bobby, Have a look at the Glue palette found here: --- Selwyn Hollis > I'd be happier if I could just control pagination, or if automatic > pagination were done sensibly. Yes, I can make a page break where I want one, but I can't eliminate > page-breaks that leave tons of white-space at the end of some pages. In > some of my notebooks, Mathematica puts the first cell on a page by > itself, using less than an inch --- and NOT because the next cell takes > a whole page. If I force the first two cells to stay together, the > problem just moves to the next page. It's enough to make Mathematica useless