>(unless it had the SequenceHold or HoldAllComplete attribute, but it has >neither of them) Which is very unfortunate, and it has been suggested in the past that SequenceHold should be added to If. Until this suggestion hopefully gets realized in a future Mathematica version I use work-arounds like: ReleaseHold[If[1 == 1, Hold[Sequence][], 2]] Rolf Mertig Mertig Consulting http://www.mertig.com ==== Something I didn't see mentioned is the fact that Mathematica almost always uses masks in the EPS of plots. I find that this complicates the editing process, and the very first thing I do in Illustrator is go Edit -> Select -> Masks and then delete them. I haven't yet encountered a plot where the Mask was necessary. -- Mark R. Diamond ==== >Mass-market >servers use an intermediate layer (a proxy server) to cache as many >images as they can on their own machines rather than going to the >network for each image, I may be wrong, but I thought that the use of a proxy server should be enabled by the user, by setting an option in his browser. Or is this you are referring to a sort of 'super proxy', transparent to the proxy a user can choose not to use? If it is a standard proxy it should be possible to disable the corresponding option in the web browser. cheers, Peltio and his two cents ==== Dear All, I have a rendering problem which stalls my mathematica. When I plot Plot[Gamma[x],{x,1,10}] everything is fine but changing the upper limit to 100 or 1000 just stalls mayhematica and I have to forcefully kill it. I use Mandrake 9.2 and have downloaded fonts and stuff with no result at all. Anybody has any idea what the problem maybe? Baris ==== > Is there an easy way to calculate the fourier series (discrete fourier > transfrom) of a real function f(x) if I already know what the > continuous fourier transform of f(x) is? Easy is a relative term, but there is a well defined relationship between the discrete and continuous Fourier transforms. > But how do I > calculate the discrete fourier transform of a function, which fourier > transfrom I know. You can find a paper which answers your question at http://www.ecf.utoronto.ca/apsc/courses/bme595f/notes/ discretevscontinuousfouriertrans2003.pdf. Ssezi ==== I guess, the best thing to do it to generate a list of values of Bessel (which is FT of your delta function) function using Table. This will be your discrete FT representation of the analytical Bessel function. Then you can proceed as usual to calculate Convolution. I have not tried it earlier, so please let me also know whether it works or not. Ravi using Table with adequote number of samples. > Is there an easy way to calculate the fourier series (discrete fourier > transfrom) of a real function f(x) if I already know what the > continuous fourier transform of f(x) is? > > Here is my particular application: > > I am doing convolutions of a 2-dimensional function f(x,y) with a > radially symmetric dirac delta-function d(a-r), where a is a constant > and r is just Sqrt[x^2+y^2]. I do the convolution by multiplying the > discrete fourier transforms of my two functions. Since I only know > f(x,y) on a grid I cannot do the convolution analytically. > > Obviously, it's not possible to represent a delta function discretely, > but if I represent the dirac delta function with a very peaked > Gaussian, I can get pretty good results, but it is not ideal. However, > the fourier transform of my dirac delta function in 2D is just a > Bessel function, so I was hoping to be able to calculate a very > accurate discrete fourier transform using that knowledge. But how do I > calculate the discrete fourier transform of a function, which fourier > transfrom I know. > > > Lasse > -- Ravi |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| | Ravinder Kumar Banyal (SRF), | | Indian Institute of Astrophysics, | | Koramangala Bangalore - 560 034. INDIA | | Ph No : 080 5530672 (IIA) 080 7931972 (Hoskote) | | 7931952 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All that is necessary for the triumph of evil is that enough good men do nothing --Edmund Burke. ==== > >> I have recently been learning a bit of functional programming >> using OCaml and was trying to translate tail recursion using auxillary >> local functions into Mathematica. > > Not sure why you really want or need these in Mathematica. My initial thought was that tail recursion is commonly used in functional programming languages to speed up functions and reduce stack usage, so it seemed an interesting exercise to translate it to a standard example Mathematica function i.e. factorial. Probably not overly useful unless I get involved with recursive data structures. > $RecursionLimit = Infinity; > > $IterationLimit = Infinity This is useful to know, thanks! > Because the code is wrong. It should read > > fact3[n_:Integer] := Module[ > {aux = Function[{i, acc}, If[i <= 0, 1, i aux[i - 1, acc]]]}, > aux[n, 1]] > No, there was a typo but that wasn't it - I meant to write aux=Function[{i,acc},If[i<=0, acc , aux[i-1,i acc]]]; ^^^ i.e. each call to aux holds the current value of the factorial being calculated so that when it hits the base case of the recursion it exits rather than recursing back upwards again. As Hartmut points out further downthread, the problem with this was trying to declare and initialise the local function in one step - in the recursive step it then tries to access the (non-existant) global function aux. Correct syntax would be ...Module[{aux}, aux=...; aux[n,1]]... > Paul Glad you still remember me! :) Hopefully not too long before I'm back for a visit - came back last July, probably back again at the end of this year. Matt ==== > Why reinvent the wheel ?? Well, I had hoped the wheel was already invented. The wheel I want is an implentation of a set of rules translating descriptions of PDEs to code, i.e., a FORTRAN or C representation, to insert into a larger, existing model. Please correct me if I am wrong, but NDSolve doesn't strike me as fitting that requirement. About a third of what we do in climatology is PDE's as normally understood; the remainder is ad hoc representation of boundary conditions and unresolved processes (cloud convection, radiative transfer). Regarding the conventional PDE part, going from a mathematical description to an executable involves a set of transformations each of which adds complexity to the model description, as well as tedium and opportunity for error in the effort. All these transformations (time differencing, space differencing, boundary conditions, domain decomposition for parallelization) are currently performed at great effort. The existing approach produces model code that is not just costly but also very opaque, and hence fails to serve some of the traditional cognitive purposes of a scientific model. What I'm after is a rapid development tool for the more Navier-Stokes-ish parts. The constraints which guide our numerical methods are quite definitely not the same as would be used in a general PDE solver. Performance is critical, as our calculations are enormous. Our accuracy requirements are very severe regarding conservation of passive tracer in ocean models, but quite lax in other ways. We are also interested, for efficiency reasons, in decomposing the problem into a vertically integrated part and a remainder. Finally, we are interested in decomposing the domain for parallelization, with careful attention to communication and bandwidth issues. What I'd like to see is a code generation tool: given formal descriptions of the PDE system, the geometry of the problem, the time differencing scheme, the space differencing scheme and the processor decomposition, to generate compilable parallel code. This would expand from order 100 lines of human-generated source code to order 10,000 lines of compilable code in C or FORTRAN. The 100 lines of human-generated code would serve as a comprehensible and reviewable model. Others have made efforts along these lines using templates in C++; the reports I have heard claim that in practice the problem with this approach is in the compile phase. The compilation of models generated with these products is reputedly time-consuming and unreliable. In any case, the efforts have been focussed on engineering problems which have substantially different performance goals than we do. My idea is to have a high-level model description language translated into a low-level high performance language like FORTRAN or C with MPI calls. Although this strikes me as a fairly obvious idea, so far I have not found anything of the sort already in existence. (Maybe it would be of little research utility outside geophysical fluid dynamics, though I think it would have a lot of didactic value in numerical methods courses.) What I'm considering here is the architecture of the translation mechanism. When I considered how to do this, it occurred to me that what I was talking about was a set of rules, so I thought about Mathematica. As described so far, the tool itself doesn't need to know very much mathematics, but once I had Mathematica in mind it occurred to me that the phase and stability analyses for these methods could be an almost free byproduct of the effort. Another approach I am considering is to use MathML and XSLT. Perhaps Mathematica's role will simply be as a MathML editor. I don't think it's realistic to build a complete climate model in Mathematica, and I'm not proposing to do that. -- mt -- Michael Tobis http://geosci.uchicago.edu/~tobis ==== > I use the Mathematica command FortranForm[exprn] to generate > FORTRAN code. I > have a number of complicated expressions and the FortranForm > output looks > fine on the screen. However, when I copy the fortran code to > a text editor, > I find that special characters like InvisibleSpace have been > inserted. > > Is there a way to copy and paste FORTRAN code without > encountering this > problem ? You can copy the expression as plain text, but a better solution might be to write it to a file via Write[...] Dave. ==== Dear all, I want to ask how to express the following terms into the form of (x1+x8), (x1-x8), (x2+x7), (x2-x7), etc. This is variable substitution. How can do this manipulation in mathematica symbolically? [ a01*x1+a02*x2+a03*x3+a04*x4+a04*x5+a03*x6+a02*x7+a01*x8] [ a05*x1+a06*x2+a07*x3+a08*x4-a08*x5-a07*x6-a06*x7-a05*x8] [ a09*x1+a10*x2-a11*x3-a12*x4-a12*x5-a11*x6+a10*x7+a09*x8] [ a13*x1-a14*x2-a15*x3-a16*x4+a16*x5+a15*x6+a14*x7-a13*x8] [ a17*x1-a18*x2-a19*x3+a20*x4+a20*x5-a19*x6-a18*x7+a17*x8] [ a21*x1-a22*x2+a23*x3+a24*x4-a24*x5-a23*x6+a22*x7-a21*x8] [ a25*x1-a26*x2+a27*x3-a28*x4-a28*x5+a27*x6-a26*x7+a25*x8] [ a29*x1-a30*x2+a31*x3-a32*x4+a32*x5-a31*x6+a30*x7-a29*x8] -Walala ==== Since Selwyn has fallen down in the venting department I will offer a few remarks. For the last few years I have used Mathematica exclusively for technical writing, mostly because it gives me better control over figure placement and keeps everything in a single file. That said, it is nonetheless an aggravating experience in many ways. The subscript/quotient font size problem is a daily irritation. Here's my question. TeX does an excellent job in this regard. TeX has been around since the '60s and is open source. Why doesn't someone at WRI just look at how TeX does it and incorporate the rules? Why reinvent the wheel especially if the wheels you produce in house always seem to have corners on the rim? A personal bugaboo of mine is the spelling checker. I don't have problems with the spelling checker in any other software, just Mathematica. Ever since 3.0 I have been trying to teach it that bivector is a word. No luck. It just keeps telling me to try bevatron instead. I tell it to learn the word, it puts it in some user defined dictionary, and then ignores it. I keep a copy of the Summer-Fall 1999 issue of Mathematica in Education and Research in a file cabinet just so I can look up how to change an unmatched bracket from pink to black whenever I want to define a multiline function (p. 87). Indications are that someone at WRI wants to develop Mathematica into a first rate technical publishing tool. It should be explained to them that this is just a waste of time and talent if the use of the tool is to be such a jealously guarded secret. If Mathematica is to have more than marginal use as a technical publication system WRI needs to produce, in house or outhouse, a Mathematica equivalent of The Joy of TeX. Cursory documentation and scattered hints in journals will not do it. On Jan 22, 2004, at 3:37 AM, Selwyn Hollis wote: > >> I didn't reply to this thread earlier because I figured one of the >> usual >> experts would pick it up and run with it, but it appears not. By >> reading >> Selwyn's answer, I think he knows how to do this but decided to vent >> about >> the method rather than explain it. > > What, me vent? I could show you venting, but I won't. > > The real issue here is why this design flaw has persisted from version > 3.0 to version 5.0. It is clearly an example of sheer corner-cutting. > There is no typographical rationale whatsoever for treating numerators > and denominators of fractions the same way as subscripts and > superscripts. > > For example, what if I want to have ScriptSizeMultipliers->1 in a > fraction that contains subexpressions with superscripts? Then the > superscripts are the same size as the bases to which they are attached, > and the whole thing looks silly -- thus I have go in and do a lot of > meticulous tweaking. > > Again, I could be missing something and have wasted countless hours in > trying to make many hundreds of pages worthy of publication. But maybe > it's my own fault for dreaming that I could approach TeX-like quality > with Mathematica. > > ----- > Selwyn Hollis > http://www.math.armstrong.edu/faculty/hollis > (edit reply-to to reply) > > > >> In the Option Inspector is an option called ScriptSizeMultipliers. >> This, >> combined with the ScriptMinSize, determines sizing for fractions and >> scripts (sorry, Selwyn). The easiest way to do what Murray and Sabit >> want >> is to set the ScriptSizeMultipliers option to 1. This could be set at >> the >> notebook or global level, as you feel appropriate, or wrapped >> individually >> around fractions if you don't want sub/superscripts to pick up the >> option >> value. >> >> To answer Sabit's second question, select the bracket of the cell >> you'd >> like to change, and use the Option Inspector to set the >> SingleLetterItalics >> option to False at the selection scope. >> >> Sincerely, >> >> John Fultz >> jfultz@wolfram.com >> User Interface Group >> Wolfram Research, Inc. >> >> > I quite agree that this is an annoyance with Mahematica's typsetting > of > mathematics. > > An underlying difficulty is that there is no separate notion of > display > math -- mathematical expressions displayed on separate lines -- as > opposed to math within normal paragraphs of text. This may be an > unfortunate front-end design limitation. > > The problem is reminiscent of the same problem in LaTeX, where > in-line, > built-up fractions (and other constructs) have their components > small. > But in LaTeX, there is an option (which one needs to apply to each > instance) to make such in-line math displaystyle, which enlarges the > components to the same large size as if they were in a display. > > I devoutly wish there were such a capability in Mathematica -- > whether a > per-instance option as with LaTeX, or a global option for a notebook. > > >> My understanding is that the size of fractions is determined by the >> same option that determines the size of subscripts and superscripts, >> which is highly unfortunate. I could be wrong about this; if so I'd >> love to find out. I find it a major pain in the neck always to have >> to >> increase the size of fractions manually. Maybe this is an >> improvement >> we can hope for in version 6.0. >> >> ----- >> Selwyn Hollis >> http://www.math.armstrong.edu/faculty/hollis >> (edit reply-to to reply) >> >> > I am trying to do some typesetting with mathematica. I noticed that > in > some styles fractions are set in reduced point size. What is the > option that would fix this? I want both denominator and the > numerator > set in the same size as the text. > > Also I have the single letter italic enabled for cells where I have > the equations but in the cells where there is a lot of text I don't > want this option. Now I copy and paste a previous cell and use it > as > new cell but I am sure there is a better way, probably with styles. > Wolfram site lists two documents about typesetting but they are not > available to download. Does anyone know a good reference for > tpesetting with mathematica? >> >> >> > > Garry Helzer Department of Mathematics University of Maryland College Park, MD 20742 301-405-5176 gah@math.umd.edu ==== After a long time using the program I noticed that in the help pages some characters (the special ones, the brackets) are shown incorrectly. I suppose there is no way to solve this from within Mathematica, I should be an environment issue Since I cannot send an attached GIF to show the problem, the effect is that when a formatted expression is shown the brackets are displayed as D or @ and some characters as mini empty boxes, bullets as the Yen currency sign and else... Carlos ==== Jim: There are two ways to post an example. display a text window into which you can copy your Input lines, and recreate your output lines in TextForm. The second way is to view your Notebook with a text editor, and then copy all of that text into a posting. This can be used by downloaders to recreate your notebook. Most simple examples are done the TextForm way. For an example of the Notebook route, see ... Sender: steve@smc.vnet.net ==== >I want to modify a notebook....first, it's overall background color is >grey...I want to change that to white.... 1) Use the menu Formal > Option Inspector. 2) Change the scope from selection to notebook. 3) In the Lookup field put Background and hit enter. 4) If there's a bullet next to Background option, click it. Otherwise, select the box on the right and choose the color. >second, it contains cells that >have a Section heading with cell inputs....I want to create a Section with >input cells that I can insert into the Section.....another words, the top >Section collapses to contain all the other Sections....how do I do this? The top Section should be a Section. The other Sections should be Subsections. Select the cells you want to change and use the Format > Style menu. >jerry blimbaum -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs http://omegaconsultinggroup.com ==== On a modern computer, package loading is quick. Unless the package is very large (or part of a large set of interdependent packages), DeclarePackage is not really necessary. Just use Get or Needs in c.m. However, if you must load the packages when f is first used, you can create a stub function. Something like: BeginPackage[a`] f := ( Clear[f]; Get[a`]; Needs[b`]; f ) EndPackage[] In[1]:= << c` In[2]:= ?f a`f f := (Clear[f]; << a`; Needs[b`]; f) So f is defined to load a` and b`, which re-defines f. In[3]:= f[1] Out[3]= 1 In[4]:= ?f a`f f[0] = 0 f[1] = 1 >Suppose we have a package a.m defining function f: > >BeginPackage[a`] >f[0] = 0 >EndPackage[] > >Then we create package b.m which introduces additional definitions for >f: > >BeginPackage[b`,a`] >f[1] = f[0] + 1 >EndPackage[] > >Now after loading b.m we'll have f[0]=0 and f[1]=1. Finally, we want to >create a package c.m that determines when b.m should be autoloaded. We >add the following line to c.m: > >DeclarePackage[b`,f] > >Unfortunately, it doesn't work that way: > >In[1]:= ><f[1] > >Out[2]= >1+f[0] > >(standalone kernel will also give f::shdw warning). The reason is that >DeclarePackage creates symbol f (with attribute Stub) in the b` context. >This implementation decision seems rather questionable: the idea of >DeclarePackage is to load b.m when f is first used, which is exactly >what we want here -- but nobody said the symbol f was needed in context >b`! > >Probably this difficulty can be avoided by some creative usage of Remove >and $NewSymbol, but simply adding Remove[b`f] to b.m won't solve the >problem completely. > >This is exactly the situation with GeometryPolytopes.m, ><packages, but not Tetrahedron, Cube and others because there are >definitions for them both in Polytopes.m and Polyhedra.m. > >Maxim Rytin -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs http://omegaconsultinggroup.com ==== MathGroup: Do all of a Notebook's Option Browser settings remain after it is best with 1.67 Magnification. After changing Global Font Magnification to 1.67, I've found some notebooks hang on to Magnification = 1, and I have to reset them to 1.67 with the Option Browser. However, when I inspect these notebooks with a text editor, their code contains neither Magnification nor 1.67. This raises the question of what happens to a Notebook's settings when Magnification = 1.67 to retain this setting. I have the impression that non-standard font magnifications will get lost in transmission. Does anyone know a way to guard against Notebook transmission losses? Harold ==== > Does anyone know if there are any public domain packages for solving > problems in reservoir engineering - I'm interested in inflow > performance, leak-off and water injection type problems. > > Robert Prince-Wright Try this web site: http://pumpjack.tamu.edu/~valko/Course_Material/Pete689%20Flow%20with%20Math ematica/ It's a university course using Mathematica for fluid flow problems in petroleum engineering. Bill Haneberg Consulting Geologist www.haneberg.com ==== Using Mathematica under Windows, the function printDirectoryNotebooks defined below prints all the Mathematica notebooks in a user-specified directory. For example: printDirectoryNotebooks[e:Temp] But it does not work using Mac OS-X. Can you indicate how it should be changed so it will be platform-independent? printNotebook[nbname_] := Module[{nb = NotebookOpen[nbname]}, NotebookPrint[nb]; NotebookClose[nb]; nbname] printDirectoryNotebooks[dirName_?StringQ] := Module[{dir = SetDirectory[dirName]}, printNotebook[dir <> / <> #] & /@ FileNames[*.nb]] In particular -- and I believe this is part of the problem -- how from within Mathematica can one determine the path-separator character directly (without, say, querying $System and then accordingly select the path-separator character)? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 ==== Unfortunately, a randomly chosen real number that ISN'T irrational according to this test still has probability 1 of being irrational. (If the probability measure is anything reasonable, anyway -- if the CDF has only countably many points of discontinuity, for instance.) The probability that a user intended the number to be rational, on the other hand, is completely imponderable. Bobby > On second thought, I think this is a better idea: > > IrrationalQ[x_] := Denominator[Rationalize[x,.0001]] > 50 > > With it, IrrationalQ[Random[]] returns True most of the time, as it > should (probability approx .85), but returns False often enough to be > interesting. > > ----- > Selwyn Hollis > http://www.math.armstrong.edu/faculty/hollis > (edit reply-to to reply) ==== > I always find me in troubles when integrating ODE that I think Mathematica > should be able to do. It's all right for the very simplest, but consider for > instance the following: > > !(DSolve[((x + 2 x^2 + x^3)) (y')[x] + (x^2) (y'')[x] == A, y, > x]) > > 'A' a constant. Well, the problem is that I don't even the clue that > Mathematica *cannot* integrate it, there is some output with gibberish, like > K$14646 and the like (those are intermediary variables I guess). If you look up the online documentation for DSolve and scroll down to the Further Examples section it says that K$ variables are used as dummy integration variables. > So what is wrong? Nothing. > Is Mathematica expected to return such outputs? Yes. Have a look at http://physics.uwa.edu.au/pub/Mathematica/MathGroup/FirstOrderDE.nb for a first-principles analysis of your ODE. By series expansion it is straightforward to show that the solution to your ODE is not analytic at x == 0. Paul -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul ==== > > I always find me in troubles when integrating ODE that I think Mathematica > should be able to do. It's all right for the very simplest, but consider for > instance the following: > > !(DSolve[((x + 2 x^2 + x^3)) (y')[x] + (x^2) (y'')[x] == A, y, > x]) > > 'A' a constant. Well, the problem is that I don't even the clue that > Mathematica *cannot* integrate it, there is some output with gibberish, like > K$14646 and the like (those are intermediary variables I guess). So what is > wrong? Is Mathematica expected to return such outputs? > Use the general formula youself with y' = z, P=x^2/(x+2x^2+x^3), Q=-A/(x+2x^2+x^3) z' + P(x) z + Q(x)==0 is solved by z = exp(int^x P(s) ds) ( int^x ( exp(- int^r P(s) ds)) Q(r) dr ) as one verifies by elementary calculus. F[x_] := Integrate[P[s1], {s1, a, x}] z[x_] := Exp[-F[x]]Integrate[Exp[F[s2]] Q[s2], {s2, a, x}] z'[x] + P[x]z[x] // FullSimplify You can not expect Mathematica or anyone else to integrate exponentials of a rational functions two times. So expect something ugly and be pleased if the formal expression is printable. In the best case some special functions may do the job or the series expansion may be simple. NIntegrate gives you every number. -- Roland Franzius ==== > > I always find me in troubles when integrating ODE that I think Mathematica > should be able to do. It's all right for the very simplest, but consider for > instance the following: > > !(DSolve[((x + 2 x^2 + x^3)) (y')[x] + (x^2) (y'')[x] == A, y, > x]) > > 'A' a constant. Well, the problem is that I don't even the clue that > Mathematica *cannot* integrate it, there is some output with gibberish, like > K$14646 and the like (those are intermediary variables I guess). So what is > wrong? Is Mathematica expected to return such outputs? The result is the general expression for first order linear ODEs. {{y[x] -> C[2] + Integrate[E^(-2*x - x^2/2 - Log[x])*C[1] + (A*E^(-2*x - x^2/2)*Integrate[E^(2*s + s^2/2)/s, {s, 0, x}])/x, x]}} The innermost dummy variables of the integral in the exponent gets an localized standard name - DSolve't - for me. The integral cannot be solved in this notation because the lower boundary 0 for s produces a singularity. You have do to some work by hand here. -- Roland Franzius ==== I'm trying to solve a fairly complicated system of related rates problems and would like to use Mathematica to expand my knowledge of some of the mathematics, as well as actually solve parts of the problem. I couldn't find any examples on the archive of solving related rates problems and would appreciate some advice. My perspective is essentially that of someone who can do most of the calculations by hand but I have no idea how to approach the problem with Mathematica. Just to put a bit of meat into this but keeping it much simpler that the problem I really want, consider an oBject (B) approaching a bullseye that has one ring at a distance R from the centre (C) of the bulls-eye. Distance from target at time t is z[t]. Angle theta is angle RBC. How can I calculate d-theta/dt. Easy enough by hand, with dz/dt as the approach velocity, and using the chain-rule to obtain d-theta/dt from d-theta/dz and dz/dt. But what is the appropriate way to set up such a problem in Mathematica? Is the chain-rule explicit in the set-up? Should I be using DSolve, and if so how? Do I need to create a dummy function for the velocity, or can I specify the relationships between theta and z, and between velocity and z and go from there. I've chosen this particular problem deliberately because of the inverse trigonometric functions that arise both here and in the actual problem I have. Guidance of any kind by way of (1) reference to a book; (2) web site; (3) example would be greatly appreciated. I noted one comment on the archive where the author seemed to be saying that learning the mathematics was the difficult part, and students could easily construct the Mathematica for related rates problems. I'm not a student ... and my problem is the reverse! -- Mark R. Diamond 3848 ==== Below I have an excerpt from a program that solves a profit maximizing problem and reports the profits of firm 1 then firm 2. I would like to add an additional element to this. I would like to assume firm 1 has developed technology that decreases costs by a certain amount every time period (iteration). As a result, although both firms made equal profits in the first time period, firm 1 will enjoy increased profits over time while firm 2's profits will remain constant. I have generated the appropriate output but I can't get my code to work so that I can plot both profit functions (firm 1 and firm 2) out together on the same graph. can anyone make any sense out of the code provided below? CODE ===== (list1=Table[{x,x1},{x,1,10,1}]; list2=Table[{x,x2},{x,1,10,1}];); For[i=1,i<5,i++,Print[CournotProfit1]; Print[CournotProfit2]; Cost1=Cost1-.1Cost1; Print[new cost firm1]; Print[Cost1]; CournotProfit1=Simplify[q1cournot*(Pcournot-Cost1)]; CournotProfit2=Simplify[q2cournot*(Pcournot-Cost2)]; x1=CournotProfit1; x2=CournotProfit2; Append[list1,x1]; Append[list2,x2]] MultipleListPlot[list1,list2] OUTPUT (profits for firm 1 and firm 2 over time (iterations)) ======= 7.11111 7.11111 7.64444 7.11111 8.12444 7.11111 8.55644 7.11111 etc.... ||||||||||||||||||||||||||||||||||||||||||||||||| Timothy S. Kochanski M.S. Economics Eugene, Oregon (541) 543-9742 Success is going from failure to failure without a loss of enthusiasm. Sir Winston Churchill |||||||||||||||||||||||||||||||||||||||||||||||||||| --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! ==== Not exactly sure what you're after, but some combination of PlotRange, AspectRatio, and ImageSize should do it; e.g., Plot[Sin[10*x], {x, 0, 2*Pi}, PlotRange -> {{-Pi,3*Pi},Automatic}, AspectRatio -> Automatic, ImageSize -> 500] ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis (edit reply-to to reply) > MathGroup: I have a function I want to Plot between 0.5 and 1.0 with a stretched > out x-axis. I want to put a horizontal magnifying glass on the > function between 0.65 and 0.75, because it wiggles a lot in this part > of its domain. I tried to find a Plot option which allows the x-axis to stretch > horizontally across the screen. I experimented with AspectRatio - 10, and found I could do y-axis (Range) stretch with no problem. But > when I tried AspectRatio -> 0.1, the y-axis collapsed, and the x-axis > did not stretch at all. I'm stumped. I can't find an x-axis stretching option that produces > more on-screen horizontal plot details. Does anyone know a way to stretch the x-axis in Mathematica Plots? Harold ==== I want to plot the two functions in one Plot output +0.5x^2-x (definition-range -3<=x<=0) -0.5x^2+x (definition-range 0<=x<=3) I can't find a mathematica 4.0 solution, please help! -ManFis - ==== I want to plot the two functions in one Plot output > +0.5x^2-x (definition-range -3<=x<=0) > -0.5x^2+x (definition-range 0<=x<=3) Plot[(1-.5x)*Abs[x],{x,-3,3}] ==== Needs[Graphics`Graphics`]; f1[x_] := 0.5x^2-x; f2[x_] := -0.5x^2+x; This works for any functions and whether or not they share a domain boundary DisplayTogether[ Plot[f1[x],{x,-3,0}], Plot[f2[x],{x,0,3}], PlotRange->All]; Since your functions are piecewise continuous you can turn one off and the other on at the common domain boundary Plot[ f1[x]+UnitStep[x]*(f2[x]-f1[x]), {x,-3,3}, PlotRange->All]; Or, since your two functions share a common form you can combine them into a single function. Plot[Abs[x](1-0.5x), {x,-3,3}, PlotRange->All]; Bob Hanlon << I want to plot the two functions in one Plot output +0.5x^2-x (definition-range -3<=x<=0) -0.5x^2+x (definition-range 0<=x<=3) I can't find a mathematica 4.0 solution, please help! ==== Plot[ Which[ x < 0, 0.5x^2 - x, True, -0.5x^2 + x], {x, -3, 3}] Jens > I want to plot the two functions in one Plot output > +0.5x^2-x (definition-range -3<=x<=0) > -0.5x^2+x (definition-range 0<=x<=3) I can't find a mathematica 4.0 solution, please help! -ManFis - ==== Bob: > Although NIntegrate works without explicitly increasing the precision. > So the precision is impacted by the sequencing of the calculations. NIntegrate[k[f], {f, 0.6214, 0.5242}] -0.139838 Can you explain what you meant by sequencing of the calculations? I calculated the integral shown above after restarting Mathematica, and I obtained the answer shown above. Harold ==== Surely someone will come up with a better example, but here are several computations of the identical (in theory) expression. Change k, and you'll see various behaviors. The first element of the output list is accurate to as many places as shown. The others are wrong to varying degrees. I didn't use Sum, because it adds in a smart order; I wanted to control things. (try setting addTable=Sum) The really curious thing is that the third and fourth results should be identical (I think) but they aren't! Also, using Attributes[addTable] = {HoldAll} changes several answers. add[x_List] := (For[sum = 0; i = 1, i <= Length[x], i++, sum += x[[i]]]; N[sum]) Attributes[addTable] = {}; addTable[x__] := add[Table[x]] first = 20; last = 40; k = 20; a = 20/9; InputForm[ N[{addTable[a^(-n) - (a + 10^(-k))^(-n), {n, first, last}], addTable[N[a^(-n)] - N[(a + 10^(-k))^(-n)], {n, first, last}], add[Table[ N[a^(n - first - last)] - N[(a + 10^(-k))^ (n - first - last)], {n, first, last}]], addTable[ N[a^(n - first - last)] - N[(a + 10^(-k))^ (n - first - last)], {n, first, last}], addTable[N[a^(-n)], {n, first, last}] - addTable[N[(a + 10^(-k))^ (-n)], {n, first, last}], addTable[ N[a^(-n)] - N[(a + 10^(-k))^ (n - first - last)], {n, first, last}]}]] {1.9748897304222703*^-26, 0., 9.137784495123884*^-24, 0., 0., -1.3234889800848443*^-23} Bobby > Bob: > Although NIntegrate works without explicitly increasing the precision. > So the precision is impacted by the sequencing of the calculations. NIntegrate[k[f], {f, 0.6214, 0.5242}] -0.139838 Can you explain what you meant by sequencing of the calculations? I > calculated the integral shown above after restarting Mathematica, and > I obtained the answer shown above. Harold ==== NIntegrate[k[f], {f, 0.6214, 0.5242}] does not give the same result as N[Integrate[k[f], {f, 0.6214, 0.5242}]]. Both are calculations with the same inexact numbers as input so the resulting precision is determined by both the precision of the input as well as the sequence of internal operations on that input. My choice of words is perhaps not precise. That is why I tend to stick to just providing a Mathematica expression. Bob Hanlon << Bob: > Although NIntegrate works without explicitly increasing the precision. > So the precision is impacted by the sequencing of the calculations. NIntegrate[k[f], {f, 0.6214, 0.5242}] -0.139838 Can you explain what you meant by sequencing of the calculations? I calculated the integral shown above after restarting Mathematica, and I obtained the answer shown above. ==== I like the organization of the help browser. I was wondering if I can organize my own Mathematica files into a browser like that? I know it ==== Harold, I'm not certain if I completely understand your question, but I'm going to take it that you just want to produce a low aspect ratio plot. You can do it if you specify the AspectRatio AND the ImageSize with two arguments for the ImageSize. Plot[Sin[x], {x, 0, 30Pi}, AspectRatio -> 0.1, ImageSize -> {600, 110}, Frame -> True, PlotLabel -> Long Sine Wave]; But notice that the aspect ratio of the ImageSize is much greater than the AspectRatio of the plot. This is because it must make room for the various labels and these change the overall plot aspect ratio. The problem is that there is no easy method to calculate the space taken by the labels. If one uses... Plot[Sin[x], {x, 0, 30[Pi]}, AspectRatio -> 0.1, ImageSize -> {600, 60}, Frame -> True, PlotLabel -> Long Sine Wave]; a poor plot is obtain. Mathematica does a poor job of automatically adjusting low aspect ratio plots and there is something of a loss of exact control here. There is no way for the user to specify precisely how the graph region, say the Frame in a Frame plot, will fit into the overall displayed region. For example, PlotRegion does not refer to the frame region but an overall region including the labels. The following plot shows that the PlotRegion extends to the left of the y frame labels and the y PlotRegion is not very well filled. There is considerable blank space at the top and bottom. Plot[Sin[x], {x, 0, 30Pi}, AspectRatio -> 0.1, ImageSize -> {600, 110}, PlotRegion -> {{0.1, 0.9}, {0, 1}}, Frame -> True, PlotLabel -> Long Sine Wave, Background -> GrayLevel[0.95]]; One solution might be to make PlotRegion refer to the frame or implied frame, but I'm not certain of all the interactions. It would be nice to have a better control of the region around the plotted frame. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ did not stretch at all. I'm stumped. I can't find an x-axis stretching option that produces more on-screen horizontal plot details. Does anyone know a way to stretch the x-axis in Mathematica Plots? Harold ==== In this case you can use the InequalityGraphics package. Needs[Graphics`InequalityGraphics`] InequalityPlot[1 < x^2 + y^2 < 2, {x, -3, 3}, {y, -3, 3}]; Here is a second, slightly more interesting example. Needs[Graphics`Colors`] InequalityPlot[1 + (1/2)*(y/(x^2 + y^2)) < 2*(x^2 + y^2) < 4, {x, -3, 3}, {y, -3, 3}, Fills -> Eggshell, BoundaryStyle -> {Olive}, Background -> Burlywood]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ AxesLabel -> {x, y}, PlotStyle -> {{}, Dashing[{0.02}]}]; ==== I don't know whether the equality should be true, but it's very clear that 10 isn't a base-10 digit! Frequencies[First[RealDigits[ pisot]]] {{2086, 0}, {422, 1}, {427, 2}, {434, 3}, {467, 4}, {444, 5}, {452, 6}, {447, 7}, {437, 8}, {381, 9}, {3, 10}} Bobby > This is wrong: In[1]:= pisot = N[((1/3)*((1/2)*(27 + 3*Sqrt[69]))^(1/3) + (2/(27 + > 3*Sqrt[69]))^(1/3))^27351, 6000]; > Out[2]:= False If you look at the value returned by RealDigits[pisot] contains three > 10's!!! > Enrique Zeleny > Universidad Autonoma de Puebla > Mexico ==== You probably don't have a binary for conversion to pbm. Try some other format. Yas > First, I verified that there were no problems with my Hard Disk. Then I > deleted the Mathematica 4.1 folder, Mathematica's Preferences folder and all > of their contents. I then re-installed Mathematica 4.1 and executed the > following commands: {4.1 for Power Macintosh (November 2, 2000), 0} Export[out.dat, {{5.7, 4.3}, {-1.2, 7.8}}] > out.dat tmp=Plot[x, {x, 0, 1}]; Export[plot.pbm, tmp] ..at which point Mathematica beeped and the MathLink icon started flashing on the > right of the menu bar. I selected 'Cancel' and received the following > output: LinkOpen::linke: MathLink error: unknown error > plot.pbm Suggestions appreciated. js > ==== There was a discussion on MatrixForm and evaluation recently. And here is an example where it is simply inconvenient. See those threads in the archive for a better explanation and ways to evaluate with MatrixForm display throghout. A rule I follow is, use MatrixForm only when you want to visualize the matrix in a Textbook form. It's not really necessary for calculations. Get rid of the MatrixForm in m1, m2 and m3. Do the calculations for mm and then display the result in MatrixForm. I get In[15]:= mm=m1+m2+m3 Out[15]= {{-1, 1, -1, 1}, {-1, -3, 3, 1}, {-1, 1, -1, 1}, {3, 1, -1, -3}, > {-1, 1, -1, 1}} In[16]:= MatrixForm[mm] Out[16]//MatrixForm= -1 1 -1 1 -1 -3 3 1 -1 1 -1 1 3 1 -1 -3 -1 1 -1 1 Yas I want to take a Column Vector and multiply it by a Row Vector to create an > Outer Matrix. In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 > Row Vector and output a 5x4 Matrix. I then want to add several of these Matrices together and obtain a final > Matrix. I tried the following: x1 = {1, -1, -1, 1, 1}; > y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; > y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; > y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] > m2 = MatrixForm[Outer [Times, x2, y2] ] > m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. > What am I doing wrong? Mike McCain > MichaelSMcCain@cs.com > ==== Mike, The problem is MatrixForm and there was just considerable discussion of the issue on MathGroup. The problem is that MatrixForm is not transparent as some of the other Forms are. So Mathematica can't add the MatrixForms. I always do it this way... (m1 = Outer [Times, x1, y1]) // MatrixForm (m2 = Outer [Times, x2, y2]) // MatrixForm (m3 = Outer [Times, x3, y3]) // MatrixForm (mm = m1 + m2 + m3) // MatrixForm The parentheses prevent MatrixForm being wrapped around m1, m2, m3 and mm. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] m2 = MatrixForm[Outer [Times, x2, y2] ] m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. What am I doing wrong? Mike McCain MichaelSMcCain@cs.com ==== right. Actually, though, we often want to copy and paste them back into Mathematica. Bobby > David: I added Bobby Treat's InputForm palette to my library. window is that subscript/superscript expressions print more > intuitively than from the InputForm palette. Consider the following example from Built-in Functions > Algebraic > Computation > Calculus > Derivative, equation 11. > Using the InputForm palette, we have this raw text ... In[11]:= > Derivative[1, 2, 3][h][x, y, z] > Out[11]= > a*(b - 1)*b*(c - 2)*(c - 1)*c* > x^(a - 1)*y^(b - 2)* > z^(c - 3) In[11]:= Derivative[1, 2, 3][h][x, y, z] -1 + a -2 + b -3 + c > Out[11]= a (-1 + b) b (-2 + c) (-1 + c) c x y z > To my eye, the TextForm expression is more intuitively and rapidly > read than Bobby's PaletteForm expression. That's why I recommend it > for postings. Best wishes, > Harold ==== here a year or two ago. Bobby > David: I added Bobby Treat's InputForm palette to my library. window is that subscript/superscript expressions print more > intuitively than from the InputForm palette. Consider the following example from Built-in Functions > Algebraic > Computation > Calculus > Derivative, equation 11. > Using the InputForm palette, we have this raw text ... In[11]:= > Derivative[1, 2, 3][h][x, y, z] > Out[11]= > a*(b - 1)*b*(c - 2)*(c - 1)*c* > x^(a - 1)*y^(b - 2)* > z^(c - 3) In[11]:= Derivative[1, 2, 3][h][x, y, z] -1 + a -2 + b -3 + c > Out[11]= a (-1 + b) b (-2 + c) (-1 + c) c x y z > To my eye, the TextForm expression is more intuitively and rapidly > read than Bobby's PaletteForm expression. That's why I recommend it > for postings. > Harold ==== Do as follows: p1 = Plot[ .5x^2 - x, {x, -3, 3}, DisplayFunction -> Identity]; p2 = Plot[- .5x^2 + x, {x, 0, 3}, DisplayFunction -> Identity]; Show[p1, p2, DisplayFunction -> $DisplayFunction]) I want to plot the two functions in one Plot output > +0.5x^2-x (definition-range -3<=x<=0) > -0.5x^2+x (definition-range 0<=x<=3) I can't find a mathematica 4.0 solution, please help! -ManFis - > -- Ravi |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| | Ravinder Kumar Banyal (SRF), | | Indian Institute of Astrophysics, | | Koramangala Bangalore - 560 034. INDIA | | Ph No : 080 5530672 (IIA) 080 7931972 (Hoskote) | | 7931952 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All that is necessary for the triumph of evil is that enough good men do nothing --Edmund Burke. ==== No dice. After some trial and error, I discovered PNM.EXE is the appropriate binary for conversion to pbm. If I select it after the beep (see below), then everything works fine until I quit the kernel. I tried explicitly including its directory in $Path, but the (re-launched) kernel still fails to find it. js > You probably don't have a binary for conversion to pbm. Try some other > format. Yas >> First, I verified that there were no problems with my Hard Disk. Then I >> deleted the Mathematica 4.1 folder, Mathematica's Preferences folder and all >> of their contents. I then re-installed Mathematica 4.1 and executed the >> following commands: >> {4.1 for Power Macintosh (November 2, 2000), 0} >> Export[out.dat, {{5.7, 4.3}, {-1.2, 7.8}}] >> out.dat >> tmp=Plot[x, {x, 0, 1}]; >> Export[plot.pbm, tmp] >> ..at which point Mathematica beeped and the MathLink icon started flashing on >> the >> right of the menu bar. I selected 'Cancel' and received the following >> output: >> LinkOpen::linke: MathLink error: unknown error >> plot.pbm >> Suggestions appreciated. >> js > ==== I must compute values of ratios n-th orthogonal polynomial with weight > cos(x) (-PI, PI). Do you have any suggestions, scripts, e-books, > informations? If it possible I ask about fast answer. Transform to y=Sin x, dy = Cos x dx and look for the family LegendreP[n,0,Sin[x]]/Sqrt[Integrate[LegendreP[n,0,x]^2]{x,0,1}]. -- Roland Franzius ==== convert it into 16 bit PNG's and use *my* PNG Import[] function from http://phong.informatik.uni-leipzig.de/~kuska/mcpng.html or write a MathLink program by your self, that uses Sam Leffers tifflib http://www.libtiff.org/ Jens > I'm trying to import a 16-bit greyscale TIFF file into Mathematica 5.0. > Is there any way to do this directly? > If not, has anybody got the structure of this kind of files, that could > help to read out the relevant information?? > Stephan Junek ==== See the help notes on Import and Export. And maybe the links contained in, http://www.faqs.org/faqs/graphics/fileformats-faq/part3/section-147.html Yas I'm trying to import a 16-bit greyscale TIFF file into Mathematica 5.0. > Is there any way to do this directly? > If not, has anybody got the structure of this kind of files, that could > help to read out the relevant information?? > Stephan Junek > ==== Needs[Graphics`ImplicitPlot`]; f1 := x^2 + y^2 == 2; f2 := x^2 + y^2 == 1; plt = ImplicitPlot[{f1, f2}, {x, -3, 3}, AxesLabel -> {x, y}, PlotStyle -> {{}, Dashing[{0.02}]}]; plt /. {{Line[pnts_]} :> {{RGBColor[1, 0, 0], Polygon[pnts]}, Line[pnts]}, {Dashing[dd_], Line[pnts_]} :> {{RGBColor[1, 1, 1], Polygon[pnts]}, {Dashing[dd], Line[pnts]}}} // Show Jens > how can fill the range between the to circles? FilledPlot will not work > with implicit functions. > thx, > Oliver Needs[Graphics`ImplicitPlot`]; > f1 := x^2 + y^2 == 2; > f2 := x^2 + y^2 == 1; > ImplicitPlot[{f1, f2}, {x, -3, 3}, > AxesLabel -> {x, y}, > PlotStyle -> {{}, Dashing[{0.02}]}]; ==== Needs[Graphics`]; InequalityPlot[1{SkyBlueDeep}]; DisplayTogether[ FilledPlot[ {Sqrt[2-x^2],-Sqrt[2-x^2]}, {x,-Sqrt[2],Sqrt[2]}, Fills->SkyBlueDeep], FilledPlot[ {Sqrt[1-x^2],-Sqrt[1-x^2]}, {x,-1,1}, Fills->White], AspectRatio->1]; FilledPlot[{Sqrt[2-x^2],-Sqrt[2-x^2], Sqrt[1-x^2]*UnitStep[1-Abs[x]], -Sqrt[1-x^2]*UnitStep[1-Abs[x]]}, {x,-Sqrt[2],Sqrt[2]}, AspectRatio->1, Fills->{White,SkyBlueDeep, SkyBlueDeep,White}, PlotRange->All]; Show[Graphics[{ SkyBlueDeep,Disk[{0, 0}, Sqrt[2]], White,Disk[{0, 0}, 1], Black, Circle[{0, 0}, Sqrt[2]], Circle[{0, 0}, 1]}], AspectRatio->1, Axes->True, AxesFront->True]; Bob Hanlon << how can fill the range between the to circles? FilledPlot will not work with implicit functions. thx, Oliver Needs[Graphics`ImplicitPlot`]; f1 := x^2 + y^2 == 2; f2 := x^2 + y^2 == 1; ImplicitPlot[{f1, f2}, {x, -3, 3}, AxesLabel -> {x, y}, PlotStyle -> {{}, Dashing[{0.02}]}]; ==== Mathematica does not find it's special fonts. You may have a) deletet the Mathematica fonts b) run on a remote display that have not the fonts Jens I see parenthesis showing as I type as H and in the > help notebooks, brackets ^shwon as @ for left bracket > nad D for right bracket ? What«s wrong ? Is it a font related problem ? A wrong > style selection ? > ==== Carlos: Please tell the Group what your configuration is (Windows, Unix, etc.), which Mathematica version you have, and which platform you are on. You could try uninstalling/reinstalling your Mathematica system. If you get that type of error in other applications with the same keys, you may have a corrupt keyboard driver. Harold ==== Plot[Sin[1/x^2], {x, 0.001, 1}, AspectRatio -> 0.1, ImageSize -> {1500, Automatic}] Jens MathGroup: I have a function I want to Plot between 0.5 and 1.0 with a stretched > out x-axis. I want to put a horizontal magnifying glass on the > function between 0.65 and 0.75, because it wiggles a lot in this part > of its domain. I tried to find a Plot option which allows the x-axis to stretch > horizontally across the screen. I experimented with AspectRatio - 10, and found I could do y-axis (Range) stretch with no problem. But > when I tried AspectRatio -> 0.1, the y-axis collapsed, and the x-axis > did not stretch at all. I'm stumped. I can't find an x-axis stretching option that produces > more on-screen horizontal plot details. Does anyone know a way to stretch the x-axis in Mathematica Plots? Harold ==== When you make the AspectRatio small, make the ImageSize large. Or you can use an inset of the magnified region: f[x_] := (x-0.5)(x-.65)(x-.675)(x-.7)(x-.725)(x-.75)(x-1); Plot[f[x],{x,.5,1}, Epilog->{Rectangle[{.5, -2*^-5}, {.8, -3*^-6}, Plot[10^9*f[x],{x,.63,.77}, AxesLabel->{None,*10^-9}, DisplayFunction->Identity]]}, ImageSize->450]; Bob Hanlon << I have a function I want to Plot between 0.5 and 1.0 with a stretched out x-axis. I want to put a horizontal magnifying glass on the function between 0.65 and 0.75, because it wiggles a lot in this part of its domain. I tried to find a Plot option which allows the x-axis to stretch horizontally across the screen. I experimented with AspectRatio -> 10, and found I could do y-axis (Range) stretch with no problem. But when I tried AspectRatio -> 0.1, the y-axis collapsed, and the x-axis did not stretch at all. I'm stumped. I can't find an x-axis stretching option that produces more on-screen horizontal plot details. Does anyone know a way to stretch the x-axis in Mathematica Plots? ==== >-----Original Message----- >Sent: Sunday, January 25, 2004 9:05 AM >To: mathgroup@smc.vnet.net >MathGroup: I have a function I want to Plot between 0.5 and 1.0 with a stretched >out x-axis. I want to put a horizontal magnifying glass on the >function between 0.65 and 0.75, because it wiggles a lot in this part >of its domain. I tried to find a Plot option which allows the x-axis to stretch >horizontally across the screen. I experimented with AspectRatio -10, and found I could do y-axis (Range) stretch with no problem. But >when I tried AspectRatio -> 0.1, the y-axis collapsed, and the x-axis >did not stretch at all. I'm stumped. I can't find an x-axis stretching option that produces >more on-screen horizontal plot details. Does anyone know a way to stretch the x-axis in Mathematica Plots? Harold > Well, Harold, let me dig up a hands-on sample (it's always better to give an example of your real problem in the posting). I leave it up to you, to distill out a method for your application. Let's assume we look at this function graph: Plot[Sin[20/(1 + x^2)], {x, -10, 10}] and want to enlage the x-axis at the more rapid oscillating part between -1 < x < 1. First manufature Graphics objects of the three sections: gm = Plot[Sin[20/(1 + x^2)], {x, -1, 1}, PlotRange -> All] g1 = Plot[Sin[20/(1 + x^2)], {x, -9, -1}, Axes -> {True, False}, PlotRange -> All] g2 = Plot[Sin[20/(1 + x^2)], {x, 1, 9}, Axes -> {True, False}, PlotRange -> All] (For the final Graphics we only want the y-axis from one part, therefore we suppress it for g1, g2; but we need to keep the x-axes, to indicate the different scaling in the final output. PlotRange -> All is necessary to get not too much from the x-axis for each graph (which would overlap later)) Then, the idea is to transform (compress) the x-coordinates of the (not so interesting) sides. scg1f = FullGraphics[ g1] /. {Line[{linepts__}] :> Line[{Unevaluated[linepts] /. {x_, y_} :> {(x + 1)/4 - 1, y}}], Text[exp_, coord_, rest___] :> Text[exp, coord /. {x_, y_} :> {(x + 1)/4 - 1, y}, rest]} scg2f = FullGraphics[ g2] /. {Line[{linepts__}] :> Line[{Unevaluated[linepts] /. {x_, y_} :> {(x - 1)/4 + 1, y}}], Text[exp_, coord_, rest___] :> Text[exp, coord /. {x_, y_} :> {(x - 1)/4 + 1, y}, rest]} as for the Text positions (the numbers indicated at the x-axes). The ReplaceAll, hence they are confined within Unevaluated[]. For the transformation of the Text primitives, we have to carefully select the coordinates. Show[scg1f, Graphics[{Hue[0, 0.3, 1], Rectangle[{-1, -1}, {1, 1}]}], FullGraphics[gm], scg2f, AspectRatio -> 1/3] (I also highlighted the region of particular interest.) A small problem seems to rest: the connection of the lines at the borders is not perfect. Of course I could manage this, but I currently see no really elegant solution for it. (If your not content I'll try!) ok, here it is: line1 = Extract[g1, Position[g1, Line[_]]] /. Line[{linepts__}] :> Line[{Unevaluated[linepts] /. {x_, y_} :> {(x + 1)/4 - 1, y}}]; line2 = Extract[g2, Position[g2, Line[_]]] /. Line[{linepts__}] :> Line[{Unevaluated[linepts] /. {x_, y_} :> {(x - 1)/4 + 1, y}}]; linem = Extract[gm, Position[gm, Line[_]]]; fullline = Apply[Join, Thread[Join[line1, linem, line2], Line], {1}]; g1emb = FullGraphics[g1][[1, 2]] /. {Line[{linepts__}] :> Line[{Unevaluated[linepts] /. {x_, y_} :> {(x + 1)/4 - 1, y}}], Text[exp_, coord_, rest___] :> Text[exp, coord /. {x_, y_} :> {(x + 1)/4 - 1, y}, rest]}; g2emb = FullGraphics[g2][[1, 2]] /. {Line[{linepts__}] :> Line[{Unevaluated[linepts] /. {x_, y_} :> {(x - 1)/4 + 1, y}}], Text[exp_, coord_, rest___] :> Text[exp, coord /. {x_, y_} :> {(x - 1)/4 + 1, y}, rest]}; gmemb = FullGraphics[gm][[1, 2]]; Show[Graphics[{{Hue[0, 0.3, 1], Rectangle[{-1, -1}, {1, 1}]}, fullline, g1emb, g2emb, gmemb}], AspectRatio -> 1/3] Perhaps it's not worth the effort as -- I fear -- it will be much less robust. The basic idea is clear however: extract the lines from the graphics, transform them accordingly and join them. For the embellishments, extract them from the FullGraphics (at the right place!) and also transform them accordingly as seen above. Finally built the Graphics from all parts and Show. -- Hartmut Wolf --- P.S. to David Park: David, in case you don't have this in your Draw package ==== /; is the short form of Condition. ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis (edit reply-to to reply) > Selwyn: I liked your gridPlot module, and it is in my library. However, I > don't understand one Mathematica programming construct you used twice. > I've neither seen it before, nor have I been able to find a > programmer's definition for it in the Mathematica 5.0 Help System. In > the line of code ... {GrayLevel[0.], AbsoluteThickness[t_], Line[{{u_, y1_}, {u_, > y2_}}]} /; you use the /-character before the semicolon. There is an earlier > line where you also use this. Other than division, I don't know what the /-character accomplishes > in this context. Does it go with the semicolon (which ends lines > without output)? I do know that if I take it out, your code > malfunctions. If there's an reference for this in the Help System, I'd also > appreciate a pointer to the correct bookmark. Harold ==== Condition is listed in the Master Index (the symbols are after the A-Z sections) as !@#... /; Bob Hanlon << I liked your gridPlot module, and it is in my library. However, I don't understand one Mathematica programming construct you used twice. I've neither seen it before, nor have I been able to find a programmer's definition for it in the Mathematica 5.0 Help System. In the line of code ... {GrayLevel[0.], AbsoluteThickness[t_], Line[{{u_, y1_}, {u_, y2_}}]} /; you use the /-character before the semicolon. There is an earlier line where you also use this. Other than division, I don't know what the /-character accomplishes in this context. Does it go with the semicolon (which ends lines without output)? I do know that if I take it out, your code malfunctions. If there's an reference for this in the Help System, I'd also appreciate a pointer to the correct bookmark. ==== John, well, your comparisons are not fair, e.g. the Hold-case goes like this In[2]:= Quit[] In[1]:= Timing[SeedRandom[123456]; ranpick3 = ReleaseHold[If[# > 0.01, Hold[], #] & /@ Table[Random[], {1000000}]]; MaxMemoryUsed[]] Out[1]= {25.377 Second, 57292888} and you see two things (1) it's clearly faster, (2) it consumes more memory (as the Table is built first completely) Now to me it's now totally unclear what you are after for. Perhaps you should try to solve your problem along the lines: In[2]:= Quit[] In[1]:= Timing[SeedRandom[123456]; Table[x = Random[Real, {0, .01}], {10000}]; MaxMemoryUsed[]] Out[1]= {0.14 Second, 1475072} Of course this is a joke, and also not one! What is your problem: execution time or memory? The strategies to overcome each are quite different. You must set your goal! -- Hartmut Wolf >-----Original Message----- >Sent: Monday, January 26, 2004 7:53 AM >To: mathgroup@smc.vnet.net >is tricky and dangerous to use. I do however still have problems that >are not resolved by the alternatives as I understand them at present. I rather regret now focusing on HoldRest as the issue here. There is a >rather more general problem with selection from lists. The >optimum list >selection strategy has been addressed most extensively in a thread on >DeleteCases (started March 2001) and the basic options were well aired >then, with the main options being: Select > DeleteCases (or Cases) > Position The primary discrimination between these was in terms of the >Timing, and >here Select still seems to be marginally preferable to >DeleteCases/Cases >and distinctly faster than Position. My present problem is >however with >the internal memory allocation, such as reported by >MaxMemoryUsed[], and >in this case I thought Sequence would help. The problem comes when there is a large amount of data to be processed, >with only selected parts returned. The specific case I have found is >when selecting immediately on calculation, so using a similar >example to >that used previously for DeleteCases: CASE 1 - Sequence[] In[1]:= >Unprotect[If]; >SetAttributes[If,SequenceHold]; >Protect[If]; >Timing[SeedRandom[123456]; > ranpick1=Table[x=Random[];If[x>0.01,Sequence[],x],{1000000}]; > MaxMemoryUsed[]] Out[4]= >{31.876 Second,6343872} CASE 2 - Hold[] In[1]:= >Timing[SeedRandom[123456]; > >ranpick2=Table[x=Random[];ReleaseHold[If[x>0.01,Hold[],x]],{1000000}]; > MaxMemoryUsed[]] Out[1]= >{47.288 Second,35045032} CASE 3 - Select In[1]:= >Timing[SeedRandom[123456]; > ranpick3=Select[Table[Random[],{1000000}],#<=0.01&]; > MaxMemoryUsed[]] Out[1]= >{18.486 Second,35112256} CASE 4 - Cases In[1]:= >Timing[SeedRandom[123456]; > ranpick4=Cases[Table[Random[],{1000000}],_?(#<=0.01&)]; > MaxMemoryUsed[]] Out[1]= >{24.465 Second,35115264} All of the above of course return identical results, and as UnPacked >arrays. Timing results are for a 266MHz Pentium II running Windows NT. advantages over Hold[]. For raw Timing, Select and Cases are quicker >than both, but also have very high MaxMemoryUsed[] results. However the use of Sequence[] here does require that If is given the >Attribute SequenceHold so, given the limited application of the >technique and the risks involved, I have now regretfully abandoned this >approach and I am also reviewing the use of Sequence elsewhere. >Actually (to be honest) I was hoping for equivalent improvements in >MaxMemoryUsed[] when operating on big PackedArrays of stored data, but >here the results are far worse when using Sequence[] than when using >Select: In[1]:= >Unprotect[If]; >SetAttributes[If,SequenceHold]; >Protect[If]; >Timing[SeedRandom[123456]; > randata=Table[Random[],{1000000}]; > ranpick1a=If[#>0.01,Sequence[],#]& /@ randata; > MaxMemoryUsed[]] Out[4]= >{26.868 Second,63143384} Basically I do need a new computer with LOTS more memory... John Tanner. > [rest snipped off] ==== Manfred, There are a number of ways to combine two plots with different domains. Let's define your two functions. f1[x_] := 1/2x^2 - x f2[x_] := -1/2x^2 + x We could combine them into one function using UnitSteps and make a regular Plot. f[x_] := f1[x](UnitStep[x + 3] - UnitStep[x]) + f2[x](UnitStep[x] - UnitStep[x - 3]) Plot[f[x], {x, -4, 4}, Frame -> True, PlotRange -> All]; But if you want to deal with them as separate functions you could combine two plots with the following statement. Block[{$DisplayFunction = Identity}, g1 = Plot[f1[x], {x, -3, 0}]; g2 = Plot[f2[x], {x, 0, 3}]; ] Show[g1, g2, Frame -> True, PlotRange -> {{-4.1, 4.1}, All}]; Here the Block statement gives a local value to $DisplayFunction so as to supress the side plots. Or you could use the DisplayTogether command from Graphics`Graphics`. Needs[Graphics`Graphics`] DisplayTogether[ Plot[f1[x], {x, -3, 0}], Plot[f2[x], {x, 0, 3}], Frame -> True, PlotRange -> {{-4.1, 4.1}, All}]; The last two methods are sometimes a little tricky because they don't always pick up all Options from the second plot. Another method is to try the DrawGraphics package from my web site below. Needs[DrawGraphics`DrawingMaster`] Draw2D[ {Draw[f1[x], {x, -3, 0}], Draw[f2[x], {x, 0, 3}]}, Frame -> True, PlotRange -> {{-4.1, 4.1}, All}]; Here the Draw statements are like the Plot statement except they just extract the primitive graphics without making side plots. You could easily graphics directives, or you could manipulate the primitive graphics before drawing. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net ==== Yes you can. I don't think it would be a good method to generally organize all your Mathematica files. At least if you create as many notebooks as I do. This is because you will have to keep updating a BrowserCategories.m file and rebuilding you Help index every time you add a new notebook. And many notebooks are just temporary one-time calculations. So just using your ordinary folder structure to organize notebooks might be better. In Windows, at least, I can put shortcuts on the desktop to particular folders so if I am working intensely on a particular subject I can quickly get to the notebooks on that subject. But if you have a settled application with perfected notebooks that you want to present to a wider audience then the Help browser format can be useful. You have to find your local Applications folder. Then create the folder structure Applications Your Specific Application folder any packages you have written for your application Documentation English BrowserCategories.m Specific Notebooks The following is an example of a BrowserCategories.m file. It is from the ConicSections package at my web site. (You could download it and install it to see how it looks in the Help Browser.) You could copy and modify this to create your own Help Browser application. BrowserCategory[ConicSections, None, {Item[Introduction, CSIntroduction.nb, CopyTag -> None], Item[Delimiter], BrowserCategory[Examples, None, {Item[Simple Problems,CSExample1.nb, CopyTag -> None]}], Item[Delimiter], BrowserCategory[Routines, None, {Item[SymbolicConic,CSSymbolicConic.nb, CopyTag -> None], Item[StandardConic,CSStandardConic.nb, CopyTag -> None], Item[SolveStandardEllipse,CSSolveStandardEllipse.nb, CopyTag -> None], Item[SolveStandardHyperbola,CSSolveStandardHyperbola.nb, CopyTag -> None], Item[GenerateCircleEquation,CSGenerateCircleEquation.nb, CopyTag -> None], Item[GenerateConicEquation,CSGenerateConicEquation.nb, CopyTag -> None], Item[ParseConic,CSParseConic.nb, CopyTag -> None], Item[TransformEllipseRules,CSTransformEllipseRules.nb, CopyTag -> None], Item[TransformParabolaRules,CSTransformParabolaRules.nb, CopyTag -> None], Item[TransformHyperbolaRules,CSTransformHyperbolaRules.nb, CopyTag -> None], Item[CompleteTheSquare,CSCompleteTheSquare.nb, CopyTag -> None], Item[QuadraticEquationQ,CSQuadraticEquationQ.nb, CopyTag -> None], Item[ExtractQuadraticCoefficients,CSExtractQuadraticCoefficients.nb, CopyTag -> None]}]}] Of course, one must always rebuild the Help browser index when the BrowserCategories.m file is changed. So for presenting a finished piece of work to others this is a nice format, but as a general method of organizing all your notebooks it's not so good. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== > is tricky and dangerous to use. I do however still have problems that > are not resolved by the alternatives as I understand them at present. I rather regret now focusing on HoldRest as the issue here. There is a > rather more general problem with selection from lists. The optimum list > selection strategy has been addressed most extensively in a thread on > DeleteCases (started March 2001) and the basic options were well aired > then, with the main options being: Select > DeleteCases (or Cases) > Position The primary discrimination between these was in terms of the Timing, and > here Select still seems to be marginally preferable to DeleteCases/Cases > and distinctly faster than Position. My present problem is however with > the internal memory allocation, such as reported by MaxMemoryUsed[], and > in this case I thought Sequence would help. The problem comes when there is a large amount of data to be processed, > with only selected parts returned. The specific case I have found is > when selecting immediately on calculation, so using a similar example to > that used previously for DeleteCases: CASE 1 - Sequence[] In[1]:= > Unprotect[If]; > SetAttributes[If,SequenceHold]; > Protect[If]; > Timing[SeedRandom[123456]; > ranpick1=Table[x=Random[];If[x>0.01,Sequence[],x],{1000000}]; > MaxMemoryUsed[]] Out[4]= > {31.876 Second,6343872} CASE 2 - Hold[] In[1]:= > Timing[SeedRandom[123456]; > ranpick2=Table[x=Random[];ReleaseHold[If[x>0.01,Hold[],x]],{1000000}]; > MaxMemoryUsed[]] Out[1]= > {47.288 Second,35045032} CASE 3 - Select In[1]:= > Timing[SeedRandom[123456]; > ranpick3=Select[Table[Random[],{1000000}],#<=0.01&]; > MaxMemoryUsed[]] Out[1]= > {18.486 Second,35112256} CASE 4 - Cases In[1]:= > Timing[SeedRandom[123456]; > ranpick4=Cases[Table[Random[],{1000000}],_?(#<=0.01&)]; > MaxMemoryUsed[]] Out[1]= > {24.465 Second,35115264} All of the above of course return identical results, and as UnPacked > arrays. Timing results are for a 266MHz Pentium II running Windows NT. advantages over Hold[]. For raw Timing, Select and Cases are quicker > than both, but also have very high MaxMemoryUsed[] results. However the use of Sequence[] here does require that If is given the > Attribute SequenceHold so, given the limited application of the > technique and the risks involved, I have now regretfully abandoned this > approach and I am also reviewing the use of Sequence elsewhere. > Actually (to be honest) I was hoping for equivalent improvements in > MaxMemoryUsed[] when operating on big PackedArrays of stored data, but > here the results are far worse when using Sequence[] than when using > Select: In[1]:= > Unprotect[If]; > SetAttributes[If,SequenceHold]; > Protect[If]; > Timing[SeedRandom[123456]; > randata=Table[Random[],{1000000}]; > ranpick1a=If[#>0.01,Sequence[],#]& /@ randata; > MaxMemoryUsed[]] Out[4]= > {26.868 Second,63143384} Basically I do need a new computer with LOTS more memory... John Tanner. > [...] You might save on memory and speed using Compile. For example: Timing[SeedRandom[123456]; ranpick3C = ( func = Compile[{},Select[Table[Random[],{10^6}],(#<=0.01&)]]; func[]); MaxMemoryUsed[]] Out[3]= {1.48 Second, 14137968} In[4]:= In[4]:= Developer`PackedArrayQ[ranpick3C] Out[4]= True This is on a 1.4 GHz machine. Without Compile we lose a factor a bit over 2 in speed and memory consumption. In[6]:= Timing[SeedRandom[123456]; ranpick3=Select[Table[Random[],{10^6}],#<=0.01&]; MaxMemoryUsed[]] Out[6]= {3.18 Second, 35216480} In[7]:= Developer`PackedArrayQ[ranpick3] Out[7]= False If you are likely only to keep a small fraction of the values generated, then you can save on memory at the expense of using an unpacked object in intermediate computations. Use of Sow/Reap (which was introduced after 2001) will allow this. It's also faster than the methods above for this example. In[1]:= Timing[SeedRandom[123456]; ranpick5C = Developer`ToPackedArray[First[Last[Reap[func = Compile[{}, Module[{x},Do[x=Random[]; If[x<=.01,Sow[x]], {10^6}]]]; func[]]]]]; MaxMemoryUsed[]] Out[1]= {0.79 Second, 2159760} Daniel Lichtblau Wolfram Research ==== is tricky and dangerous to use. I do however still have problems that are not resolved by the alternatives as I understand them at present. I rather regret now focusing on HoldRest as the issue here. There is a rather more general problem with selection from lists. The optimum list selection strategy has been addressed most extensively in a thread on DeleteCases (started March 2001) and the basic options were well aired then, with the main options being: Select DeleteCases (or Cases) Position The primary discrimination between these was in terms of the Timing, and here Select still seems to be marginally preferable to DeleteCases/Cases and distinctly faster than Position. My present problem is however with the internal memory allocation, such as reported by MaxMemoryUsed[], and in this case I thought Sequence would help. The problem comes when there is a large amount of data to be processed, with only selected parts returned. The specific case I have found is when selecting immediately on calculation, so using a similar example to that used previously for DeleteCases: CASE 1 - Sequence[] In[1]:= Unprotect[If]; SetAttributes[If,SequenceHold]; Protect[If]; Timing[SeedRandom[123456]; ranpick1=Table[x=Random[];If[x>0.01,Sequence[],x],{1000000}]; MaxMemoryUsed[]] Out[4]= {31.876 Second,6343872} CASE 2 - Hold[] In[1]:= Timing[SeedRandom[123456]; ranpick2=Table[x=Random[];ReleaseHold[If[x>0.01,Hold[],x]],{1000000}]; MaxMemoryUsed[]] Out[1]= {47.288 Second,35045032} CASE 3 - Select In[1]:= Timing[SeedRandom[123456]; ranpick3=Select[Table[Random[],{1000000}],#<=0.01&]; MaxMemoryUsed[]] Out[1]= {18.486 Second,35112256} CASE 4 - Cases In[1]:= Timing[SeedRandom[123456]; ranpick4=Cases[Table[Random[],{1000000}],_?(#<=0.01&)]; MaxMemoryUsed[]] Out[1]= {24.465 Second,35115264} All of the above of course return identical results, and as UnPacked arrays. Timing results are for a 266MHz Pentium II running Windows NT. advantages over Hold[]. For raw Timing, Select and Cases are quicker than both, but also have very high MaxMemoryUsed[] results. However the use of Sequence[] here does require that If is given the Attribute SequenceHold so, given the limited application of the technique and the risks involved, I have now regretfully abandoned this approach and I am also reviewing the use of Sequence elsewhere. Actually (to be honest) I was hoping for equivalent improvements in MaxMemoryUsed[] when operating on big PackedArrays of stored data, but here the results are far worse when using Sequence[] than when using Select: In[1]:= Unprotect[If]; SetAttributes[If,SequenceHold]; Protect[If]; Timing[SeedRandom[123456]; randata=Table[Random[],{1000000}]; ranpick1a=If[#>0.01,Sequence[],#]& /@ randata; MaxMemoryUsed[]] Out[4]= {26.868 Second,63143384} Basically I do need a new computer with LOTS more memory... John Tanner. >It may be of some interest to point out that one can often use Hold and >ReleaseHold instead of Sequence, with similar effect (and sometimes >with fewer problems). For example: >ReleaseHold[{{0, 1, 2, 3, 2}, 3, 2} /. 2 -> Hold[]] >{{0,1,3},3} Carl Woll's OrderedUnion can also be written using this approach: OrderedUnion[li_] := ReleaseHold[Block[{i}, > i[n_] := (i[n] = Hold[]; n); i /@ li]] >OrderedUnion[{1,4,3,17,3,5,5,17,11,4}] {1,4,3,17,5,11} (I have not tried comparing its performance with Carl's original >version). Andrzej Kozlowski >Chiba, Japan >http://www.mimuw.edu.pl/~akoz/ > John, >> it was >> an undocumented function and the only mention to it I found was from >> Roman >> Maeder (who is, or was an insider; and Carl Woll certainly had read his >> books). >> Almost ever the use of Sequence can be avoided (although it might come >> handy), and in this group its use has been popularized more than it >> deserves. Even OrderedUnion -- which was a stroke of genius at its >> time -- >> nowadays with the modern versions of Mathematica (packed arrays, >> improved >> Split, Ordering) clearly no longer is the fastest way to do it! >> Sequence should be used with care and presupposes an exact knowledge >> and >> understanding of the Mathematica evaluation sequence. >> (Further comments interspersed) > -----Original Message----- >> To: mathgroup@smc.vnet.net > Sent: Monday, January 19, 2004 11:15 AM > To: mathgroup@smc.vnet.net > Inspired by Carl Woll's OrderedUnion (for which many, many thanks!) I > have found similar uses for Sequence[], such as using > replacement rules: In[1]:= {{0,1,2,3,2},3,2} /. 2->Sequence[] Out[1]= {{0, 1, 3}, 3} > The right way to do that: >> In[2]:= DeleteCases[{{0, 1, 2, 3, 2}, 3, 2}, 2, 2] >> Out[2]= {{0, 1, 3}, 3} > But I recently found an unexpected result: In[1]:= If[1 == 1, Sequence[], 2] Out[1]= 2 > Well, it should be expected, Sequence will be flattened out when the >> arguments are evaluated _before_ the expression If itself is being >> evaluated >> (unless it had the SequenceHold or HoldAllComplete attribute, but it >> has >> neither of them) >> In[4]:= Attributes[If] >> Out[4]= {HoldRest, Protected} >> Such in a first step >> If[1 == 1, Sequence[], 2] >> is evaluated to >> If[True, Sequence[], 2] >> now Sequence objects will be flattened out irrespectively of HoldRest, >> therefore the expression is transformed to >> If[True, 2] >> only then rules for If are applied, hence Out[1] > Now when presented in this form it is obvious, that Sequence[] is > being flattened out of the arguments to If. The wanted behaviour of > If in this case can be restored if SequenceHold is applied: In[3]:= Unprotect[If]; > SetAttributes[If, SequenceHold]; > Protect[If]; In[6]:= If[1 == 1, Sequence[], 2] Out[6]= Sequence[] > Dont't do that! We cannot overview the consequences of such a global >> intervention. Instead act locally: >> In[7]:= If[1 == 1, Unevaluated[Sequence[]], 2] >> Out[7]= Sequence[] >> This now allows to do other things, e.g. >> In[3]:= Map[If[# === 2, Unevaluated[Sequence[]], #] &, >> {{0, 1, 2, 3, 2}, 3, 2}, 2] >> Out[3]= {{0, 1, 3}, 3} > But If has (I now find) the Attribute HoldRest, and Hold does not > flatten out Sequence[] so I don't understand why that does not apply > here also. > Hold has the attributes >> In[6]:= Attributes[Hold] >> Out[6]= {HoldAll, Protected} >> hence it flattens out Sequence[..] >> In[5]:= Hold[Sequence[], If[1 == 1, Sequence[], 2]] >> Out[5]= Hold[If[1 == 1, Sequence[], 2]] >> (Of course there will be no operation for and _within_ the held >> expression.) > In[7]:= xx[1+2,2+3,3+4] Out[7]= xx[3,5,7] In[8]:= SetAttributes[xx,HoldRest] In[9]:= xx[1+2,2+3,Sequence[],3+4] Out[9]= xx[3,2+3,3+4] > You just showed that HoldRest has nothing to do with all that. > Relatively few built-in functions have SequenceHold applied: {AbsoluteTiming, Rule, RuleDelayed, Set, SetDelayed, TagSet, > TagSetDelayed, Timing, UpSet, UpSetDelayed} And also relatively few built-in functions have HoldRest applied: {Assuming, DumpSave, If, PatternTest, RuleDelayed, Save, Switch} > Yes, the main reason is for so-called lazy evaluation. Would you >> imagine >> what happend when If lacked this attribute? Not only that many parts >> of the >> expression had to be evaluated in vain, and never used for the result, >> also >> side effects would become completely unpredictable (more than is >> anyway). > I will therefore now be much more careful of the use of Sequence! At > present I don't want to be more daring and apply these attributes > wholesale without understanding why this is happening. There must be > other cases where Sequence can have unexpected effects - I now > understand some of the problems I had when trying to use to > modify $Post - > reallyBig needs to cope with Sequence[] and Sequence[__]. -- > mantra- curse Microsoft, curse... web - > http%##www.janacek.demon.co.uk/ > I hate this 'orrible computer, I really ought to sell it: > It never does what I want, but only what I tell it. > I agree, see also the Book about evaluation (e.g. ¤A.4.1) >> -- >> Hartmut Wolf > -- mantra- curse Microsoft, curse... web - http^%%www.janacek.demon.co.uk/ I hate this 'orrible computer, I really ought to sell it: It never does what I want, but only what I tell it. ==== I have one integration and minimization problem. A function of interest is defined as follows: model[l_,h_,scale_,shape_,tt]=Integrate[{den[l, h, t]*PDF[GammaDistribution[shape, scale], {tt - t}]}, {t, 0, tt}] model[l_,h_,scale_,shape_,tt] is convolution function between first den[l, h, t] which is in my calculation cumulative distribution function and probability density function GammaDistribution[shape, scale]. So the convoluted function is strictly positive and should be continuous and differentiable at all points. Now it is NOT possible to get closed form for this convolution function, and as an output I get some long expression. When I had plot this function for some parameter values it turned out to be correct. Now the problem I run into was when I try to use this model[l_,h_,scale_,shape_,tt] function to fit actual data. I used NMinimize on the function that is to be minimized (see bellow). This is standard routine for minimization. Dat2 file is a data file. squares =Plus @@ Table[((model[l, h, scale, shape, tt] /.tt -> (dat2[[i,1]] -dat2[[i,2]]))^2, {i, Length[dat2]}]; nminsol=NMinimize[{squares}, {l, h, scale, shape},Method->{NelderMead}] The problem was that it did not converge and I got report that the The function (145.080813 -(6.93321450269*10^-18 [maginaryI] did not evaluate to a number at the point (h ->0.006370727396825097`,(l->0.128041641382088), (scale-> 72.43025153),(shape-> 5.8088417556) (Note that I constrained parameters which is not presented in NMinimize function! above) I tried different methods for minimization but it did not work out. When I paid close attention to the output of the Îtable' in Îsquares' above, I found some complex number (real + imaginary). After some further research I found that convoluted function model[l_,h_,scale_,shape_,tt] behaves chaotically for some parameter values, which was surprised for me, because both function that were used to construct it were regular probability functions. I guess these irregularities were because of mathematica used some numerical integration in order to approximate complicated convolution function. Also, I used realonly package in order to turn-off imaginary part of the function output but it did not help. Obviously Îrealonly' will not prevent imaginary number when NMinimize is used. I would appreciate any suggestion. Mario Fific Department of Cognitive Psychology Indiana University ==== > I want to plot the two functions in one Plot output > +0.5x^2-x (definition-range -3<=x<=0) > -0.5x^2+x (definition-range 0<=x<=3) I can't find a mathematica 4.0 solution, please help! -ManFis - Here is one way: fun[x_] := If[-3 <= x <= 0, 0.5*x^2 - x, 0.5*x^2 + x]; Plot[fun[x], {x, -3, 3}]; ========== Hugh Walker Gnarly Oaks ==== Frank, a simple approach may be to convert to html using the Save As Special menu item. All Mathematica input and output becomes gifs, then import the relevant ones. Mariusz > Frank Richter 1/24/2004 4:10:11 AM > Dear Group, please advise me on how to import graphics into Word. Me 4.90.3000 equipped with MS Word 2000. I need to import formulaes into the text of my PhD thesis. I tried all options: copy as : bitmap, metafile save selection as : bitmap, wmf, emf but in each case the brackets in the formula get marred. I couldn't find any other advice on the net as well. Frank ==== Remove MatrixForm from your lines m1 = ..., m2 = ... etc Mariusz > 1/25/2004 3:55:38 AM > I want to take a Column Vector and multiply it by a Row Vector to create an Outer Matrix. In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 Row Vector and output a 5x4 Matrix. I then want to add several of these Matrices together and obtain a final Matrix. I tried the following: x1 = {1, -1, -1, 1, 1}; y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] m2 = MatrixForm[Outer [Times, x2, y2] ] m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. What am I doing wrong? Mike McCain MichaelSMcCain@cs.com ==== remove the MatrixForm[], MatrixForm[] is a format function that wrap around your expression and hinder Plus[] to work as expected. Jens > I want to take a Column Vector and multiply it by a Row Vector to create an > Outer Matrix. In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 > Row Vector and output a 5x4 Matrix. I then want to add several of these Matrices together and obtain a final > Matrix. I tried the following: x1 = {1, -1, -1, 1, 1}; > y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; > y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; > y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] > m2 = MatrixForm[Outer [Times, x2, y2] ] > m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. What am I doing wrong? > Mike McCain > MichaelSMcCain@cs.com ==== MatrixForm objects don't add, because they're not matrices. But your code works perfectly for me, because (see a recent thread on MatrixForm), I have installed the following code in my Init.m file (thanks to Andrzej Kozlowski): Unprotect[MatrixForm]; HeadTest[func_] := Intersection[{func}, {If, List, Set, SetDelayed, UpSet, UpSetDelayed, TagSet, TagSetDelayed, Format, MakeBoxes, MakeExpression, ToBoxes, Shallow, Short, Hold, HoldForm, HoldComplete, HoldPattern, Verbatim, Blank, BlankSequence, BlankNullSequence, Alternatives, Pattern, Optional, Repeated, RepeatedNull, Condition, PatternTest, Rule, RuleDelayed, FullForm, InputForm}] === {} MatrixForm[MatrixForm[m_]] ^:= MatrixForm[m]; MatrixForm /: (f_?HeadTest)[ a1___, a2_MatrixForm, a3___] := Module[{result}, result = Replace[{a1, a2, a3}, MatrixForm -> Identity, 2, Heads -> True]; result = f @@ result; If[MatrixQ[result], MatrixForm[result], result]] Protect[MatrixForm]; Bobby I want to take a Column Vector and multiply it by a Row Vector to create an > Outer Matrix. In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 > Row Vector and output a 5x4 Matrix. I then want to add several of these Matrices together and obtain a final > Matrix. I tried the following: x1 = {1, -1, -1, 1, 1}; > y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; > y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; > y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] > m2 = MatrixForm[Outer [Times, x2, y2] ] > m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. > What am I doing wrong? Mike McCain > MichaelSMcCain@cs.com ==== Sorry, it was Ted Ersek's code, not Andzej's. Andrzej had posted a slightly less complete solution, and I got confused. Bobby > MatrixForm objects don't add, because they're not matrices. But your > code works perfectly for me, because (see a recent thread on > MatrixForm), I have installed the following code in my Init.m file > (thanks to Andrzej Kozlowski): Unprotect[MatrixForm]; > HeadTest[func_] := > Intersection[{func}, {If, List, Set, SetDelayed, UpSet, > UpSetDelayed, > TagSet, TagSetDelayed, Format, MakeBoxes, MakeExpression, ToBoxes, > Shallow, > Short, Hold, HoldForm, HoldComplete, HoldPattern, Verbatim, Blank, > BlankSequence, > BlankNullSequence, Alternatives, Pattern, Optional, Repeated, > RepeatedNull, > Condition, PatternTest, Rule, RuleDelayed, FullForm, InputForm}] > === {} > MatrixForm[MatrixForm[m_]] ^:= MatrixForm[m]; > MatrixForm /: (f_?HeadTest)[ > a1___, a2_MatrixForm, a3___] := Module[{result}, result = > Replace[{a1, > a2, a3}, MatrixForm -> Identity, 2, Heads -> True]; > result = f @@ result; > If[MatrixQ[result], MatrixForm[result], result]] > Protect[MatrixForm]; Bobby > I want to take a Column Vector and multiply it by a Row Vector to create an > Outer Matrix. In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 > Row Vector and output a 5x4 Matrix. I then want to add several of these Matrices together and obtain a final > Matrix. I tried the following: x1 = {1, -1, -1, 1, 1}; > y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; > y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; > y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] > m2 = MatrixForm[Outer [Times, x2, y2] ] > m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. > What am I doing wrong? Mike McCain > MichaelSMcCain@cs.com ==== x1 = {1, -1, -1, 1, 1}; y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; y3 = {-1, -1, 1, 1}; MatrixForm[m1=Outer [Times, x1, y1] ] MatrixForm[m2=Outer [Times, x2, y2] ] MatrixForm[m3=Outer [Times, x3, y3] ] MatrixForm[mm = m1 + m2 + m3] Or better yet, do away with all of the MatrixForm by setting your Default Output FormatType to TraditionalForm Bob Hanlon << I want to take a Column Vector and multiply it by a Row Vector to create an Outer Matrix. In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 Row Vector and output a 5x4 Matrix. I then want to add several of these Matrices together and obtain a final Matrix. I tried the following: x1 = {1, -1, -1, 1, 1}; y1 = {1, 1, -1, -1}; x2 = {-1, 1, -1, 1, -1}; y2 = {1, -1, 1, -1}; x3 = {1, 1, -1, -1, 1}; y3 = {-1, -1, 1, 1}; m1 = MatrixForm[Outer [Times, x1, y1] ] m2 = MatrixForm[Outer [Times, x2, y2] ] m3 = MatrixForm[Outer [Times, x3, y3] ] mm = m1 + m2 + m3 MatrixForm[mm] The output that I get is incorrect and does not combine into a single Matrix. ==== > I want to plot the two functions in one Plot output > +0.5x^2-x (definition-range -3<=x<=0) > -0.5x^2+x (definition-range 0<=x<=3) > I can't find a mathematica 4.0 solution, please help! One solution would be Show[Block[{$DisplayFunction = Identity}, {Plot[0.5*x^2 - x, {x, -3, 0}], Plot[-0.5*x^2 + x,{x, 0, 3}]}], PlotRange -> All]; -- ==== I recently wanted to smooth out some noisy data and compare it with a fitting procedure. My enquires led me to ListConvolve. Going through the examples provided in the help files, some questions arose which I hope someone will be able to answer for me or point me to some book or something that goes through this type of analysis. 1. How does one choose an appropriate kernel? 2. I want the same number of data points as my original set of points. Yet, despite the documentation, even the example returns a list which is shorter than the original data set. How do you control this? 3. The plot in the example looks great compared with the noisy generated data, but the spread of y-values after ListConvolve is applied is completely different. Does anyone use ListConvolve regularly for smoothing data. If so, your help would be greatly appreciated. Yas ==== > Recently, I started to use the arXiv > (http://www.wolfram.com/solutions/publishing/stylearxiv.html) style sheet > for my technical writing, but found a frustrating bug in it. There are two > styles in the style sheet, EquationNumbered and Equation (in some other > standard style sheets, these correspond to the NumberedEquation and > DisplayedFormula). When I first input an equation, which does not have the > equation number on the right, it behaves normal. Then if I input a > numbered equation, the equation number on the right appears as 2 rather > than 1. It seems that arXiv counts all equations (numbered or displayed) > and increment the equation count by one for all of them. This occurs on > both PC under WinXP and Mac under OS X 10.3.2. Any ideas of fixing the Open arXiv.nb (which is the StyleSheet Notebook), scroll down to the Style Menu Shortcuts section, and select the Prototype for Style Equation cell (the inner-most cell bracket). If you unformat this cell (Format menu | Show Expression) you will see that one of the options for the Style of Equation cells is CounterIncrements->Equation If you delete this option and reformat the cell then Equation cells will no longer increment the Equation counter. Paul -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul ==== Please consider the lorenz system for example. In[2]:= solution=NDSolve[{Derivative[1][x][t][Equal]-y[t]-z[t],x[0][Equal]-0.04, Derivative[1][y][t][Equal]x[t]+0.425*y[t],y[0][Equal]-0.3, Derivative[1][z][t][Equal]2-(4-x[t])*z[t],z[0][Equal]0.52},{x[t], y[t],z[t]},{t,0,25}]; ParametricPlot3D[Evaluate[{x[t],y[t],z[t]}/.solution],{t,0,25}, PlotPoints -> 1000,PlotRange ->All]; above shows a parametric plot of x, y and z. but let's say for some reason I want to plot the following.. x+y vs time x+z vs y how do I achieve this? is this possible in mathematica? as always any and all thoughts are appreciated. thank you all in advance sean ==== I have one integration and minimization problem. A function of interest is defined as follows: model[l_,h_,scale_,shape_,tt]=Integrate[{den[l, h, t]*PDF[GammaDistribution[shape, scale], {tt - t}]}, {t, 0, tt}] model[l_,h_,scale_,shape_,tt] is convolution function between first den[l, h, t] which is in my calculation cumulative distribution function and probability density function GammaDistribution[shape, scale]. So the convoluted function is strictly positive and should be continuous and differentiable at all points. Now it is NOT possible to get closed form for this convolution function, and as an output I get some long expression. When I had plot this function for some parameter values it turned out to be correct. Now the problem I run into was when I try to use this model[l_,h_,scale_,shape_,tt] function to fit actual data. I used NMinimize on the function that is to be minimized (see bellow). This is standard routine for minimization. Dat2 file is a data file. squares =Plus @@ Table[((model[l, h, scale, shape, tt] /.tt -> (dat2[[i,1]] -dat2[[i,2]]))^2, {i, Length[dat2]}]; nminsol=NMinimize[{squares}, {l, h, scale, shape},Method->{NelderMead}] The problem was that it did not converge and I got report that the The function (145.080813 -(6.93321450269*10^-18 [maginaryI] did not evaluate to a number at the point (h ->0.006370727396825097`,(l->0.128041641382088), (scale-> 72.43025153),(shape-> 5.8088417556)ä (Note that I constrained parameters which is not presented in NMinimize function! above) I tried different methods for minimization but it did not work out. When I paid close attention to the output of the table in squares above, I found some complex number (real + imaginary). After some further research I found that convoluted function model[l_,h_,scale_,shape_,tt] behaves chaotically for some parameter values, which was surprised for me, because both function that were used to construct it were regular probability functions. I guess these irregularities were because of mathematica used some numerical integration in order to approximate complicated convolution function. Also, I used realonly package in order to turn-off imaginary part of the function output but it did not help. Obviously realonly will not prevent imaginary number when NMinimize is used. I would appreciate any suggestion. Mario Fific Department of Cognitive Psychology Indiana University ==== > For the last few years I have used Mathematica exclusively for > technical writing, mostly because it gives me better control over > figure placement and keeps everything in a single file. That said, it > is nonetheless an aggravating experience in many ways. The > subscript/quotient font size problem is a daily irritation. Here's my > question. TeX does an excellent job in this regard. TeX has been around > since the '60s and is open source. Why doesn't someone at WRI just look > at how TeX does it and incorporate the rules? Why reinvent the > wheel especially if the wheels you produce in house always seem to have > corners on the rim? A personal bugaboo of mine is the spelling checker. I don't have > problems with the spelling checker in any other software, just > Mathematica. Ever since 3.0 I have been trying to teach it that > bivector is a word. No luck. It just keeps telling me to try bevatron > instead. I tell it to learn the word, it puts it in some user defined > dictionary, and then ignores it. I keep a copy of the Summer-Fall 1999 issue of Mathematica in Education > and Research in a file cabinet just so I can look up how to change an > unmatched bracket from pink to black whenever I want to define a > multiline function (p. 87). The best solution is to match unmatched brackets using [AutoLeftMatch] or [AutoRightMatch] > Indications are that someone at WRI wants to develop Mathematica into a > first rate technical publishing tool. It should be explained to them > that this is just a waste of time and talent if the use of the tool > is to be such a jealously guarded secret. If Mathematica is to have more than marginal use as a technical > publication system WRI needs to produce, in house or outhouse, a > Mathematica equivalent of The Joy of TeX. Cursory documentation and > scattered hints in journals will not do it. Paul -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul ==== You miss the whole point of the complaints about page-breaking. Evidently you've never used a REAL typesetting program like (La)TeX. One wants the program to handle page breaks for printed material transparently, automatically -- normally FILLING a page to the bottom margin of typeset material. Of course, one should still have the option to override the automatic processing -- e.g., to force an extra line onto a page, or to force a line or two to the next page (and accordingly add slight amounts of additional space between lines on the shortened page) to avoid a widow. And graphical content (or, for that matter, other particular kinds of cells) need to be able to float. > You can control page breaks as follows: 1. Selecting a cell above or below the place where you want the page break. > 2. Open up the Option Inspector (Ctrl Shift O in Windows). > 3. Click down to Cell Options Page Breaking. > 4. Select whatever page breaking options you want. Steve Luttrell >>I couldn't agree more. I haven't even learned to control page breaks >>-- and that needs to be COMPLETELY transparent. >>Bobby -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 ==== One can affect page breaks by adjusting the spacing between cells. This is incredibly tedious to do with the Options Inspector, but there is a palette named Glue (find it at MathSource) that lets you select a whole page of heterogeneous cells and shrink or expand the between-cell spacings. I've used it extensively, and it cuts the time needed to page-break a 50 page document from several hours down to about an hour (for me anyway---I'm rather picky). ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis (edit reply-to to reply) > The trouble with controlling page breaks may be due, in part, to a > central paradigm of the Front End, namely, as a medium primarily for > display on computer screens and secondairly for printout from a > computer > screen. A real typesetting functionality would facilitate page-breaking > (automatically) within cells. Mathematica does not like to break > within > cells. Of course one CAN apply the Option Inspector setting to change > PageBreakWithin to True from its default Automatic and hope for the > best. >> I couldn't agree more. I haven't even learned to control page breaks >> -- and that needs to be COMPLETELY transparent. >> Bobby > Since Selwyn has fallen down in the venting department I will offer a > few remarks. For the last few years I have used Mathematica exclusively for > technical writing, mostly because it gives me better control over > figure placement and keeps everything in a single file. That said, it > is nonetheless an aggravating experience in many ways. The > subscript/quotient font size problem is a daily irritation. Here's my > question. TeX does an excellent job in this regard. TeX has been > around > since the '60s and is open source. Why doesn't someone at WRI just > look > at how TeX does it and incorporate the rules? Why reinvent the > wheel especially if the wheels you produce in house always seem to > have > corners on the rim? A personal bugaboo of mine is the spelling checker. I don't have > problems with the spelling checker in any other software, just > Mathematica. Ever since 3.0 I have been trying to teach it that > bivector is a word. No luck. It just keeps telling me to try bevatron > instead. I tell it to learn the word, it puts it in some user defined > dictionary, and then ignores it. I keep a copy of the Summer-Fall 1999 issue of Mathematica in > Education > and Research in a file cabinet just so I can look up how to change > an > unmatched bracket from pink to black whenever I want to define a > multiline function (p. 87). Indications are that someone at WRI wants to develop Mathematica > into a > first rate technical publishing tool. It should be explained to them > that this is just a waste of time and talent if the use of the tool > is to be such a jealously guarded secret. If Mathematica is to have more than marginal use as a technical > publication system WRI needs to produce, in house or outhouse, a > Mathematica equivalent of The Joy of TeX. Cursory documentation and > scattered hints in journals will not do it. On Jan 22, 2004, at 3:37 AM, Selwyn Hollis wote: > I didn't reply to this thread earlier because I figured one of the > usual > experts would pick it up and run with it, but it appears not. By > reading > Selwyn's answer, I think he knows how to do this but decided to > vent > about > the method rather than explain it. >> What, me vent? I could show you venting, but I won't. >> The real issue here is why this design flaw has persisted from >> version >> 3.0 to version 5.0. It is clearly an example of sheer >> corner-cutting. >> There is no typographical rationale whatsoever for treating >> numerators >> and denominators of fractions the same way as subscripts and >> superscripts. >> For example, what if I want to have ScriptSizeMultipliers->1 in a >> fraction that contains subexpressions with superscripts? Then the >> superscripts are the same size as the bases to which they are >> attached, >> and the whole thing looks silly -- thus I have go in and do a lot of >> meticulous tweaking. >> Again, I could be missing something and have wasted countless hours >> in >> trying to make many hundreds of pages worthy of publication. But >> maybe >> it's my own fault for dreaming that I could approach TeX-like >> quality >> with Mathematica. >> ----- >> Selwyn Hollis >> http://www.math.armstrong.edu/faculty/hollis >> (edit reply-to to reply) > In the Option Inspector is an option called ScriptSizeMultipliers. > This, > combined with the ScriptMinSize, determines sizing for fractions > and > scripts (sorry, Selwyn). The easiest way to do what Murray and > Sabit > want > is to set the ScriptSizeMultipliers option to 1. This could be set at the > notebook or global level, as you feel appropriate, or wrapped > individually > around fractions if you don't want sub/superscripts to pick up the > option > value. To answer Sabit's second question, select the bracket of the cell > you'd > like to change, and use the Option Inspector to set the > SingleLetterItalics > option to False at the selection scope. Sincerely, John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. > I quite agree that this is an annoyance with Mahematica's >> typsetting >> of >> mathematics. >> An underlying difficulty is that there is no separate notion of >> display >> math -- mathematical expressions displayed on separate lines -- >> as >> opposed to math within normal paragraphs of text. This may be an >> unfortunate front-end design limitation. >> The problem is reminiscent of the same problem in LaTeX, where >> in-line, >> built-up fractions (and other constructs) have their components >> small. >> But in LaTeX, there is an option (which one needs to apply to each >> instance) to make such in-line math displaystyle, which >> enlarges the >> components to the same large size as if they were in a display. >> I devoutly wish there were such a capability in Mathematica -- >> whether a >> per-instance option as with LaTeX, or a global option for a >> notebook. > My understanding is that the size of fractions is determined by > the > same option that determines the size of subscripts and > superscripts, > which is highly unfortunate. I could be wrong about this; if so > I'd > love to find out. I find it a major pain in the neck always to > have > to > increase the size of fractions manually. Maybe this is an > improvement > we can hope for in version 6.0. ----- > Selwyn Hollis > http://www.math.armstrong.edu/faculty/hollis > (edit reply-to to reply) > I am trying to do some typesetting with mathematica. I noticed >> that >> in >> some styles fractions are set in reduced point size. What is the >> option that would fix this? I want both denominator and the >> numerator >> set in the same size as the text. >> Also I have the single letter italic enabled for cells where I have > the equations but in the cells where there is a lot of text I don't > want this option. Now I copy and paste a previous cell and use >> it > as >> new cell but I am sure there is a better way, probably with styles. > Wolfram site lists two documents about typesetting but they are not > available to download. Does anyone know a good reference for >> tpesetting with mathematica? Garry Helzer > Department of Mathematics > University of Maryland > College Park, MD 20742 > 301-405-5176 > gah@math.umd.edu > > -- > Murray Eisenberg murray@math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street fax 413 545-1801 > Amherst, MA 01003-9305 ==== The trouble with controlling page breaks may be due, in part, to a central paradigm of the Front End, namely, as a medium primarily for display on computer screens and secondairly for printout from a computer screen. A real typesetting functionality would facilitate page-breaking (automatically) within cells. Mathematica does not like to break within cells. Of course one CAN apply the Option Inspector setting to change PageBreakWithin to True from its default Automatic and hope for the best. > I couldn't agree more. I haven't even learned to control page breaks > -- and that needs to be COMPLETELY transparent. Bobby >>Since Selwyn has fallen down in the venting department I will offer a >>few remarks. >>For the last few years I have used Mathematica exclusively for >>technical writing, mostly because it gives me better control over >>figure placement and keeps everything in a single file. That said, it >>is nonetheless an aggravating experience in many ways. The >>subscript/quotient font size problem is a daily irritation. Here's my >>question. TeX does an excellent job in this regard. TeX has been around >>since the '60s and is open source. Why doesn't someone at WRI just look >>at how TeX does it and incorporate the rules? Why reinvent the >>wheel especially if the wheels you produce in house always seem to have >>corners on the rim? >>A personal bugaboo of mine is the spelling checker. I don't have >>problems with the spelling checker in any other software, just >>Mathematica. Ever since 3.0 I have been trying to teach it that >>bivector is a word. No luck. It just keeps telling me to try bevatron >>instead. I tell it to learn the word, it puts it in some user defined >>dictionary, and then ignores it. >>I keep a copy of the Summer-Fall 1999 issue of Mathematica in Education >>and Research in a file cabinet just so I can look up how to change an >>unmatched bracket from pink to black whenever I want to define a >>multiline function (p. 87). >>Indications are that someone at WRI wants to develop Mathematica into a >>first rate technical publishing tool. It should be explained to them >>that this is just a waste of time and talent if the use of the tool >>is to be such a jealously guarded secret. >>If Mathematica is to have more than marginal use as a technical >>publication system WRI needs to produce, in house or outhouse, a >>Mathematica equivalent of The Joy of TeX. Cursory documentation and >>scattered hints in journals will not do it. >>On Jan 22, 2004, at 3:37 AM, Selwyn Hollis wote: > >I didn't reply to this thread earlier because I figured one of the >>usual >>experts would pick it up and run with it, but it appears not. By >>reading >>Selwyn's answer, I think he knows how to do this but decided to vent >>about >>the method rather than explain it. What, me vent? I could show you venting, but I won't. The real issue here is why this design flaw has persisted from version >3.0 to version 5.0. It is clearly an example of sheer corner-cutting. >There is no typographical rationale whatsoever for treating numerators >and denominators of fractions the same way as subscripts and >superscripts. For example, what if I want to have ScriptSizeMultipliers->1 in a >fraction that contains subexpressions with superscripts? Then the >superscripts are the same size as the bases to which they are attached, >and the whole thing looks silly -- thus I have go in and do a lot of >meticulous tweaking. Again, I could be missing something and have wasted countless hours in >trying to make many hundreds of pages worthy of publication. But maybe >it's my own fault for dreaming that I could approach TeX-like quality >with Mathematica. ----- >Selwyn Hollis >http://www.math.armstrong.edu/faculty/hollis >(edit reply-to to reply) >>In the Option Inspector is an option called ScriptSizeMultipliers. >>This, >>combined with the ScriptMinSize, determines sizing for fractions and >>scripts (sorry, Selwyn). The easiest way to do what Murray and Sabit >>want >>is to set the ScriptSizeMultipliers option to 1. This could be set >> at >>the >>notebook or global level, as you feel appropriate, or wrapped >>individually >>around fractions if you don't want sub/superscripts to pick up the >>option >>value. >>To answer Sabit's second question, select the bracket of the cell >>you'd >>like to change, and use the Option Inspector to set the >>SingleLetterItalics >>option to False at the selection scope. >>Sincerely, >>John Fultz >>jfultz@wolfram.com >>User Interface Group >>Wolfram Research, Inc. >I quite agree that this is an annoyance with Mahematica's typsetting >of >mathematics. An underlying difficulty is that there is no separate notion of >display >math -- mathematical expressions displayed on separate lines -- as >opposed to math within normal paragraphs of text. This may be an >unfortunate front-end design limitation. The problem is reminiscent of the same problem in LaTeX, where >in-line, >built-up fractions (and other constructs) have their components > small. >But in LaTeX, there is an option (which one needs to apply to each >instance) to make such in-line math displaystyle, which enlarges the >components to the same large size as if they were in a display. I devoutly wish there were such a capability in Mathematica -- >whether a >per-instance option as with LaTeX, or a global option for a notebook. >My understanding is that the size of fractions is determined by the >>same option that determines the size of subscripts and superscripts, >>which is highly unfortunate. I could be wrong about this; if so I'd >>love to find out. I find it a major pain in the neck always to have >>to >>increase the size of fractions manually. Maybe this is an >>improvement >>we can hope for in version 6.0. >>----- >>Selwyn Hollis >>http://www.math.armstrong.edu/faculty/hollis >>(edit reply-to to reply) >I am trying to do some typesetting with mathematica. I noticed that >in >some styles fractions are set in reduced point size. What is the >option that would fix this? I want both denominator and the >numerator >set in the same size as the text. Also I have the single letter italic enabled for cells where I >> have >the equations but in the cells where there is a lot of text I >> don't >want this option. Now I copy and paste a previous cell and use it >as >new cell but I am sure there is a better way, probably with >> styles. >Wolfram site lists two documents about typesetting but they are >> not >available to download. Does anyone know a good reference for >tpesetting with mathematica? > >>Garry Helzer >>Department of Mathematics >>University of Maryland >>College Park, MD 20742 >>301-405-5176 >>gah@math.umd.edu > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 ==== My bigger problem is too-early page breaks, not the too-late kind. And there's no WYSIWG (even with page-breaks showing), so I have to print every time I want to check on how much white space is being produced. I have seen pages printed with just one short cell. Bobby > The trouble with controlling page breaks may be due, in part, to a > central paradigm of the Front End, namely, as a medium primarily for > display on computer screens and secondairly for printout from a computer > screen. A real typesetting functionality would facilitate page-breaking > (automatically) within cells. Mathematica does not like to break within > cells. Of course one CAN apply the Option Inspector setting to change > PageBreakWithin to True from its default Automatic and hope for the best. > I couldn't agree more. I haven't even learned to control page breaks > -- and that needs to be COMPLETELY transparent. Bobby >>Since Selwyn has fallen down in the venting department I will offer a >>few remarks. >>For the last few years I have used Mathematica exclusively for >>technical writing, mostly because it gives me better control over >>figure placement and keeps everything in a single file. That said, it >>is nonetheless an aggravating experience in many ways. The >>subscript/quotient font size problem is a daily irritation. Here's my >>question. TeX does an excellent job in this regard. TeX has been around >>since the '60s and is open source. Why doesn't someone at WRI just look >>at how TeX does it and incorporate the rules? Why reinvent the >>wheel especially if the wheels you produce in house always seem to have >>corners on the rim? >>A personal bugaboo of mine is the spelling checker. I don't have >>problems with the spelling checker in any other software, just >>Mathematica. Ever since 3.0 I have been trying to teach it that >>bivector is a word. No luck. It just keeps telling me to try bevatron >>instead. I tell it to learn the word, it puts it in some user defined >>dictionary, and then ignores it. >>I keep a copy of the Summer-Fall 1999 issue of Mathematica in Education >>and Research in a file cabinet just so I can look up how to change an >>unmatched bracket from pink to black whenever I want to define a >>multiline function (p. 87). >>Indications are that someone at WRI wants to develop Mathematica into a >>first rate technical publishing tool. It should be explained to them >>that this is just a waste of time and talent if the use of the tool >>is to be such a jealously guarded secret. >>If Mathematica is to have more than marginal use as a technical >>publication system WRI needs to produce, in house or outhouse, a >>Mathematica equivalent of The Joy of TeX. Cursory documentation and >>scattered hints in journals will not do it. >>On Jan 22, 2004, at 3:37 AM, Selwyn Hollis wote: > >I didn't reply to this thread earlier because I figured one of the >>usual >>experts would pick it up and run with it, but it appears not. By >>reading >>Selwyn's answer, I think he knows how to do this but decided to vent >>about >>the method rather than explain it. What, me vent? I could show you venting, but I won't. The real issue here is why this design flaw has persisted from version >3.0 to version 5.0. It is clearly an example of sheer corner-cutting. >There is no typographical rationale whatsoever for treating numerators >and denominators of fractions the same way as subscripts and >superscripts. For example, what if I want to have ScriptSizeMultipliers->1 in a >fraction that contains subexpressions with superscripts? Then the >superscripts are the same size as the bases to which they are attached, >and the whole thing looks silly -- thus I have go in and do a lot of >meticulous tweaking. Again, I could be missing something and have wasted countless hours in >trying to make many hundreds of pages worthy of publication. But maybe >it's my own fault for dreaming that I could approach TeX-like quality >with Mathematica. ----- >Selwyn Hollis >http://www.math.armstrong.edu/faculty/hollis >(edit reply-to to reply) >>In the Option Inspector is an option called ScriptSizeMultipliers. >>This, >>combined with the ScriptMinSize, determines sizing for fractions and >>scripts (sorry, Selwyn). The easiest way to do what Murray and Sabit >>want >>is to set the ScriptSizeMultipliers option to 1. This could be set >> at >>the >>notebook or global level, as you feel appropriate, or wrapped >>individually >>around fractions if you don't want sub/superscripts to pick up the >>option >>value. >>To answer Sabit's second question, select the bracket of the cell >>you'd >>like to change, and use the Option Inspector to set the >>SingleLetterItalics >>option to False at the selection scope. >>Sincerely, >>John Fultz >>jfultz@wolfram.com >>User Interface Group >>Wolfram Research, Inc. >I quite agree that this is an annoyance with Mahematica's typsetting >of >mathematics. An underlying difficulty is that there is no separate notion of >display >math -- mathematical expressions displayed on separate lines -- as >opposed to math within normal paragraphs of text. This may be an >unfortunate front-end design limitation. The problem is reminiscent of the same problem in LaTeX, where >in-line, >built-up fractions (and other constructs) have their components > small. >But in LaTeX, there is an option (which one needs to apply to each >instance) to make such in-line math displaystyle, which enlarges the >components to the same large size as if they were in a display. I devoutly wish there were such a capability in Mathematica -- >whether a >per-instance option as with LaTeX, or a global option for a notebook. >My understanding is that the size of fractions is determined by the >>same option that determines the size of subscripts and superscripts, >>which is highly unfortunate. I could be wrong about this; if so I'd >>love to find out. I find it a major pain in the neck always to have >>to >>increase the size of fractions manually. Maybe this is an >>improvement >>we can hope for in version 6.0. >>----- >>Selwyn Hollis >>http://www.math.armstrong.edu/faculty/hollis >>(edit reply-to to reply) >I am trying to do some typesetting with mathematica. I noticed that >in >some styles fractions are set in reduced point size. What is the >option that would fix this? I want both denominator and the >numerator >set in the same size as the text. Also I have the single letter italic enabled for cells where I >> have >the equations but in the cells where there is a lot of text I >> don't >want this option. Now I copy and paste a previous cell and use it >as >new cell but I am sure there is a better way, probably with >> styles. >Wolfram site lists two documents about typesetting but they are >> not >available to download. Does anyone know a good reference for >tpesetting with mathematica? > >>Garry Helzer >>Department of Mathematics >>University of Maryland >>College Park, MD 20742 >>301-405-5176 >>gah@math.umd.edu > ==== You can control page breaks as follows: 1. Selecting a cell above or below the place where you want the page break. 2. Open up the Option Inspector (Ctrl Shift O in Windows). 3. Click down to Cell Options Page Breaking. 4. Select whatever page breaking options you want. Steve Luttrell > I couldn't agree more. I haven't even learned to control page breaks > -- and that needs to be COMPLETELY transparent. Bobby ==== I thought that I could use something like this to assert that all variables are real and not complex: {$Post , $Assumptions} = {Refine, _Symbol [Element] Reals}; It seems to work with: Sqrt[x^2]] Abs[x] and Refine[Sqrt[x^2], x > 0] x But I would like not to use Refine to make additional assumptions. Instead I would like to use Assuming: Assuming[x > 0, Sqrt[x^2]] Abs[x] Why doesn't Assuming (or the Block equivalent) apply Refine automatically ?!?! Greetings from Croatia, drago ==== Bruce, use this: Through[{Mean, Variance}[X]] drago > Let commands C1 and C2 have common argument X, e.g., C1 is Mean, C2 is > Variance and X is a list of reals. Although C1@X and C2@X execute each, how can you merge these into a command > that uses X once? I've seen this done but can't find the notes. > ==== Re Mathematica 5.0. In a text cell, I want to write a piecewise function... f(x) = 5x, x < -2 7x, x in [-2,3] 6x, x > 3 ...displayed with a lefthand side big curly brace that covers all lines top-to-bottom, together with centering the f(x) = on brace-center. How would I do this? I've put the righthand side into a 3x2 table and using the BasicTypesetting palette, choose the curly brace button. This nearly works except that righthand side blank lines destroy the otherwise perfect look. The problem persists when I change brace size (using Format/Size). Bruce ==== On second thought, I think this is a better idea: IrrationalQ[x_] := Denominator[Rationalize[x,.0001]] > 50 With it, IrrationalQ[Random[]] returns True most of the time, as it should (probability approx .85), but returns False often enough to be interesting. ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis (edit reply-to to reply) ==== This is a pretty wild idea, but how about the following as a criterion for deeming a single-precision floating-point number between 0 and 1 to be irrational: It's irrational if its base-10 form contains all 10 digits, more precisely, if IrrationalQ[x_] := Length[Union[IntegerDigits[Round[10^16*x]]]] == 10 returns True. Then grph = Plot[If[IrrationalQ[x], x, 0], {x, 0, 1}, PlotPoints -> 100] draws a graph that, with a little imagination, suggests what the graph of If[x is irrational, x, 0] could look like. Still better is Show[Graphics[{AbsolutePointSize[1.5], Point[#]} & /@ (grph/.Graphics[{{Line[z_]}}, ___] -> z)]] This is all nonsense, of course, but fun nonetheless. Experiments show that IrrationalQ[Random[]] returns True with probability roughly 0.07. (Anybody have a clue why?) ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis (edit reply-to to reply) Can you help me? How do write expressions in Mathematica for functions and sequences > such as the following: f(x) = {1/x, x is irrational > {x^2, x rational > and f(n) = 1/n, n odd > n^2, n even I am a new user and find the manual rather daunting. Best wishes > Laurence Keegan > ==== I would like to find a way for composing a list of functions over a list of numbers. I have the list {{f, g, h}, {a, b, c, d}} (f, g, h are functions and a, b, c, d are numbers) I would like to obtain h[g[f[a, b], c], d] Since it's for a real program, I had to do it in any way. So I did it as I show below: In[1]:= kk = {{f, g, h}, {a, b, c, d}} Out[1]= {{f, g, h}, {a, b, c, d}} In[2]:= result1 = {kk[[2,1]]}; For[i = 1, i < Length[kk[[2]]], i++, AppendTo[result1, kk[[1,i]]]; AppendTo[result1, kk[[2,i + 1]]]]; result1 Out[2]= {a, f, b, g, c, h, d} In[3]:= result2 = StringJoin @@ ToString /@ result1 Out[3]= afbgchd In[4]:= result3 = StringInsert[result2, ~, Range[2, StringLength[result2]]] Out[4]= a~f~b~g~c~h~d In[5]:= result4 = ToExpression[result3] Out[5]= h[g[f[a, b], c], d] But I'm really sure that it can be done much better. Could you help me? ==== > Is there is simple way to Convert automatic objects to literal via code > rather than using the menu command? The front end tokens are documented at http://documents.wolfram.com/v5/FrontEnd/FrontEndTokens/ However, if you go to the Input Menu I cannot see any documentation for this command. If you open the menu setup file, MenuSetup.tr, you will find the following code for doing what you want: Item[Convert Automatic Objects to Literal, FrontEndExecute[{FrontEnd`NotebookReleaseHold[ FrontEnd`NotebookSelection[FrontEnd`InputNotebook[]]]}]], Paul -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul ==== > > Could anybody help me to find out how can I interpolate a matrix? > > Let'us have a 10x10 matrix and I'd like to make a DensityPlot by > resolution of 100x100 for example. Use Interpolation. Here is some (indexed) data: Table[{x, y, Cos[x y]}, {x, 0, 1, 0.2}, {y, 0, 1, 0.2}] Interpolate (after converting to a one-dimensional data list), cosint=Interpolation[Flatten[%, 1]] and then plot: DensityPlot[cosint[x,y],{x,0,1},{y,0,1},PlotPoints->100, Mesh-> False]; Paul -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul ==== > I have an n*n Table. for example: > t1 = Table[Random[Integer, {0, 10}], {k}, {k}]; It would be better to include k in the function definition: t1[k_] := Table[Random[Real, {0, 10}], {k}, {k}]; > I want to rearrange the elements in t1 randomly (my actual t1 has real > data) such that for each entry t1[[i,j]] a random neighbor t1[[i+m,i+n]] > is chosen to replace it. Once that neighbor is chosen, it can still be > used to replace any of its other neighbors. In the reshuffling an entry > can replace itself. Currently I have the size of the neighborhood fixed > at 9 cells (-1<= m,n <= 1) but eventually, I need to extend it to 25 > (-2 <= m, n <= 2), 49, etc. Here is one way to do this. Load the DiscreteMath stub: < Am running Mathematica 5.0 under WinXP Home, a want to generate one = > random variable from a Wishart distribution. > > The code: > > Needs[Statistics`]; > Random[WishartDistribution[{{1,0}, {0,1}}, 4] This is missing a closing ] > returns the error non-rectangular tensor encountered. > > What am I doing wrong? Nothing else that I can see. I think that it is a bug. Paul -- The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul