NDSolve seems to have difficulties with solving integral equation. n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z, > t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n, > [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0}*[Sigma]norm[z, > t], {z, 0.01, 1}, {t, 0.01, 2}] Mathematica returns a message NDSolve::deql: The first argument must have both an equation and an > initial condition. which I cannot understand. > Can anybody tell what's wrong with my attempt? I am not really sure that your question isn't a joke. NDSolve solves differential equations, not integral equations. Although there are relations between these topics, they are certainly not the same. ==== evaluating the following gives you a sample x=x+1 button: NotebookPut@Notebook[{Cell[BoxData[ ButtonBox[(x = (x + 1)), RuleDelayed[ButtonFunction, CompoundExpression[If[Not[ ValueQ[x]], Set[x, 0]], Set[x, Plus[x, 1]]]], Rule[ButtonEvaluator, Automatic]] ], NotebookDefault, PageBreakAbove -> True, CellTags -> GeneratedButtonBoxx=x+1]}, ClosingAutoSave -> True, Editable -> False, WindowToolbars -> {}, PageWidth -> 299.5, WindowSize -> {89., 29.}, WindowMargins -> {{92., Automatic}, {Automatic, 56.}}, WindowFrame -> Palette, WindowElements -> {}, WindowFrameElements -> CloseBox, WindowClickSelect -> False, ScrollingOptions -> {PagewiseScrolling -> True}, ShowCellBracket -> False, CellMargins -> {{0., 0.}, {Inherited, 0.}}, Active -> True, CellOpen -> True, ShowCellLabel -> False, ShowCellTags -> False, ImageMargins -> {{0., Inherited}, {Inherited, 0.}}, Magnification -> 1.5] (* ********************************* *) Now, how do you create such a button in less than a minute? ... : One way is to just create a section cell and the underlying ButtonFunction code as input cells, i.e., type interactively such that you get something like: NotebookPut[Notebook[ {Cell[CellGroupData[ {Cell[x=x+1, Section], Cell[If[!ValueQ[x], x=0], Input], Cell[x=x+1, Input]}, Open]]}]] Then hit the F2B (function to Button) button in ButtonTools.nb ( my freeware button tools from http://www.mertig.com/mathdepot ) and you get the button. With the HP and VP you can easily and quickly generate (horizontally or verically) palettes. Check out the Help button, or also the source code. It basically is all straightforward and there is actually documentation about all those ButtonFunction features somewhere. I agree that the whole Button-design could have been made better, but up to a point is quite useful. Of course the world is used to better GUI's these days but if you really need nice GUI's and buttons, use Java and JLink ( and there are also simple examples in the JLink manual of how to do this ). If you don't like Java, go with VBA and use the nice Mahematica for Active X product from http://www.episoft.com Rolf Mertig Mertig Consulting http://www.mertig.com ==== try In[1]:=Clear[a,b,c,d,x,y] x= {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}}; y = {a,b,c,d}; LinearSolve[x,y] s01= LinearSolve[x,y][[1]] Out[4]={-a+b,-a+c,a-b-c+d,a} Out[5]=-a+b In[6]:=g[a_,b_] =s01 Out[6]=-a+b In[7]:=g[1,3] Out[7]=2 *NEVER* use capital letters at the beginning of a variable's name! Never! Matthias Bode Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de -----UrsprÌ.b9ngliche Nachricht----- Gesendet: Freitag, 23. August 2002 06:25 An: mathgroup@smc.vnet.net Betreff: := Does not assign variables properly. Why? Here's a piece of a conversion I had with Mathematica. Why is a[A_,B_] := LinearSolve[X,Y][[1]] not giving me the function I expect? In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}}; In[262]:= Y = {A,B,C,D}; In[263]:= LinearSolve[X,Y] Out[263]= {-A+B,-A+C,A-B-C+D,A} In[264]:= LinearSolve[X,Y][[1]] Out[264]= -A+B In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]] In[266]:= a[1,3] Out[266]= -A+B The output above is not what I want. I want 2. Here's what I expect: In[267]:= a[A_,B_] := -A+B; In[268]:= a[1,3] Out[268]= 2 This output is what I expect. What is the difference between the two? ==== First of all, just look at your own posting below. You clearly have a *(Times) where a , (comma) should be. Presumably your input ought to be: n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z, t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n, [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0},[Sigma]norm[z, t], {z, 0.01, 1}, {t, 0.01, 2}] However, even in the corrected version the equation can't be solved. First of all you will get the complaint: NDSolve::bcedge: Boundary conditions must be specified at the edge of the spatial domain. In other words Mathematica wants a boundary condition for [Sigma]norm[z, 0.1] or alternatively you should use {z,0,1} in NDSolve. But actually I do not think this equation is solvable by any numerical scheme even if you could provide the initial conditions at the edge of the boundary that Mathematica requests. To evaluate the integral in your equation NDSolve needs to know the values of [Sigma]norm[z, t] for all z between 0 and 1 and a given t, but this knowledge is not available at any stage of the evaluation. I am not really an expert, but this seems to me a clear example of an equation that is not solvable by any numerical means. By the way, the fact that you know a solution to a differential equation, and even the fact that the solution is very simple does not imply that the equation can be solved by any known method, except of course guessing, which computer programs generally do not use. Andrzej Kozlowski Toyama International University JAPAN On Friday, August 23, 2002, at 05:25 AM, Toshiyuki ((Toshi)) Meshii NDSolve seems to have difficulties with solving integral equation. n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == > 3*z*Integrate[[Sigma]norm[z, > t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n, > [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == > 0}*[Sigma]norm[z, > t], {z, 0.01, 1}, {t, 0.01, 2}] Mathematica returns a message NDSolve::deql: The first argument must have both an equation and an > initial condition. which I cannot understand. > Can anybody tell what's wrong with my attempt? > ==== >Here's a piece of a conversion I had with Mathematica. >Why is a[A_,B_] := LinearSolve[X,Y][[1]] not giving >me the function I expect? In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}}; >In[262]:= Y = {A,B,C,D}; >In[263]:= LinearSolve[X,Y] >Out[263]= {-A+B,-A+C,A-B-C+D,A} >In[264]:= LinearSolve[X,Y][[1]] >Out[264]= -A+B >In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]] >In[266]:= a[1,3] >Out[266]= -A+B The output above is not what I want. I want 2. Here's >what I expect: In[267]:= a[A_,B_] := -A+B; >In[268]:= a[1,3] >Out[268]= 2 This output is what I expect. What is the difference between >the two? X={{0,0,0,1},{1,0,0,1}, {0,1,0,1},{1,1,1,1}}; Y={A,B,C,D}; a[A_,B_]:= LinearSolve[X,Y][[1]]; ?a Global`a a[A_, B_] := LinearSolve[X,Y][[1]] Note that the RHS of the stored definition is not a function of the arguments. Now add Evaluate to RHS a[A_,B_]:= Evaluate[LinearSolve[X,Y][[1]]]; ?a Global`a a[A_, B_] := -A + B a[1,3] 2 Bob Hanlon Chantilly, VA USA ==== All of this looks like a mistake to me because it seems far too easy. But anyway, here is the solution that makes almost no use of Mathematica. First of all, your equation is not a differential equation so there is no point using DSolve. Secondly the use of z in Integrate[[Sigma]norm[z]^n*z, {z, 0, d}] is deceptive, since you are integrating over z, so let's replace it by something else, say s. So your equation is: (3*z)/d^3)*Integrate[[Sigma]norm[s]^n*s, {s, 0, d}] ==[Sigma]norm[z]^n which is supposed to hold true for every z>0. Re-write it as Integrate[[Sigma]norm[s]^n*s, {s, 0, d}]/d^3 =[Sigma]norm[z]^n/3z for all z. However, the left hand side is a function of d, independent of z, so we can write: [Sigma]norm[z_]:=(3z*g[d])^(1/n) Let's take this as a definition and substitute in the original equation In[2]:= Simplify[((3*z)*Integrate[[Sigma]norm[s]^n*s, {s, 0, d}])/d^3 == [Sigma]norm[z]^n, {d > 0, n > 0, z > 0}] Out[2]= True That means you can take g to be an arbitrary function of d. Andrzej Kozlowski Toyama International University JAPAN On Friday, August 23, 2002, at 05:25 AM, Toshiyuki ((Toshi)) Meshii > How can I solve the following integral equation? > Mathematica seems not to work. > Is there any way? DSolve[((3*z)/d^3)*Integrate[[Sigma]norm[z]^n*z, {z, 0, d}] == > [Sigma]norm[z]^n, [Sigma]norm[z], z] note: z>0 & n>1 I know that the answer is simple and > $B&R(Bnorm[z_] = (1 + 1/(2*n))*(z/d)^(1/n) > ==== But suddenly the following Errormessage appears: /usr/bin/local/mathematica: file or directory not found (Maybe its more a UNIX-Problem or has to do with Mandrake-updates ... but so far everything except of Mathematica seems to work fine.) Of course I checked for the File (it is indeed there) and (a hint from a Unix-usegroup) the needed libs libc.so.5, libm.so.5 are in /lib/ too. Had anyone had, ore better solved, a similar problem? greetings Detlef ==== How can I create a Mathematica thing (function? program?) that would automatically open a browser page, and give my username and pwd to log me into a https:.... site? The server's login page has a script resetting fields: and the relevant input cells are Nicholas ==== Howdy, I'm trying to figure out the correct syntax to do the following. I have some function with three arguments, and I want to syntactically describe the single-argument function that holds two of those arguments constant (i.e. without creating that single-argument function). More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s}, c = Floor[state/base]; s = Mod[state,base]; multiplier*s + c ] where I have a generalize 'machine', defined by the radix and multiplier, which converts one state into another state. So I'd like to be able to do something like this: NestList[Machine[10,7,#], 3, 22] to get the series of states that the radix-10 multiplier-7 machine runs through (starting with state 3). However, this syntax doesn't seem to do what I want. I hope that description makes sense. It seems like there must be a syntax to describe the function Machine[10,7,#]. Anyone have any ideas? Bob H ==== There is a following problem with Mathematica 4.2: >when i try to load Help Browser, i get a message: >building help browser index (first time only) >scanning index file >and Mathematica stops responding: you have to >kill process. There was no such a problem with >version 4.1. Is there is a solution to that? I'd start with the following FAQ. http://support.wolfram.com/mathematica/interface/helpbrowser/howrebuildindex .html ==== >I'd start with the following FAQ. http://support.wolfram.com/mathematica/interface/helpbrowser/howrebuildinde x.html 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). ==== People encounter this all the time. It is because SelectionEvaluate does not do what you think. It does not work like ToExpression, which causes immediate kernel evaluation. Instead it works like when you press Shift-Enter, which selects a cell for evaluation after all current evaluations have finished. See http://support.wolfram.com/mathematica/kernel/interface/selectionevaluate.ht ml Trying to manipulate notebooks from the kernel I found >an unexpected bahavior with Mathematica. First I tried the following commands one by one (they are not int >the same cell, and they are not selected at same time >for evaluation) nb = NotebookCreate[]; >i = 0; >(* Purpose is a Do loop here *) >NotebookDelete[nb] (*1*) >NotebookWrite[nb, ++i, All] (*2*) >SelectionEvaluate[nb] (*3*) >SelectionMove[nb, All, Cell] (*4*) If I repeat evaluating coomands (*1,2,3,4*) one by one >what is shown in the created notebook is an animation >of the index i in the same cell. >Naturally a loop must do the job. However when I >intent to collect (*1,2,3,4*) in the same cell the >result is not the same even whitout the Do loop (I >mean just evaluating this cell several times) I would be grateful if some can explain what's going >on here or if there is something wrong with my >machine. ==== >Here's a piece of a conversion I had with Mathematica. >Why is a[A_,B_] := LinearSolve[X,Y][[1]] not giving >me the function I expect? In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}}; >In[262]:= Y = {A,B,C,D}; >In[263]:= LinearSolve[X,Y] >Out[263]= {-A+B,-A+C,A-B-C+D,A} >In[264]:= LinearSolve[X,Y][[1]] >Out[264]= -A+B >In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]] >In[266]:= a[1,3] >Out[266]= -A+B The output above is not what I want. I want 2. Here's >what I expect: In[267]:= a[A_,B_] := -A+B; >In[268]:= a[1,3] >Out[268]= 2 This output is what I expect. What is the difference between >the two? This is a common misconception about what := does. What it does is set up a variable replacement for the unevaluated expression, not the evaluated expression. So a[A_,B_] := LinearSolve[X,Y][[1]] a[1,3] is similar to doing ReleaseHold[ Hold[ LinearSolve[X,Y][[1]] ] /. {A->1, B->3} ] which means that only explicit instances of A and B are replaced. What you are attempting is done with =. This assigns the function to the evaluated expression. In[5]:=a[A_,B_] = LinearSolve[X,Y][[1]] Out[5]=-A+B In[6]:=a[1,3] Out[6]=2 There are certain situations where you get a different result if you evaluate with the values or replace the values in the symbolic evaluation. (This example is not one of them.) Using = does the later. If you want to do the former, you should use := and have the right hand side use A and B explicitly or you could use a Block. In[7]:=a[b_,c_] := Block[{A=b, B=c}, LinearSolve[X,Y][[1]] ] In[8]:=a[1,3] Out[8]=2 -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html ==== >Normally I don't feel so stupid, but I'm trying to create an interactive >Mathematica notebook, and I'm stuck at square one. Specifically, how do I do something like create a button to add a number (or >perform other mathematical functions) and then display or otherwise >manipulate the result (eventually I want to be able to click a button that >increments/decrements an angle and animate the resulting transformation of a >vector, with an eye to finally simulating a simple robotic arm complete with >simple controls to manipulate the arm). I want to have a variable (or matrix or whatever) defined as a global >variable x, and then perform x = x+1 when a button is clicked. I've been >using and programming computers for almost 25 years and I can't follow >Wolfram's documentation. Is it just me, or is he always this obtuse when >explaining things? I mean, given the amazing power of the Mathematica >system, a sample list of buttons in a notebook that you could select and >examine how they were implemented, would have been nice. I can't find such a >list, and this seems to be par for the course for the rest of the >documentation as well. Button programming can be very confusing at first. It has a whole series of quirks that make it in many ways unique to Mathematica and programming in general. This causes a lot of head-scratching, but once you understand what's going on things get easier. The key is to create a button that uses the kernel (by default it only uses the front end). Here's a simple example to help you get started. In[1]:= x=1; In[2]:=ButtonBox[Increment x,Active->True, ButtonEvaluator->Automatic, ButtonFunction:>Print[x = ,++x] ]//DisplayForm Some random things to note: - ButtonEvaluator->Automatic. This says use the kernel to implement the ButtonFunction. - Buttons only create side-effects. They generate no output. What you see when you press the button is the result of 2 side effects. One from ++, which changes the value of x. The other from Print, which creates a cell. - Print is, in general, a poor side-effect to use in a button. It's difficult to control where the Print cell is placed. It is worth your while to learn how to use other front end side-effect functions (such as NotebookRead and NotebookWrite) when using buttons. Here are some further resources you might find helpful: http://support.wolfram.com/mathematica/interface/buttons/ http://library.wolfram.com/conferences/devconf99/hinton/Buttons19991022.nb http://library.wolfram.com/conferences/devconf2001/horton2/horton2.nb -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html ==== How do I change format used for tick mark labels in a 2D plot? I would like to use DigitBlock->3 option of NumberForm to format large numbers appearing as tick mark labels on a histogram. Alexander ==== As Daniel Lichtblau pointed out, the statement below about vertices is nonsense. Consider two overlapping rectangles arranged as a cross. You need to compute intersections and test them instead of vertices. Begin forwarded message: Begin forwarded message: Dear colleagues, any hints on how to implement a very fast routine in Mathematica for > testing if two rectangles have an intersection area? > Frank Brand > Here is one approach. Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then > Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as > you walk along the line though b and c in the direction from b to c. > ( If the result is zero, then a lies on the line.) The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the algorithm depends essentially on how fast this quantity can > be computed. Suppose we write a function LeftSide[a,{b,c}] that computes > the sign of the determinant. Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a > convex polygon traced counterclockwise. Then a lies within or on the > boundary of the polygon if and only if none of the numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1]. Now use the fact that if two convex polynomials overlap, then some > vertex of one of them must lie inside or on the boundary of the other. If an overlap of positive area is required, then the check is that only > +1 appears--not that -1 does not appear. For two rectangles ( or parallelograms) this approach requires the > evaluation of 16 determinants, so it may be a bit expensive. If the > points have rational coordinates, then (positive) denominators may be > cleared in the homogeneous coordinates and the computations can be done > in integer arithmetic, at the cost of at least three more > multiplications per determinant. Garry Helzer Department of Mathematics University of Maryland College Park, MD 20742 301-405-5176 gah@math.umd.edu ==== While playing arounf with patterns and substitutions, I came across the following behavior which I didn't expect: z := SomeHead[{{1, 2}, {3, 4}}] z /. {SomeHead[q_] -> Flatten[q]} While this _does_ yield the desired result {1,2,3,4}, Mathematica complains: Flatten::normal: Nonatomic expression expected at position 1 in Flatten[q]. ........as if it is trying to evaluate Flatten[q], with q not bound to {{1,2},{3,4}}. Could anybody explain why this happens? Sidney Cadot ==== > While playing arounf with patterns and substitutions, I came across the > following behavior which I didn't expect: z := SomeHead[{{1, 2}, {3, 4}}] > z /. {SomeHead[q_] -> Flatten[q]} While this _does_ yield the desired result {1,2,3,4}, Mathematica complains: Flatten::normal: Nonatomic expression expected at position 1 in > Flatten[q]. ........as if it is trying to evaluate Flatten[q], with q not bound to > {{1,2},{3,4}}. Could anybody explain why this happens? > Sidney Cadot during the Replaceall (/.) Mathematica first evaluate the rule SomeHead[q_] -> Flatten[q] . q is stilla symbol then and will be replaces when /. is used. You can avoid this Problem by using a delayed rule SomeHead[q_] :> Flatten[q] or using thr Rule Somehead->Flatten. ==== > ............... I came across the > following behavior which I didn't expect: z := SomeHead[{{1, 2}, {3, 4}}] > z /. {SomeHead[q_] -> Flatten[q]} While this _does_ yield the desired result {1,2,3,4}, Mathematica complains: Flatten::normal: Nonatomic expression expected at position 1 in > Flatten[q]. >............ > Could anybody explain why this happens? Sidney, The clue is that, before any replacing is done, z is evaluated to SomeHead[{{1, 2}, {3, 4}}]; SomeHead[q_] is evaluated to SomeHead[q_] Flatten[q] is evaluated to Flatten[q] and the message is generated saying essentially nothing to flatten. *Then* the replacement SomeHead[{{1, 2}, {3, 4}}] /. {SomeHead[q_] -> Flatten[q]} is performed. It would be better here to use RuleDelayed, :>, instead of Rule, ->, since Flatten[q] would not then be evaluated. z:=SomeHead[{{1,2},{3,4}}] z/.{SomeHead[q_]:>Flatten[q]} {1,2,3,4} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 ==== Never mind my question, I should have used a delayed rule there (:> instead of ->). Bit silly of me. ==== Suppose f is a function of n real variables, and returns a vector of n real variables. What is the correct syntax to find a root of f using FindRoot? For instance, the following works with n=7, but I would need to change the code if I changed the value of n: f[p_] := Table[fk[p, k], {k,n}]; pn = {p1,p2,p3,p4,p5,p6,p7}; f1 := f[pn] [[1]]; f2 := f[pn] [[2]]; f3 := f[pn] [[3]]; f4 := f[pn] [[4]]; f5 := f[pn] [[5]]; f6 := f[pn] [[6]]; f7 := f[pn] [[7]]; theRoot = FindRoot[{f1==0,f2==0,f3==0,f4==0,f5==0,f6==0,f7==0}, {p1, 1/n},{p2, 1/n},{p3, 1/n},{p4, 1/n},{p5, 1/n}, {p6, 1/n},{p7, 1/n}]; -- ==== >NDSolve seems to have difficulties with solving integral equation. >n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == >3*z*Integrate[[Sigma]norm[z, t]^n*z, {z, 0, 1}] - [Sigma]norm[z, >t]^n, [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == >0}*[Sigma]norm[z, t], {z, 0.01, 1}, {t, 0.01, 2}] >Mathematica returns a message NDSolve::deql: The first argument must have both an equation and an > initial condition. A general solution to a differential equation includes a constant of integration. It isn't possible to arrive a numerical solution without providing sufficient information to determine this constant. Specifying the initial condition provides this information. Look at the examples using the help browser to see what NDSolve needs. ==== >I'm trying to figure out the correct syntax to do the following. I have >some function with three arguments, and I want to syntactically describe >the >single-argument function that holds two of those arguments constant (i.e. >without creating that single-argument function). More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s}, > c = Floor[state/base]; s = Mod[state,base]; > multiplier*s + c > ] where I have a generalize 'machine', defined by the radix and multiplier, >which converts one state into another state. So I'd like to be able to >do >something like this: NestList[Machine[10,7,#], 3, 22] to get the series of states that the radix-10 multiplier-7 machine runs >through (starting with state 3). However, this syntax doesn't seem to >do >what I want. I hope that description makes sense. It seems like there must be a syntax >to describe the function Machine[10,7,#]. > I assume that you want base rather than radix in the definition (or vice versa). Machine[base_, multiplier_, state_]:= Module[{c, s}, c=Floor[state/base]; s=Mod[state, base]; multiplier*s+c]; NestList[Function[Machine[10,7,#]],3,22] {3, 21, 9, 63, 27, 51, 12, 15, 36, 45, 39, 66, 48, 60, 6, 42, 18, 57, 54, 33, 24, 30, 3} The abbreviation for Function[body] is body& %==NestList[Machine[10, 7, #]&, 3, 22] True Bob Hanlon Chantilly, VA USA ==== >While playing arounf with patterns and substitutions, I came across the >following behavior which I didn't expect: z := SomeHead[{{1, 2}, {3, 4}}] >z /. {SomeHead[q_] -> Flatten[q]} While this _does_ yield the desired result {1,2,3,4}, Mathematica complains: Flatten::normal: Nonatomic expression expected at position 1 in >Flatten[q]. ........as if it is trying to evaluate Flatten[q], with q not bound to >{{1,2},{3,4}}. Could anybody explain why this happens? z:=SomeHead[{{1,2},{3,4}}] The error is associated with defining the Rule not executing it. Note that you get the error with {SomeHead[q_]->Flatten[q]}; Use RuleDelayed z/.{SomeHead[q_]:>Flatten[q]} {1, 2, 3, 4} Bob Hanlon Chantilly, VA USA ==== Can anyone help me with this problem. If I have an n-element list, (say where each element is itself a list), such as {{a,b}, {a,b}, {a,b}} is there a way to strip off the outermost nesting of the list to obtain just a sequence of of these n elements, that is {a,b},{a,b},{a,b} so that I can use this for input for some function. I would like to do something like Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N dynamically. The problem, of course, is that the output of the Table command is one big list and Outer is expecting a sequence of N separate lists after SomeFunction. ==== Bob, Apply[Sequence,{{a,b},{c,d}}] Sequence[{a,b},{c,d}] Outer[F,Apply[Sequence,Table[{a,b},{3}]]] {{{F[a,a,a],F[a,a,b]},{F[a,b,a],F[a,b,b]}},{{F[b,a,a],F[b,a,b]}, {F [b,b,a],F[b,b,b]}}} --- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Can anyone help me with this problem. If I have an n-element list, (say where each element is itself a > list), such as {{a,b}, {a,b}, {a,b}} > is there a way to strip off the outermost nesting of the list to > obtain just a sequence of of these n elements, that is > {a,b},{a,b},{a,b} so that I can use this for input for some function. I would like to do something like > Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N > dynamically. > The problem, of course, is that the output of the Table command is one > big list > and Outer is expecting a sequence of N separate lists after > SomeFunction. ==== Can anyone help me with this problem. If I have an n-element list, (say where each element is itself a > list), such as {{a,b}, {a,b}, {a,b}} > is there a way to strip off the outermost nesting of the list to > obtain just a sequence of of these n elements, that is > {a,b},{a,b},{a,b} so that I can use this for input for some function. I would like to do something like > Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N > dynamically. > The problem, of course, is that the output of the Table command is one > big list > and Outer is expecting a sequence of N separate lists after > SomeFunction. > Sequence@@{{a,b}, {a,b}, {a,b}} resp. Apply[Sequence, {{a,b}, {a,b}, {a,b}}] will do it. CU, -- / Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== some function with three arguments, and I want to syntactically describe the single-argument function that holds two of those arguments constant (i.e. without creating that single-argument function). More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s}, c = Floor[state/base]; s = Mod[state,base]; multiplier*s + c ] where I have a generalize 'machine', defined by the radix and multiplier, which converts one state into another state. So I'd like to be able to do something like this: NestList[Machine[10,7,#], 3, 22] to get the series of states that the radix-10 multiplier-7 machine runs through (starting with state 3). However, this syntax doesn't seem to do what I want. I hope that description makes sense. It seems like there must be a syntax to describe the function Machine[10,7,#]. Anyone have any ideas? Bob H ==== Sidney, With a direct rule Mathematica tries to Flatten the symbol q immediately. You want a delayed rule to avoid the error message. z /. SomeHead[q_] :> Flatten[q] Park djmp@earthlink.net http://home.earthlink.net/~djmp/ {{1,2},{3,4}}. Could anybody explain why this happens? Sidney Cadot ==== Lucas, I hope that your question will provoke a number of replies because I think it is an interesting topic. First, it would be nice if Mathematica had a ShowPrecedence statement to quickly retrieve a precedence number for any command. It is a bit time consuming to search through the table in Section A.2.7. Next, it would be nice if the user could set the precedence for operators that don't have built-in definitions. Since it appears that you can't do that, is it possible to switch the meanings of Plus and CirclePlus in your theory? Are you depending on the numerical behavior of Plus? Go with the precedence that Mathematica gives you. Or you could use something like VerticalBar or RightTee which have lower precedence than Plus, but perhaps don't have the look that you want. You could try to use the Notation package for your CirclePlus sum. But I always find the Notation package difficult to use and like to use StandardForm as much as possible. One possibility is... !((([Sum]+(i = 1)%5 x[i])) /. Plus -> CirclePlus) These are weak answers to your question, but maybe they will bring in more discussion. Park djmp@earthlink.net http://home.earthlink.net/~djmp/ desired effect. Also, I would like to introduce a notation like N [BigCirclePlus] x[[i]] --> x[[1]] [CirclePlus] x[[2]] [CirclePlus] .... i=0 analagous to summation, but mathematica does not appear to offer the CirclePlus in a large format. to relate this to the case above, x[1] = (a + b) and x[2] = (c + d), so each indexed element is a subexpression. Finally, I would like to be able to set up the CirclePlus operator such that the following algebraic relations hold: Sum BigCirclePlus E = BigCirclePlus Sum E i j ij j i ij d d -- BigCirclePlus E = BigCirclePlus -- E dx j j j dx j -Lucas Scharenbroich -MLS Group / JPL ==== You are quite right, Mathematica does evaluate Flatten[q] before substituting {{1, 2}, {3, 4}}. It then issues the error message and returns Flatten[q]. Only now {{1, 2}, {3, 4}} is substituted for q, Flatten[{{1, 2}, {3, 4}}] is evaluated and you get the right answer. To avoid all this just use RuleDelayed instead of Rule: In[1]:= z := SomeHead[{{1, 2}, {3, 4}}]; In[2]:= z /. {SomeHead[q_] :> Flatten[q]} Out[2]= {1,2,3,4} Andrzej Kozlowski Toyama International University JAPAN While playing arounf with patterns and substitutions, I came across the > following behavior which I didn't expect: z := SomeHead[{{1, 2}, {3, 4}}] > z /. {SomeHead[q_] -> Flatten[q]} While this _does_ yield the desired result {1,2,3,4}, Mathematica > complains: Flatten::normal: Nonatomic expression expected at position 1 in > Flatten[q]. ........as if it is trying to evaluate Flatten[q], with q not bound to > {{1,2},{3,4}}. Could anybody explain why this happens? > Sidney Cadot ==== > [...] Y = {A,B,C,D}; [...] > In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]] > In[266]:= a[1,3] > Out[266]= -A+B The output above is not what I want. I want 2. [...] You are mixing the (global (*)) symbols A and B with the (local (*)) patterns A_ and B_. If you want to replace the (global) solution with local values you should write In[4]:= a[AA_, BB_] := LinearSolve[X, Y][[1]] /. {A -> AA, B -> BB}; a[1, 3] Out[5]= 2 ________________ (*) as far we can say that in Mathematica -- Rainer Gruber ==== NestList[Machine[10,7,#], 3, 22] You almost have it: NestList[Machine[10,7,#]&, 3, 22] More elegantly, you can defined Machine this way: Machine[radix_,multiplier_][state_] := ... Then you can write NestList[Machine[10,7], 3, 22] Tom Burton ==== > z := SomeHead[{{1, 2}, {3, 4}}] > z /. {SomeHead[q_] -> Flatten[q]} While this _does_ yield the desired result {1,2,3,4}, Mathematica complains: Flatten::normal: Nonatomic expression expected at position 1 in > Flatten[q]. The -> operator is prompt: It permits evaluation of the RHS Flatten[q] immediately, before it is used in the substitution. Evidently, q was undefined before you tried this, so Flatten[q]'s evaluation yielded itself. Later, in the process of substitution, with q set as you intended, Flatten evaluated again, this time yielding the desired result. Try it again after setting q to something. Then you get not only the complaint but also the wrong answer. To avoid these issues, use the delayed operator :> instead of the prompt operator ->. A rule of thumb is: Use delayed operators := and :> when the LHS (SomeHead[q_] in your case) contains a blank (_). Tom Burton ==== Mark: In: ?K Out: K is a default generic name for a summation index in a symbolic sum. Turns out that there are seven single-letter symbols. In: ClearAll[Global`*]; Select[Names[*], (StringLength[#] == 1) &] Out: {C, D, E, I, K, N, O} K is a little weird, because it's not Protected. In: Attributes[{C, D, E, I, K, N, O}] Out: {{NHoldAll, Protected}, {Protected, ReadProtected}, {Constant, Protected, ReadProtected}, {Locked, Protected, ReadProtected}, {}, {Protected}, {Protected, ReadProtected}} ---- Selwyn Hollis > I just learned that K is a System` Symbol: > Information[K] > Context[K] > I learned this due to an error message: > Block[{K = 1}, Sum[j, {j, i}]] > The same message can be generated by the following: > K := 1 > Sum[j, {j, i}] > The message can be eliminated by Removing K: > Remove[K] > Block[{K = 1}, Sum[j, {j, i}]] > K := 1 > Sum[j, {j, i}] > Surely, this is not intentional. > --Mark. > ==== Dear Mathgroup I have convert pde to ode like this du_i/dt = 1-4 u_i + .02 (u_i-1 ö 2 u_i + u i+1)/(delta (x))^3 + (u_i)^3 v_i dv_i /dt = 3 u_i + .02 (v_i-1 ö 2 v_i + u i+1)/(delta (x))^3 - (u_I)^3 v_i delta(x)=(i)/(N+1) x_i= (i)/(N+1) Boundary condition u_0 (t) = 1 = u_N+1(t) v_0(t) = 3 = v_N+1(t), Initial conditio u_i(0) = 1+sin (2 pi x_i ) v_i = 3 For i = 1,·., N Time Interval =[t_o, t_end] = [0,10] Could i get code in Mathematica (by using Euler of 4 Runge - Kutta..)to solve this ordinary differential equation. I am very happy if you give me help Khaled _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx ==== > Dear Mathgroup > I have convert pde to ode like this du_i/dt = 1-4 u_i + .02 (u_i-1 ? 2 u_i + u i+1)/(delta (x))^3 + (u_i)^3 > v_i dv_i /dt = 3 u_i + .02 (v_i-1 ? 2 v_i + u i+1)/(delta (x))^3 - (u_I)^3 > v_i delta(x)=(i)/(N+1) x_i= (i)/(N+1) Boundary condition > u_0 (t) = 1 = u_N+1(t) > v_0(t) = 3 = v_N+1(t), Initial conditio > u_i(0) = 1+sin (2 pi x_i ) > v_i = 3 > For i = 1,?., N > Time Interval =[t_o, t_end] = [0,10] Since this is 1+1 dimensional initial value problem, Mathematica can do the discretization for you automatically. Just use NDSolve[{ D[u[t, x], t] == 1 - 4 u[t, x] + 0.02 D[u[t, x], x, x] + u[t, x]^3 v[t, x], D[v[t, x], t] == 3u[t, x] + 0.02 D[v[t, x], x, x] + u[t, x] ^3v[t, x], u[t, 0] == u[t, 1] == 1, u[0, x] == 1 + Sin[2 Pi x], v[t, 0] == v[t, 1] == 3, v[0, x] == 3}, {u, v}, {t, 0, 10}, {x, 0, 1}] Mathematica by default uses fourth order differences instead of the second order you specified above. If you really want second order spatial differences with the exact spacing you defined, you can use NDSolve[{D[u[t, x], t] == 1 - 4 u[t, x] + 0.02 D[u[t, x], x, x] + u[t, x]^3 v[t, x], D[v[t, x], t] == 3u[t, x] + 0.02 D[v[t, x], x, x] + u[t, x] ^3v[t, x], u[t, 0] == u[t, 1] == 1, u[0, x] == 1 + Sin[2 Pi x], v[t, 0] == v[t, 1] == 3, v[0, x] == 3}, {u, v}, {t, 0, 10}, {x, 0, 1}, StartingStepSize -> 1./206, MaxSteps -> {1000, 300}, DifferenceOrder -> 2] Interestingly enough, either way you do it, Mathematica is only able to carry out the solution out to about t == 0.035 or so. This appears to be because the nonlinearity is causing the solution to form a nonsingularity which appears as a cusp with rapidly rising height. is because of the (delta (x))^3 in .02 (u_i-1 ? 2 u_i + u i+1)/(delta (x))^3 Any finite difference formula for the second derivative on a uniform grid will involve (delta (x))^2 -- i.e. squared, not cubed. At a fixed grid space, the extra power will have the effect of making the diffusion coefficient larger by a factor of n (which for your range of interest effectively removes to formation of the discontinuity). Presumably the (delta (x))^3 was a typo as was the u_i+1 instead of v_i+1 in .02 (v_i-1 ? 2 v_i + u i+1) However, if you really wanted the cubed power, here is how you could manually do the discretization with Mathematica: n = 205; X = N[Range[1, n]/(n + 1)]; U[t_] = Map[u[#][t] &, Range[1, n]]; V[t_] = Map[v[#][t] &, Range[1, n]]; eqns = Join[ Thread[D[U[t], t] == 1 - 4 U[t] + 0.02 ListCorrelate[N[{1, -2, 1} n^3], U[t], {2, 2}, 1] + U[t]^3 V[t]], Thread[ D[V[t], t] == 3 U[t] + 0.02 ListCorrelate[N[{1, -2, 1} n^3], V[t], {2, 2}, 3] + U[t]^3 V[t]], Thread[U[0] == 1 + Sin[X]], Thread[V[0] == 3 + 0. X]]; NDSolve[eqns, Join[U[t], V[t]], {t, 0, 10}] > Could i get code in Mathematica (by using Euler of 4 Runge - Kutta..)to > solve this ordinary differential equation. I do not recommend solving this with either an Euler method or a RungeKutta method for the reason that the potential formation of discontinuities could make the ODEs stiff. The default method Mathematica uses automatically switches to methods appropriate for stiff ODEs when needed. If you want to use a RungeKutta method, you can use NDSolve[eqns, Join[U[t], V[t]], {t, 0, 10}, Method->RungeKutta] This uses the Runge-Kutta-Fehlberg 4(5) method. > I am very happy if you give me help > Khaled > _________________________________________________________________ > MSN Photos is the easiest way to share and print your photos: > http://photos.msn.com/support/worldwide.aspx ==== I am a newbie to mathematica. I have a 14 functions which are the function of r,theta and phi. I want to do some mathematical operation over them. How can I do? Can it be possible to call them in Do or For loop with some index? Please suggest. Raj ==== Is there an easy (elegant?) way to generate the set of all k-tuples taking values from some set (list) S? I want the arguments of the function to be k (the length of the tuples) and the set S. That is, KTuples[3,{a,b}] should produce {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}. ==== Bob, KTuples[n_,lst_]:= Distribute[Table[{a,b},{n}],List] KTuples[3,{a,b}] {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Is there an easy (elegant?) way to generate the set of all k-tuples > taking values from some set (list) S? I want the arguments of the > function to be k (the length of the tuples) and the set S. That is, > KTuples[3,{a,b}] should produce > {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}. > ==== Here's my contestant: < Is there an easy (elegant?) way to generate the set of all k-tuples > taking values from some set (list) S? I want the arguments of the > function to be k (the length of the tuples) and the set S. That is, > KTuples[3,{a,b}] should produce > {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}. > ==== > Is there an easy (elegant?) way to generate the set of all k-tuples > taking values from some set (list) S? I want the arguments of the > function to be k (the length of the tuples) and the set S. That is, > KTuples[3,{a,b}] should produce > {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}. Here's a first implementation: ktuples[k_, set_List] := Map[ set[[#]] &, Flatten[ Array[ List, Table[ Length[set], {k}]], k - 1]] In[31]:= ktuples[3,{a,b}] Out[31]= {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}} -Nevin ==== Does anyone know if there are any publications that describe the integration of above? In particular I am working with a 4 gaussian process with joint pdf p(x1,y1,x2,y2) transformed to-> p(r1,r2,theta1,theta2), the processes have non-zero mean and I would like to integrate the joint pdf twice (over r1 and r2) and obtain an expression for the pdf of the phase angles between p(theta1,theta2). I could assume that the means are the same (to make life easier). Has anyone come accross this - it doesn't seem that unusual to me. I am asking because the integrals are becoming 'interesting'. thankyou for any tips. ==== Start Excel and go to Tools -> Macro -> Security..., then on the Security Level tab click on Medium and then click OK. ----- Original Message ----- > My original version of MathLink for Excel (MLX.xla) was for Excel 97, and > It worked fine. Then I upgraded the package to Excel 2000 by unloading the > macro from the Wolfram site. It continued working perfectly on my old > environment (Windows 98 + Mathematica 4.1). > But I recently upgraded to Mathematica 4.2 under Windows 2000; and when > trying to load the macro (MLX.xla) for Excel2000, I got (in Excel 2000) > the > following message: This workbook contains a type of macro (Microsoft > Excel > version 4.0 macro) that cannot be disable nor signed. Therefore, this > workbook cannot be opened under high security level. > Does any one have any experience on this? > Emilio Martin-Serrano > > ==== Download the newest patch from wolfram research - this should theoretically help. > Group, My original version of MathLink for Excel (MLX.xla) was for Excel 97, and > It worked fine. Then I upgraded the package to Excel 2000 by unloading the > macro from the Wolfram site. It continued working perfectly on my old > environment (Windows 98 + Mathematica 4.1). But I recently upgraded to Mathematica 4.2 under Windows 2000; and when > trying to load the macro (MLX.xla) for Excel2000, I got (in Excel 2000) the > following message: This workbook contains a type of macro (Microsoft Excel > version 4.0 macro) that cannot be disable nor signed. Therefore, this > workbook cannot be opened under high security level. Does any one have any experience on this? > Emilio Martin-Serrano > ==== >I'm sorry for that my question is not clear,I have correct below. > I have a very interesting math problem:If I have a scales,and I >> have 40 things that their mass range from 1~40 which each is a nature >> number,and now I can only make 4 counterweights to measure out each >> mass of those things.Question:What mass should the counterweights >> be??? >> The answer is that 1,3,9,27 and I wnat to use mathematica to solve >> this problem. >> In fact,I think that this physical problem has various >> answer,ex.2,4,10,28 >> this way also work,because if I have a thing which weight 3 , and I >> can measure out by comparing 2<3<4 . But,If I want to solve this math >> problem: >> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature numbers. >> and {k1,k2,k3,k4}={1,0,-1} >> How to solve it ?? >> mathematica solving method. appreciate any idea sharing >> sincerely >> bryan > Just use brute force. Needs[DiscreteMath`Combinatorica`]; var = {a, b, c, d}; n = Length[var]; s = Outer[Times, var, {-1, 0, 1} ]; f = Flatten[Outer[Plus, Sequence@@s]]; Since the length of f is just 3^n then the range of numbers to be covered should be {-(3^n-1)/2, (3^n-1)/2}. Consequently, the largest of the weights can not exceed (3^n-1)/2 - (1+2+...+(n-1)) or ((3^n-1) - n(n-1))/2 34 Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ KSubsets[Range[((3^n-1) - n(n-1))/2], n], Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&]) {{a -> 1, b -> 3, c -> 9, d -> 27}} Bob Hanlon Chantilly, VA USA ==== Can we please get a response from WRI? i.e. regarding: In[1]:= Limit[ (Log[x]^Log[Log[x]])/ x , x->Infinity] Out[2]:= Infinity It should be 0 Jonathan Rockmann mtheory@msn.com ==== I'm finding that the ImageSize option in Export has no effect when exporting Cell or Notebook objects. For instance, the following two commands produce precisely the same graphic: Export[image1.jpg, Cell[Some cell contents, Text, FontSize -> 100]] Export[image2.jpg, Cell[Some cell contents, Text, FontSize -> 100], ImageSize -> {576, 288}] Has anyone encountered this problem before? (This is with Mathematica 4.1.5 and Mac OS X.) ---- Selwyn Hollis slhollis@mac.com ==== Does anyone know how to get the JavaPlot window (or any windows of this type) which can be seen at http://www.wolfram.com/products/mathematica/newin42/java.html that WRI advertises comes with 4.2? Jonathan mtheory@msn.com ==== How can I get mathematica to display the inverse of functions like: f(x) = x^2 - 7*x + 10 or f(x) = cos(3*x + 1/2*pi) or f(x) = (x - 3) / (x + 2) I'm having trouble getting the syntax right. ==== G'day, Looks like you forgot to define base in your Machine function and when using pure functions, don't forget the ampersand. Thus NestList[Machine[10,7,#]&, 3, 22] returns {3, 8, 4, 2, 1, 7, 10, 5, 9, 11, 12, 6, 3, 8, 4, 2, 1, 7, 10, 5, 9, 11, 12} with base = 2. Yas > Howdy, I'm trying to figure out the correct syntax to do the following. I have > some function with three arguments, and I want to syntactically describe the > single-argument function that holds two of those arguments constant (i.e. > without creating that single-argument function). More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s}, > c = Floor[state/base]; s = Mod[state,base]; > multiplier*s + c > ] where I have a generalize 'machine', defined by the radix and multiplier, > which converts one state into another state. So I'd like to be able to do > something like this: NestList[Machine[10,7,#], 3, 22] to get the series of states that the radix-10 multiplier-7 machine runs > through (starting with state 3). However, this syntax doesn't seem to do > what I want. I hope that description makes sense. It seems like there must be a syntax > to describe the function Machine[10,7,#]. Anyone have any ideas? Bob H > ==== >I'm sorry for that my question is not clear,I have correct below. >> ajvp7h$ibk$1@smc.vnet.net>... > I have a very interesting math problem:If I have a scales,and I > have 40 things that their mass range from 1~40 which each is a nature > number,and now I can only make 4 counterweights to measure out each > mass of those things.Question:What mass should the counterweights > be??? > The answer is that 1,3,9,27 and I wnat to use mathematica to solve > this problem. > In fact,I think that this physical problem has various > answer,ex.2,4,10,28 > this way also work,because if I have a thing which weight 3 , and I > can measure out by comparing 2<3<4 . But,If I want to solve this math > problem: > {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature >numbers. > and {k1,k2,k3,k4}={1,0,-1} > How to solve it ?? > mathematica solving method. appreciate any idea sharing > sincerely > bryan > >Just use brute force. Needs[DiscreteMath`Combinatorica`]; >var = {a, b, c, d}; n = Length[var]; >s = Outer[Times, var, {-1, 0, 1} ]; >f = Flatten[Outer[Plus, Sequence@@s]]; >Since the length of f is just 3^n then the range of numbers >to be covered should be {-(3^n-1)/2, (3^n-1)/2}. >Consequently, the largest of the weights can not exceed >(3^n-1)/2 - (1+2+...+(n-1)) or ((3^n-1) - n(n-1))/2 >34 >Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ KSubsets[Range[((3^n-1) - n(n-1))/2], n], Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&]) >{{a -> 1, b -> 3, c -> 9, d -> 27}} > A modification to my earlier response. Since you are try to cover all of the values up to (3^n-1)/2 then you can speed up the brute force method by requiring that a+b+c+d == (3^n-1)/2 Needs[DiscreteMath`Combinatorica`]; var = {a,b,c,d}; n = Length[var]; m = (3^n-1)/2; s = Outer[Times, var, {-1,0,1} ]; f = Flatten[Outer[Plus, Sequence@@s]]; k= Select[KSubsets[Range[m - n(n-1)/2], n], (Plus @@ #) == m&]; Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ k, Sort[#[[2]]] == Range[-m,m]&]) {{a -> 1, b -> 3, c -> 9, d -> 27}} Bob Hanlon Chantilly, VA USA ==== Some functions with vector arguments work as expected and some give errors. I would appreciate if someone can clarify why. First an example of a function definition that works fine : f[u_,v_] := u.v Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 + y1 y2. Now an example that does not work : g[u_,v_] := u-v Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, y1-y2} but instead one gets error messages. Why ? And how do I fix g (i.e write a function that outputs the difference of 2 vectors). ==== I do not know why you are getting a message, using your own code I get the result you expect. > Some functions with vector arguments work as expected and some give > errors. I would appreciate if someone can clarify why. First an example of a function definition that works fine : > f[u_,v_] := u.v > Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 + > y1 y2. Now an example that does not work : > g[u_,v_] := u-v > Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, > y1-y2} but instead one gets error messages. Why ? And how do I fix g (i.e write a function that outputs the > difference of 2 vectors). ==== > Now an example that does not work : > g[u_,v_] := u-v > Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, > y1-y2} but instead one gets error messages Works fine for me. Please check that you have no existing definitions for the symbols used. Clear[g,x1,x2,y1,y2]; g[u_,v_]:=u-v g[{x1,y1},{x2,y2}] {x1-x2,y1-y2} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Some functions with vector arguments work as expected and some give > errors. I would appreciate if someone can clarify why. First an example of a function definition that works fine : > f[u_,v_] := u.v > Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 + > y1 y2. Now an example that does not work : > g[u_,v_] := u-v > Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, > y1-y2} but instead one gets error messages. Why ? And how do I fix g (i.e write a function that outputs the > difference of 2 vectors). ==== Some functions with vector arguments work as expected and some give > errors. I would appreciate if someone can clarify why. First an example of a function definition that works fine : > f[u_,v_] := u.v > Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 + > y1 y2. Now an example that does not work : > g[u_,v_] := u-v > Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, > y1-y2} but instead one gets error messages. Why ? And how do I fix g (i.e write a function that outputs the > difference of 2 vectors). > in fact this call works fine on my Mathematicas (3.0 up to 4.1). Did You really use the minus character? Maybe some erroneous code was assigned to g before. Restart Mathematica or use Remove[g] to really start up from the beginning. Sincerly -- / Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== Garry, Here's a solution using your LeftSide concept; it works perfectly but takes twice as much time as my solution. Both solutions look at every vertex of both rectangles, but mine uses two sides from each and yours requires looking at all four sides of each rectangle. I'd think yours should be a trifle faster than this, though. There may be efficiencies I'm missing (in both solutions). ClearAll[cis, rect, pickRect, extent, cannotIntersect, intersects, daveRect] cis[t_] := {Cos@t, Sin@t} rect[{pt : {_, _}, angle_, {len1_, len2_}}] := Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2 cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}] daveRect := {{Random[], Random[]}, Random[] + Pi/2, {Random[], Random[]}} pickRect := rect@daveRect extent[r1_, r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] - r1[[{2, 3}]]).Transpose@r2) cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 < min1 || min2 > max1 intersects[r1_, r2_] := Catch[ If[cannotIntersect[#], Throw[False]] & /@ Flatten[Transpose[Outer[extent, {r1}, {r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}], 1]; Throw[True]] ClearAll[leftSide,leftIntersects,sides] sides[a_List]:=Partition[Join[a,{First@a}],2,1] leftSide[{a_,b_},{{c_,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c f>0 leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&! Or@@(And@@#&/@leftSide[b,sides@a]) davePairs={daveRect,daveRect}&/@Range[10000]; rectanglePairs=Map[Reverse@rect[#]&,davePairs,{2}]; Timing[right=intersects[Sequence@@#]&/@rectanglePairs;] Timing[test=leftIntersects[Sequence@@#]&/@rectanglePairs;] right[Equal]test {3.187999999999999*Second, Null} {6.765000000000001*Second, Null} True -----Original Message----- intersection Begin forwarded message: Dear colleagues, any hints on how to implement a very fast routine in Mathematica for > testing if two rectangles have an intersection area? > Frank Brand > Here is one approach. Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then > Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as > you walk along the line though b and c in the direction from b to c. > ( If the result is zero, then a lies on the line.) The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the algorithm depends essentially on how fast this quantity can > be computed. Suppose we write a function LeftSide[a,{b,c}] that computes > the sign of the determinant. Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a > convex polygon traced counterclockwise. Then a lies within or on the > boundary of the polygon if and only if none of the numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1]. Now use the fact that if two convex polynomials overlap, then some > vertex of one of them must lie inside or on the boundary of the other. If an overlap of positive area is required, then the check is that only > +1 appears--not that -1 does not appear. For two rectangles ( or parallelograms) this approach requires the > evaluation of 16 determinants, so it may be a bit expensive. If the > points have rational coordinates, then (positive) denominators may be > cleared in the homogeneous coordinates and the computations can be done > in integer arithmetic, at the cost of at least three more > multiplications per determinant. ==== I would like to have a list of all the directives that can be used for command in the Windows Start Menu). I am especially interested in a directive with which you can appoint a file which has to be evaluated by the kernel after it has been launched. I imagine that such a directive looks like -f filename, but I can not find a list of the correct directives. The Mathematica version I have is 4.1 on a Windows NT system. Rene Klaver ==== > 1) Get data from excel into a coordinate > list {x,y,z} > e.g. Node 1, {x1,y1,z1} > Node 2, {x2,y2,z2} > etc... Why not just use data = ReadList[filename, Table[Number, {4}]]; Alternatively, data = ReadList[filename, Number, RecordLists->True]; data = Partition[data, 4]; cord = {#[[1]], #[[2]], #[[3]]}& /@ data; > 2) Convert from Rectangular to > Cylindrical (maybe) Coordinate tranforms live in Calculus`VectorAnalysis`. It's straightforward to write a function that uses > 3) Plot3D the data This will be tricky -- ListSurfacePlot3D plots f[x, y]. ListContourPlot3D which plots f[x, y, z] can be quite slow. > > 4) Generate a harmonic bessel function for that > plot3D/graph 5) Find the equation(s) that spits out > these harmonic > bessel functions (which I think might be in the general form > of Hankel > Function solutions to the Helmholtz equation which shows > cylinder harmonics > of order v) Maybe I misunderstand ... isn't this the same as fitting a bessel function to your data? For this, you can use Statistics`NonlinearFit`. > I can figure out step 5 if I can get steps 1 through 4 > figured out. If > anyone can write a recipe for me to follow that would be > great, or even some > tips and clues...Anything!!! Dave. ==== You've gotten some very helpful responses so I'm just going to add a couple of comments. The following is an example of yet another type of button that you can use as a model. Copy and paste the following code into a notebook. When you evaluate it, it will create a button within the same notebook which when pressed evaluates the entire notebook. Sort of like selecting from the menu is something in the notebook already to evaluate. So input 1+2 (and don't hit enter) somewhere in the notebook so that you can see what the effect of the button is. DisplayForm[Button[Evaluate*Notebook,ButtonFunction:>FrontEndExecute [FrontEndToken[EvaluateNotebook]],ButtonEvaluator->None,Active->True]] It has the nice feature that it doesn't get stuck in a loop creating the button over and over again. However, with some enthusiasm you can make this happen too. Personally, I am fascinated by the Java integration in version 4.2. But I wouldn't recommend it to anyone who is just starting to program in Mathematica. Further, there is hardly enough material contained in the Help Browser to make sense of much of it. It is always a good idea to have several basic constructs of efficient, useful programs that can serve as models when programming. If you look at some of the MathGroup archived threads you will find similar complaints that the Mathematica documentation is confusing. Jonathan Rockmann mtheory@msn.com ----- Original Message ----- I want to have a variable (or matrix or whatever) defined as a global variable x, and then perform x = x+1 when a button is clicked. I've bee n using and programming computers for almost 25 years and I can't follow Wolfram's documentation. Is it just me, or is he always this obtuse when explaining things? I mean, given the amazing power of the Mathematica system, a sample list of buttons in a notebook that you could select and examine how they were implemented, would have been nice. I can't find such a list, and this seems to be par for the course for the rest of the documentation as well. ==== This was REALLY interesting. Here's a solution that looks only at the 7,560 relevant combinations. It first chooses three numerators. Then it chooses two denominators for the first fraction. Then two denominators for the second fraction. The last fraction is determined at that point. << DiscreteMath`Combinatorica` ClearAll[f, g, h, j] r = Range[1, 9]; f = KSubsets[#1, #2] &; g[r_List, n_Integer, {}] := f[r, n] g[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@ f[Complement[r, e], n] g[r_List, n_Integer, e : {__?VectorQ}] := Flatten[g[r, n, #] & /@ e, 1] h[r_List, e : {__?VectorQ}] := Join[#, Complement[r, #]] & /@ e j[{a_, b_, c_, d_, e_, f_, g_, h_, i_}] := a/(d e) + b/(f g) + c/(h i) Timing[Select[h[r, Fold[g[r, #2, #1] &, {}, {3, 2, 2}]], j@# == 1 &]] {0.532 Second, {{1, 5, 7, 3, 6, 8, 9, 2, 4}}} Hence the only solution is 1/(3*6)+5/(8*9)+7/(2*4) -----Original Message----- University Professor of Philanthropy and the Law Director, National Center on Philanthropy and the Law New York University School of Law Room 206A 110 West 3rd Street New York, N.Y. 10012-1074 -----Original Message----- byran ________________________________________________________________________ service. For more information on a proactive anti-virus service working around the clock, around the globe, visit http://www.messagelabs.com ________________________________________________________________________ ==== Here's a solution using your LeftSide concept; it works perfectly but takes twice as much time as my solution. Both solutions look at every vertex of both rectangles, but mine uses two sides from each and yours requires looking at all four sides of each rectangle. I'd think yours should be a trifle faster than this, though. There may be efficiencies I'm missing (in both solutions). ClearAll[cis, rect, pickRect, extent, cannotIntersect, intersects, daveRect] cis[t_] := {Cos@t, Sin@t} rect[{pt : {_, _}, angle_, {len1_, len2_}}] := Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2 cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}] daveRect := {{Random[], Random[]}, Random[] + Pi/2, {Random[], Random[]}} pickRect := rect@daveRect extent[r1_, r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] - r1[[{2, 3}]]).Transpose@r2) cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 < min1 || min2 > max1 intersects[r1_, r2_] := Catch[ If[cannotIntersect[#], Throw[False]] & /@ Flatten[Transpose[Outer[extent, {r1}, {r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}], 1]; Throw[True]] ClearAll[leftSide,leftIntersects,sides] sides[a_List]:=Partition[Join[a,{First@a}],2,1] leftSide[{a_,b_},{{c_,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c f>0 leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&! Or@@(And@@#&/@leftSide[b,sides@a]) davePairs={daveRect,daveRect}&/@Range[10000]; rectanglePairs=Map[Reverse@rect[#]&,davePairs,{2}]; Timing[right=intersects[Sequence@@#]&/@rectanglePairs;] Timing[test=leftIntersects[Sequence@@#]&/@rectanglePairs;] right[Equal]test {3.187999999999999*Second, Null} {6.765000000000001*Second, Null} True -----Original Message----- intersection Begin forwarded message: Dear colleagues, any hints on how to implement a very fast routine in Mathematica for > testing if two rectangles have an intersection area? > Frank Brand > Here is one approach. Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then > Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as > you walk along the line though b and c in the direction from b to c. > ( If the result is zero, then a lies on the line.) The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the algorithm depends essentially on how fast this quantity can > be computed. Suppose we write a function LeftSide[a,{b,c}] that computes > the sign of the determinant. Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a > convex polygon traced counterclockwise. Then a lies within or on the > boundary of the polygon if and only if none of the numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1]. Now use the fact that if two convex polynomials overlap, then some > vertex of one of them must lie inside or on the boundary of the other. If an overlap of positive area is required, then the check is that only > +1 appears--not that -1 does not appear. For two rectangles ( or parallelograms) this approach requires the > evaluation of 16 determinants, so it may be a bit expensive. If the > points have rational coordinates, then (positive) denominators may be > cleared in the homogeneous coordinates and the computations can be done > in integer arithmetic, at the cost of at least three more ==== Garry, Also note your solution requires rectangle points to be in clockwise order (mine doesn't), but yours works for arbitrary convex polygons as written. -----Original Message----- ClearAll[cis, rect, pickRect, extent, cannotIntersect, intersects, daveRect] cis[t_] := {Cos@t, Sin@t} rect[{pt : {_, _}, angle_, {len1_, len2_}}] := Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2 cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}] daveRect := {{Random[], Random[]}, Random[] + Pi/2, {Random[], Random[]}} pickRect := rect@daveRect extent[r1_, r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] - r1[[{2, 3}]]).Transpose@r2) cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 < min1 || min2 > max1 intersects[r1_, r2_] := Catch[ If[cannotIntersect[#], Throw[False]] & /@ Flatten[Transpose[Outer[extent, {r1}, {r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}], 1]; Throw[True]] ClearAll[leftSide,leftIntersects,sides] sides[a_List]:=Partition[Join[a,{First@a}],2,1] leftSide[{a_,b_},{{c_,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c f>0 leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&! Or@@(And@@#&/@leftSide[b,sides@a]) davePairs={daveRect,daveRect}&/@Range[10000]; rectanglePairs=Map[Reverse@rect[#]&,davePairs,{2}]; Timing[right=intersects[Sequence@@#]&/@rectanglePairs;] Timing[test=leftIntersects[Sequence@@#]&/@rectanglePairs;] right[Equal]test {3.187999999999999*Second, Null} {6.765000000000001*Second, Null} True -----Original Message----- intersection Begin forwarded message: Dear colleagues, any hints on how to implement a very fast routine in Mathematica for > testing if two rectangles have an intersection area? > Frank Brand > Here is one approach. Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then > Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as > you walk along the line though b and c in the direction from b to c. > ( If the result is zero, then a lies on the line.) The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the algorithm depends essentially on how fast this quantity can > be computed. Suppose we write a function LeftSide[a,{b,c}] that computes > the sign of the determinant. Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a > convex polygon traced counterclockwise. Then a lies within or on the > boundary of the polygon if and only if none of the numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1]. Now use the fact that if two convex polynomials overlap, then some > vertex of one of them must lie inside or on the boundary of the other. If an overlap of positive area is required, then the check is that only > +1 appears--not that -1 does not appear. For two rectangles ( or parallelograms) this approach requires the > evaluation of 16 determinants, so it may be a bit expensive. If the > points have rational coordinates, then (positive) denominators may be > cleared in the homogeneous coordinates and the computations can be done > in integer arithmetic, at the cost of at least three more > multiplications per determinant. Garry Helzer Department of Mathematics University of Maryland College Park, MD 20742 301-405-5176 gah@math.umd.edu ==== Try this: Off[Remove::rmnsm] Remove[Global`p@, Global`p@@] n = 7; pn = Unique[p] & /@ Range[10] f[p_] = Array[fk[p, #] &, n] f[p] fEq[p_] = MapThread[Equal, {f[p], Array[0 &, n]}] -----Original Message----- f2 := f[pn] [[2]]; f3 := f[pn] [[3]]; f4 := f[pn] [[4]]; f5 := f[pn] [[5]]; f6 := f[pn] [[6]]; f7 := f[pn] [[7]]; theRoot = FindRoot[{f1==0,f2==0,f3==0,f4==0,f5==0,f6==0,f7==0}, {p1, 1/n},{p2, 1/n},{p3, 1/n},{p4, 1/n},{p5, 1/n}, {p6, 1/n},{p7, 1/n}]; -- John MacCormick Systems Research Center, HP Labs, 1501 Page Mill Road, ==== the problem, but I duplicated it just now, so I'm puzzled. I'm using Windows XP Home, and System`Private`$BuildNumber is 168634. 4.2 for Microsoft Windows (June 5, 2002) f[n_] := Log[n]^Log[Log[n]] Limit[f[n]/n, n -> Infinity] Infinity -----Original Message----- By the way, Mathematica gets the following limit wrong: f[n_] := Log[n]^Log[Log[n]] Limit[f[n]/n, n -> Infinity] Infinity That limit is zero. For the Sieve to be polynomial, we only need the sequence to be BOUNDED (for some power of n in the denominator). ==== Garry, No, you don't have to compute intersections, and yes, you can test vertices only. I haven't coded it yet, but the LeftSide idea seems like a good one. It is sufficient to test whether all vertices of one convex polygon are on the left (out) side of some side of the second polygon (both polygons in clockwise order). If that happens for any side of either polygon, the polygons don't intersect. In the cross example, some vertices are to the right for every side you try. -----Original Message----- intersection Begin forwarded message: Dear colleagues, any hints on how to implement a very fast routine in Mathematica for > testing if two rectangles have an intersection area? > Frank Brand > Here is one approach. Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then > Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as > you walk along the line though b and c in the direction from b to c. > ( If the result is zero, then a lies on the line.) The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the algorithm depends essentially on how fast this quantity can > be computed. Suppose we write a function LeftSide[a,{b,c}] that computes > the sign of the determinant. Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a > convex polygon traced counterclockwise. Then a lies within or on the > boundary of the polygon if and only if none of the numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1]. Now use the fact that if two convex polynomials overlap, then some > vertex of one of them must lie inside or on the boundary of the other. If an overlap of positive area is required, then the check is that only > +1 appears--not that -1 does not appear. For two rectangles ( or parallelograms) this approach requires the > evaluation of 16 determinants, so it may be a bit expensive. If the > points have rational coordinates, then (positive) denominators may be > cleared in the homogeneous coordinates and the computations can be done > in integer arithmetic, at the cost of at least three more > multiplications per determinant. ==== > I want to make an animation that simulate the Doppler Effect, just 2D > circles travel out one by one, and at the same time,the origin of the > wave also moves toward one direction. I have no idea to make the speed > of the wave origin and the speed of traveling wave independent.Is > sincerely bryan circles, but the second one includes two lines which approximate the shock waves, I believe. The arguments of the functions are vx & vy (velocities in x & y directions) and tstart, tend, tstep which determine how many circles to draw and the spacing of the circles. I just used the Do loop to make the pictures, & then you can select the cells & pick Animate. dopp[vx_,vy_,tstart_,tend_,tstep_]:=Show[Graphics[Table[{Hue[t/tend],Circle[ {vx*t,vy*t},tend-t]},{t,tstart,tend,tstep}]],AspectRatio->Automatic,Axes->Tru e,PlotLabel->Mach Sqrt(vx^2+vy^2)]; doppcone[vx_,vy_,tend_,tstep_]:=Show[Graphics[Table[{Hue[t/tend],Circle [{vx*t,vy*t},tend-t]},{t,0,tend,tstep}]],Graphics[Line[{{-tend*Sin[If[vx==0, 0,ArcTan[vy/vx]]],tend*Cos[If[vx==0,0,ArcTan[vy/vx]]]},{Sign[vx]*Cos[If[vx==0 ,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^2+vy^2] - tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sin[If[vx==0,0,ArcTan[vy/vx]]]*Sign[vx]* (tend-tstep)*sqrt[vx^2+vy^2]+tstep*Cos[If[vx==0,0,ArcTan[vy/vx]]]}}]],Graphic s[Line[{{tend*Sin[If[vx==0,0,ArcTan[vy/vx]]],-tend*Cos[If[vx==0,0,ArcTan[vy/v x]]]},{Sign[vx]*Cos[If[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^2+vy^2]+t step*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sign[vx]*Sin[If[vx==0,0,ArcTan[vy/vx]]]*( tend-tstep)*s rt[vx^2+vy^2]-tstep*Cos[If[vx==0,0,ArcTan[vy/vx]]]}}]],AspectRatio->Automati c,Axes->True]; Do[dopp[i,0,0,10,1],{i,0,1.4,0.2}]; Hope I did that without typos - I can't see how to post the notebook ==== It would take me a lot of time to understand how functions like SelectionEvaluate works... Cesar. > People encounter this all the time. It is because > SelectionEvaluate does > not do what you think. It does not work like > ToExpression, which causes > immediate kernel evaluation. Instead it works like > when you press > Shift-Enter, which selects a cell for evaluation > after all current > evaluations have finished. See > http://support.wolfram.com/mathematica/kernel/interface/selectionevaluate.ht ml > __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com ==== > How can I get mathematica to display the inverse of functions like: f(x) = x^2 - 7*x + 10 or f(x) = cos(3*x + 1/2*pi) or f(x) = (x - 3) / (x + 2) I'm having trouble getting the syntax right. > Solve[y==x^2-7*x+10, x] {{x -> (1/2)*(7 - Sqrt[9 + 4*y])}, {x -> (1/2)*(7 + Sqrt[9 + 4*y])}} x^2-7*x+10 /. % // ExpandAll {y, y} Solve[y == Cos[3*x+1/2*Pi], x] {{x -> -(ArcSin[y]/3)}} Cos[3*x+1/2*Pi] /. % {y} Solve[y == (x-3)/(x+2), x] {{x -> (-3 - 2*y)/(-1 + y)}} (x-3)/(x+2) /. % // Simplify {y} Bob Hanlon Chantilly, VA USA ==== > I am a newbie to mathematica. I have a 14 functions which are the > function of r,theta and phi. I want to do some mathematical operation > over them. How can I do? Can it be possible to call them in Do or For > loop with some index? > As a general rule avoid Do and For loops and just operate on Lists or Map (/@) onto lists. g /@ {f1[r,theta,phi], f2[r,theta,phi], f3[r,theta,phi]} {g[f1[r, theta, phi]], g[f2[r, theta, phi]], g[f3[r, theta, phi]]} This can be written more compactly as g /@ (#[r,theta,phi]& /@ {f1,f2,f3}) {g[f1[r, theta, phi]], g[f2[r, theta, phi]], g[f3[r, theta, phi]]} Bob Hanlon Chantilly, VA USA ==== > Is there an easy (elegant?) way to generate the set of all k-tuples > taking values from some set (list) S? I want the arguments of the > function to be k (the length of the tuples) and the set S. That is, > KTuples[3,{a,b}] should produce > {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}. > kTuples[n_Integer?Positive, s_List] := Flatten[Outer[List, Sequence@@Table[s,{n}]],n-1]; s = {a,b}; kTuples[3, {a,b}] {{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}} Length[kTuples[10, {a,b}]] 1024 Bob Hanlon Chantilly, VA USA ==== > If I have an n-element list, (say where each element is itself a > list), such as {{a,b}, {a,b}, {a,b}} > is there a way to strip off the outermost nesting of the list to > obtain just a sequence of of these n elements, that is > {a,b},{a,b},{a,b} so that I can use this for input for some function. I would like to do something like > Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N > dynamically. > The problem, of course, is that the output of the Table command is one > big list > and Outer is expecting a sequence of N separate lists after > SomeFunction. > Use Sequence kTuples[n_Integer?Positive,s_List]:= Flatten[Outer[List,Sequence@@Table[s,{n}]],n-1]; s = {a,b,c,d,e}; n =3; Length[kTuples[n,s]] == Length[s]^n True Bob Hanlon Chantilly, VA USA ==== f[Sequence@@{{a,b}, {a,b}, {a,b}}] f[{a, b}, {a, b}, {a, b}] -----Original Message----- dynamically. The problem, of course, is that the output of the Table command is one big list and Outer is expecting a sequence of N separate lists after SomeFunction. ==== f[x_] = x^2 - 7*x + 10 g[x_] = Cos[3*x + 1/2*Pi] h[x_] = (x - 3)/(x + 2) Off[Solve::ifun] Solve[f[x] == y, x] Solve[g[x] == y, x] Solve[h[x] == y, x] -----Original Message----- ==== f[x_] = x^2 - 7*x + 10; g[x_] = Cos[3*x + 1/2*Pi]; h[x_] = (x - 3)/(x + 2); #[x] & /@ {f, g, h} {10 - 7*x + x^2, -Sin[3*x], (-3 + x)/(2 + x)} -----Original Message----- ==== I get the expected results. I suspect g was already defined at the time. For instance you might have set g={a,b} previously. ClearAll[g] goes before defining the function g. -----Original Message----- Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2, y1-y2} but instead one gets error messages. Why ? And how do I fix g (i.e write a function that outputs the difference of 2 vectors). ==== In[1]:= ktuples[n_Integer, d_List] := Flatten[Outer[List, Sequence @@ Table[d, {n}]], 2] In[2]:= ktuples[3, {a, b}] Out[2]= {{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}} Tomas Garza ----- Original Message ----- ==== kTuples[k_Integer?Positive, s_List] := Partition[Flatten@Outer[List, Sequence @@ (s & /@ Range[k])], k] kTuples[3, {a, b}] -----Original Message----- Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== The trick is to use the Sequence Function. Try the following code and you will see how it works. abcd = CharacterRange[a, d] abcd1 = Flatten[Outer[{#1, #2} &, abcd, abcd], 1] abcd2 = Outer[First[#]*Last[#] &, Sequence[abcd1], 1] abcd2 uses the list of lists you have created to load as a sequence of arguments to outer. You need the third argument to operate on the parts of the list if this is your goal. Read the description of Sequence. It also works in contexts other than Outer. Richard Palmer > Can anyone help me with this problem. If I have an n-element list, (say where each element is itself a > list), such as {{a,b}, {a,b}, {a,b}} > is there a way to strip off the outermost nesting of the list to > obtain just a sequence of of these n elements, that is > {a,b},{a,b},{a,b} so that I can use this for input for some function. I would like to do something like > Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N > dynamically. > The problem, of course, is that the output of the Table command is one > big list > and Outer is expecting a sequence of N separate lists after > SomeFunction. ==== Dear Group I would like to know, if is possible to solve Integrate[(exp[-a/x])/(x^2-b^2),{x,0,infinity}] with a and b constant ( Real ) using Mathematica. Valdeci Mariano ********************************************************************* Valdeci Mariano de Souza Master«s Degree of Applied Physics - Unesp/Rio Claro - State of S.8bo Paulo - Brazil Laboratory of Electrical Measurements phone : ( 0XX19 ) 526 - 2237 ********************************************************************* ==== > Is there an easy (elegant?) way to generate the set of all k-tuples > taking values from some set (list) S? I want the arguments of the > function to be k (the length of the tuples) and the set S. That is, > KTuples[3,{a,b}] should produce > {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b,b}}. Method 1: Distribute[Table[{a,b},{3}],List] Method 2: Needs[DiscreteMath`Combinatorica`]; Strings[{a,b},3] Rob Pratt Department of Operations Research http://www.unc.edu/~rpratt/ ==== > Does anyone know how to get the JavaPlot window (or any windows of this type) > which can be seen at > http://www.wolfram.com/products/mathematica/newin42/java.html > that WRI advertises comes with 4.2? Well, I don't know if any tools (like that Window/Palette) written in Java are in the M_4.2 box, but if you know a little Java Programming, you can easily write something like that yourself; eg. using the MathGraphicsJPanel which allows you to display Mathematica Graphics Expressions in a Java Component, simply by calling its setCommand() Method (I hope that's correct, I am writing that from memory); eg. a simple JFrame with a MathGraphicsJPanel would be programmed like this: (* This code is necessary for setting up J/Link *) < {NumberPoint -> ,}] ; However, Import is not the function I'd like to use, because it is realy slow over large files. I wonder if someone knows a way to use something faster than Import (I namely think of ReadList) with coma-numbers? ==== I'm a poor physicist trying to figure out how to sort out the physical from the non-physical solutions to a problem. To do that, I need to be able to look at an expression and pick out a subexpression, the part under the radical. For example, say I've got the expression a b x^2 + 5 x^3 + 5 Sqrt[4 - x^2] I'd like to pick out 4 - x^2, which would then tell me that x is between +/- 2. I know there has got to be an easy way to do it, but I can't find it. Any help would be appreciated. Steve Beach asb4@psu.edu http://www.thebeachfamily.org ==== Bob, Mathematica has commands to do exactly what you wish and their use is fairly common. The first command is Apply (@@ in prefix form) and the second command is Sequence. If you have a list of arguments such as... arglist = {{a, b}, c, {d, e}, 3, Report -> True}; you can insert them into a function, f, simply by applying f to the list. f @@ arglist f[{a, b}, c, {d, e}, 3, Report -> True] If you want to insert them into another function, h, that also has other arguments, then you can use Sequence and Apply. h[firstarg, Sequence @@ arglist, Compile -> False] h[firstarg, {a, b}, c, {d, e}, 3, Report -> True, Compile -> False] Park djmp@earthlink.net http://home.earthlink.net/~djmp/ The problem, of course, is that the output of the Table command is one big list and Outer is expecting a sequence of N separate lists after SomeFunction. ==== Bob, KTuples[n_Integer?Positive, elements_List] := Flatten[Outer[List, Sequence @@ Table[elements, {n}]], n - 1] KTuples[3, {a, b}] {{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}} Outer produces an array of all the elements but we have to flatten it to get it down to a two-level array. Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Raj, You could include an index for the function in the argument list, or make a clear separation between parameters and variables as follows (I just use two functions). f[1][r_, t_, p_] := 2r Sin[t] f[2][r_, t_, p_] := r Cos[t]Sin[p] You could then sum them, for example, by Sum[f[i][r, t, p], {i, 1, 2}] r Cos[t] Sin[p] + 2 r Sin[t] Or perhaps you wish to sum the derivatives of the functions with respect to the second argument, t. Sum[Derivative[0, 1, 0][f[i]][r, t, p], {i, 1, 2}] 2 r Cos[t] - r Sin[p] Sin[t] Perhaps you can define all your functions in terms of integer parameters. g[n_, m_][r_, t_, p_] := r^(m - n)Sin[m t]Cos[n p] You could then sum as follows. Sum[g[n, m][r, t, p], {m, 1, 3}, {n, 1, 3}] Cos[p]*Sin[t] + (Cos[2*p]*Sin[t])/r + (Cos[3*p]*Sin[t])/r^2 + r*Cos[p]*Sin[2*t] + Cos[2*p]*Sin[2*t] + (Cos[3*p]*Sin[2*t])/r + r^2*Cos[p]*Sin[3*t] + r*Cos[2*p]*Sin[3*t] + Cos[3*p]*Sin[3*t] Or perhaps you want to take the square of the derivatives of the functions with respect to the first argument, r... Sum[(Derivative[1, 0, 0][g[n, m]][r, t, p])^2, {m, 1, 3}, {n, 1, 3}] (Cos[2*p]^2*Sin[t]^2)/r^4 + (4*Cos[3*p]^2*Sin[t]^2)/ r^6 + Cos[p]^2*Sin[2*t]^2 + (Cos[3*p]^2*Sin[2*t]^2)/ r^4 + 4*r^2*Cos[p]^2*Sin[3*t]^2 + Cos[2*p]^2*Sin[3*t]^2 If possible, try to steer away from For and Do loops and use functional programming as much as you can. At first it may seem strange, but it is much more powerful and easier once you get used to it. Ask further questions to MathGroup with SPECIFIC examples and you will get a lot of help on how to use functional programming. Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== , Except in a few cases, Mathematica will not automatically generate the inverse function for you. You will have to Solve the equations and construct the inverse function yourself. In two of your three cases there are actually multiple inverse functions. Taking the easy one first. Clear[x]; Solve[f[x] == f, x][[1, 1]] // Simplify x[f_] = x /. % x -> (3 + 2*f)/(1 - f) (3 + 2*f)/(1 - f) So we now have the inverse function. x[f] (3 + 2*f)/(1 - f) For the quadratic equation there are two solution. Clear[x] sols = Solve[f[x] == f, x] {{x -> (1/2)*(7 - Sqrt[9 + 4*f])}, {x -> (1/2)*(7 + Sqrt[9 + 4*f])}} We define the two solutions and identify them by an index. x[1][f_] = x /. sols[[1, 1]] x[2][f_] = x /. sols[[2, 1]] (1/2)*(7 - Sqrt[9 + 4*f]) (1/2)*(7 + Sqrt[9 + 4*f]) For the third example there is a double infinity of solutions. Clear[x] sols = Solve[f[x] == f, x] Solve::ifun: Inverse functions are being used by !(Solve), so some solutions may not be found. {{x -> -(ArcSin[f]/3)}} Using some trigonometry we can define the solutions as (I hope I got this right) Clear[x]; x[1, n_][f_] = (-ArcSin[f] + 2 Pi n)/3 x[2, n_][f_] = (-Pi + ArcSin[f] + 2Pi n)/3 Here are some of the solutions for f = 1/2. Table[x[1, n][1/2], {n, -5, 5}]~Join~Table[x[1, n][1/2], {n, -5, 5}] // Sort f /@ % {-((61*Pi)/18), -((61*Pi)/18), -((49*Pi)/18), -((49*Pi)/18), -((37*Pi)/18), -((37*Pi)/18), -((25*Pi)/18), -((25*Pi)/18), -((13*Pi)/18), -((13*Pi)/18), -(Pi/18), -(Pi/18), (11*Pi)/18, (11*Pi)/18, (23*Pi)/18, (23*Pi)/18, (35*Pi)/18, (35*Pi)/18, (47*Pi)/18, (47*Pi)/18, (59*Pi)/18, (59*Pi)/18} {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2} Generally, when you want inverse functions you are going have to do some work. Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== g[u_, v_] := u - v g[{x1, y1}, {x2, y2}] {x1 - x2, y1 - y2} Park djmp@earthlink.net http://home.earthlink.net/~djmp/ y1-y2} but instead one gets error messages. Why ? And how do I fix g (i.e write a function that outputs the difference of 2 vectors). ==== >If I have an n-element list, (say where each element is itself a >list), such as {{a,b}, {a,b}, {a,b}} is there a way to strip off the >outermost nesting of the list to obtain just a sequence of of these n >elements, that is {a,b},{a,b},{a,b} so that I can use this for input >for some function. Try Sequence@@ as in the following: In[1]:= x={{a,b},{a,b},{a,b}}; In[2]:= g[x_,y_,z_]:=x(y.z) In[3]:= g[Sequence@@x] Out[3]= !({a ((a^2 + b^2)), b ((a^2 + b^2))}) ==== Why is it that when I type, say, Table[ Plot[ Sin[n x],{x,0,Pi}], {n, 1,5}] my output is marked in the righthand column with 3 cell ``markers, with the middle marker encompassing the output (and *only* the output). However, when I try something like Table[Show[Graphics[ etc., etc]], {n, 1,5}] the middle cell marker on the righthand side of the notebook also includes the input command? The reason that this is important for me is that I am doing an animation; and after the animation I would like to delete all the graphic images; but when I use Show[Graphics[ this would mean deleting the input command as well. Could someone explain this to me and also make a suggestion so how I could use Show[Graphics[ ] and have the middle cell marker *only* encompass the output. ==== > Because it depends on how you get there. For instance, > Limit[(1-x)^(1/x), x->0] gives 1/E, while Limit[(1-x)^(1/x^2), x->0] > gives 0. You are correct. However, that last limit claim is somewhat deceptive. Based on it, one might conclude, incorrectly, that the direction of approach to 0 is immaterial. Note that, although Limit[(1-x)^(1/x^2), x->0, Direction-> -1] yields 0, Limit[(1-x)^(1/x^2), x->0, Direction-> +1] yields Infinity. Thus, when Mathematica says that Limit[(1-x)^(1/x^2), x->0] is 0, it is making a hidden assumption of direction of approach. > In fact, you can construct similar examples in which > 1^Infinity = anything you like. Well, yes, as long as you don't like negative values. > 1^[Infinity] => Indeterminate, unexpected. Naively expected: 1. > For which reason(s) is 1^[Infinity] defined as Indeterminate? -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service ==== >Because it depends on how you get there. For instance, >>Limit[(1-x)^(1/x), x->0] gives 1/E, while Limit[(1-x)^(1/x^2), x->0] >>gives 0. > You are correct. However, that last limit claim is somewhat deceptive. > Based on it, one might conclude, incorrectly, that the direction of > approach to 0 is immaterial. Note that, although > Limit[(1-x)^(1/x^2), x->0, Direction-> -1] yields 0, > Limit[(1-x)^(1/x^2), x->0, Direction-> +1] yields Infinity. > Thus, when Mathematica says that Limit[(1-x)^(1/x^2), x->0] is 0, it is > making a hidden assumption of direction of approach. Actually it seems you've discovered a bug in Limit. If we allow complex values, then Limit[(1-x)^(1/x^2), x->0, Direction-> +1] should be 0, which is evident from the graph of Abs[(1-x)^(1/x^2)]. Mathematica gives Infinity for Limit[Abs[(1-x)^(1/x^2)], x->0, Direction-> +1] as well. If we don't allow complex values, then Limit[(1-x)^(1/x^2), x->0, Direction-> +1] can't exist at all (even as Infinity or -Infinity). >>In fact, you can construct similar examples in which >>1^Infinity = anything you like. Well, yes, as long as you don't like negative values. Some of my favorite numbers are negative, such as (1 + x I)^(I Pi/Log[1 + x I]) = -1 Note that this has the form 1^Infinity as x->0. >1^[Infinity] => Indeterminate, unexpected. Naively expected: 1. >>For which reason(s) is 1^[Infinity] defined as Indeterminate? > ==== Dear members, There is an equivalent of Or (||) to be used with patterns: Alternative (|). I couldn't find an equivalent for And (&&) and Not (!). I don't know if they don't exist, or it is just that I can`t find them. Julio ==== Is there a possibility that Mathematica gives me a function to given pairs of values? In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And I what like to know the corresponding function (what is in this example obviously f[x]=x^2). TIA Sven ==== Ok, I thank you for your help. The values {1,2},{2,4},{3,9} were only an example. And the 2 in the first pair should actually be an 1.... But this doesn't matter since you understood the problem. I also knew the problem, that I have to give something like a model for the function... Unfortunatly, I have no idea, how the function looks like. I thought, that Matematica is maybe able to compare these values with known functions (and combinings of them). But it looks like there is no way... Anyway, the real pairs of values are: {{0.5,3.45058},{1,5.3352},{1.5,6.9328},{1.8,7.306},{1.9,7.2962},{2, 7.2163},{2.5,5.8877},{3,3.7307},{3.4464,2.0000},{4,0.6928},{5,0.04575}} At first, I thougt that the function is something like the density function of the standard normal distribution... Thus, I tried the following function (and lots of modifications): (a + e*x)(2[Pi] Exp[0.5 (c*x^d + b)^2]) Unfortunatly, the result wasn't very accurate... I know, that this is not longer a problem a Mathematica, but I just wanted to let you know... Anyway, I thank you all for your help. Sven ==== Sven It may be obvious to you that 1^2=2 (surely not ?), 2^2=4 and 3^2=9, but to me your pairs look like they were derived from the function f[x]=x+x! (that is Factorial[x], not an x followed by an expression of surprise). But I could not find a Mathematica function to support my argument - or to support yours for that matter. I guess you could try Fit and its related functions ... Mark Westwood Is there a possibility that Mathematica gives me a function to given > pairs of values? > In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And I > what like to know the corresponding function (what is in this example > obviously f[x]=x^2). TIA > Sven ==== I have a lot of different files, containing data (already formatted for mathematica) which is supposed to be imported as tables with names derived from the original file name. Problem being: Scan[(StringDrop[#,-4]=Import[#];DeleteFile[#])&,FileNameList] only gives StringDrop protected..... What I also do not like about the above command is, that the data files are deleted. How can I get what I would like to have? Bettina ==== Does anybody know how to install Postscript Fonts Type 1, using Mathematica 4.2 under Mac OSX 10.1.5? -- Daniel AMIGUET Avenue du L.8eman 59 CH 1005 Lausanne +41 21/728 0730 ==== Not sure what you're asking here. Installation of type 1 fonts has nothing to do with Mathematica. You put them in your Library:Fonts folder. A shot in the dark: I have a feeling your difficulty might be related to the FontType option. Open the Option Inspector, show option values for Global, and look under Formatting Options > Font Options > PrivateFontOptions. Change the setting of FontType to Outline. --- Selwyn Hollis slhollis@mac.com > Does anybody know how to install Postscript Fonts Type 1, using > Mathematica 4.2 under Mac OSX 10.1.5? ==== Dear members, For long calculations, sometimes a message appears, telling the program is out of disk space. The kernel shuts down. I searched the archives for the list, and found a number of postings on this issue, but none of them solved my problem. I have 1.7 G of free space in my internal hard disk, but also have 22 G free in my Buslink USB external hard drive. I would like to use this space for the calculations. In Windows98 (control panel, system, performance, advanced, virtual memory) there is an option to use this space, but it seems like its either internal disk or external disk. I didn't dare to change it to the external disk, because I received a scary message from W98 (you may not be able to restart your computer). If I change the settings, will I be able to restart the PC? Is there a way to use both disks succesively? Is there a way to use the external one, but without restarting the computer? Is it possible to do this directly from Mathematica? Julio ==== Why does Mod[3.5,0.1] gives 0.1? However, 3.5 - 0.1 Quotient[3.5,0.1] gives 0 -Souvik ==== I have a problem with DigitQ and letterQ I would like for a string to yeild True when run with DigitQ if the the string looks like this: {1,2} and false if it looks like this: Right now both strings return False because of { , }. So, if there were anyway to include the charecters {, }, and , into the DigitQ 0-9 list temperarelly that would work, but I am sure there is Charles ==== Charles Does Apply[And, Map[DigitQ, list]] do what you want ? Mark Westwood I have a problem with DigitQ and letterQ I would like for a string to > yeild True when run with DigitQ if the the string looks like this: > {1,2} > and false if it looks like this: > Right now both strings return False because of { , }. So, if there > were anyway to include the charecters {, }, and , into the > DigitQ 0-9 list temperarelly that would work, but I am sure there is > Charles ==== I have been having difficulty using the distribution packages. In a package I created, I can't get the CDF function to evaluate, and I can't figure out the problem. Below I have included a very simple (and useless) package I created that runs in to the same problem. I want to use the numerical value of the CDF for a normal distribution. When I call TestFunction, this is the output: Global`glibb`Private`CDF[Global`glibb`Private`NormalDistribution[0, 1], -1] Global`glibb`Private`CDF[Global`glibb`Private`NormalDistribution[0., 1.], -1.] Calls to CDF return similar outputs in my useful packages. The package I am currently working with was originally written for Mathematica 2.0, and I am trying to update it to work with 4.0. I was told that all the functions were tested thoroughly in the 2.0 implementation and worked fine. TEST PACKAGE: file glibb.m ------------------------------------------------------------ BeginPackage[`glibb`, {Statistics`ContinuousDistributions`} ] glibb::usage = glibb is a test package. TestFunction::usage = TestFunction[]. Begin[`Private`] TestFunction[] := Module[{alpha,alpha2}, alpha = CDF[NormalDistribution[0,1], -1]; Print[alpha]; alpha2 = N[CDF[NormalDistribution[0,1],-1]]; Print[alpha2]; ]; End[ ] EndPackage[ ] ------------------------------------------------------------- Aaron ==== Here's a start: pairs = {{1, 1}, {2, 4}, {3, 9},{4,16}} ClearAll[f, g] g[{a_, b_}] := (f[a] = b) g /@ pairs ?? f That defines f only at the points in your list of ordered pairs. If you want to identify a polynomial (or other) fit, you could use Fit, if you have in mind what the functional form might be. Unfortunately, it might not do what you expect! You can also use Interpolation to define f on the range of values you have. expr1 = Fit[pairs, {1, x}, x] expr3 = Fit[pairs, {1, x, x^2}, x] expr4 = Fit[pairs, {1, x, x^2, x^3}, x] expr5 = Fit[pairs, {1, x, x^2, x^3, x^4}, x] expr6 = Interpolation[pairs] Plot[Evaluate[# - x^2], {x, 1, 3}] & /@ {expr1, expr2, expr3, expr4, expr5, expr6[x]}; -----Original Message----- ==== You're getting the error because you're trying to set StringDrop (of an argument) equal to something. The name of a variable is a Symbol, not a string, so you need to change the result of StringDrop into a Symbol, and then set that symbol equal to the result of Import. If you don't want the files deleted, for heaven's sake take DeleteFile out of the command! Scan[(name = Symbol@StringDrop[#, -4]; Evaluate@name =.; Evaluate[name] = Import[#, Text]) &, FileNameList] (I was testing using Text files.) -----Original Message----- Bettina ==== >Is there a possibility that Mathematica gives me a function to given >pairs of values? >In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And I >what like to know the corresponding function (what is in this example >obviously f[x]=x^2). You have to give it a model to which to fit the data. Needs[Statistics`NonlinearFit`]; data = {{1,1},{2,4},{3,9}}; model = a*x^2+b*x+c; NonlinearFit[data, model, x, {a,b,c}]//Chop 1.*x^2 Bob Hanlon Chantilly, VA USA ==== >Why does Mod[3.5, 0.1] gives 0.1? However, >3.5 - 0.1 Quotient[3.5, 0.1] gives 0 Lack of precision because you used machine numbers. Mod[3.5, 0.1] 0.1 Mod[35/10, 1/10] 0 Mod[Rationalize[3.5], 0.1] 0. Mod[3.5, Rationalize[0.1]] 0. Bob Hanlon Chantilly, VA USA ==== expr = {1,2}; And @@ (DigitQ /@ (ToString /@ (ToExpression@expr))) True That works if all the strings you'll apply it to are in that list format. If not, then something like this works... expr1 = {1,2,; expr2 = {1,2,m; f[expr_] := (Intersection[#1, Characters[01234567890,{}]] == Union[#1] & )[Characters[expr]] f[expr1] f[expr2] True False -----Original Message----- DigitQ 0-9 list temperarelly that would work, but I am sure there is Charles ==== As a follow up to 's example: Some students seem to think that lim n->0 (1+(1/n))n = 1. Their reasoning is this: When n->0, then 1+(1/n) -> 1. Now compute lim n->0 1 n = 1. This reasoning is just too simplistic. You have to deal with both of the n's in the expression (1+(1/n))n at the same time -- i.e., the y both go to infinity simultaneously; you can't figure that one goes to infinity and then the other goes to infinity. In fact, if you let the other one go to infinity first, you'd get a different answer: lim n->0 (1+0.0000001)n = 0. So evidently the answer lies somewhere between 1 and 0. Easy methods do not work on this problem. The correct answer is a number that is near 2.718. (It's an important constant, known to mathematicians as e = aprrox. 2.718281828...) There's no way you could get that by an easy method. Jonathan Rockmann mtheory@msn.com ----- Original Message ----- In other words, if f(x) approaches 1 and g(x) increases without bound, f(x)^g(x) need not approach 1. Consider the limit of (1+1/x)^x as x increases without bound, for example. ==== The default setting for FractionBox seems to be to have fonts smaller than the rest of the fonts in the cell. How can I globally set the fonts to be the same in a FractionBox as the default font size for the cell (which I know how to set but cannot figure out what to do with FractionBox). I do not want to manually change each specific character on account of there being too many and also I have the default cell font size for print out different from working and wrapping a Stylebox[ , fontSize-> ] around a character seems to lock the fontsize and therefore messes up the way it looks when printed. thanks Mike ==== Julio, I don't think there is a direct analog but it is easy to make up something that is equivalent. The following will return True for all Symbols that are not x or y. test1 := MatchQ[#1, _Symbol] && !MatchQ[#1, x | y] & test1 /@ {1, Sin[x], x, y, z} {False, False, False, False, True} Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Is there some easy way of changing a certain character in a NumberedEquation cell without doing it manually? eg. Where ever D (in italics) appears in an equation it is replaced by D (bold, no italics). thanks Mike ==== Aaron, When I add the line <Is there a possibility that Mathematica gives me a function to given >pairs of values? In other words: I have several pairs like {1, 2}, {2, >4}, {3, 9}. And I what like to know the corresponding function (what >is in this example obviously f[x]=x^2). There are infinitely many possible functions that can generate the particular list in your example. Specifically f[x]:={x, x^2 +(x-1)(x-2)(x-3)g[x]} for any g[x] will work. For Mathematica to determine a specific function it would be necessary to make assumptions about g[x]. Any assumptions made are certain to be wrong for some problem. If you know the relationship between the numbers is expressed by a polynomial, then you could use InterpolatingPolynomial In[1]:=InterpolatingPolynomial[Table[{n, n^2}, {n, 3}], x] // Simplify Out[1]=x^2 ==== OK! I found I could add this statement after BeginPackage, rather than adding the other two contexts: PrependTo[$ContextPath, #] & /@ {Statistics`Common`DistributionsCommon`, Statistics`NormalDistribution`} But, of course, it really should be BeginPackage[glibb`, {Statistics`Common`DistributionsCommon`, Statistics`NormalDistribution`}] To find out where a set of functions are really coming from, you can load the packages you THINK they're in and then find out where they really are, like this: < Is there a possibility that Mathematica gives me a function to given > pairs of values? > In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And I > what like to know the corresponding function (what is in this example > obviously f[x]=x^2). Is that really obvious? How about: In[7]:= Rationalize[Fit[{{1, 2}, {2, 4}, {3, 9}}, {x, x^2, x^3}, {x}]] Out[7]= 3*x - (3*x^2)/2 + x^3/2 In[8]:= % /. {{x -> 1}, {x -> 2}, {x -> 3}} Out[8]= {2, 4, 9} Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== No there isn't one. In fact the only sensible cases in which you might wish to use a And for patterns seem to be the cases where either all patterns arise from pure functions by means of _? (PatternTest) or where at most one pattern does not arise in that way. In the first case it is clearly simpler to use ordinary && as in: In[13]:= Cases[Range[10], _?(PrimeQ[#1] && #1 > 3 & )] Out[13]= {5, 7} the other case is when you mix a true pattern and a pattern test. e.g: IIn[14]:= Cases[{0,1,1.5,2},_Integer?(#>1&)] Out[14]= {2} I can't think of any way you could try to combine two patterns that do not arise from pure functions, so I don't think such an And would be very useful. A Not for patterns might be perhaps somewhat useful, but it can always be constructed by means of the MatchQ predicate: In[15]:= Cases[{0,1,1.5,2},_?(!MatchQ[#,_Integer]&)] Out[15]= {1.5} Dear members, There is an equivalent of Or (||) to be used with patterns: Alternative > (|). I couldn't find an equivalent for And (&&) and Not (!). I don't > know if they don't exist, or it is just that I can`t find them. > Julio > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I think the Help Browser is only approximately correct on this point. Although it says: Mod[m, n] is equivalent to m - n Quotient[m, n] this is only really always true for exact numbers. Thus in your case: In[21]:= Mod[Rationalize[3.5],Rationalize[0.1]] Out[21]= 0 and same for In[22]:= Rationalize[3.5]-Rationalize[0.1 ]Quotient[Rationalize[3.5],Rationalize[0.1]] Out[22]= 0 For inexact numbers this relationship holds almost everywhere. I suspect this is due to the fact that arithmetic in Mathematica is in fact binary. Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ Why does Mod[3.5,0.1] gives 0.1? However, > 3.5 - 0.1 Quotient[3.5,0.1] gives 0 > -Souvik ==== Is there a publicly available Mathematica 3.0 notebook that implements the Primes is in P? http://www.msnbc.com/news/792126.asp ==== Anybody can help me? I have any program in Mathematica 3.0, I am changing to Mathematica 4.0, but I have problem in this point, with NDSolve in this equation !(* RowBox[{ RowBox[{EXERUIDO, =, RowBox[{NDSolve, [, RowBox[{ RowBox[{{, RowBox[{ RowBox[{ RowBox[{ SuperscriptBox[y, [Prime], MultilineFunction->None], [, x, ]}], ==, ((coefac[x] ((1 - alfaam/alfaem)) + alfaam etas)/(y[x] /. sinalfinal))}], ,, (y[0] == 0)}], }}], ,, y, ,, ({x, 0, Z})}], ]}]}], ;}]) NDSolve::ndnum: Encountered non-numerical value for a derivative at !(x) == !(0.`). NDSolve::ndnum: Encountered non-numerical value for a derivative at !(x) == !(0.`). In Mathematica 3.0 resolve this equation without problem. I dont know what can I do to resolve this problem. S.8ergio Milo ==== Good luck with a function like 1 + Sin[x], which has infinitely many roots but never changes sign! Or Sin[1/x], which has infinitely many roots converging on 0, but no limit for the function at 0. Or... still worse... 1 + Sin[1/x], which has BOTH problems. -----Original Message----- In[2]:= points = Cases[g, Line[x_] -> x, Infinity][[1]]; We make a list of the signs of the y values: In[3]:= signs = Sign /@ Transpose[Cases[g, Line[x_] -> x, Infinity][[ 1]]][[2]]; We find the points where the sign changes: In[4]:= positions = Position[Rest[signs]*Rest[RotateRight[signs]], -1] Out[4]= {{27}, {51}, {74}, {101}, {126}, {149}, {177}, {200}, {226}, {252}} We make a list of starting points for FindRoot: In[5]:= starts = First[Transpose[Extract[points, positions]]] Out[5]= {2.7825096162536145, 6.080185995733974, 8.787418231655966, 12.198138489619575, 15.464841498197309, 18.61672099859868, 21.92859710988888, 24.46767425065356, 27.840417480532142, 31.139545383515845} We find the roots: In[6]:= (FindRoot[Sin[x] == 0, {x, #1}, WorkingPrecision -> 20] & ) /@ starts Out[6]= {{x -> 3.141592653589793238462643383255068`20}, {x -> 6.283185307179586476925286766538051`20}, {x -> 9.424777960769379715387930149825109`20}, {x -> 12.566370614359172953850573533079026`20}, {x -> 15.707963267948966192313216916378673`20}, {x -> 18.849555921538759430775860299681079`20}, {x -> 21.991148575128552669238503682979946`20}, {x -> 25.132741228718345907701147066183302`20}, {x -> 28.274333882308139146163790449476032`20}, {x -> 31.415926535897932384626433832775678`20}} This question has been asked frequently so you can find various approaches, including this one, in the archives. Of course there is no guarantee. For very complex functions you may well miss some roots. The situation can become a lot more complicated if your equation has multiple roots. Andrzej Can Mathematica find (localize) ALL roots of non-polynomial equation eq[x]==0 on a given segment x in [a,b], a,b=Real?? (for example Sin[x]==0, for 0.1 ==== > I have a problem with DigitQ and letterQ I would like for a string to > yeild True when run with DigitQ if the the string looks like this: > {1,2} > and false if it looks like this: > Right now both strings return False because of { , }. So, if there > were anyway to include the charecters {, }, and , into the > DigitQ 0-9 list temperarelly that would work, but I am sure there is > Charles > Try this Dresser[string_String]:= Module[{x},x=StringReplace[string, ->]; If[Or[StringTake[x,1]!=(,StringTake[x,-1]!=)],Return[False]]; Apply[And, NumberQ[#]&/@ToExpression[{<>StringDrop[StringDrop[x,1],-1]<>}]]] This function trims blanks. It will do a bit more than you require -- return True for (#,#,#,...#). However you can easily make the fix to limit it to two. Additionally, you can quickly modify the code to get the numbers back. The setup will also let you easily modify it to integers, positive integers, Numerics, etc. Richard Palmer ==== I would like to plot this function : 1 n(e)=______________ Exp[b(e-mu)]+1 and get a graphic like that, with the letters n(e) ^ | | 1| ____________ | | | | |_______________ _____________________ e mu / how can i do it, i specified SetAttributes{b,constant} etc ... but it don't work please help me, i use mathematica 4 ==== Hail physics-friend! The Tick command enables you to label ticks on axes. Here: Module[ { mu = .1, b = 100 }, Plot[1/(1 + Exp[-b (mu - e)]) , {e, 0, 2 mu} , Ticks -> {{{mu, mu}}, Range[0, 1, .2]} , AxesLabel -> {e, n(e)} ] ] Your ascii picture looks nice too! Note there are no axis-arrows provided with above plot, look for them in some recent message in this group. Bye, Borut > I would like to plot this function : > 1 > n(e)=______________ > Exp[b(e-mu)]+1 and get a graphic like that, with the letters n(e) > ^ > | > | > 1| ____________ > | > | > | | > |_______________ _____________________ e > mu / how can i do it, i specified > SetAttributes{b,constant} etc ... but it don't work please help me, i use mathematica 4 ==== Here's a similar solution that averages points on either side of sign changes, to get better initial starts for FindRoot: g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction -> Identity]; points = First@Cases[g, Line[x_] -> x, Infinity]; signs = Sign /@ points[[All, 2]]; positions = Union[#, # + 1] &@Flatten@Position[Rest[signs*RotateRight@signs], -1] starts = 1/2Plus @@@ Partition[points[[positions, 1]], 2] x /. (FindRoot[Sin[x] == 0, {x, #1}] &) /@ starts {27, 28, 51, 52, 74, 75, 101, 102, 126, 127, 149, 150, 177, 178, 200, 201, 226, 227, 252, 253} {3.09198, 6.26091, 9.13801, 12.5265, 15.7722, 18.9688, 22.0933, 24.8161, 28.1494, 31.4348} {3.14159, 6.28319, 9.42478, 12.5664, 15.708, 18.8496, 21.9911, 25.1327, 28.2743, 31.4159} -----Original Message----- In[2]:= points = Cases[g, Line[x_] -> x, Infinity][[1]]; We make a list of the signs of the y values: In[3]:= signs = Sign /@ Transpose[Cases[g, Line[x_] -> x, Infinity][[ 1]]][[2]]; We find the points where the sign changes: In[4]:= positions = Position[Rest[signs]*Rest[RotateRight[signs]], -1] Out[4]= {{27}, {51}, {74}, {101}, {126}, {149}, {177}, {200}, {226}, {252}} We make a list of starting points for FindRoot: In[5]:= starts = First[Transpose[Extract[points, positions]]] Out[5]= {2.7825096162536145, 6.080185995733974, 8.787418231655966, 12.198138489619575, 15.464841498197309, 18.61672099859868, 21.92859710988888, 24.46767425065356, 27.840417480532142, 31.139545383515845} We find the roots: In[6]:= (FindRoot[Sin[x] == 0, {x, #1}, WorkingPrecision -> 20] & ) /@ starts Out[6]= {{x -> 3.141592653589793238462643383255068`20}, {x -> 6.283185307179586476925286766538051`20}, {x -> 9.424777960769379715387930149825109`20}, {x -> 12.566370614359172953850573533079026`20}, {x -> 15.707963267948966192313216916378673`20}, {x -> 18.849555921538759430775860299681079`20}, {x -> 21.991148575128552669238503682979946`20}, {x -> 25.132741228718345907701147066183302`20}, {x -> 28.274333882308139146163790449476032`20}, {x -> 31.415926535897932384626433832775678`20}} This question has been asked frequently so you can find various approaches, including this one, in the archives. Of course there is no guarantee. For very complex functions you may well miss some roots. The situation can become a lot more complicated if your equation has multiple roots. Andrzej Can Mathematica find (localize) ALL roots of non-polynomial equation eq[x]==0 on a given segment x in [a,b], a,b=Real?? (for example Sin[x]==0, for 0.1 ==== Perhaps it's worth recalling that probably the simplest method seems to be the one posted some time ago by Adam Strzebonski In[1]:= f[x_] = Normal[Sin[10.1*Pi*x] + O[x]^100]; In[2]:= 10.1*Pi*Select[x /. NSolve[f[x] == 0, x], Im[#1] == 0 && 0.1/(Pi*10.1) <= #1 <= 1 & ] Out[2]= {31.41492328081239, 28.274379350873716, 25.132740219910605, 21.991148587034512, 18.84955591555759, 15.707963269122267, 12.56637061424962, 9.424777960775808, 6.283185307178523, 3.141592653590188} The problem is of course that it is difficult to know how long a Taylor series to take, whehter one has found all the roots and how accurate the answers are, although with careful analysis this may be a useful approach. Andrzej Kozlowski > Here's a similar solution that averages points on either side of sign > changes, to get better initial starts for FindRoot: g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction -> Identity]; > points = First@Cases[g, Line[x_] -> x, Infinity]; > signs = Sign /@ points[[All, 2]]; > positions = > Union[#, # + 1] &@Flatten@Position[Rest[signs*RotateRight@signs], > -1] > starts = 1/2Plus @@@ Partition[points[[positions, 1]], 2] > x /. (FindRoot[Sin[x] == 0, {x, #1}] &) /@ starts {27, 28, 51, 52, 74, 75, 101, 102, 126, 127, 149, 150, > 177, 178, 200, 201, 226, 227, 252, 253} {3.09198, 6.26091, 9.13801, 12.5265, 15.7722, 18.9688, 22.0933, 24.8161, > 28.1494, 31.4348} {3.14159, 6.28319, 9.42478, 12.5664, 15.708, 18.8496, 21.9911, 25.1327, > 28.2743, 31.4159} -----Original Message----- > Sent: Friday, August 09, 2002 4:18 AM In your example, yes. Here is one way (adapted from a slightly different problem in Stan Wagon's Mathematica in Action) We make use of Mathematica's ability to plot graphs: > In[1]:= > g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction - Identity]; We make a list of all the coordinates of the points represented on the > graph. In[2]:= > points = Cases[g, Line[x_] -> x, Infinity][[1]]; We make a list of the signs of the y values: In[3]:= > signs = Sign /@ Transpose[Cases[g, Line[x_] -> x, Infinity][[ > 1]]][[2]]; We find the points where the sign changes: In[4]:= > positions = Position[Rest[signs]*Rest[RotateRight[signs]], > -1] Out[4]= > {{27}, {51}, {74}, {101}, {126}, {149}, {177}, {200}, {226}, > {252}} We make a list of starting points for FindRoot: In[5]:= > starts = First[Transpose[Extract[points, positions]]] Out[5]= > {2.7825096162536145, 6.080185995733974, 8.787418231655966, > 12.198138489619575, 15.464841498197309, 18.61672099859868, > 21.92859710988888, 24.46767425065356, 27.840417480532142, > 31.139545383515845} > We find the roots: In[6]:= > (FindRoot[Sin[x] == 0, {x, #1}, WorkingPrecision - 20] & ) /@ starts Out[6]= > {{x -> 3.141592653589793238462643383255068`20}, > {x -> 6.283185307179586476925286766538051`20}, > {x -> 9.424777960769379715387930149825109`20}, > {x -> 12.566370614359172953850573533079026`20}, > {x -> 15.707963267948966192313216916378673`20}, > {x -> 18.849555921538759430775860299681079`20}, > {x -> 21.991148575128552669238503682979946`20}, > {x -> 25.132741228718345907701147066183302`20}, > {x -> 28.274333882308139146163790449476032`20}, > {x -> 31.415926535897932384626433832775678`20}} > This question has been asked frequently so you can find various > approaches, including this one, in the archives. Of course there is no > guarantee. For very complex functions you may well miss some roots. The > situation can become a lot more complicated if your equation has > multiple roots. Andrzej > Can Mathematica find (localize) ALL roots of non-polynomial equation >> eq[x]==0 >> on a given segment x in [a,b], a,b=Real?? >> (for example Sin[x]==0, for 0.1 Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== Better yet, avoid unnecessary contortions: f[x_] = Normal[Sin[x] + O[x]^100]; Plot[f[x] - Sin[x], {x, 0.1, 10Pi}, PlotRange -> All]; Select[x /. NSolve[f[x] == 0, x], Im[#1] == 0 && 0.1 ? #1 ? 10.1Pi &] {3.14159, 6.28319, 9.42478, 12.5664, 15.708, 18.8496, 21.9911, 25.1327, 28.2744, 31.4156} The Plot should tell us whether we have enough terms in the Series. -----Original Message----- Out[2]= {31.41492328081239, 28.274379350873716, 25.132740219910605, 21.991148587034512, 18.84955591555759, 15.707963269122267, 12.56637061424962, 9.424777960775808, 6.283185307178523, 3.141592653590188} The problem is of course that it is difficult to know how long a Taylor series to take, whehter one has found all the roots and how accurate the answers are, although with careful analysis this may be a useful approach. Andrzej Kozlowski > Here's a similar solution that averages points on either side of sign > changes, to get better initial starts for FindRoot: g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction -> Identity]; > points = First@Cases[g, Line[x_] -> x, Infinity]; > signs = Sign /@ points[[All, 2]]; > positions = > Union[#, # + 1] &@Flatten@Position[Rest[signs*RotateRight@signs], > -1] > starts = 1/2Plus @@@ Partition[points[[positions, 1]], 2] > x /. (FindRoot[Sin[x] == 0, {x, #1}] &) /@ starts {27, 28, 51, 52, 74, 75, 101, 102, 126, 127, 149, 150, > 177, 178, 200, 201, 226, 227, 252, 253} {3.09198, 6.26091, 9.13801, 12.5265, 15.7722, 18.9688, 22.0933, 24.8161, > 28.1494, 31.4348} {3.14159, 6.28319, 9.42478, 12.5664, 15.708, 18.8496, 21.9911, 25.1327, > 28.2743, 31.4159} -----Original Message----- > Sent: Friday, August 09, 2002 4:18 AM In your example, yes. Here is one way (adapted from a slightly different problem in Stan Wagon's Mathematica in Action) We make use of Mathematica's ability to plot graphs: > In[1]:= > g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction - Identity]; We make a list of all the coordinates of the points represented on the > graph. In[2]:= > points = Cases[g, Line[x_] -> x, Infinity][[1]]; We make a list of the signs of the y values: In[3]:= > signs = Sign /@ Transpose[Cases[g, Line[x_] -> x, Infinity][[ > 1]]][[2]]; We find the points where the sign changes: In[4]:= > positions = Position[Rest[signs]*Rest[RotateRight[signs]], > -1] Out[4]= > {{27}, {51}, {74}, {101}, {126}, {149}, {177}, {200}, {226}, > {252}} We make a list of starting points for FindRoot: In[5]:= > starts = First[Transpose[Extract[points, positions]]] Out[5]= > {2.7825096162536145, 6.080185995733974, 8.787418231655966, > 12.198138489619575, 15.464841498197309, 18.61672099859868, > 21.92859710988888, 24.46767425065356, 27.840417480532142, > 31.139545383515845} > We find the roots: In[6]:= > (FindRoot[Sin[x] == 0, {x, #1}, WorkingPrecision - 20] & ) /@ starts Out[6]= > {{x -> 3.141592653589793238462643383255068`20}, > {x -> 6.283185307179586476925286766538051`20}, > {x -> 9.424777960769379715387930149825109`20}, > {x -> 12.566370614359172953850573533079026`20}, > {x -> 15.707963267948966192313216916378673`20}, > {x -> 18.849555921538759430775860299681079`20}, > {x -> 21.991148575128552669238503682979946`20}, > {x -> 25.132741228718345907701147066183302`20}, > {x -> 28.274333882308139146163790449476032`20}, > {x -> 31.415926535897932384626433832775678`20}} > This question has been asked frequently so you can find various > approaches, including this one, in the archives. Of course there is no > guarantee. For very complex functions you may well miss some roots. The > situation can become a lot more complicated if your equation has > multiple roots. Andrzej > Can Mathematica find (localize) ALL roots of non-polynomial equation >> eq[x]==0 >> on a given segment x in [a,b], a,b=Real?? >> (for example Sin[x]==0, for 0.1 Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== hi, I wanted to know if anybody has tried simulating DSSS.. or tracking code DSSS ...any spread spectrum simulation on mathematica. please let me know if any pointers are available on the net. thanks __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com ==== Dear friends I wish to build a function to obtain from a list (i.e.:) list = {a1, a2, a3, a4}; and output like this: {{f[a2, a1, a2]}, {f[a3, a1, a2], f[a3, a2, a3]}, {f[a4, a1, a2], f[a4, a2, a3], f[a4, a3, a4]}} This following function work fine function1[tau1_] := Table[Table[ f[Extract[tau1, j + 1], Extract[tau1, i], Extract[tau1, i + 1]], {i, 1, Length[tau1] - Length[tau1] + j}], {j, 1, Length[tau1] - 1}] function1[list] // TableForm but I think is not so eleghant. I will appreciate any help to build a more effecient and eleghant solution Guillermo Sanchez ==== > I have solved the problem with the fonts. It required modifying the Format > Type Styles at the end of the style sheet. So my only remaining question now is, are there any known problems associated > with modifying these fonts to Arial, or sharing problems if I save a notebook > in Arial then pass it on to someone who uses the default style sheet? The answer to your question depends on two criteria: 1) Does the notebook you're sharing contain a private copy of your modified style sheet, or is the notebook configured to use a shared version of your modified style sheet? If the notebook contains a private copy, then the front end on the recipients machine will attempt to use the font settings as you specified. If not, then the notebook will use the shared default style sheet on his or her system, which means your font settings will not be used. 2) If the answer to (1) was private copy, then the next question is whether Arial is installed on the end user's system. Bear in mind that Arial started out as a Microsoft-specific TrueType font that was supposed to provide a sans-serifed font akin to Helvetica. There is a possibility that Mac users might not have this font available on their system. The same is especially true for Unix users, whose X servers may not support TrueType fonts or whose system administrators have not installed Arial and configured the X server to use it. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== Dave's answer also works in patterns Cases[{1, Sin[x], x, y, z}, _?(MatchQ[#, _Symbol] && !MatchQ[#, x | y]&)] {z} Bob Hanlon Chantilly, VA USA >I don't think there is a direct analog but it is easy to make up something >that is equivalent. The following will return True for all Symbols that >are not x or y. test1 := MatchQ[#1, _Symbol] && !MatchQ[#1, x | y] & test1 /@ {1, Sin[x], x, y, z} >{False, False, False, False, True} Park >djmp@earthlink.net >http://home.earthlink.net/~djmp/ >Dear members, There is an equivalent of Or (||) to be used with patterns: Alternative >(|). I couldn't find an equivalent for And (&&) and Not (!). I don't >know if they don't exist, or it is just that I can`t find them. ==== > Does anyone know how to change the default (ASCII?) Input font which is > used by Mathematica on every Input line to something easier for me to > read like, Arial? After getting some excellent advice on working with style sheets, I have > been able to configure the front end substantially but am still unable > to change what is, however universal, still a difficult font for me to > read. Front end style sheets include prototypes for Mathematica format types like StandardForm and InputForm. You will find these settings near the bottom of the style sheet notebook. If a cell style is configured to use a format type, then the settings in the format type protoptype cell will override the settings in the cell style itself. For example, suppose you change the FontFamily option value in Input to Arial. By default, the Input style uses the StandardForm format type. The prototype for StandardForm includes the FontFamily option with its value set to Courier. To ensure that Arial is used, you need to change the FontFamily option in the StandardForm prototype cell. Bear in mind that this will cause all cell styles, such as Output, that use StandardForm to inherit this font as well. Another caveat for you is that some format types (InputForm and OutputForm, for example), assume a monospaced font is being used to display text. It is probably not a good idea to use Arial for these format types. Choose a monospaced sans serifed font like Lucida Console instead. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== SM> In Mathematica 3.0 resolve this equation without problem. Sure not. Mathematica 3.0 returns exactly the same warning messages as Mathematica 4.0 does. Mathematica got stymied because to get to a sensible output you must 1) use, in NDSolve, not {x, 0, Z} but something like {x, 0, 1} so Mathematica's algorithms could know over which range they must work and calculate the stepsize(s) required 2) define coefac[x], alfaam, alfaem, etas, sinalfinal in terms of constants and/or functions of x and/or y[x] to get Mathematica the opportunity to plunge into numeric values How could you recognize your own bug? Just pay attention to those ominous words non-numerical value ;-) In fact, you asked Mathematica kinda to find the numeric value of the expression x without defining x. You cannot do it, Mathematica cannot do it, nobody can do it. Best wishes, Vladimir =============================================================== ==== Ted Ersek has a package on MathSource called Rootsearch that is pretty decent at finding roots. Here is how it works on your examples. << Enhancements`Rootsearch` RootSearch[Sin[x] + 1 == 0, {x, -30, 30}] {{x -> -26.7035}, {x -> -20.4204}, {x -> -14.1372}, {x -> -7.85398}, {x -> -1.5708}, {x -> 4.71239}, {x -> 10.9956}, {x -> 17.2788}, {x -> 23.5619}, {x -> 29.8451}} The last example is of course more difficult because there are an infinite number of roots clustered around zero. However, if we want to find the roots in a given range: roots = RootSearch[1 + Sin[1/x] == 0, {x, 0.005, 0.01}] Length[roots] {{x -> 0.00501275}, {x -> 0.00517577}, {x -> 0.00534975}, {x -> 0.00553582}, {x -> 0.00573531}, {x -> 0.00594972}, {x -> 0.00618077}, {x -> 0.0064305}, {x -> 0.00670126}, {x -> 0.00699582}, {x -> 0.00731747}, {x -> 0.00767012}, {x -> 0.00805848}, {x -> 0.00848826}, {x -> 0.00896648}, {x -> 0.00950179}} 16 1 + Sin[1/x] /. roots {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.} Plot[1 + Sin[1/x], {x, 0.005, 0.01}]; Not too bad. Park djmp@earthlink.net http://home.earthlink.net/~djmp/ equation In your example, yes. Here is one way (adapted from a slightly different problem in Stan Wagon's Mathematica in Action) We make use of Mathematica's ability to plot graphs: In[1]:= g = Plot[Sin[x], {x, 0.1, 10.1*Pi}, DisplayFunction -> Identity]; We make a list of all the coordinates of the points represented on the graph. In[2]:= points = Cases[g, Line[x_] -> x, Infinity][[1]]; We make a list of the signs of the y values: In[3]:= signs = Sign /@ Transpose[Cases[g, Line[x_] -> x, Infinity][[ 1]]][[2]]; We find the points where the sign changes: In[4]:= positions = Position[Rest[signs]*Rest[RotateRight[signs]], -1] Out[4]= {{27}, {51}, {74}, {101}, {126}, {149}, {177}, {200}, {226}, {252}} We make a list of starting points for FindRoot: In[5]:= starts = First[Transpose[Extract[points, positions]]] Out[5]= {2.7825096162536145, 6.080185995733974, 8.787418231655966, 12.198138489619575, 15.464841498197309, 18.61672099859868, 21.92859710988888, 24.46767425065356, 27.840417480532142, 31.139545383515845} We find the roots: In[6]:= (FindRoot[Sin[x] == 0, {x, #1}, WorkingPrecision -> 20] & ) /@ starts Out[6]= {{x -> 3.141592653589793238462643383255068`20}, {x -> 6.283185307179586476925286766538051`20}, {x -> 9.424777960769379715387930149825109`20}, {x -> 12.566370614359172953850573533079026`20}, {x -> 15.707963267948966192313216916378673`20}, {x -> 18.849555921538759430775860299681079`20}, {x -> 21.991148575128552669238503682979946`20}, {x -> 25.132741228718345907701147066183302`20}, {x -> 28.274333882308139146163790449476032`20}, {x -> 31.415926535897932384626433832775678`20}} This question has been asked frequently so you can find various approaches, including this one, in the archives. Of course there is no guarantee. For very complex functions you may well miss some roots. The situation can become a lot more complicated if your equation has multiple roots. Andrzej Can Mathematica find (localize) ALL roots of non-polynomial equation eq[x]==0 on a given segment x in [a,b], a,b=Real?? (for example Sin[x]==0, for 0.1 ==== I think you meant Limit[(1 + 1/n)^n, n -> Infinity], which is EXACTLY e. (1 + 1/n)n // Simplify 1+n -----Original Message----- infinity and then the other goes to infinity. In fact, if you let the other one go to infinity first, you'd get a different answer: lim n->0 (1+0.0000001)n = 0. So evidently the answer lies somewhere between 1 and 0. Easy methods do not work on this problem. The correct answer is a number that is near 2.718. (It's an important constant, known to mathematicians as e = aprrox. 2.718281828...) There's no way you could get that by an easy method. Jonathan Rockmann mtheory@msn.com ----- Original Message ----- In other words, if f(x) approaches 1 and g(x) increases without bound, f(x)^g(x) need not approach 1. Consider the limit of (1+1/x)^x as x increases without bound, for example. ==== The other one is easy too, via L'Hospital's rule: Limit[(1 + 1/n)^n, n -> Infinity] == Exp[Limit[n Log[1 + 1/n], n -> Infinity]] == Exp[Limit[D[Log[1 + 1/n], n]/D[1/n, n], n -> Infinity]] == Exp[Limit[n/(1 + n), n -> Infinity]] == Exp[1] Lim -----Original Message----- As a follow up to 's example: Some students seem to think that lim n->0 (1+(1/n))n = 1. Their reasoning is this: When n->0, then 1+(1/n) -> 1. Now compute lim n->0 1 n = 1. This reasoning is just too simplistic. You have to deal with both of the n's in the expression (1+(1/n))n at the same time -- i.e., the y both go to infinity simultaneously; you can't figure that one goes to infinity and then the other goes to infinity. In fact, if you let the other one go to infinity first, you'd get a different answer: lim n->0 (1+0.0000001)n = 0. So evidently the answer lies somewhere between 1 and 0. Easy methods do not work on this problem. The correct answer is a number that is near 2.718. (It's an important constant, known to mathematicians as e = aprrox. 2.718281828...) There's no way you could get that by an easy method. Jonathan Rockmann mtheory@msn.com ----- Original Message ----- In other words, if f(x) approaches 1 and g(x) increases without bound, f(x)^g(x) need not approach 1. Consider the limit of (1+1/x)^x as x increases without bound, for example. ==== MathGroup, I don't know why all of my symbols disappeared when I copied and pasted to the last post I submitted. My last post makes no sense. I bet you now I'm going to get a flood of comments about this. Sorry. It should say: A lot of people think that Lim n->00 (1+(1/n))^n 1. Their reasoning is this: When n->00, then 1+(1/n)->1. Now compute lim n->00 1^n =1. Of course, this reasoning is too simple. You have to deal with both of the n's in the expression (1+(1/n))^n at the same time -- i.e., they both go to infinity simutaneously: you can't figure that one goes to infinity and then the other goes to infinity. And in fact, if you let the other one go to infinity first, you'd get a different answer: lim n->00 (1+.0000001)^n=00. So evidently the answer lies somewhere between 1 and 00. That doesn't tell us much; my point here is that easy methods do not work on this problem. The correct answer is a number that is near 2.718281828 ... i.e. the constant e. There's no way you could get that by an easy method. Jonathan mtheory@msn.com ----- Original Message ----- 0. So evidently the answer lies somewhere between 1 and 0. Easy methods do not work on this problem. The correct answer is a number that is near 2.718. (It's an important constant, known to mathematicians as e = aprrox. 2.718281828...) There's no way you could get that by an easy method. Jonathan Rockmann mtheory@msn.com ----- Original Message ----- In other words, if f(x) approaches 1 and g(x) increases without bound, f(x)^g(x) need not approach 1. Consider the limit of (1+1/x)^x as x increases without bound, for example. ==== No problems getting a bmp image into mathematica using import and assigning a name like g to it. Once the image is in (a displacement/deformation image created by Cosmos/Works in SolidWorks) I need to be able to generate some kind of table of (x,y,z) or (r, theta, phi) coordinates of the graph, and then interpolate the data into a harmonic function (In particular Bessel functions due to the nature of the geometry of the object being studied)...I am using Mathematica 4 and get lost...Been able to generate a Raster list, however whenever I try to manipulate this data I get errors, so obviously generating a raster is not the correct procedure...HELP!!! Jerry Mahabub ==== when trying to build (after first install) or rebuild the help index my system (Win XP) always hangs e.g. the build seems not to come to an end. In the task manager i see mathematica.exe consuming 99% of available processor time and using more and more memory. What can i do to get this index file built correctly ? Please help. ==== You have to somehow specify the values of your constants (unless you want to go to a 3D graphic). One possibility would be as follows In[1]:= n[e_,b_,mu_]:=1/(Exp[b(e-mu)]+1); In[2]:= Plot[n[e, b, mu] /. {b -> 1, mu -> 1}, {e, 0, 10}, AxesLabel -> {e, n(e)}, Epilog -> {Line[{{1, 0}, {1, n[1, 1, 1]}}], Text[mu, {0.91, -0.02}]}]; Tomas Garza ----- Original Message ----- > ^ > | > | > 1| ____________ > | > | > | | > |_______________ _____________________ e > mu / how can i do it, i specified > SetAttributes{b,constant} etc ... but it don't work please help me, i use mathematica 4 ==== In a message dated 8/11/02 6:39:20 AM, remi.dumasNOSPAM@club-internet.fr >I would like to plot this function : > 1 >n(e)=______________ > Exp[b(e-mu)]+1 and get a graphic like that, with the letters n(e) > ^ > | > | >1| ____________ > | > | > | | > |_______________ _____________________ e > mu > / how can i do it, i specified >SetAttributes{b,constant} etc ... but it don't work please help me, i use mathematica 4 Needs[Graphics`Legend`]; Needs[Graphics`Arrow`]; 1/(Exp[b(e-mu)]+1); Rewrite the expression as 1/(Exp[b*mu(e/mu-1)]+1); % == %% // Simplify True In order to Plot the normalized function you must provide one or more specific values for the product b*mu With[{btm =4, edmMax = 3}, Plot[1/(Exp[btm(edm-1)]+1), {edm,0,edmMax}, AxesLabel-> {ToString[TraditionalForm[e/mu]], n(e}}, PlotStyle -> Hue[2/3], Epilog -> { Arrow[{.9*edmMax,0}, {1.07*edmMax,0}, HeadCenter->.25], Arrow[{0,.9}, {0,1.1}, HeadCenter->.25]}, PlotRange -> {{0,1.07*edmMax},{0,1.1}}]]; For multiple values With[{btmMin = -1,btmMax =4,edmMax = 3,n = 6}, Plot[Evaluate[ Table[1/(Exp[btm(edm-1)]+1), {btm,btmMin, btmMax, (btmMax-btmMin)/(n-1)}]], {edm,0,edmMax}, AxesLabel-> {ToString[TraditionalForm[e/mu]], n(e}}, PlotStyle -> Table[Hue[(btm-btmMin)/(btmMax-btmMin+3)], {btm,btmMin,btmMax, (btmMax-btmMin)/(n-1)}], PlotLegend-> Table[btm, {btm,btmMin,btmMax, (btmMax-btmMin)/(n-1)}], LegendPosition->{.85,-.35}, LegendLabel->b*mu =, Epilog -> { Arrow[{.9*edmMax,0}, {1.07*edmMax,0}, HeadCenter->.25], Arrow[{0,.9}, {0,1.1}, HeadCenter->.25]}, PlotRange -> {{0,1.07*edmMax},{0,1.1}}, ImageSize -> 400]]; Just for laughs : With[{btmMin = -4,btmMax =4,edmMax = 2,n = 600}, Plot[Evaluate[ Table[1/(Exp[btm(edm-1)]+1), {btm,btmMin, btmMax, (btmMax-btmMin)/(n-1)}]], {edm,0,edmMax}, AxesLabel-> {ToString[TraditionalForm[e/mu]], n(e}}, PlotStyle -> Table[Hue[(btm-btmMin)/(btmMax-btmMin+3)], {btm,btmMin,btmMax, (btmMax-btmMin)/(n-1)}], Epilog -> { Arrow[{.9*edmMax,0}, {1.07*edmMax,0}, HeadCenter->.25], Arrow[{0,.9}, {0,1.1}, HeadCenter->.25]}, PlotRange -> {{0,1.07*edmMax},{0,1.1}}, ImageSize -> 400]]; Bob Hanlon Chantilly, VA USA ==== Have you tried the option inspector? You have there the possibility to change the font for a cell, a notebook or any selection: Format | OptionInspector | FormattingOptions | FontOptions. BTW, I tried Arial, but I found it more difficult to read.... ----- Original Message ----- ==== Assuming that you are using StandardForm for input, you'll probably want to change that form's font family. Edit the style sheet (I suggesting importing a private copy), then scroll down the sheet to FormatTypeStyles. Select the Standard Form cell and change the font to whatever you want. All StandardForm cells in your notebook will change. Hope this helps. Tom Burton ==== In terms of Mathematica this can be expressed as the difference between the following: In[1]:= Limit[Limit[(1 + y/n)^m, n -> Infinity], m -> Infinity] Out[1]= 1 In[2]:= Limit[(1 + y/Abs[x])^Abs[x], x -> Infinity] Out[2]= E^(I*Im[y] + Re[y]) The latter can of course be made equal to any number, real or complex except 0. So the whole original confusion relates to the meaning of 1^Infinity. If one interpreted it in the first sense (or simply as Limit[1^x,x->Infinity]) than the answer would have been 1. However, Mathematica adopts the more general approach, considering an expression involving Infinity to be Indeterminate unless all ways of representing it as a limit lead to the same answer. Of course one should not take this too strictly, for Mathematica gives: In[3]:= Infinity! Out[3]= Infinity although a pretty good case can be made for Sqrt[2Pi], see :) Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > MathGroup, > Ê > I don't know why all ofÊmy symbols disappeared when I copied and pasted > toÊmy last post.Ê My last post makes no sense.Ê I bet you now I'm going > to get a flood of comments about this.Ê Sorry.Ê > Ê > It should say: > Ê > A lot of people think that Lim n->00 (1+(1/n))^n =1.Ê Their reasoning > is this:Ê When n->00, then 1+(1/n)->1.Ê Now compute lim n->00 1^n =1. > Of course, this reasoning is too simple.Ê You have to deal with both of > the n's in the expression (1+(1/n))^n at the same time -- i.e., they > both go to infinity simutaneously: you can't figure that one goes to > infinity and then the other goes to infinity.Ê And in fact, if you let > the other one go to infinity first, you'd get a different answer: lim > n->00 (1+.0000001)^n=00.Ê So evidently the answer lies somewhere > between 1 and 00.Ê That doesn't tell us much; my point here is that > easy methods do not work on this problem.Ê The correct answer is a > number that is near 2.718281828... i.e. the constant e.Ê There's no > way you could get that by an easy method. ----- Original Message ----- > Sent: Sunday, August 11, 2002 6:12 AM > Ê > As a follow up to 's example: Some students seem to think that lim n->0 (1+(1/n))n = 1. Their > reasoning > is this: When n->0, then 1+(1/n) -> 1. Now compute lim n->0 1 n = 1. > This reasoning is just too simplistic. You have to deal with both of > the n's > in the expression (1+(1/n))n at the same time -- i.e., the > y both go to infinity simultaneously; you can't figure that one goes to > infinity > and then the other goes to infinity. In fact, if you let the other one > go > to infinity first, you'd get a different answer: lim n->0 > (1+0.0000001)n = > 0. So evidently the answer lies somewhere between 1 and > 0.Ê Easy methods do not work on this problem. The correct answer is a number that is near 2.718. (It's an important > constant, > known to mathematicians as e = aprrox. 2.718281828...) There's no way > you > could get that by an easy method. Jonathan Rockmann > mtheory@msn.com ----- Original Message ----- > 0^[Infinity] => 0, as expected; > 0.9^[Infinity] => 0, as expected; > 2^[Infinity] => Infinity, as expected; > 1^[Infinity] => Indeterminate, unexpected. Naively expected: 1. > For which reason(s) is 1^[Infinity] defined as Indeterminate? Presumably because, as a limit form, 1^Infinity is indeterminate. > In other words, if f(x) approaches 1 and g(x) increases without bound, > f(x)^g(x) need not approach 1. Consider the limit of (1+1/x)^x as x > increases without bound, for example.