mm-609 === Subject: Re: How if I want to assume that ------- > Does there exist a 'assume' function in Mathematica? > For example, I want to assume that > { x>y } Have a look at the *Assuming* built-in function: http://documents.wolfram.com/mathematica/functions/Assuming /J.M. === Subject: Re: How if I want to assume that ------- what do ?Assuming and ?Refine and the Assumptions option .... and the second argument of Simplify[] and FullSimplify[] ... Jens kong dong schrieb im | | Does there exist a 'assume' function in Mathematica? | For example, I want to assume that | { x>y } | | === Subject: Re: Also force AxesOrigin to be in the lower right corner? and what does: data = Table[{x, Sin[x]}, {x, 0, 2Pi, 2Pi/128}]; ListPlot[data, AxesOrigin -> Min /@ Transpose[N[data]], Frame -> False]; Jens Jason Quinn schrieb |I want to force the x-axis to lie on the bottom of the graph regardless | of a specific dataset. What's the best way to do this? I've been trying | plotting the dataset and grabbing the lower-right corner of the | plotrange with AbsoluteOptions. This works but seems absurdly | complicated and I feel like I'm missing the forest for the trees. Is | there a better way than this: | | firstplot = ListPlot[dataset, DisplayFunction -> Identity]; | ListPlot[dataset, AxesLabel -> {x, y}, AxesOrigin -> | {AbsoluteOptions[firstplot, PlotRange][[1, 2, 1, 1]], | AbsoluteOptions[firstplot, PlotRange][[1, 2, 2, 1]]}, DisplayFunction | -> $DisplayFunction]; | | Jason | === Subject: Re: How if I want to assume that ------- Integrate[1/(x-y),{x,0,5}] If[Re[y] >= 5 || Re[y] <= 0 || Im[y] != 0, Log[5 - y] - Log[-y], Integrate[1/(x - y), {x, 0, 5}, Assumptions -> !(Re[y] >= 5 || Re[y] <= 0 || Im[y] != 0)]] Simplify[%,{x>y,y>5}] Log[(y - 5)/y] Integrate[1/(x-y),{x,0,5},Assumptions->{x>y,y>5}] Log[(y - 5)/y] Assuming[{x>y,y>5},Integrate[1/(y-x),{x,0,5}]] Log[y/(y - 5)] Bob Hanlon === > Subject: How if I want to assume that ------- > Does there exist a 'assume' function in Mathematica? > For example, I want to assume that > { x>y } === Subject: Re: Also force AxesOrigin to be in the lower right corner? A simple approach would be to use a frame rather than an axes. ListPlot[dataset, Frame -> True, Axes -> False]; === > Subject: Also force AxesOrigin to be in the lower right corner? > I want to force the x-axis to lie on the bottom of the graph regardless > of a specific dataset. What's the best way to do this? I've been trying > plotting the dataset and grabbing the lower-right corner of the > plotrange with AbsoluteOptions. This works but seems absurdly > complicated and I feel like I'm missing the forest for the trees. Is > there a better way than this: > firstplot = ListPlot[dataset, DisplayFunction -> Identity]; > ListPlot[dataset, AxesLabel -> {x, y}, AxesOrigin -> > {AbsoluteOptions[firstplot, PlotRange][[1, 2, 1, 1]], > AbsoluteOptions[firstplot, PlotRange][[1, 2, 2, 1]]}, DisplayFunction > -> $DisplayFunction]; > Jason === Subject: finding the position of a pattern in list I am working on a program to do the following: My data is a list of 0 and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to find the positions of all the pattern of {0,1}. In my previous example, the first {0,1} is at 2 and and the second {0,1} appears at 7. I can write a loop to do this, but I have several thousands such lists, the computation will be time consuming using loop. My question is whether it is possible to use the pattern match to do this quickly. If not for the list, do I need to convert the list to Gang Ma === Subject: Re: Increment and AddTo > can anybody explain the following behaviour: > i = 0; > v = {1, 2, 3}; > v[[++i]] += 10; > gives > {1,11,3} > i has been incremented by 2! Using Trace the reason should be clear. Trace gives: Trace[v[[++i]] += 10;] {v[[++i]]+= 10;,{v[[++i]]+= 10,{{v,{1,2,3}},{++i,{i,0},{i=1,1}, 1},{1,2,3}[[1]],1},{{1+10,11}, v[[++i]]=11,11},11},Null} Since x+=dx is explicitly equivalent to x=x+dx it should be clear that x will be evaluated at least once before the assignment is done, that results in the expression x+dx evaluating to 11 in this case. Set[Part[_,_]] has special semantics though, the second argument of Part has to be evaluated before the assignment to know where the substitution must be made. Since Set has the attribute HoldFirst the second argument to Part is ++i not 1 so ++i gets evaluated again as you can see in the Trace where the expression v[[++i]]=11 gets evaluated. At that point ++i has already been evaluated once so obviously i will be incremented twice. > i++ is even more interesting: > i = 1; > v = {1, 2, 3}; > v[[i++]] += 10; > gives: > {1,11,3} It's pretty much the same story, i++ gets evaluated twice, however the final value of i which I get is 3 not 2 which makes sense. > Further: > i = 0; > v = {1, 2, 3}; > ++v[[++i]] ; > gives: > {1,2,3} > Again i has been incremented by 2, but v has not been touched at all. ++ is not equivalent to a Set expression so ++v[[++i]] does not share the special semantics that Set and Part do and the result of the expression does not modify the value of anything. Ssezi === Subject: Re: Increment and AddTo Well I think I can explain it, but ... ++i is executed twice as indicated below in bold-red. The first time as part of determining the value of the index to find the value to be added to 5 (since pre-fix, I think this is correct) and then a second time as part of the expression to find where the sum should be assigned to in the indexed string (I'd assume this execution is a surprise). Therefore, it is effectively start i=0, autoincrement i, find the v[i] or v[1], add to 5, now to assign back first autoincrement i, then assign 6 back to v[2]. Paul Using trace. Clear [ i, v ] Trace[ i = 0; v = {1, 2, 3}; v[[++i]] += 5; v; i ] {i=0;v={1,2,3};vP++iT+=5;v;i,{i=0,0},{v={1,2,3},{1,2,3}},{vP++iT+=5,{{v, {1,2,3}},{++i,{i,0},{i=1,1},1},{1,2,3}P1T,1},{{1+5,6},vP++iT=6,6},6},{v, {1,6,3}},{i,2},2} -----Original Message----- === Subject: Increment and AddTo can anybody explain the following behaviour: i = 0; v = {1, 2, 3}; v[[++i]] += 10; v i gives {1,11,3} 2 i has been incremented by 2! i++ is even more interesting: i = 1; v = {1, 2, 3}; v[[i++]] += 10; v i gives: {1,11,3} 2 again i is incremented by 2, but for the sum v[[1]] is used and stored in v[[2]] Further: i = 0; v = {1, 2, 3}; ++v[[++i]] ; v i gives: {1,2,3} 2 Again i has been incremented by 2, but v has not been touched at all. Daniel === Subject: Re: Matrix multiplication problem fixed via dot operation. > To answer my own posting, it looks like the dot operator is needed > when the matrices aren't both square. > E.g.: a row vector with components a and b times a column vector with > components c and d will yield the correct result, the dot-product. > I'm still puzzled why Mathematica doesn't do the same thing without the dot. > Chris Young Beware: though you got no error messages in case of multiplying square matrices with a space between them (as opposed to a dot), the result is NOT a dot product (matrix multiplication), but the matrices are multiplied element by element, e.g. if C = A B then C[[1,1]] equals A[[1,1]] * B[[1,1]], etc. In short, the ordinary multiplication has the attribute Listable. (It can be very useful, e.g. when you have a vector variable x and a vector (list) of coefficients a, to compose them into a x.) Kristjan Kannike The same person at different times can seem like a different person; sometimes that person is you. -- Peter Norvig === Subject: Printing book style sheet I would like to export some of my notebooks as appendices to a book ( B5 format )The book is written in Framemaker 7.1 > For this I would like to import PDF output prints from Mathematica. I wonder I there is anyone who has nice printing style Style sheets for Mathematica that gives me nice output formats for adding to a book Tnx Ger de Graaf . === Subject: Re: ?? >make a Graphics[] object out of your density plot >and >than transform the polygons, i.e, >gr = DensityPlot[ > Re[SphericalHarmonicY[4, 2, th, phi]], {th, >0, Pi}, {phi, 0, 2Pi}, > PlotPoints -> {64, 128}] // Graphics; >gg = gr /. Raster[bm_, {{x1_, y1_}, {x2_, y2_}}, >{z1_, z2_}, ___] :> > Block[{n, m, dx, dy, poly}, > {n, m} = Dimensions[bm]; > dx = (x2 - x1)/m; dy = (y2 - y1)/n; > poly[{j_, i_}] := Block[{p}, p = >{x1, y1} + {dx, dy}*{i - 1, j - 1}; > Polygon[{p, p + {dx, 0}, p + {dx, >dy}, p + {0, dy}}]]; > MapIndexed[{GrayLevel[(#1 - >z1)/(z2 - z1)], poly[#2]} &, bm, {2}] > ]; >Show[Graphics3D[{EdgeForm[], > gg[[1]]} /. {(h : (Polygon | Line))[pnts_] :> > Polygon[{Cos[#[[2]]]*Sin[#[[1]]], >Sin[#[[2]]]*Sin[#[[1]]], > Cos[#[[1]]]} & /@ pnts], > GrayLevel[g_] :> SurfaceColor[Hue[g]]} > ] This is awesome!! Jens > Jens >Bob Buchanan >schrieb im Newsbeitrag >| I have numerically approximated the omega-limit >set of a model of a spherical, magnetic pendulum. >For a grid of theta and phi coordinates on the >unit sphere I have numerically solved the >Hamiltonian system of ODEs governing the pendulum >until it comes to rest (or pretty close to rest). >The data is in the form of a rectangular array >which I can easily display as a rectangular list >density plot. >| Is there a way to wrap this density plot back >around the surface of the unit sphere --- >something like a ListSphericalDensityPlot[] >function? >| I don't think there is an already defined >function to perform this type of operation. Is >there an easy way to do it myself? >| Bob Buchanan >| Bob.Buchanan@millersville.edu === Subject: Re: Code to translate to negative base... >Does anyone have code to translate to a negative base? Surprinsingly enough, this is very simple, although not much known among students. I find the approach below conceptually very intuitive and ellegant: everything depends on a REMAINDER function. Suppose that you already have implemented the traditional algorithm that gives you the digits of a integer number N in base B, for B>0 in Integers. Then, just enter with a negative value for B and you will get what you want. Let me ellaborate on this a little. We can see the traditional algorithm as a Mathematica command, say (although below IĞll not give any formatting instructions) myBaseForm[A, B, r] where r is a REMAINDER FUNCTION, that is, a rule r[A, B] such that A is congruent to r[A,B] mod B. The Euclidean remainder -- the standard one -- is given by r[A_, B_] := A - Abs[B]*Floor[A/Abs[B]] or, using Mathematica Mod, r[A_, B_] := Mod[A, Abs[B]] For each A in Integers, this gives the UNIQUE number r such that A is congruent to r mod B and 0<=r {True, True, False, False}, Axes -> None, Prolog -> {AbsolutePointSize[3]}, ImageSize -> 450]; Or with DrawGraphics this could be done more simplt as Needs[DrawGraphics`DrawingMaster`] Draw2D[ {AbsolutePointSize[3], Point /@ dataset}, Frame -> {True, True, False, False}, ImageSize -> 450]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I want to force the x-axis to lie on the bottom of the graph regardless of a specific dataset. What's the best way to do this? I've been trying plotting the dataset and grabbing the lower-right corner of the plotrange with AbsoluteOptions. This works but seems absurdly complicated and I feel like I'm missing the forest for the trees. Is there a better way than this: firstplot = ListPlot[dataset, DisplayFunction -> Identity]; ListPlot[dataset, AxesLabel -> {x, y}, AxesOrigin -> {AbsoluteOptions[firstplot, PlotRange][[1, 2, 1, 1]], AbsoluteOptions[firstplot, PlotRange][[1, 2, 2, 1]]}, DisplayFunction -> $DisplayFunction]; Jason === Subject: Re: How if I want to assume that ------- There is the Assuming statement, often used with integrals, and the Assumptions option used in Simplify and FullSimplify. Look them up in Help. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Does there exist a 'assume' function in Mathematica? For example, I want to assume that { x>y } === Subject: Contour Plot Can anyone explain to me how the contour plot shows that the limit possibly exits or doesnt exit? === Subject: Re: Counting the number of paths in a network You need to use HamiltonianCycle. Here is an example of how this solves your problem: <I am interested in counting the number of paths from a node in a > network back to that node, counting loops (cycles) only once. Is > there any readily available code that does this? > I found some code posted here a few years ago that counts the number > of paths between two nodes, but am having trouble modifying it to > complete the loop (it also enumerates each path, but I'm not really > interested in that). > More academically, is there perhaps a better measurement for the > fundamental feature --namely the number of options available to > someone to get information around a system? > John > John Q. Dickmann > Research Assistant > Lean Aerospace Initiative > Massachusetts Institute of Technology > Bldg 41-205 > 77 Massachusetts Ave. > Cambridge, MA 02139 > jqd@mit.edu > 401-225-3511 === Subject: Re: Counting the number of paths in a network John, Check out the combinatorica package. Skienna's new textbook is helpful on how to use the package though the Hlep menus gives the basics. Computational Discrete Mathematica. Combinatorics and Graph Theory with Mathematica 0-521-80686-0 Brian === Subject: Re: Re: Re: Not Using a Text Editor Interface for Mathematica Maybe something like a data flow diagram would help. For instance, if your processing looks like this g[t_]:=f[t]-f[t-1]; then it is usually represented diagrammatically as (evaluate the code below to generate the diagram): << Graphics`Arrow` $TextStyle = {FontSize -> 16, FontWeight -> Bold}; {a, b} = {1/10, 1/5}; Show[Graphics[{Arrow[{0, 0}, {1, 0}], Arrow[{0, 1}, {1/2 - a, 1}], Circle[{1/2, 1}, a], Text[!(z^(-1)), {1/2, 1}], Arrow[{1/2 + a, 1}, {1, 1}], Arrow[{1, 1}, {3/2 - b/Sqrt[2], 1/2 + b/Sqrt[2]}], Arrow[{1, 0}, {3/2 - b/Sqrt[2], 1/2 - b/Sqrt[2]}], Circle[{3/2, 1/2}, b], Text[-, {3/2, 1/2}], Arrow[{3/2 + b, 1/2}, {2, 1/2}]}], AspectRatio -> 1/2]; Steve Luttrell > On 2/21/06, Steve Luttrell >> Diagrams can suggest better ways of doing the number crunching, or they >> can >> even suggest ways of avoiding the number crunching altogether; I have no >> idea whether either of these happy scenarios holds in your application >> area. > Most of my applications are analysis from data of electronic circuits, > data loggers and the like. > But using more diagrams looks like a nice idea, and thus I would be > happy if someone pointed to more applications of diagrams in the area > of Electronics and Electrical Engineering. === Subject: Re: Combining ContourPlot and Plot G'day, Show[ GraphicsArray[{ Plot[x, {x, -1, 1}, DisplayFunction -> Identity], ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, DisplayFunction -> Identity]} ] ] Yas > Hi group, > The title says it all really. I want something like > Show[Plot[x,{x,-1,1}],ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}]] > I've looked through the usenet archive to no avail. > James === Subject: Re: Combining ContourPlot and Plot >Hi group, >The title says it all really. I want something like >Show[Plot[x,{x,-1,1}],ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}]] >I've looked through the usenet archive to no avail. >James If you change the order of the plots it works fine << Graphics`Graphics` plot1=Plot[x,{x,-1,1},PlotStyle->Hue[1]] plot2=ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}] DisplayTogether[plot2,plot1] Show[plot2,plot1] Hope this helps Pratik === Subject: Re: Combining ContourPlot and Plot You need to put the Plot on top of the ContourPlot Needs[Graphics`]; Show[ ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}, DisplayFunction->Identity], Plot[x,{x,-1,1},PlotStyle->Red, DisplayFunction->Identity], DisplayFunction->$DisplayFunction]; DisplayTogether[ ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}], Plot[x,{x,-1,1},PlotStyle->Red]]; Bob Hanlon === > Subject: Combining ContourPlot and Plot > Hi group, > The title says it all really. I want something like > Show[Plot[x,{x,-1,1}],ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}]] > I've looked through the usenet archive to no avail. > James === Subject: Re: Can't multiply non-square matrices. G'day, Is this what you were after? x = {{a, b}} y = {c, d} x.y Yas > Is there a way to multiply non-square matrices? E.g., a 3-row by 2-row > matrix times a 2-row by 1-row matrix should yield a 3-row by 1-row > matrix, if I remember my linear algebra correctly. > Instead when I do something like > (a b) (c) > (d) > I get an error involving Thread::tdlen: > Thread::tdlen: Objects of unequal length in {{a, b}}{{c}, {d}} cannot be > combined. > (The (c) and (d) above represent a 2-dimensional column vector, > with one pair of parenthese around them.) > I entered the line > << LinearAlgebra`MatrixManipulation` > but this doesn't seem to help. > Any help appreciated. > Chris Young === Subject: Re: Can't multiply non-square matrices. > Is there a way to multiply non-square matrices? E.g., a 3-row by 2-row > matrix times a 2-row by 1-row matrix should yield a 3-row by 1-row > matrix, if I remember my linear algebra correctly. > Instead when I do something like > (a b) (c) > (d) > I get an error involving Thread::tdlen: > Thread::tdlen: Objects of unequal length in {{a, b}}{{c}, {d}} cannot be > combined. > (The (c) and (d) above represent a 2-dimensional column vector, > with one pair of parenthese around them.) > I entered the line > << LinearAlgebra`MatrixManipulation` > but this doesn't seem to help. > Any help appreciated. > Chris Young Hi Chris, Your row vector {a, b} has extraneous parentheses around it. In[1]:= {{a,b}} {{c},{d}} Thread::tdlen: Objects of unequal length in {{a, b}}{{c}, {d}} cannot be combined. Out[1]= {{a,b}} {{c},{d}} Compare with In[2]:= {a,b} {{c},{d}} Out[2]= {{a c},{b d}} In[3]:= {a,b}.{{c},{d}} Out[3]= {a c+b d} In[4]:= {a,b}.{c,d} Out[4]= a c+b d In[5]:= {a,b} {c,d} Out[5]= {a c,b d} /J.M. === Subject: Re: Can't multiply non-square matrices. {a, b}.{{c}, {d}} ?? the usual Times[] * does an element-wise multiply. Jens Chris Young schrieb | Is there a way to multiply non-square matrices? E.g., a 3-row by 2-row | matrix times a 2-row by 1-row matrix should yield a 3-row by 1-row | matrix, if I remember my linear algebra correctly. | | Instead when I do something like | | (a b) (c) | (d) | | I get an error involving Thread::tdlen: | | Thread::tdlen: Objects of unequal length in {{a, b}}{{c}, {d}} cannot be | combined. | | (The (c) and (d) above represent a 2-dimensional column vector, | with one pair of parenthese around them.) | | I entered the line | << LinearAlgebra`MatrixManipulation` | but this doesn't seem to help. | | Any help appreciated. | | Chris Young | === Subject: Re: Also force AxesOrigin to be in the lower right corner? >I want to force the x-axis to lie on the bottom of the graph >regardless of a specific dataset. What's the best way to do this? >I've been trying plotting the dataset and grabbing the lower-right >corner of the plotrange with AbsoluteOptions. This works but seems >absurdly complicated and I feel like I'm missing the forest for the >trees. Is there a better way than this: >firstplot = ListPlot[dataset, DisplayFunction -> Identity]; >ListPlot[dataset, AxesLabel -> {x, y}, AxesOrigin -> >{AbsoluteOptions[firstplot, PlotRange][[1, 2, 1, 1]], >AbsoluteOptions[firstplot, PlotRange][[1, 2, 2, 1]]}, >DisplayFunction -> $DisplayFunction]; How about ListPlot[dataset, Axes -> None, Frame -> {True, True, None, None}, FrameLabel -> {x, y}]; -- To reply via email subtract one hundred and four === Subject: WolframSSH vs mathssh and private key command line option In trying to set up a remote kernel connection to a linux machine, I am wondering the following about the Kernel configuration dialog box. It uses java -jar mathssh, but mathssh doesn't exist in my Mathematica installation directory. I do have C:Program FilesWolfram ResearchMathematica5.2SystemFilesJavaWolframSSH.jar Why is it trying to use a program that doesn't exist? Also, what is the command line option to specify the location of the private key file? Win XP Mathematica 5.2.0 Student Edition... === Subject: Re: General--Making the DisplayFormula style in ArticleModern look like Traditional > I'm still attempting to use Mathematica to typeset homework. I'm having all > sorts of difficulty trying to figure out how to get Mathematica to do what I > want it to do, so I appreciate any help that you can give. I don't have a > particularly deep question right now, but I am acutely aware that I don't > really feel like I know what is going on. > display formula. I would like the formulas that I write to come out > looking like TraditionalForm, but they default to StandardForm. I can > certainly change this every time I read a formula, but it would be nice to > be able to edit the style sheet so that it defaults to TraditionalForm > instead of StandardForm. Try as I might, though, I haven't been able to do > this. Any suggestions? If you do Format | Edit Style Sheet ... and go to the Formulas and Programming Section and select the DisplayFormula style and then do Format | Show Expression you will see that one option for cells of this type is DefaultFormatType->DefaultInputFormatType Now, since I bet that your DefaultInputFormatType is StandardForm, you will see why formulas in DisplayFormula style are in StandardForm. Personally, I think that this default setting is wrong. For display formulas you nearly always want DefaultFormatType->TraditionalForm so, if you change this in the Style Sheet everything will work as expected. You can also change the Notebook or Global settings of the DefaultFormatType using Format | Option Inspector and modfifying the appropriate CommonDefaultFormatTypes. Alternatively, if you change Cell | Default Input FormatType to TraditionalForm (which is my preference for Input and Output) then you will get formulas in TraditionalForm. and Solutions2005.nb at http://physics.uwa.edu.au/pub/ElectroMagnetism/Exams/Solutions/ Paul _______________________________________________________________________ Paul Abbott Phone: 61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: General--Making the DisplayFormula style in ArticleModern look like Traditional Rob, The following steps should get you where you want: (i) Open up a new notebook and select from the menu items Format |Style Sheet|ArticleClassic (ii) Import a private copy of the style sheet by selecting from menu items Format | Edit Style Sheet . The style sheet for your notebook should appear. (iii) Go to the Formulas and Programming Section of the style sheet notebook and select the cell called Prototype for style DisplayFormula (iv) Open up the option inspector from menu item Format |Option Inspector. The Option Inspector Dialog box should open. (v) With the cell in Step (iii) selected, and the option values in the Dialog box set on Selection, type in Lookup box: CommonDefaultFormatTypes . The option inspector should take you to the section: New Cell Defaults | CommonDefaultFormats ->{...} (vi) Under the Input section change 'StandardForm' to 'TraditionalForm' Now you should be able to type in your formulas with the default traditionalForm fonts. You can short cut this process by going directly to the Style Sheet and clicking on the cell you selected in Step (iii) and opening up the cell using the menu item: Format | Show Expression. All the options for that cell will be displayed and you can simply add the option: CommonDefaultFormatTypes->{Input->TraditionalForm}. Then click on Show Expression and you are done. Hope this helps, Brian ps: Paul Abbot is an expert on the use of TraditionalForm in his class notebooks. Check out his responses to the mathgroup on this subject. === Subject: Re: LeftClick+Shift+Enter Reassign Hello James, I don't have a specific answer to your question but have something related. I have been experimenting with various ways to cut down on keystrokes and mouse gestures within Mathematica. I queried the forum on Jan 27 and got some interesting reponses. One useful method I have found is to use a Windows based macro writing program called MacroExpress (Google it and download a free trial). With this program it is very easy to assign keyboard macros to perform most Mathematica operations. Also, and this speaks to your question, you can assign these macros to a floating menu. I placed a macro for shift enter on such a menu and can evaluate a selected cell with a single left mouse click. In a similar vein, I have installed a speech recognition program called Dragon Naturally Speaking. With it I can evaluate a selected cell by saying Press shift enter Finally, it's relatively inexpensive to find a mouse with all sorts of programmable buttons. Tom Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=8477#p8477 === Subject: Re: Checking function syntax > How can I make my own functions give an error if they are called with > the wrong syntax? This is a FAQ -- but not so easy to find (a search on argx is a good way to find the answer). > For example, if I define this function > In[37]:= > MyFunc1[x_,y_]:=Tuples[{x,y},2] > and then Map MyFunc2 over the result > In[38]:= > Map[MyFunc2,MyFunc1[a,b]] > I get this (correct, desired) output. > Out[38]= > {MyFunc2[{a,a}],MyFunc2[{a,b}],MyFunc2[{b,a}],MyFunc2[{b,b}]} > However, if I inadvertently added a third argument > In[39]:= > Map[MyFunc2,MyFunc1[a,b,c]] > then I get this (correct, but undesired) output > Out[39]= > MyFunc1[MyFunc2[a],MyFunc2[b],MyFunc2[c]] > I would prefer to get some sort of error message in the second case, > such as the built-in function Sin[...] produces when called with the > wrong number of arguments. > In[41]:= > Sin[1.] > Out[41]= > 0.841471 > In[42]:= > Sin[2,3] > Sin::argx : Sin called with 2 arguments; 1 argument is expected. Out[42]= > Sin[2,3] The following rule issues an error message (using the built-in Message mechanism via argrx -- look this up in the Help Browser) if f is called with an incorrect number (e.g. != 2) of arguments: f[args___]:= Null/; Length[{args}] != 2 && Message[f::argrx, f, Length[{args}], 2] As a side-effect of evaluating the Condition the rule on the right-hand side computes the number of arguments using Length and prints a message when it is not equal to two. f[1,2,3] f::argrx: f called with 3 arguments; 2 arguments are expected. More... f[1, 2, 3] Paul _______________________________________________________________________ Paul Abbott Phone: 61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: Checking function syntax > How can I make my own functions give an error if they are called with > the wrong syntax? Try this : Here is your standard definition : MyFunc1[x_, y_] := Tuples[{x, y}, 2] Define your error message : MyFunc1::WrongInput = A sensible error message for incorrect input `1` Create the rule that match wrong input : MyFunc1[u___] := Message[MyFunc1::WrongInput, u] Check normal function call : Map[MyFunc2, MyFunc1[a, b]] And incorrect one : Map[MyFunc2, MyFunc1[a, b, c]] Mind the fact that in some situations some rules might have equal priorities, in which case rule definition ordering defines which rule will be called. === Subject: Re: Checking function syntax and adding MyFunc::warg=Worng number of arguments. MyFunc1[x___] /; Length[{x}]!=2:=(Message[MyFunc::warg];MyFunc1[x]) will not help ??? Jens Chris Rodgers | | How can I make my own functions give an error if they are called with | the wrong syntax? | | For example, if I define this function | | In[37]:= | MyFunc1[x_,y_]:=Tuples[{x,y},2] | | and then Map MyFunc2 over the result | | In[38]:= | Map[MyFunc2,MyFunc1[a,b]] | | I get this (correct, desired) output. | | Out[38]= | {MyFunc2[{a,a}],MyFunc2[{a,b}],MyFunc2[{b,a}],MyFunc2[{b,b}]} | | However, if I inadvertently added a third argument | | In[39]:= | Map[MyFunc2,MyFunc1[a,b,c]] | | then I get this (correct, but undesired) output | | Out[39]= | MyFunc1[MyFunc2[a],MyFunc2[b],MyFunc2[c]] | | I would prefer to get some sort of error message in the second case, | such as the built-in function Sin[...] produces when called with the | wrong number of arguments. | | In[41]:= | Sin[1.] | Out[41]= | 0.841471 | In[42]:= | Sin[2,3] | Sin::argx : Sin called with 2 arguments; 1 argument is expected. Out[42]= | Sin[2,3] | | | Chris. | === Subject: Re: Checking function syntax Hi Chris, your problem can be solved by noting that special definitions are examined before more general ones. Here is an example: Remove[f]; f[a_, b_] := Print[Right number of arguments]; f[___] := Print[Wrong number of arguments]; f[1] f[1, 2] f[1, 2, 3] Daniel > How can I make my own functions give an error if they are called with > the wrong syntax? > For example, if I define this function > In[37]:= > MyFunc1[x_,y_]:=Tuples[{x,y},2] > and then Map MyFunc2 over the result > In[38]:= > Map[MyFunc2,MyFunc1[a,b]] > I get this (correct, desired) output. > Out[38]= > {MyFunc2[{a,a}],MyFunc2[{a,b}],MyFunc2[{b,a}],MyFunc2[{b,b}]} > However, if I inadvertently added a third argument > In[39]:= > Map[MyFunc2,MyFunc1[a,b,c]] > then I get this (correct, but undesired) output > Out[39]= > MyFunc1[MyFunc2[a],MyFunc2[b],MyFunc2[c]] > I would prefer to get some sort of error message in the second case, > such as the built-in function Sin[...] produces when called with the > wrong number of arguments. > In[41]:= > Sin[1.] > Out[41]= > 0.841471 > In[42]:= > Sin[2,3] > Sin::argx : Sin called with 2 arguments; 1 argument is expected. Out[42]= > Sin[2,3] > Chris. === Subject: Re: Matrix multiplication problem fixed via dot operation. > To answer my own posting, it looks like the dot operator is needed > when the matrices aren't both square. No -- the Dot operator is _always_ needed when you want to (matrix) multiply two matrices. > E.g.: a row vector with components a and b times a column vector with > components c and d will yield the correct result, the dot-product. > I'm still puzzled why Mathematica doesn't do the same thing without the dot. Because if you have two objects of the same dimension and multiply them together using Times, you get element-by-element multiplication. For example, {{a,b},c} {{d,e},f} Paul _______________________________________________________________________ Paul Abbott Phone: 61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: Matrix multiplication problem fixed via dot operation. >To answer my own posting, it looks like the dot operator is >needed when the matrices aren't both square. >E.g.: a row vector with components a and b times a column vector >with components c and d will yield the correct result, the >dot-product. >I'm still puzzled why Mathematica doesn't do the same thing without >the dot. Because it is very useful to do things like: In[3]:={a,b} {c,d} Out[3]={a c,b d} And since for me (and I suspect most others) the need to multiply lists of things in the manner above arises much more frequently than the need for matrix multiplication, I am glad Mathematica reserves the implied multiplication syntax for this rather than matrix multiplication when matrices are involved. -- To reply via email subtract one hundred and four === Subject: Re: Map-like behaviour for functions of more than a single argument? Matt === Subject: Re: Combining ContourPlot and Plot Hi James See if this helps < Red], ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, ContourShading -> False]] Antonio === Subject: Re: Combining ContourPlot and Plot Show @@ Block[{$DisplayFunction = Identity}, { ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}], Plot[x, {x, -1, 1}, PlotStyle -> {{RGBColor[1, 1, 0]}}] } ] ??? Jens schrieb im Newsbeitrag | Hi group, | | The title says it all really. I want something like | | Show[Plot[x,{x,-1,1}],ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}]] | | I've looked through the usenet archive to no avail. | | | James | === Subject: Re: Combining ContourPlot and Plot Hi James, you have to take care what is drawn first. Obvioulsy the Plot is overwritten by ContourPlot. Simply reverse the plot commands: Show[ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}], Plot[x, {x, -1, 1}]] Daniel > Hi group, > The title says it all really. I want something like > Show[Plot[x,{x,-1,1}],ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}]] > I've looked through the usenet archive to no avail. > James === Subject: Re: Combining ContourPlot and Plot >The title says it all really. I want something like >Show[Plot[x,{x,-1,1}],ContourPlot[x^2+y^2,{x,-1,1},{y,-1,1}]] >I've looked through the usenet archive to no avail. Is this what you want? Show[ Block[{$DisplayFunction = Identity}, {ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}], Plot[x, {x, -1, 1}]}]]; I've done two things differently. First, I've used Block to temporarily set $DisplayFunction to Identity, suppressing display of the individual plots. Second, I've reversed the order in which the plots are made. Several of the default options for ContourPlot conflict with the defaults for Plot. When the graphics are combined, the first value of an option determines the way the combined graphics appears. For example, Plot[x,{x,-1,1},AspectRatio->1,AspectRatio->1/GoldenRule]; plots with an aspect ratio of 1. Also, given the large dark area in the contour plot, I think the following combination is more visually informative Show[ Block[{$DisplayFunction = Identity}, {ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, ContourShading -> False], Plot[x, {x, -1, 1}, PlotStyle -> Red]}]]; -- To reply via email subtract one hundred and four