Anyone know how to shade the background of just a portion of a plot? I've tried placing shaded rectangles behind the plot using Show, DisplayTogether, Epilog, and Prolog and all permutations (2^4) thereof. I have a framed and gridded plot, and I want to shade a region. create the axes and grids myself. ==== completely... Are you saying that ANY of the implementations (say, in C) of > SDP algorithms are having this precision problem? I'm really not an expert in SDP, I just stumbled upon it in a paper where > these methods are used to fit a covariance matrix, and I would like to try > this method in Mathematica... So, does anybody know of Mathematica implementations? Or maybe using > MathLink to call some C algorithms of SDP? > Dirk If you are working with real data it'll probably contain so much noise that the precision problem becomes a non-issue. A simple way to use SDP in Mathematica would be to install a solver on your system (e.g., csdp or dsdp are freely available). These solvers read SDP problems as text files and write their results in text files. So all you have to do is learn about the data format they use, write your SDP problem to disk, call the solver, read the result back into Mathematica. This isn't exactly beautiful, but chances are that it's relatively easy to get it to work. ==== No real weirdness here. The answer is correct. Applying Simplify to your resulting expression gives what you expect. << Calculus`VectorAnalysis` SetCoordinates[Spherical[r, theta, phi]] Simplify[Laplacian[Exp[r^2]]] Out[14]//OutputForm= 2 r 2 2 E (3 + 2 r ) The form you obtained initially is due to the way that Mathematica represents the Laplacian. Try the following which will produce a general form of the Laplacian for a function of r,theta and phi Laplacian[f[r, theta, phi]] If you compare the resulting output to a typical formula in a published text you will observe that Mathematica expands out all the terms involving differentian and leaves any terms involving trig functions of theta unsimplified. The two forms look quite different but are equivalent. Adam Smith When I do: < SetCoordinates[Spherical[r, theta, phi] > Laplacian[ Exp[r^2] ] Mathematica gives: 2 2 > r 2 r 4 > Csc[theta] (6 E r Sin[theta] + 4 E r Sin[theta]) > ------------------------------------------------------ > 2 > r Which is wrong since Exp[r^2] is not a function of theta or phi. > Why is Mathematica giving this result? Pete ==== Mathematica is right because Csc[th] cancel with the common factor Sin[theta] Mathematica has the general formula implemented and it simplify not automatical the result. Jens > When I do: < SetCoordinates[Spherical[r, theta, phi] > Laplacian[ Exp[r^2] ] Mathematica gives: 2 2 > r 2 r 4 > Csc[theta] (6 E r Sin[theta] + 4 E r Sin[theta]) > ------------------------------------------------------ > 2 > r Which is wrong since Exp[r^2] is not a function of theta or phi. Why is Mathematica giving this result? Pete ==== I'm a biologist who tries to use Mathematica to model population fluctuations. When trying a set of differential equations that are supposed to work properly I get the problems with keeping the system persistent or avoiding equations taking negative values (which in a biological population is absurdity). ------------------------------------ (*Defining the system*) sol := NDSolve[{V'[t] == U[t] (1 - V[t]/Kv[t]) - (A V[t] H[t])/(V[t] +[Alpha] M[t] + B), M'[t] == u[t] M[t] (1 - M[t]/Km) - ([Alpha] A M[t] H[t])/(V[t] +[Alpha] M[t] + B), H'[t] == R H[t] (A (V[t] + [Alpha] M[t])/(V[t] + [Alpha] M[t] +B) - G[t]), V[0] == 1000, M[0] == 1000, H[0] == 2}, {V, M, H}, {t, 0, 10000}, MaxSteps -> 10000] (*Defining the constant parameters*) A = 15; [Alpha] = 0.5; B = 70; Km = 1000; R = 10.7/A; (*As I want to simulate seasons with winter during 0= 10; u[t_] := 0 /; m[t] [LessEqual] 10; u[t_] := 12/2 /; m[t] > 10; G[t_] := 0.63*A /; m[t] [LessEqual] 10; G[t_] := 0.44*A /; m[t] > 10; Kv[t_] := 100 /; m[t] [LessEqual] 10; Kv[t_] := 1000 /; m[t] > 10; (*And now I wish to see how the system behaves, so I plot it) sol1 = sol; Plot[{V[t] /. sol1, M[ t] /. sol1, H[t] /. sol1}, {t, 0, 19}, PlotRange -> All, PlotPoints -> 200, PlotStyle -> {Hue[0.3], Hue[0.6], Hue[0.0]}]; ----------------------------- And now the problems: 1) I get the error message: step size is effectively zero; singularity or stiff system suspected. What does it mean exactly? I guess the reason for the message is due H[t] taking negative values, and therefore the two other variables V[t]&M[t] shooting into infinity. As this is a biological system, the negative values are absurd. The lowest realistic value should be zero. Is it possible somehow to tell to Mathematica it? Or to set some boundaries? So this is my main question -how to prohibit the variables reaching negative values? When I play around with StartingStepSize and decrease it, I get rid of the error message. But the results depend and differ very much depending on its value. If StartingStepSize-> 1/20 then H[t]->0, and V[t]=M[t]=1000 whereas in case of StartingStepSize-> 1/40 H[t]->0, V[t]=0.00004, M[t]=0.22. Why do these results differ so much? 2) If I change the initial conditions to MaxSteps -> 10000, StartingStepSize -> 1/20, Method -> {FixedStep, Method -> LinearlyImplicitModifiedMidpoint} then I get the system to be persistent, even if all the variables now and then reach negative values. And I guess therefore I can not relay on the results. thanks a lot for any help Maano =Û=Û=Û=Û=Û= Û=Û=Û=Û=Û=[ CapitalUHat]=Û=Û=Û=Û=[Ca pitalUHat]=Û=Û=Û=Û=[Capi talUHat]=Û= Maano Aunapuu MSc, PhD student Animal Ecology Dept. of Ecology and Environmental Science Ume.8c University SE -901 87 Ume.8c, SWEDEN http://www.eg.umu.se/sve/personal/maano_aunapuu.htm http://www.norrmejerier.se/plupp/ =Û=Û=Û=Û=Û= Û=Û=Û=Û=Û=[ CapitalUHat]=Û=Û=Û=Û=[Ca pitalUHat]=Û=Û=Û=Û=[Capi talUHat]=Û= ==== Can anyone explain the following timing results. In[1]:= Table[First[Sum[i,{i,1,10^i}]//Timing],{i,1,12}] Out[1]= {0. Second,0. Second,0. Second,0.02 Second,0.36 Second,4.02 Second,0.19 Second,0.04 Second,0.04 Second,0.04 Second,0.04 Second,0.04 Second} For upper limits large than 10^6 the time drops dramatically. You can check this by comparing Sum[i, {i, 1, 10^6 + 1}]//Timing with Sum[i, {i, 1, 10^6}]//Timing. I suspect that what is happing is that for upper limits less than 10^6 Sum does the sum by adding the numbers but for upper limits larger than 10^6 Sum does the computation with a symbolic upper limit to get In[6]:= Sum[i,{i,1,j}] Out[6]= j (1 + j) --------- 2 and then evaluates the upper limit. This would explain the constant times from i=10^7 to i=10^12. Can anyone confirm or refute this? ==== I am trying to numerically solve a 2-dimentional (x,t) ODE system. The general solution is like, for all x in (0,1), D[ f[x,t] , t ] == g1[ x, u[x,t] , Integrate[ f[y,t] , {y,A,B} ] , t ], D[ u[x,t] , t ] == g2[ x, u, t ], where g's are functions, for which I have already got their explicit expressions. But let me omit, as they are so complicated. The problem would be that A and B are the values of InverseFunction of f, namely, A = min{ y such that f(y) = x } and B = max{ y such that f(y) = x }. Can anyone tell me if NDSolve can handle, in principle, inverse functions like this? If so, would you tell me how I could do that, please? Kan Takeuchi Ph.D. candidate in Economics at the University of Michigan. ==== >-----Original Message----- >Sent: Wednesday, December 17, 2003 1:55 PM >To: mathgroup@smc.vnet.net >-----Original Message----- >To: mathgroup@smc.vnet.net >>Sent: Tuesday, December 16, 2003 12:21 PM >>To: mathgroup@smc.vnet.net I have something like this: (two lists(sublistTNW1 and >>sublistTNW2)), containing both time (Integer) and a value (Real)). >>The following function pick-up the next dataset(time,value) >>out of sublistTNW2 after the given time (sublistTNW1[[i,1]]). NextEvent[t_, list_] := Select[list, (#[[1]] >= t) &, 1] >>For[i = 1, i < 500, >>{ >> NextEvent[sublistTNW1[[i, 1]], sublistTNW2] >>}; i++] Calling the function in the for-loop very often (f.ex 500 >>times or more) is indeed very slowly. Trying to compile the function >>testfunc = >> Compile[{{t, _Integer}, {list, _Real, 2}}, Select[list, >>(#[[1]] >= t) &, 1]] takes no effect in speed-up. Perhabs I've used the >>compile-Function not correctly? How can I use lists with different data types in compile? >>{list, _Real, 2} (s.a.) is not exactly right, because the list >>is in the format {_Integer,_Real}. marko > Marko, I make a model of your computation, hope it applies. I don't thing your computation make stoo much sense unless >sublistTNW2 is sorted. I also suppose sublistTNW1 is sorted. >If not, try to reformulate your problem. Now the model: > >In[1]:= n0 = 100000; >In[2]:= >sublistTNW2 = Sort[Table[{Random[Integer, {1, n0}], Random[]}, {n0}]]; >In[3]:= >sublistTNW1 = Sort[Table[Random[Integer, {1, n0}], {500}]]; In[4]:= NextEvent[t_, list_] := Select[list, (#[[1]] >= t) &, 1] >In[6]:= r = {}; For[i = 1, i <= 15, > AppendTo[r, NextEvent[sublistTNW1[[i]], sublistTNW2]]; i++]; r = > Flatten[r, 1] >Out[6]= >{{210, 0.0739654}, {290, 0.571214}, {294, 0.192693}, > {304, 0.718815}, {701, 0.202688}, {1216, 0.140055}, > {1276, 0.335399}, {1454, 0.593851}, {1472, 0.6723}, > {1604, 0.271997}, {1905, 0.962603}, {1922, 0.74373}, > {2009, 0.217664}, {2125, 0.584308}, {2584, 0.476056}} In[7]:= Length[r] >Out[7]= 15 This is just to check for correctness for an alternative algorithm. >Now we test your's: In[8]:= For[i = 1, i <= 50, NextEvent[sublistTNW1[[i]], >sublistTNW2]; i++] >// Timing >Out[8]= {4.587 Second, Null} In[9]:= For[i = 1, i <= 100, NextEvent[sublistTNW1[[i]], >sublistTNW2]; i++] >// Timing >Out[9]= {20.5 Second, Null} In[10]:= For[i = 1, i <= 150, NextEvent[sublistTNW1[[i]], >sublistTNW2]; i++] >// Timing >Out[10]= {47.608 Second, Null} You see: you algorithm is O[n^2], which is prohibitive in this case. >The reason is clear: for (sorted sublists) we start always at >the beginning, >such we get longer and longer scans. This simple trick continues scanning at the last hit: > >In[11]:= i = 1; Select[sublistTNW2, > If[#[[1]] >= sublistTNW1[[i]], ++i; True, False] &, 15] >Out[11]= >{{210, 0.0739654}, {290, 0.571214}, {294, 0.192693}, > {304, 0.718815}, {701, 0.202688}, {1216, 0.140055}, > {1276, 0.335399}, {1454, 0.593851}, {1472, 0.6723}, > {1604, 0.271997}, {1905, 0.962603}, {1922, 0.74373}, > {2009, 0.217664}, {2125, 0.584308}, {2584, 0.476056}} In[12]:= % == r >Out[12]= True Same result as for the reference algorithm. Now test: > >In[17]:= >i = 1; Select[sublistTNW2, If[#[[1]] >= sublistTNW1[[i]], ++i; > True, False] &, 50]; // Timing >Out[17]= {0.38 Second, Null} In[18]:= >i = 1; Select[sublistTNW2, If[#[[1]] >= sublistTNW1[[i]], ++i; > True, False] &, 100]; // Timing >Out[18]= {0.811 Second, Null} In[19]:= >i = 1; Select[sublistTNW2, If[#[[1]] >= sublistTNW1[[i]], ++i; > True, False] &, 150]; // Timing >Out[19]= {1.142 Second, Null} In[20]:= >i = 1; Select[sublistTNW2, If[#[[1]] >= sublistTNW1[[i]], ++i; > True, False] &, 200]; // Timing >Out[20]= {1.512 Second, Null} >So the algorithm is linear (and scans sublistTNW2 only once, instead of >repeating at beginning of sublistTNW2 over and over). >Whether this algorithms is really appropriate depends on more >properties of your problem, you didn't report. Just try it! >Other strategies were to to binay search (sorted) sublistTNW2, >or to splice in sublistTNW1 as markers, Sort and Split. Perhaps others... >-- >Hartmut Wolf Marko, here now my promised explanations and comparisons: data: In[1]:= n1 = 7; In[2]:= sublistTNW1 = Sort[Table[{Random[Integer, {0, n0}], Random[]}, {n1}]] Out[2]= {{2, 0.285281}, {4, 0.228988}, {5, 0.0569614}, {8, 0.387688}, {16, 0.982228}, {18, 0.253338}, {18, 0.40502}} In[3]:= n2 = 20; In[4]:= sublistTNW2 = Sort[Table[{Random[Integer, {0, n0}], Random[]}, {n2}]] Out[4]= {{1, 0.539148}, {2, 0.726261}, {3, 0.827974}, {5, 0.343456}, {5, 0.422791}, {6, 0.0319436}, {6, 0.453189}, {8, 0.681286}, {10, 0.467884}, {11, 0.578041}, {13, 0.704192}, {13, 0.92887}, {14, 0.21612}, {16, 0.0822718}, {16, 0.719935}, {17, 0.231015}, {17, 0.322158}, {18, 0.472525}, {19, 0.754313}, {20, 0.831389}} In[11]:= i = 1; s = Select[sublistTNW2, If[First[#] >= First[sublistTNW1[[i]]], ++i; True, False] &, Length[sublistTNW1]] Out[11]= {{2, 0.726261}, {5, 0.343456}, {5, 0.422791}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}, {19, 0.754313}} Compare that result with In[8]:= sublistTNW1 Out[8]= {{2, 0.285281}, {4, 0.228988}, {5, 0.0569614}, {8, 0.387688}, {16, 0.982228}, {18, 0.253338}, {18, 0.40502}} you see the weekness of the idea, perhaps the third hit should be identical to the second (and sixth to seventh). The answer, whther ok or not, however, must come from your application. Your algorithm gives a different result here: In[9]:= s = Function[comp, Select[sublistTNW2, First[#] >= First[comp] &, 1]] /@ sublistTNW1 Out[9]= {{{2, 0.726261}}, {{5, 0.343456}}, {{5, 0.343456}}, {{8, 0.681286}}, {{16, 0.0822718}}, {{18, 0.472525}}, {{18, 0.472525}}} Now it would not be too easy to fix my (not quite so brilliant) idea. On the other side, perhaps, dubletts should not show up in the result. Such if you wanted In[10]:= s0 = Union[Flatten[s, 1]] Out[10]= {{2, 0.726261}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}} a fix would be much easier. In[12]:= i = 1; len = Length[sublistTNW1]; s2 = Select[sublistTNW2, If[i <= len && (this = First[#]) >= First[sublistTNW1[[i]]], While[(++i <= len) && this >= First[sublistTNW1[[i]]]]; True, False] &] Out[12]= {{2, 0.726261}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}} When we get a hit, we just skip all other search keys, which would give the same hit (in your algorithm) Merge/Sort/Split approach: This is another idea I had indicated in my first post. We merge both lists sorted, say sublistTNW1 would be all red, then in the result after each red element, the next black one would be the corresponding hit. Split just is a fast way to locate the markers. As we do not have colors, we tag sublistTNW1 In[21]:= markers = Transpose[ {sublistTNW1[[All, 1]], Table[-1, {Length[sublistTNW1]}]}] Out[21]= {{2, -1}, {4, -1}, {5, -1}, {8, -1}, {16, -1}, {18, -1}, {18, -1}} In[22]:= Sort[Join[markers, sublistTNW2]] Out[22]= {{1, 0.539148}, {2, -1}, {2, 0.726261}, {3, 0.827974}, {4, -1}, {5, -1}, {5, 0.343456}, {5, 0.422791}, {6, 0.0319436}, {6, 0.453189}, {8, -1}, {8, 0.681286}, {10, 0.467884}, {11, 0.578041}, {13, 0.704192}, {13, 0.92887}, {14, 0.21612}, {16, -1}, {16, 0.0822718}, {16, 0.719935}, {17, 0.231015}, {17, 0.322158}, {18, -1}, {18, -1}, {18, 0.472525}, {19, 0.754313}, {20, 0.831389}} In[23]:= Split[%, Last[#1] =!= -1 &] Out[23]= {{{1, 0.539148}, {2, -1}}, {{2, 0.726261}, {3, 0.827974}, {4, -1}}, {{5, -1}}, {{5, 0.343456}, {5, 0.422791}, {6, 0.0319436}, {6, 0.453189}, {8, -1}}, {{8, 0.681286}, {10, 0.467884}, {11, 0.578041}, {13, 0.704192}, {13, 0.92887}, {14, 0.21612}, {16, -1}}, {{16, 0.0822718}, {16, 0.719935}, {17, 0.231015}, {17, 0.322158}, {18, -1}}, {{18, -1}}, {{18, 0.472525}, {19, 0.754313}, {20, 0.831389}}} In[24]:= Rest[First /@ %] Out[24]= {{2, 0.726261}, {5, -1}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, -1}, {18, 0.472525}} Markers that still show up here indicate dubletts. We might drop them if not desired. In[25]:= s3 = DeleteCases[%, {_, -1}] Out[25]= {{2, 0.726261}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}} In[26]:= s0 Out[26]= {{2, 0.726261}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}} Binary Search: In[28]:= << DiscreteMath`Combinatorica` In[29]:= ?BinarySearch In[31]:= klist = sublistTNW2[[All, 1]] Out[31]= {1, 2, 3, 5, 5, 6, 6, 8, 10, 11, 13, 13, 14, 16, 16, 17, 17, 18, 19, 20} The keys in the list to be searched In[32]:= slist = sublistTNW1[[All, 1]] Out[32]= {2, 4, 5, 8, 16, 18, 18} The list of the search keys. In[33]:= BinarySearch[klist, #] & /@ slist Out[33]= {2, 7/2, 5, 8, 15, 18, 18} Direct hits are given by integer indices, otherwise (for us) the interesting element would be given by the next integer In[34]:= Ceiling[%] Out[34]= {2, 4, 5, 8, 15, 18, 18} We see one of the two dublett pairs (the index 18 repeats). But where has the other gone? In[35]:= sublistTNW2[[Union[%]]] Out[35]= {{2, 0.726261}, {5, 0.343456}, {5, 0.422791}, {8, 0.681286}, {16, 0.719935}, {18, 0.472525}} Here it comes up again! The reason is, binary search stops when it gets a hit. If we want the lowest of all possible hits, we have to do some corrective work: There also is another point, if we search for a key that is too large, we get an index out of bounds. In[36]:= s4 = Module[{klist = sublistTNW2[[All, 1]], slist = sublistTNW1[[All, 1]], flist, k0, pos}, flist = Union[((If[(k0 = Ceiling[BinarySearch[klist, #1]]) <= Length[klist], While[klist[[k0--]] == klist[[k0]]]; ++k0, 0]) &) /@ slist]; pos = Position[flist, _?Positive, {1}, 1]; pos = If[Length[pos] > 0, pos[[1, 1]] - 1, 1]; flist = Drop[flist, {1, pos}]; sublistTNW2[[flist]]] Out[36]= {{2, 0.726261}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}} Now what is the other variant? When it should exactly reproduce your algorithm, i.e. dubletts included? Recall In[99]:= s Out[99]= {{{2, 0.726261}}, {{5, 0.343456}}, {{5, 0.343456}}, {{8, 0.681286}}, {{16, 0.0822718}}, {{18, 0.472525}}, {{18, 0.472525}}} This is easiest with binary search (just replace Union by Sort): In[100]:= as4 = Module[{klist = sublistTNW2[[All, 1]], slist = sublistTNW1[[All, 1]], flist, k0, pos}, flist = Sort[((If[(k0 = Ceiling[BinarySearch[klist, #1]]) <= Length[klist], While[klist[[k0--]] == klist[[k0]]]; ++k0, 0]) &) /@ slist]; pos = Position[flist, _?Positive, {1}, 1]; pos = If[Length[pos] > 0, pos[[1, 1]] - 1, 1]; flist = Drop[flist, {1, pos}]; sublistTNW2[[flist]]] Out[100]= {{2, 0.726261}, {5, 0.343456}, {5, 0.343456}, {8, 0.681286}, {16, 0.0822718}, {18, 0.472525}, {18, 0.472525}} In[101]:= as4 == (as = Flatten[s, 1]) Out[101]= True With Merge/Sort/Split this is In[103]:= as3 = Module[{markers = Transpose[{sublistTNW1[[All,1]], Table[-1, {Length[sublistTNW1]}]}], ss}, ss = Split[Sort[Join[markers, sublistTNW2]], Last[#1] =!= -1 & ]; Reverse[ Block[{last=Sequence[]}, If[#[[2]]===-1,last,last=#]&/@Reverse[Rest[First/@ss]]]] ]; In[104]:= as3 == as Out[104]= True Now a comparison for performance: (but be aware that asymptotic complexity is different for different algorithms below) In[121]:= n1 = 200; In[122]:= sublistTNW1 = Sort[Table[{Random[Integer, {0, n0}], Random[]}, {n1}]]; In[123]:= n2 = 10000; In[124]:= sublistTNW2 = Sort[Table[{Random[Integer, {0, n0}], Random[]}, {n2}]]; Your algorithm on these data: In[125]:= s0 = Union[ Flatten[Function[comp, Select[sublistTNW2, First[#] >= First[comp] &, 1]] /@ sublistTNW1, 1]]; // Timing Out[125]= {18.917 Second, Null} Single Scan: In[126]:= s2 = Block[{i = 1, len = Length[sublistTNW1], this}, Select[sublistTNW2, If[i <= len && (this = First[#]) >= First[sublistTNW1[[i]]], While[(++i <= len) && this >= First[sublistTNW1[[i]]]]; True, False] &]]; // Timing Out[126]= {0.591 Second, Null} In[127]:= s2 == s0 Out[127]= True Merge/Sort/Split In[128]:= s3 = Module[{markers = Transpose[ {sublistTNW1[[All,1]], Table[-1, {Length[sublistTNW1]}]}], ss}, ss = Split[Sort[Join[markers, sublistTNW2]], Last[#1] =!= -1 & ]; DeleteCases[Rest[First /@ ss], {_, -1}]];//Timing Out[128]= {0.26 Second, Null} In[129]:= s3 == s0 Out[129]= True Binary Search In[130]:= (s4 = Module[{klist = sublistTNW2[[All, 1]], slist = sublistTNW1[[All, 1]], flist, k0, pos}, flist = Union[((If[(k0 = Ceiling[BinarySearch[klist, #1]]) <= Length[klist], While[klist[[k0--]] == klist[[k0]]]; ++k0, 0]) &) /@ slist]; If[Length[flist] > 0 && flist[[1]] === 0, flist = Rest[flist]]; sublistTNW2[[flist]]]); // Timing Out[130]= {1.632 Second, Null} In[131]:= s4 == s0 Out[131]= True -- Hartmut Wolf ==== >-----Original Message----- >Sent: Sunday, December 14, 2003 12:23 PM >To: mathgroup@smc.vnet.net > >Second assignment: L[[2]]=2, or Set[Part[L,2],2]. Here L is >not evaluated >(because assigment treats Part in a special way -- if there >were another >non-holding function instead of Part, L would be evaluated), >so there's simply >no Sequence objects here and SequenceHold can't have any effect. > > We certainly agree that after the second assignment L[[1]]= Sequence[1,1] > has the value {Sequence[1,1], 0}, (it would have the same value after the > assignment Set[L[[1]],1,1], but that is, as shown, a different story). Now > why does L[[2]] = 2, overwrite that 0, and not the second 1 from > Sequence[1,1]? This simply is because of the HoldFirst property of Set > (such L ist *not* evaluated, does *not* result to {1, 1, 0}[[2]] at lhs, and > as a special form behaves like an Upvalue for Part just redefining the > second slot, and leaving everthing else untouched (of course, we might say), > hence the result. > One correction: L in Set[Part[L,2],2] is left unevaluated *not* just because of the HoldFirst attribute of Set. Documentation for Set says: If lhs is of the form f[args], then args are evaluated. So Part is an exception from an exception. Maxim Rytin ==== I want to solve this equation: f'(p)=0. With the restrictions 0 p > 0 && k > 2 && n > k, p] but no solution is found. -------------------------------------------------------------------- The above problem is the same with the equation: x^(a+1) * (1-x)^(b-1) = (x^a) * (1-x)^b with the restrictions 0 x=0.5 But how can i solve this in Mathematica 5.0 or 4.2? The: Needs[Algebra`InequalitySolve`] InequalitySolve[x^(a+1) * (1-x)^(b-1) == (x^a) * (1-x)^b && 1 > x > 0 && a > b > 1, x] doesn't work. -------------------------------------------------------------------- And generally because in Mathematica 5.0, Reduce can solve inequalities, how can i solve the (a^b)*(b^a)>0 with a>b>0. (Which is true of course) The: Reduce[(a^b)*(b^a)>0 && a>b>0,{a,b}] doesn't find it. ==== is there some free packs which to solve this kind of problems ==== InputForm. That can be done in various ways. For instance, (your input)//InputForm The result can be copied and pasted without hassles. The best solution is due to Omega Consulting--a palette that copies as InputForm, so that you don't have to actually change the contents of your notebook to accomplish the task. I put the palette in C:Documents and SettingsAll UsersApplication DataMathematicaApplicationsInputFormFrontEndPalettes Create that directory (you can use a different name for the InputForm directory if you want) first, then select the following text, copy and paste it into Mathematica (answer yes when it asks if you want to convert the expression), and the result should be a new palette on your screen. Close Mathematica, and it should ask if you want to save the untitled palette. Save it in the above directory, name it whatever you want (I named it InputForm), and reopen Mathematica. File>Palettes should show the new palette, and you're in bidness. Select anything you want to copy into a text program, push the palette button, and paste where you want it. Bobby code follows... Notebook[{ Cell[BoxData[ ButtonBox[ RowBox[{ RowBox[{Copy, , As}], n, , InputForm}], ButtonFunction:>Module[ {cpy, cpynb, evalnb}, CompoundExpression[ Set[ cpy, NotebookRead[ InputNotebook[ ]]], If[ SameQ[ cpy, {}], Return[ ]], Set[ cpynb, NotebookCreate[ Visible -> False]], NotebookWrite[ cpynb, cpy], SelectionMove[ cpynb, All, Notebook], FrontEndExecute[ { FrontEndToken[ cpynb, SelectionConvert, InputForm]}], Set[ evalnb, NotebookPut[ Notebook[ Map[ Cell[ #, Input]&, { BoxData[ RowBox[ {cpynb, =, ToBoxes[ cpynb]}]], FrontEndExecute[{FrontEndToken[cpynb, CopySpecial,PlainText]}], NotebookClose[cpynb], NotebookClose[EvaluationNotebook[]]}], Visible -> False]]], SelectionMove[ evalnb, All, Notebook], SelectionEvaluate[ evalnb], Null]], ButtonEvaluator->Automatic, Active->True]], NotebookDefault, CellMargins->{{Inherited, Inherited}, {7, Inherited}}, PageBreakAbove->True, CellLabelMargins->{{12, Inherited}, {Inherited, Inherited}}, InputAutoReplacements->{ ->->[Rule], :>->[RuleDelayed], <=->[LessEqual], >=->[GreaterEqual], !=->[NotEqual], ==->[Equal], Inherited}, TwoByteSyntaxCharacterAutoReplacement->True, Hyphenation->True, LineSpacing->{1.25, 0}, ScriptMinSize->9, CounterIncrements->Text, StyleMenuListing->None, FontFamily->Courier] }, ScreenRectangle->{{0, 1280}, {0, 967}}, ClosingAutoSave->True, Editable->False, WindowToolbars->{}, PageWidth->334, WindowSize->{116, 56}, WindowMargins->{{Automatic, 5}, {72, Automatic}}, WindowFrame->Palette, WindowElements->{}, WindowFrameElements->CloseBox, WindowClickSelect->False, ScrollingOptions->{PagewiseScrolling->True, VerticalScrollRange->Fit}, ShowCellBracket->False, CellMargins->{{0, 0}, {Inherited, 0}}, Active->True, CellOpen->True, ShowCellLabel->False, ShowCellTags->False, ImageMargins->{{0, Inherited}, {Inherited, 0}}, Magnification->1.5 ] ==== That's precisely why I suggested you read a little about the Mathematica basics (BTW, you may use the Help Browser, where a copy of The Book is found). The output of a Solve execution is always given in terms of what is called a replacement rule, i.e., something like {x -> something}. Now, you must know the meaning of that in order to use the solution. See e.g. Section 1.5.7 (click Help and then The Mathematica Book | A Practical Introduction | Symbolic Mathematics | Solving Equations). There you'll find enough material to keep you busy (and interested, I hope). Tomas ----- Original Message ----- > Also, unfortunatly I dont have a book because I bought a student version > that did not include it. Stefan >There should be no problem, in principle. Watch out for your syntax, though. >Equal sign must be replaced by two equal signs, and there should be a space >between coefficients and variables. Try this > >In[5]:= >Solve[{A1*x + B1*y + C1*z == D1, > A2*x + B2*y + C2*z == D2, A3*x + B3*y + C3*z == > D3}, {x, y, z}] > >Out[5]= >{{x -> -((B3*C2*D1 - B2*C3*D1 - B3*C1*D2 + B1*C3*D2 + > B2*C1*D3 - B1*C2*D3)/((-A3)*B2*C1 + A2*B3*C1 + > A3*B1*C2 - A1*B3*C2 - A2*B1*C3 + A1*B2*C3)), > y -> -((A3*C2*D1 - A2*C3*D1 - A3*C1*D2 + > A1*C3*D2 + A2*C1*D3 - A1*C2*D3)/ > (A3*B2*C1 - A2*B3*C1 - A3*B1*C2 + A1*B3*C2 + > A2*B1*C3 - A1*B2*C3)), > z -> -((A3*B2*D1 - A2*B3*D1 - A3*B1*D2 + > A1*B3*D2 + A2*B1*D3 - A1*B2*D3)/ > ((-A3)*B2*C1 + A2*B3*C1 + A3*B1*C2 - A1*B3*C2 - > A2*B1*C3 + A1*B2*C3))}} > >I suggest you spend some time reading the Mathematica Book (at least the >first part). > >Tomas Garza > >Mexico City >--- Original Message ----- > >To: Sent: Wednesday, December 17, 2003 6:54 AM > >>I wonder if Mathematica can give me the theoretical answer on linear >>equations. In other words, can it solve these equations without haveing >>the numbers. >>Example: >> I have three equations, and three unknowns; >> EQ1 = A1x + B1y + C1z = D1 >> EQ2 = A2x + B2y + C2z = D2 >> EQ3 = A3x + B3y + C3z = D3 >>....and get the theoretical answer; >> A2*D3 - A3*D2 A1*D2 - A2*D1 >> ------------- - ------------- >> A2*B3 - A3*B2 A1*B2 - A2*B1 >> z = ------------------------------- >> A2*C1 - A1*C2 A3*C2 - A2*C3 >> ------------- - ------------- >> A1*B2 - A2*B2 A2*B3 - A3*B2 >> (A1*D2 - A2*D1) + (A2*C1 - A1*C2)*z >> y = ----------------------------------- >> (A1*B2 - A2*B1) >> D1 - B1*y - C1*z >> x = ---------------- >> A1 >>I can do this by hand but I need to implement it in a program I write >>and it is so easy to make errors when you solve it by hand. Especially >>since I need the solution for 4,5,6 and 7 equations/unknonws. >>I have no idea how to work with matrixs in my programing language so >>please dont give me that as a hint :) >>Stefan > > ==== Some of you already know this, but here's a nice way to clean up performs copy as InputForm. Note to Wolfram: THIS SHOULD BE BUILT IN TO THE MATHEMATICA MENUS! I put the palette in C:Documents and SettingsAll UsersApplication DataMathematicaApplicationsInputFormFrontEndPalettes Step 1) Create that directory (you can use a different name for the InputForm directory if you want, or use a directory that already exists in that position, like Utilities). Step 2) Select the code below (all of it, and nothing else). Step 3) Copy it. Step 4) Paste it into Mathematica. Step 5) Answer yes when Mathematica asks if you want to convert the expression. (Then you should see a new, untitled palette on your screen.) Step 6) Close Mathematica, and it should ask if you want to save the untitled palette. Save it in the above directory, name it whatever you want. I named mine InputForm, so it became InputForm.nb. Step 7) Reopen Mathematica. Step 8) File>Palettes should show the new palette, and you're in bidness. I leave the palette always open. Select anything you want to copy into a text program, push the palette button, and paste where you want it. If the button turns out bigger than you like, reduce the number after Magnification-> near the bottom of the code. Bobby code follows... Notebook[{ Cell[BoxData[ ButtonBox[ RowBox[{ RowBox[{Copy, , As}], n, , InputForm}], ButtonFunction:>Module[ {cpy, cpynb, evalnb}, CompoundExpression[ Set[ cpy, NotebookRead[ InputNotebook[ ]]], If[ SameQ[ cpy, {}], Return[ ]], Set[ cpynb, NotebookCreate[ Visible -> False]], NotebookWrite[ cpynb, cpy], SelectionMove[ cpynb, All, Notebook], FrontEndExecute[ { FrontEndToken[ cpynb, SelectionConvert, InputForm]}], Set[ evalnb, NotebookPut[ Notebook[ Map[ Cell[ #, Input]&, { BoxData[ RowBox[ {cpynb, =, ToBoxes[ cpynb]}]], FrontEndExecute[{FrontEndToken[cpynb, CopySpecial,PlainText]}], NotebookClose[cpynb], NotebookClose[EvaluationNotebook[]]}], Visible -> False]]], SelectionMove[ evalnb, All, Notebook], SelectionEvaluate[ evalnb], Null]], ButtonEvaluator->Automatic, Active->True]], NotebookDefault, CellMargins->{{Inherited, Inherited}, {7, Inherited}}, PageBreakAbove->True, CellLabelMargins->{{12, Inherited}, {Inherited, Inherited}}, InputAutoReplacements->{ ->->[Rule], :>->[RuleDelayed], <=->[LessEqual], >=->[GreaterEqual], !=->[NotEqual], ==->[Equal], Inherited}, TwoByteSyntaxCharacterAutoReplacement->True, Hyphenation->True, LineSpacing->{1.25, 0}, ScriptMinSize->9, CounterIncrements->Text, StyleMenuListing->None, FontFamily->Courier] }, ScreenRectangle->{{0, 1280}, {0, 967}}, ClosingAutoSave->True, Editable->False, WindowToolbars->{}, PageWidth->334, WindowSize->{116, 56}, WindowMargins->{{Automatic, 5}, {72, Automatic}}, WindowFrame->Palette, WindowElements->{}, WindowFrameElements->CloseBox, WindowClickSelect->False, ScrollingOptions->{PagewiseScrolling->True, VerticalScrollRange->Fit}, ShowCellBracket->False, CellMargins->{{0, 0}, {Inherited, 0}}, Active->True, CellOpen->True, ShowCellLabel->False, ShowCellTags->False, ImageMargins->{{0, Inherited}, {Inherited, 0}}, Magnification->1.5 ] ==== this list does have the odd prof. kicking around. what if someone was to evaluate the integral 1/(Log[x]) . A tough one to be sure. Nothing I've tried comes even close to cracking this one. Mathematica gives an answer which includes an integral of (?) something yet undiscovered. Every book on calculus says that there is no answer to it. Well finding areas of parabolas and such was truly difficult before Leibniz and Newton. My way of thinking is that there are yet fundamental theorms yet undiscovered.and this is why the above integral can not be evaluated as yet. ==== > I've been having trouble using the arXiv style sheet on a Mac running > OSX 10.3 and Mathematica 5.0. After installation the style sheet and palette > appears, and documents that I've created using this style sheet on a > Windows system look ok, but I cannot get the palette to function > Does this ring a bell with anyone? Possibly this is related to a problem I've been having with the AuthorTools palette that ships with Mathematica 5.0. Clicking on one of the buttons is supposed to open another palette that lets you easily access a group of related things. Currently, when I click on one of the buttons, I get a beep and a message stating the requested evaluator is not defined. However, if I look at the definitions for the buttons and enter those directly into a frontend notebook, the second palette opens as it should with no error message. Also, I have used the AuthorTools sucessfully in the past. Clearly, something has changed in my setup. But, I use this particular palette so infrequently I've no idea what changed between now and the last time it was working correctly. FWIW, I also run Mathematica 5.0 on a Mac running OSX 10.3 -- ==== Is there a normal way to adjust the line thickness in ParametricPlot3D? In mere ParametricPlot, I can give the line thickness in options: ParametricPlot[{t, t^2}, {t, 0, 1}, PlotStyle -> Thickness[0.02]] In 3D, this is almost the same: ParametricPlot3D[{t, t^2, t^3}, {t, 0, 1}] except that ParametricPlot3D does not allow the option PlotStyle (gives an error for unknown option). I can adjust the line thickness by doing it like this: fig = ParametricPlot3D[{t, t^2, t^3}, {t, 0, 1}]; fig[[1]] = Prepend[fig[[1]], Thickness[0.02]]; Show[fig] I'm just being curious, is there any easier way? ==== Fellow Mathematica Users, I have a simulation that sometimes requires arbitrary precision calculations in order to converge, however at the beginning when the numbers are large such expensive calculations are unnecessary as machine precision calculations will do. So I'm looking for a way to calculate the maximum error that my numbers can be off by at a given precision (then when my numbers become small enough that they risk being subsumed by error, I can proactively increase the precision). As I understand from a discussion I've been having on comp.arch.mathematics here: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&threadm=4nllpjfc8a.fs f%40edgedsp4.rtp.ericsson.se&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26gr oup%3Dcomp.arch.arithmetic the accuracy in calculating the functions Log[] and x^y typically vary with the compiler/math library chosen for a given hardware platform (something I found to be quite surprising at the time). So I presume that Mathematica's machine precision calculations will also be subject to the choice of math library/compiler chosen when Mathematica was compiled as these calculations are done directly by the supporting platform. So my first question is, does anyone know what compiler/math library was used to compile Mathematica on the Windows/Intel platform? Better yet can anyone tell me what the maximum error would be for Log[x] and x^y when done on Mathematica machine precision numbers on Wintel machines? (I suspect this will be on the order of 1 ulp from my discussion on comp.arch.arithmetic). Secondly can anyone tell me what those error bounds would be for Mathematica's arbitrary-precision calculations which I presume are done primarily by Mathematica routines. Lastly, for the basic operations of addition, subtraction, multiplication and division on arbitrary precision numbers, I presume the result is exactly rounded (ie: within 0.5 ulp of the correct answer), is this a fair assumption? Any and all help will be very much appreciated! terry ==== y1 ... original family y2 ... orthogonal family You have the problems because you didn't simplify the expression for y2', in which you should plug y1, and you'll see the DE gets solvable, ie. y2' = (#^2+C)^2 / (#^2-C) & The solution is cute. Borut Levart Slovenia > 17 December 2003 I am working with the family of functions y[x,C] = x / ( x^2 + C) where x is the independent variable and C>0 is a parameter. I am interested in the family of functions which are orthogonal to the above > function. y_ortho[x,D] = f[x,D] where x is the independent variable and D is a parameter. The family of functions y[x,C] has the differential equation y'[x] = y[x]/x - 2 (y[x])^2 The orthogonal trajectories would have the negative inverse for their > differential equation y_ortho'[x] = -1/y'[x] = x / (2 x (y_ortho[x])^2 - y_rtho[x]) Using DSolve on y'[x] DSolve[y'[x] == y[x]/x - 2y[x]^2, y[x], x] gives y[x] -> x / (x^2 + C[1]) as expected. When I use DSolve on y_ortho'[x], there is no solution !(DSolve[(y')[x] == x/(2 x y[x]^2 - y[x]), y[x], x]) gives the above statement back. If any of you know how to solve the differential equation y_ortho'[x] = x / (2 x (y_ortho[x])^2 - y_rtho[x]) I would appreciate your input. I have looked through a few books on differential equations and haven't been > able to find an answer. Read ==== Mathematica 5.0 m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm Transpose[m] this just does nothing. it simply prints back what I typed with m in MatrixForm but does not actually do the transpose. But when I do m = { {1, 2, 3}, {4, 5, 6} } Transpose[m] it works. It seems that the function Transpose does not like to accept a list in 'MatrixForm' ? I use a MatrixForm to see the matrix better. Does this mean one have to removed the MatrixForm each time before calling Transpose? ==== > phi is the function : phi[u_,v_]=u^4+v^3 For calculating the Laplacian at u=3 and v=4 , is better : How about Laplacian[f_]:= Laplacian[f]= Function[{x,y}, Evaluate[Derivative[2,0][f][x,y]+Derivative[0,2][f][x,y]]] This computes and stores the Laplacian of phi as a pure function. Then you can compute values a particular points, such as Laplacian[phi][3,4] efficiently. The Mathematica Journal 7:2 (1998): 113-117. Paul this ?? Laplacien2[f_][x_,y_]:= > Module[{expr,p,q,Dpp,Dqq,subs}, > expr = f[p,q]; (* Set *) > Dpp=D[expr,{p,2}]; > Dqq=D[expr,{q,2}]; > subs={p->x,q->y}; > Dpp+Dqq/.subs] Laplacien2[phi][3,4] or this ??? Laplacien3[f_][x_,y_]:= > Module[{g,p,q,Dpp,Dqq,subs}, > g[p_,q_] = f[p,q]; (* Set *) > Dpp=D[g[p,q],{p,2}]; > Dqq=D[g[p,q],{q,2}]; > subs={p->x,q->y}; > Dpp+Dqq/.subs] Laplacien3[phi][3,4] or this ???? Laplacien4[f_][x_,y_]:= > Module[{g,p,q,Dpp,Dqq,subs}, > g[p_,q_] := f[p,q]; (* Set Delayed *) > Dpp=D[g[p,q],{p,2}]; > Dqq=D[g[p,q],{q,2}]; > subs={p->x,q->y}; > Dpp+Dqq/.subs] Laplacien4[phi][3,4] > -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul