A102 === Subject: Packages without packages > Yet I'd like to explain better what is my larger problem is: > to break down a big project in pieces, it is correct then to save big > chunks of code definitions as packages? In my musing on packages, I've been thinking that I tend to have a fair number of individual projects on different physical topics, which I keep in individual folders or directories, and each of which tends to have its own set of project-specific modules or packages. And, my packages in fact consist almost totally of just Module definitions, sometimes lengthy, which implement some complicated computational algorithm or create some plot or table generally specific to that project. So, why futz with the complexity of Mathematica's global package mechanism at all? How about a packages without packages approach. For each project, I typically have one or a few project notebooks which, essentially, explore physics questions and prepare reports or memos or documents that I file or send to others (and in which I may want to present a lot of graphic or tabular results, with a lot of associated commentary, but very little detailed code). So, why not associate with each project a ProjectModules.nb notebook which contains nothing but the definitions of any major or lengthy Modules or := formula definitions tht I use in that project's notebooks. This ProjectModules.nb notebook **can reside right in the folder for that project** -- in fact, it can be open all the time I'm working on any of the notebooks for that project, with its window minimized. If I decide I want to reformat a graphic that is created in one of those project notebooks by a certain Module, I can open ProjectModules.nb window, do the editing of that Module, and re-execute the whole notebook very quickly (it doesn't _do_ any work when re=executed; just redefines stuff). Shifting over to work on a different project? Just open the folder for that project; restart Mathematica to clear out all the sludge from the previous project; execute the ProjectModules.nb in that folder; and start on whatever other notebook(s) that use those modules. I'm not knocking that basic packages concept, for those who may need it. But for me, packages without packages may offer: 1) Modularity 2) Simplicity 3) I always know what's going on. 4) Freedom from cross-project confusion 5) Freedom from the complexities of the whole package system (and from Wolfram's compulsion to keep changing it) (and from their inability to document these changes usefully) === Subject: Mathlink: How do I pass arbitrary data from Mathematica to C? I am trying to write some code to interface Mathematica to a closed- source library written in C. I'm using Mathlink for this, which is typically used to interface Mathematica to external functions - see for example For example, if the library has a function 'f' with the following prototype: int f(int x, int y); the following in a Mathlink template (.tm file) will allow me to call this function from Mathematica by the name Foo, if I link to the library., create an executable, then install that executable in Mathematica with Install[]. :Begin: :Function: f :Pattern: Foo[x_Integer, y_Integer] :Arguments: {x, y} :ArgumentTypes: {Integer, Integer} :ReturnType: Integer :End: (There is no need for me to write the function f, as that has been done. I just need to link to the library containing the function f, in much the same way you use the 'pow' function in C without writing it - you would just link to the maths library.). I have no problem with the above - it all works as expected. The problem occurs with a function 'g', which instead of having only integer arguments, takes a pointer to some data. The format of the data is not specified - the C function just needs to know where in memory the data is, and how many bytes there are. The C prototype is int g(const void *data, long nbytes); Does anyone know how I can write a Mathematica template so when I link with the function 'g', I can pass the data properly? Note, that since the library is closed-source, I am not able to change the calling method in any way. But I expect it should be possible to write an interface in C, such that data is passed from Mathematica in a form compatible with Mathematica, and then converts it to a from the C library accepts. But I am stuck as how to do this. If its not possible to do this with a template, can it be done by writing it all in C? If so, how? I don't want Mathematica to try to interpret the data in any way - just to pass an address of where the data is in memory, and also the number of bytes of data. Than the library function g will return an integer, which I want to pass back to Mathematica. Someone suggested that I might look at the C code generated by mcc to work out how to do this, (perhaps making use of MLPutInteger), but I can't work out how to do this. Does that make sense? Any ideas how to pass arbitrary data to a C program? I have a similar issue in trying to get arbitrary data from C to Mathematica, but that is another story. === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? I sent a post a few minutes ago in which I said the data might be a binary file, I think I then gave the way I might read that as BinaryReadList[filename.dat,Character8] If I did (and I dont have a record of the post, which had not appeared yet), then I was wrong. I should have used BinaryReadList[filename.dat,Byte] I think. The point I need to get over is that the data format is not set in stone, so I need a way of transfering an arbitrary collection of bytes === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? Unfortunately, I don't fully understand your question, but I hope the > following example of how I would use the function in C will help. I'll > call the function write_to_hardware and another read_from_hardware. I > do in fact want to use both functions in Mathematica, although I have > only asked about one so far. main() > { > void *huminity_value; I think that variable names are messed up a bit. I suppose that this should be void *result, right? > double humidity, temperature; > int days_since_calibration; > int error_code; humidity=malloc(5000); /* all data received is under 5000 bytes */ And this is result = malloc(5000); Is this correct? > error_code=write_to_hardware(RESET,5); > error_code=write_to_hardware(HUMIDITY,9); /* take a measurement of > humidity */ > error_code=read_from_hardware(result,5000); /* read humidity */ > humidity=atof(result); error_code=write_to_hardware(TEMPERATURE,11); /* take a measurement > of temperature */ > error_code=read_from_hardware(result,5000); /*read tempeature */ > temperature=atof(result); printf(humidity=%lf temperature=%lf n,humidity, temperature); } The C functions definitions are int write_to_hardware( const void *data,long length_of_command_in_bytes); > int read_from_hardware(void *data, long size_of_buffer_to_store_results); If you always work with character strings, why don't you use char * instead of void *? > In Mathematica I'd like to do something like WriteToHardware(RESET, 5) > WriteToHardware(HUMIDITY, 9); > (humidity would be a Mathematica string in this case) This is not correct Mathematica syntax. In Mathematica functions are called with f[], not f(). This Mathematica interface looks OK except that it is not necessary to pass the string length to WriteToHardware. A Mathematica string is visible as a char * and and int (its length) on the C side (see the reverse example). But the point to note is that whilst in these examples the data sent > was text, and the data received was text, this might not always be the > case. Potentially the data sent might be a binary file which > calibrates the thermometer. You still need to represent the data in some way in Mathematica. You can represent it as strings, or you can represent it as a list of integers (bytes). Probably the former will be more useful. representations. Did you take a look at the MathLink example programs? There is one for working with strings (reverse) and one for working with integer arrays (sumalist). You could use these examples as starting points. All you have to do is create C wrapper functions that call read_from_hardware() and write_to_hardware(), and make these wrapper functions accessible from Mathematica. Does that make it any clearer? > === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? > > int g(const void *data, long nbytes); ... > I don't want Mathematica to try to interpret the data in any way - > just to pass an address of where the data is in memory, and also the > number of bytes of data. Than the library function g will return an > integer, which I want to pass back to Mathematica. I think that there is a misunderstanding here. Everyone has assumed in their replies that you would like to transmit the data that const void *data is pointing to between the C program and Mathematica. However, it seems to me that the data is actually handled by the C program, and *never* by Mathematica. So Mathematica should only know about very simple objects that somehow *refer to* this special object that is stored in memory by the C program (and not Mathematica). Please clarify this important point. If this is the case, then one could use a Mathematica object someObject[ptr, len], where ptr and len are integers, and encode the pointer to the data and the length of the data. Only this someObject[] object would be passed to the C program (easily achievable with .tm templates), which in turn would decode the two values (ptr and len) to obtain a pointer and a length. This would work for as long as all the someObject[] objects are constructed by the C program. But if the user examines the structure of someObject[] and tries to construct someObjects with arbitrary ptr and len values, then the C program will get some invalid pointers, and will most likely crash. So I would suggest maintaining a table on the C side, which translates some identifier (e.g. a single integer) to a (ptr, len) pair. The identifier would be used on the Mathematica side, and the C program could check for validity of identifiers before translating them to pointers, to avoid invalid pointers and crashes. === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? > Does that make sense? Any ideas how to pass arbitrary data to a C > program? You won't be able to do this directly. You will have to write your own C function that converts the data from a Mathematica type to the raw data your function is expecting. This is not very difficult. Try something like this (not tested): /* MyFile.tm */ :Begin: :Function: myFunc :Pattern: MyFunc[reals:(_Real...)] :Arguments: { reals } :ArgumentTypes: Manual :ReturnType: Manual :End: /* library function to call */ extern int g(const double* theData, int theLength); void myFunc(void) { double* theData; int* theDims; char** theHeads; int theDepth; if(MLGetReal64Array(stdlink, &theData, theDims, &theHeads, &theDepth)) { int theLength = theDims[0], i, theResult; for(i = 1; i < theDepth; i++) theLength *= theDims[i]; theResult = g(theData, theLength); MLReleaseReal64Array(stdlink, theData, theDims, theHeads, theDepth); MLPutInteger(stdlink, theResult); } else MLPutSymbol(stdlink, $Failed); } === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? Does that make sense? Any ideas how to pass arbitrary data to a C > program? You won't be able to do this directly. You will have to write your > own C function that converts the data from aMathematicatype to the > raw data your function is expecting. This is not very difficult. Try > something like this (not tested): /* MyFile.tm */ :Begin: > :Function: myFunc > :Pattern: MyFunc[reals:(_Real...)] > :Arguments: { reals } > :ArgumentTypes: Manual > :ReturnType: Manual > :End: > But this makes nom sence to me, as my data is not necessarily going to consist of real numbers. It might do, but I certainly dont wish to assume thst. > /* library function to call */ > extern int g(const double* theData, int theLength); > The function I am calling will have the prototype int g (void *data, int length_of_data) I did wonder if it should be treated as a collection of unsigned characters, but I'm not sure if a Mathematica String would be appropiate, as then characters like n (new line) might have some significance, which I dont want them to. === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? > I am trying to write some code to interface Mathematica to a closed- > source library written in C. I'm using Mathlink for this, which is > typically used to interface Mathematica to external functions - see > for example > For example, if the library has a function 'f' with the following > prototype: int f(int x, int y); the following in a Mathlink template (.tm file) will allow me to call > this function from Mathematica by the name Foo, if I link to the > library., create an > executable, then install that executable in Mathematica with > Install[]. :Begin: > :Function: f > :Pattern: Foo[x_Integer, y_Integer] > :Arguments: {x, y} > :ArgumentTypes: {Integer, Integer} > :ReturnType: Integer > :End: (There is no need for me to write the function f, as that has been > done. I just need to link to the library containing the function f, in > much the same way you use the 'pow' function in C without writing it - > you would just link to the maths library.). I have no problem with the above - it all works as expected. The problem occurs with a function 'g', which instead of having only > integer arguments, takes a pointer to some data. The format of the > data is not specified - the C function just needs to know where in > memory the data is, and how many bytes there are. The C prototype is int g(const void *data, long nbytes); Does anyone know how I can write a Mathematica template so when I link > with the function 'g', I can pass the data properly? Note, that since > the library is closed-source, I am not able to change the calling > method in any way. But I expect it should be possible to write an > interface in C, such that data is passed from Mathematica in a form > compatible with Mathematica, and then converts it to a from the C > library accepts. But I am stuck as how to do this. If its not possible to do this with a template, can it be done by > writing it all in C? If so, how? I don't want Mathematica to try to interpret the data in any way - > just to pass an address of where the data is in memory, and also the > number of bytes of data. Than the library function g will return an > integer, which I want to pass back to Mathematica. Someone suggested that I might look at the C code generated by mcc to > work out how to do this, (perhaps making use of MLPutInteger), but I > can't work out how to do this. Does that make sense? Any ideas how to pass arbitrary data to a C > program? I have a similar issue in trying to get arbitrary data from C to > Mathematica, but that is another story. > When you pass data over MathLink, you are communicating between two processes - so no pointers can be passed. It certainly sounds as though you need to write an interface routine in C - as you suggest. Presumably you know the structure of this data, so perhaps you could transmit it from Mathematica in pieces and assemble it in the required format in the interface routine. Perhaps you should tell us the structure of this data, and how big it is. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? > I am trying to write some code to interface Mathematica to a closed- > source library written in C. I'm using Mathlink for this, which is > typically used to interface Mathematica to external functions - see > for example http://reference.wolfram.com/mathematica/tutorial/SettingUpExternalFu... For example, if the library has a function 'f' with the following > prototype: int f(int x, int y); the following in a Mathlink template (.tm file) will allow me to call > this function from Mathematica by the name Foo, if I link to the > library., create an > executable, then install that executable in Mathematica with > Install[]. :Begin: > :Function: f > :Pattern: Foo[x_Integer, y_Integer] > :Arguments: {x, y} > :ArgumentTypes: {Integer, Integer} > :ReturnType: Integer > :End: (There is no need for me to write the function f, as that has been > done. I just need to link to the library containing the function f, in > much the same way you use the 'pow' function in C without writing it - > you would just link to the maths library.). I have no problem with the above - it all works as expected. The problem occurs with a function 'g', which instead of having only > integer arguments, takes a pointer to some data. The format of the > data is not specified - the C function just needs to know where in > memory the data is, and how many bytes there are. The C prototype is int g(const void *data, long nbytes); Does anyone know how I can write a Mathematica template so when I link > with the function 'g', I can pass the data properly? Note, that since > the library is closed-source, I am not able to change the calling > method in any way. But I expect it should be possible to write an > interface in C, such that data is passed from Mathematica in a form > compatible with Mathematica, and then converts it to a from the C > library accepts. But I am stuck as how to do this. If its not possible to do this with a template, can it be done by > writing it all in C? If so, how? I don't want Mathematica to try to interpret the data in any way - > just to pass an address of where the data is in memory, and also the > number of bytes of data. Than the library function g will return an > integer, which I want to pass back to Mathematica. Someone suggested that I might look at the C code generated by mcc to > work out how to do this, (perhaps making use of MLPutInteger), but I > can't work out how to do this. Does that make sense? Any ideas how to pass arbitrary data to a C > program? I have a similar issue in trying to get arbitrary data from C to > Mathematica, but that is another story. When you pass data over MathLink, you are communicating between two > processes - so no pointers can be passed. It certainly sounds as though > you need to write an interface routine in C - as you suggest. Presumably > you know the structure of this data, so perhaps you could transmit it > from Mathematica in pieces and assemble it in the required format in the > interface routine. Perhaps you should tell us the structure of this data, and how big it is. David Baileyhttp://www.dbaileyconsultancy.co.uk The data will be passed to some hardware via a library routine written in C. For example, the first bit of data might bea command like RESET, the next might be LOADFILE The next bit of data might be a binary file. Hence I need to find a way of passing an arbitrary collection of bytes. It might be one byte, two bytes, three bytes ... up to a couple MB or so. I will know the exact length. It it was a file I wanted to send, then I assume something like data=BinaryReadList[filenane.dat,Character8] would be suitable to read it, then I would need to send the contents of 'data' But equally the data might just be a bit of text. === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? a) MathLink is a protocol, i.e., it *must* transmit data b) MathLink is always buffered, i.e., you will *never* get the true address of a pointer in the Mathematica kernel c) only the kernel developer know how a data structure is organized in the kernel, i.e., a array of integers *may* be a memory block of successive integers but it can be also an array of pointers to integers d) for a general expression you have to build your own tree like structure of the Mathematica expression by setting the argument type to Manual > I am trying to write some code to interface Mathematica to a closed- > source library written in C. I'm using Mathlink for this, which is > typically used to interface Mathematica to external functions - see > for example > For example, if the library has a function 'f' with the following > prototype: int f(int x, int y); the following in a Mathlink template (.tm file) will allow me to call > this function from Mathematica by the name Foo, if I link to the > library., create an > executable, then install that executable in Mathematica with > Install[]. :Begin: > :Function: f > :Pattern: Foo[x_Integer, y_Integer] > :Arguments: {x, y} > :ArgumentTypes: {Integer, Integer} > :ReturnType: Integer > :End: (There is no need for me to write the function f, as that has been > done. I just need to link to the library containing the function f, in > much the same way you use the 'pow' function in C without writing it - > you would just link to the maths library.). I have no problem with the above - it all works as expected. The problem occurs with a function 'g', which instead of having only > integer arguments, takes a pointer to some data. The format of the > data is not specified - the C function just needs to know where in > memory the data is, and how many bytes there are. The C prototype is int g(const void *data, long nbytes); Does anyone know how I can write a Mathematica template so when I link > with the function 'g', I can pass the data properly? Note, that since > the library is closed-source, I am not able to change the calling > method in any way. But I expect it should be possible to write an > interface in C, such that data is passed from Mathematica in a form > compatible with Mathematica, and then converts it to a from the C > library accepts. But I am stuck as how to do this. If its not possible to do this with a template, can it be done by > writing it all in C? If so, how? I don't want Mathematica to try to interpret the data in any way - > just to pass an address of where the data is in memory, and also the > number of bytes of data. Than the library function g will return an > integer, which I want to pass back to Mathematica. Someone suggested that I might look at the C code generated by mcc to > work out how to do this, (perhaps making use of MLPutInteger), but I > can't work out how to do this. Does that make sense? Any ideas how to pass arbitrary data to a C > program? I have a similar issue in trying to get arbitrary data from C to > Mathematica, but that is another story. > === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? On 27 Mar, 13:15, -Peer Kuska Do you have an example of this, where the format of the data is not > known in advance? Do you think this is a Mathematica problem ? It would help if there were more examples in the examples directory. There are only 1090 lines including all C files, the make file, all the templates. That's not exactly over-generous for examples. Many examples on the web use addtwo.c so are not really much additional help. I feel there needs to be a number of more complex examples. > It is up to *you* to set up your data structure. My data structure is very simple - I just want to pass potentially random data from Mathematica to the C code. I do not expect Mathematica to understand the format - just pass it. The use of String may be OK, as that is an const unsigned char (I might be wrong about the unsigned), but I'm not sure if Mathematica will handle special characters any different from others. Karen === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? On 24 Mar, 06:45, -Peer Kuska a) MathLink is a protocol, i.e., it *must* transmit data Understood > b) MathLink is always buffered, i.e., you will *never* > get the true address of a pointer in the Mathematica kernel Understood > c) only the kernel developer know how a data structure is organized > in the kernel, i.e., a array of integers *may* be a memory block > of successive integers but it can be also an array of pointers > to integers OK, I can see I cant make such assumptions. > d) for a general expression you have to build your own tree like > structure of the Mathematica expression by setting the argument > type to Manual Do you have an example of this, where the format of the data is not known in advance? It *must* be considered just a collection of bytes of data. The data can be any length from one byte to about a MB. It might be binary data, but will probably be text. The data will be passed to some hardware. The format of the data depends on the hardware. Hence I just want to pass what is a collection of bytes. I cant assume they will be integers (they might be), I cant assume they will be floating point values (they might be). I am trying to write some code to interface Mathematica to a closed- > source library written in C. I'm using Mathlink for this, which is > typically used to interface Mathematica to external functions - see > for example http://reference.wolfram.com/mathematica/tutorial/SettingUpExternalFu... For example, if the library has a function 'f' with the following > prototype: int f(int x, int y); the following in a Mathlink template (.tm file) will allow me to call > this function from Mathematica by the name Foo, if I link to the > library., create an > executable, then install that executable in Mathematica with > Install[]. :Begin: > :Function: f > :Pattern: Foo[x_Integer, y_Integer] > :Arguments: {x, y} > :ArgumentTypes: {Integer, Integer} > :ReturnType: Integer > :End: (There is no need for me to write the function f, as that has been > done. I just need to link to the library containing the function f, in > much the same way you use the 'pow' function in C without writing it - > you would just link to the maths library.). I have no problem with the above - it all works as expected. The problem occurs with a function 'g', which instead of having only > integer arguments, takes a pointer to some data. The format of the > data is not specified - the C function just needs to know where in > memory the data is, and how many bytes there are. The C prototype is int g(const void *data, long nbytes); Does anyone know how I can write a Mathematica template so when I link > with the function 'g', I can pass the data properly? Note, that since > the library is closed-source, I am not able to change the calling > method in any way. But I expect it should be possible to write an > interface in C, such that data is passed from Mathematica in a form > compatible with Mathematica, and then converts it to a from the C > library accepts. But I am stuck as how to do this. If its not possible to do this with a template, can it be done by > writing it all in C? If so, how? I don't want Mathematica to try to interpret the data in any way - > just to pass an address of where the data is in memory, and also the > number of bytes of data. Than the library function g will return an > integer, which I want to pass back to Mathematica. Someone suggested that I might look at the C code generated by mcc to > work out how to do this, (perhaps making use of MLPutInteger), but I > can't work out how to do this. Does that make sense? Any ideas how to pass arbitrary data to a C > program? I have a similar issue in trying to get arbitrary data from C to > Mathematica, but that is another story. === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? > Do you have an example of this, where the format of the data is not > known in advance? Do you think this is a Mathematica problem ? It is up to *you* to set up your data structure. But typedef struct Atom { int what; union { long int N; double D; struct Symbol *S; } Entry; } Atom; may do that. And your data structure may be typedef struct Expression { int what; union { Atom *atm; struct { struct Expression *First; struct Expression *Rest; } List; } Entry; } Expression; clearly you need a symbol table and more data types than long int and double, rationals and complex may be added. It *must* be considered just a collection of bytes > of data. The data can be any length from one byte to about a MB. It > might be binary data, but will probably be text. > The data will be passed to some hardware. The format of the data > depends on the hardware. Hence I just want to pass what is a > collection of bytes. I cant assume they will be integers (they might > be), I cant assume they will be floating point values (they might > be). > === Subject: Re: Mixing immediate assignment and delayed assignment === Subject: Re: ListPlot Joined/Filling bug? >When I try to generate the following plot: >ListPlot[{ >{15138, 15309, 15341, 15640, 16109, 16675, 16730, 16756, 16797, >17006, 17412, 17880, 18034, 18081, 18101, 18171, 18390, 18569, >18821, 18830}, >{45373, 45784, 46153, 47525, 48197, 50014, 50141, 50239, 50342, >50942, 51950, 52198, 52336, 52393, 52450, 52746, 53282, 53861, >54593, 54624}, >{52282, 52487, 52633, 53318, 53766, 57825, 58235, 58333, 58564, >59470, 60302, 61050, 61238, 61348, 61460, 61752, 62331, 63000, >63731, 63792}, >{11595, 11635, 11663, 11829, 11912, 12704, 12793, 12807, 12845, >13026, 13226, 13372, 13427, 13459, 13477, 13550, 13692, 13840, >14023, 14027}, >{67539, 68026, 68260, 69793, 70561, 77539, 77729, 77868, 78137, >80199, 81310, 81882, 82106, 82219, 82302, 82647, 83241, 83960, >84724, 84785} >}, Joined -> True] >I consistently hang Mathematica to the point where I have to restart >its kernel in order to restore functionality. Oddly, if Joined->True >is replaced with Filling->Axis, the problem persists, but if either >options is removed (so just the markers are plotted), the plot is >generated as expected. >Is anyone else seeing this behavior? >Any ideas what might be causing the problem? >I'm using 32-bit Mathematica 6.0.2.0 on Mac OS X 10.5. With: In[6]:= $Version Out[6]= 6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007) running on 10.5.2, I have no problem simply pasting this into Mathematica and getting the expected result. So, my guess would be there is a problem with version 6.02 of Mathematica or a problem with your installation of Mathematica. === Subject: Funny behaviour of ClipboardNotebook[] (Q: How to copy programmatically?) When pasting quoted text from an e-mail, Mathematica will offer to remove the quoting marks. It says: The text you are pasting appears to be from a quoted email. Do you want Mathematica to remove the quoting marks before pasting it? (Yes|No) Here is a quoted expression to try this: > {9, > 0, > 7, > 8, > 7, > 2, > 5, > 0, > 7, > 1} The dialogue box also comes up when evaluating the following to access the clipboard programmatically: NotebookGet@ClipboardNotebook[] This is expected and understandable. But the dialogue box appears when using NotebookPut[] too if the clipboard contains a quoted expression! NotebookPut[Notebook[{abc}], ClipboardNotebook[]] Why does this happen? Is it a bug? Also, is this the correct way to *copy* a string to the clipboard programmatically? It does work, but I am not sure if Notebook[{abc}] (with no Cells) is a correct Notebook expression. (Where is the correct syntax documented?) === Subject: Possible values for the Method option for Graphics?? One of the very disappointing things about the documentation is that the possible values for certain options are very difficult to find. For example, take NIntegrate. The doc page mentions the Method option, but it does not say what the possible values are. Clicking the link just takes us to a generic information page for Method which doesn't even mention NIntegrate. It turns out that the values *are* documented at tutorial/NIntegrateOverview, but it is not at all obvious that one should look there. noticed that Graphics has a Method option too. What are the possible values and where are they documented? Szabolcs Horv.87t === Subject: Re: Possible values for the Method option for Graphics?? > One of the very disappointing things about the documentation is that the > possible values for certain options are very difficult to find. For example, take NIntegrate. The doc page mentions the Method option, > but it does not say what the possible values are. Clicking the link > just takes us to a generic information page for Method which doesn't > even mention NIntegrate. It turns out that the values *are* documented > at tutorial/NIntegrateOverview, but it is not at all obvious that one > should look there. noticed that Graphics has a Method option too. What are the possible > values and where are they documented? Szabolcs Horv=E1t One is CylinderPoints, which I believe is documented in Cylinder. Jason Merrill === Subject: Re: Possible values for the Method option for Graphics?? >> noticed that Graphics has a Method option too. What are the possible >> values and where are they documented? One is CylinderPoints, which I believe is documented in Cylinder. > There is also SpherePoints, and both of these are mentioned in the documentation for Graphics3D. But what are the possible values for Graphics (not Graphics3D)? === Subject: Re: Mathematica hangs... As you observe the last cell evaluation does not terminate in a reasonable time ~ 2 mins on my MacBook Pro running Leopard Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.1 for Mac OS X x86 (64 - bit) (June 19, 2007) MacOS X V 10.5 .20 > Hello everyone, That's a bug report. I'm running v. 6.0.2 on a MacBook Pro under Leopard 10.5.2. I have a > notebook, nothing fancy, which hangs Mathematica when I execute it. As > a test, you can download this notebook from http://guerom00.free.fr/clutter/Notebook.zip It hangs at the last cell, when I want to plot the function, and I > have to quit the kernel. The same notebook runs perfectly on a MacPro under Tiger 10.4.11 so I > guess it is Leopard specific. Can anyone confirm the issue ? === Subject: Bug: AbsoluteOptions does not work with ViewMatrix The documentation states that With the setting ViewMatrix->Automatic, explicit forms for the matrix m can be found using AbsoluteOptions[g,ViewMatrix]. http://reference.wolfram.com/mathematica/ref/ViewMatrix.html However, AbsoluteOptions[Graphics3D[Cuboid[]], ViewMatrix] gives {ViewMatrix -> Automatic} This is the case even if the graphic has been rotated before using AbsoluteOptions. This is just one of the many graphics options in v6 which do not work with AbsoluteOptions. For many v6 options implementing AbsoluteOptions may be problematic, but I believe that ViewMatrix is not one of these, therefore this is a bug. === Subject: Strange behaviour of DialogInput and DialogCreate in 6.0.1 I am trying to use DialogInput to allow users of my notebook to set parameters in a nice graphical way. I'm running into a few problems and was hoping someone might point me in the right direction. The first problem is, if I set a variable using the result of DialogInput, I can't use that variable in subsequent commands in that cell. Below is a simple example (put contents in a single cell): In[1]:= test = 5 test = DialogInput[{Some Result, DefaultButton[DialogReturn[10]]}] Pause[1] Print[Hello] Pause[1] test Out[1]= 5 Out[1]= 10 Hello Out[5]= test I'm not sure I understand what's going on here. The final call of test appears to have *no* value, not even the original value 5 that was set. Now if we create a second cell, In[2]:= test Out[2]= 10 So it appears the variable does get set at some point, just not at the time I expect it to be set. The second problem I'm running into is that if I use a Dynamic around a global variable in a dialog, it will not update that variable when I exit from the dialog. In fact, one of the examples from the Help file doesn't work as advertised for me: In[1]:= CreateDialog[{TextCell[Enter a name: ], InputField[Dynamic[nm], String], DefaultButton[DialogReturn[ret = nm]]}]; In[1]:= ret Out[1]= ret Note that the history index is not incremented after the CreateDialog call. The third problem I have would probably be solved if I can get workarounds to the first two. That is, I want to make the dialog from DialogInput modal. I don't see how to do that. I would use CreateDialog or DialogNotebook, but as I mentioned, I don't appear to have any working mechanism to return values. Any suggestions of what I might be doing wrong or workarounds would be much appreciated. Januk === Subject: Writing variables in strings (opened from text files) Hello everyone, Can someone please help me with the following issue? I am importing a text file that I want to manipulate (replace some parts) and these parts shall be variables. Please help. I tried putting more commas for the variable but it didn't worked. I also tried with the ToString Here is a sample of what I want to do: game = Import[c:textfile.txt, Text]; w = 1500; game1 = StringReplace[gametheory, ( 3,) :> ( w,)]; game1 = StringReplace[gametheory1, ( 4,) :> ( w,)]; game1 = StringReplace[gametheory1, ( 5,) :> ( w,)]; game1 = StringReplace[gametheory1, ( 6,) :> ( w,)]; Export[c:textfile.txt, game1, Text]; === Subject: Re: Writing variables in strings (opened from text files) game = ToString[Table[RandomInteger[{1, 10}], {200}]]; and w = 1500; StringReplace[game, { 3, -> <> ToString[w] <> ,, 4, -> <> ToString[w] <> ,, 5, -> <> ToString[w] <> ,, 6, -> <> ToString[w] <> ,}] ?? > Hello everyone, Can someone please help me with the following issue? I am importing a > text file that I want to manipulate (replace some parts) and these > parts shall be variables. Please help. I tried putting more commas for > the variable but it didn't worked. I also tried with the ToString Here is a sample of what I want to do: game = Import[c:textfile.txt, Text]; w = 1500; game1 = StringReplace[gametheory, ( 3,) :> ( w,)]; > game1 = StringReplace[gametheory1, ( 4,) :> ( w,)]; > game1 = StringReplace[gametheory1, ( 5,) :> ( w,)]; > game1 = StringReplace[gametheory1, ( 6,) :> ( w,)]; Export[c:textfile.txt, game1, Text]; === Subject: Converting 3D graphics to 2D polygons In versions prior to 6 it was possible to convert 3D graphics to 2D like this: Graphics@Graphics3D[Cuboid[{0, 0, 0}]] // Show This does not work any more in v6. (Note that I am not trying to embed a 3D graphic into a 2D graphic, which can be done with Inset, but I would like to get the 2D projection of 3D points, lines and polygons.) Is there a way to do this in v6? One can use an ugly hack like ImportString@ExportString[Graphics3D[Cuboid[]], PDF] but this will break up all the polygons to many little pieces. === Subject: Re: Converting 3D graphics to 2D polygons > In versions prior to 6 it was possible to convert 3D graphics to 2D like > this: Graphics@Graphics3D[Cuboid[{0, 0, 0}]] // Show This does not work any more in v6. (Note that I am not trying to embed > a 3D graphic into a 2D graphic, which can be done with Inset, but I > would like to get the 2D projection of 3D points, lines and polygons.) Is there a way to do this in v6? One can use an ugly hack like > ImportString@ExportString[Graphics3D[Cuboid[]], PDF] > but this will break up all the polygons to many little pieces. This topic sounds interesting, and I've ever thought about something similar. Wish the following example be helpful :) GraphicsGrid[{MapIndexed[Function[{meshf, coord}, Plot3D[(Pi - (x^2 + y^2))/4, {x, -5, 5}, {y, -5, 5}, PlotRange -> All, PlotPoints -> 40, MeshFunctions -> meshf, Mesh -> 40, RegionFunction -> Function[{x, y, z}, 3 > Abs[(x - 1)^2 + y + ((3*z)/4)^2] > 1], PlotStyle -> None] /. Graphics3D[x_, y__] :> Graphics[x, AspectRatio -> Automatic] /. GraphicsComplex[x_, y_, z__] :> GraphicsComplex[(Drop[#1, coord] & ) /@ x, y]], {#1 & , #2 & , #3 & }]}] === Subject: 3D import/export format problems/bugs The following function gives errors with the DXF and 3DS formats in Mathematica 6.0.2: impexp[gr_Graphics3D, fmt_String] := ImportString[ExportString[gr, fmt], fmt] The graphic that gives errors is an example from the documentation: gr2 = Graphics3D[ Table[With[{p = {i, j, k}/5}, {RGBColor[p], Opacity[.75], Cuboid[p, p + .15]}], {i, 5}, {j, 5}, {k, 5}]] impexp[gr2,DXF] gives errors because of problems with ExportString[#, DXF] while impexp[gr2,3DS] generates an incorrect output. The reason why I was experimenting with the impexp[] function was that the PolygonIntersections option is not available any more in v6 (it is suggested to use options for Export instead), and I wanted to see how much of the formatting is preserved when 3D objects are transferred through different output formats. === Subject: Re: Viewpoint selector for Mac in 6.0? Ravi, 1) Make your plot. 2) Use the mouse to obtain the viewpoint that you want. 3) Right in front (on the left) of the plot output type 'Options[' and right after the plot (on the right) type ', Viewpoint'] and then evaluate. 4) That will give you the current Viewpoint option, which you could then copy into the plot Input specification. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hello friends, It appears that the viewpoint selector for 3D graphics is absent in 6.0 > (Mac version). Is there an alternate way to manually choose a view > (other than trying different viewpoints repeatedly)? Suggestions > appreciated. Ravi > University of Washington > === Subject: Re: Viewpoint selector for Mac in 6.0? On Mar 22, 1:52 am, Ravi Balasubramanian (Mac version). Is there an alternate way to manually choose a view > (other than trying different viewpoints repeatedly)? Suggestions > appreciated. Ravi > University of Washington You can try this: Manipulate[ Module[{x, y, z}, x = r Sin[[Theta]] Cos[[Phi]]; y = r Sin[[Theta]] Sin[[Phi]]; z = r Cos[[Theta]]; Graphics3D[Cylinder[], ViewPoint -> {x, y, z}] ], ViewPoint, {{r, 3}, 1.5, 10, Appearance -> Labeled}, {{[Theta], Pi/4}, 0, Pi, Appearance -> Labeled}, {{[Phi], Pi/6}, -Pi, Pi, Appearance -> Labeled} ] === Subject: Re: Viewpoint selector for Mac in 6.0? > Hello friends, It appears that the viewpoint selector for 3D graphics is absent in 6.0 > (Mac version). Is there an alternate way to manually choose a view > (other than trying different viewpoints repeatedly)? Suggestions > appreciated. Here's a view point selector for you. I am not sure that I do the copying right, so corrections are welcome. Click the buttons to copy the values. viewPointSelector[gr_Graphics3D] := DynamicModule[ {vp = ViewPoint /. Options[Graphics3D], vv = ViewVertical /. Options[Graphics3D], va = ViewAngle /. Options[Graphics3D]}, Module[{copy}, copy[expr_] := NotebookPut[Notebook[{ToString[expr]}], ClipboardNotebook[]]; Panel[Column[ {Show[gr, ViewPoint -> Dynamic[vp], ViewVertical -> Dynamic[vv], ViewAngle -> Dynamic[va], SphericalRegion -> True, ImageSize -> 380], Grid[ {{Button[ViewPoint, copy[vp]], Dynamic[vp]}, {Button[ViewVertical, copy[vv]], Dynamic[vv]}, {Button[ViewAngle, copy[va]], Dynamic[va]}}, Alignment -> {Left, Baseline}]} ], ImageSize -> 400 ]]] (Side note: It would be nice if an automatically indented StandardForm expression would preserve the indentation levels exactly when copied.) === Subject: Re: Problem involving NDSolve I posted a solution to this problem on 12 March 08. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > So here's my dilemma. I am trying to solve a differential equation with > complex roots. Mathematica is taking the incorrect root at certain points > when the function crosses over itself. I generated a set of all points at > which this occurs. The set is ProblemList={2.8, 5.599, 8.398} I now want to use these points in a function. My function is ComplexRoot[t_]:= If[Abs[t - ProblemList[[1]]] > .01 && Abs[t - > ProblemList[[2]]] > .01 && Abs[t - ProblemList[[ 3]]] > .01, > Evaluate[I*(2 + 1/2)(I*x[t])^(1 + 1/2)], Evaluate[p'[t - .01]]] The goal here is to have Mathematica take the correct root for all t other > than the problem t values, and at those t values simply continue in the > direction it was heading previously. So I want to then plug into the > differential equation solution=NDSolve[{x'[t] == 2p[t], x[0] == 0, p'[t]==ComplexRoot[t], p[0] > == 1}, > {x, p}, {t,0,10}, WorkingPrecision -> 30, MaxSteps -> Infinity][[1]]; and not get an error. Right now it gives me an error saying that I > haven't literally matched the independent variables. If it works, the following graph should have two loops and look like an > infinity sign with one of the loops being smaller than the other. ParametricPlot[{Re[p[t]] /. solution, Im[p[t]] /. solution}, > Evaluate[{t,0,10}],PlotRange -> {{-2, 2}, {-2, 2}}] What can I do to fix this issue? Any and all help is greatly appreciated. Alex > === Subject: Grabbing a value from a Dynamic Object Hi Folks, I am trying to use a series of control objects, specifically PopupMenus, so that the input to one PopupMenu will be used dynamically to provide the range of values for the subsequent PopupMenu. My area is not computer science, but I believe I get the idea that Dynamic is not evaluated in the kernal, but rather simply formatted in the front end of Mathematica. To extract a Dynamic value I have been attempting to use the command CurrentValue with no sucess. Here is my basic code: x = Null; y = Null; totgrades = PopupMenu[Dynamic[x], Range[12]] temp1 = CurrentValue[totgrades] gradesnow = PopupMenu[Dynamic[y], Range[temp1]] I keep getting the error message: Range::range: Range specification in Range[FrontEnd`CurrentValue[BoxData[3]]] does not have appropriate bounds. >> I understand that the Head of temp1 is NOT a number, but rather is a FrontEnd`CurrentValue.......so, how do I get a number that the second PopupMenu can actually use to produce a range of potential inputs from the user? I certainly appreciate any advice you might have! Mathematica is a wonderful piece of software, but there are times when it is truly frustating for a beginner. Todd _____ _ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs === Subject: Re: Grabbing a value from a Dynamic Object > Hi Folks, I am trying to use a series of control objects, > specifically PopupMenus, so that the input to one > PopupMenu will be used dynamically to provide the > range of values for the subsequent PopupMenu. My area is not computer science, but I believe I > get the idea that Dynamic is not evaluated in the > kernal, but rather simply formatted in the front end > of Mathematica. To extract a Dynamic value I have > been attempting to use the command CurrentValue with > no sucess. Here is my basic code: x = Null; y = Null; > totgrades = PopupMenu[Dynamic[x], Range[12]] > temp1 = CurrentValue[totgrades] > gradesnow = PopupMenu[Dynamic[y], Range[temp1]] > I keep getting the error message: Range::range: Range specification in > Range[FrontEnd`CurrentValue[BoxData[3]]] does not have > appropriate bounds. I understand that the Head of temp1 is NOT a number, > but rather is a FrontEnd`CurrentValue.......so, how do > I get a number that the second PopupMenu can actually > use to produce a range of potential inputs from the > user? I certainly appreciate any advice you might have! > Mathematica is a wonderful piece of software, but > there are times when it is truly frustating for a > beginner. Dynamic[x] is usually used for *displaying* (or sometimes setting) the value of x. x must not be wrapped in Dynamic when its value is used. Try this: PopupMenu[Dynamic[x], Range[12]] Dynamic@PopupMenu[Dynamic[y], Range[x]] === Subject: Re: Grabbing a value from a Dynamic Object I don't think you need CurrentValue. Try evaluating this example: PopupMenu[Dynamic[x], Range[12]] Dynamic[PopupMenu[Dynamic[y], Range[x]]] Is that what you want? > Hi Folks, I am trying to use a series of control objects, > specifically PopupMenus, so that the input to one > PopupMenu will be used dynamically to provide the > range of values for the subsequent PopupMenu. My area is not computer science, but I believe I > get the idea that Dynamic is not evaluated in the > kernal, but rather simply formatted in the front end > of Mathematica. To extract a Dynamic value I have > been attempting to use the command CurrentValue with > no sucess. Here is my basic code: x = Null; y = Null; > totgrades = PopupMenu[Dynamic[x], Range[12]] > temp1 = CurrentValue[totgrades] > gradesnow = PopupMenu[Dynamic[y], Range[temp1]] I keep getting the error message: Range::range: Range specification in > Range[FrontEnd`CurrentValue[BoxData[3]]] does not have > appropriate bounds. I understand that the Head of temp1 is NOT a number, > but rather is a FrontEnd`CurrentValue.......so, how do > I get a number that the second PopupMenu can actually > use to produce a range of potential inputs from the > user? I certainly appreciate any advice you might have! > Mathematica is a wonderful piece of software, but > there are times when it is truly frustating for a > beginner. Todd _____ _ > Never miss a thing. Make Yahoo your home page.http://www.yahoo.com/r/hs === Subject: Re: finding positions of elements in a list > I also tried Position but it wasn't clear to me if a pattern can be used for this. Hi. You have answers, but I see you were stuck on using Position. Here's one way if you ever need to use it: pts = {{20, 109}, {21, 50}, {20, 110}, {22, 60}}; Position[pts, {___, n_} /; n > 80] {{1}, {3}} Extract[pts, %] {{20, 109}, {20, 110}} -- HTH :>) Dana DeLouis > Hi. Having a few problems here with what I think should be a simple operation. I have a list as shown: mylist={{20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106}, {21, 107},...} It's a list of {x,y} co-ordinates of some data points I'm analysing. I want to create a new list which contains only those data points whose y co-ordinate is greater than 80 ie. mylist[[n,2]]>80. Problem is, I can't work out how to use Select to do this when each element in the list has an x and a y co-ordinate. If I split the list into x and y co-ordinates and searched for those y values greater than 80, I would have a list of those y-values but would not know the corresponding x-values. I also tried Position but it wasn't clear to me if a pattern can be used for this. === Subject: Re: finding positions of elements in a list >> I also tried Position but it wasn't clear to me if a pattern can be used > for this. Hi. You have answers, but I see you were stuck on using Position. > Here's one way if you ever need to use it: > pts = {{20, 109}, {21, 50}, {20, 110}, {22, 60}}; Position[pts, {___, n_} /; n > 80] {{1}, {3}} Extract[pts, %] {{20, 109}, {20, 110}} There is one important caveat though, which is not present with Cases or Select. Position[] searches the expression at all levels. Suppose that we are trying to find those pairs whose second element is not 1. In[1]:= pts = RandomInteger[2, {10, 2}] Out[1]= {{1, 0}, {0, 0}, {2, 0}, {0, 2}, {2, 0}, {1, 2}, {2, 2}, {2, 1}, {1, 1}, {0, 1}} In[2]:= Position[pts, {___, n_} /; n =!= 1] Out[2]= {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {}} Note the {} at the end of the list. It indicates that the complete expression matches too. There are many little details that can hide this behaviour for most input lists (e.g. using a different pattern or != instead of =!=), but it is good to mention that it is possible to only match against the elements of the list by using a level specification: Position[pts, {___, n_}, {1}] This might seem like a trivial detail, but I have been bitten by this type of mistake more than once. === Subject: SoundNote: velocity? Is there a way to set the velocity for the noteon midi message generated by SoundNote? I see there is an option for setting the volume of the note, but with midi volume and velocity are distinct concepts. Did that distinction get lost in Mathematica? === Subject: Re: Which function can do this? > Greeting all! > Now I need a function to transform a polynomial about x to the one > about x-1 > eg: x^3+2x^2+3x+4= (x-1)^3+5(x-1)^2+10(x-1)+10 > Does Mathematica supply a function to do this? -- > Best Wishes! > Yes. Normal[x^3 + 2*x^2 + 3*x + 4 + O[x, 1]^4] (x - 1)^3 + 5*(x - 1)^2 + 10*(x - 1) + 10 Andrzej Kozlowski === Subject: Which function can do this? Greeting all! Now I need a function to transform a polynomial about x to the one about x-1 eg: x^3+2x^2+3x+4= (x-1)^3+5(x-1)^2+10(x-1)+10 Does Mathematica supply a function to do this? -- Best Wishes! === Subject: Re: Which function can do this? Elements schrieb am 23.03.2008 07:02: > Greeting all! > Now I need a function to transform a polynomial about x to the one about x-1 > eg: x^3+2x^2+3x+4= (x-1)^3+5(x-1)^2+10(x-1)+10 > Does Mathematica supply a function to do this? > In[1]:= (x^3+2x^2+3x+4 /. x -> (y+1) // Simplify) /. y -> (x-1) Out[1]= 10 + 10*(-1 + x) + 5*(-1 + x)^2 + (-1 + x)^3 === Subject: Re: Which function can do this? Eliminate[{x^3 + 2 x^2 + 3 x + 4 == y, x - 1 == z}, x] /. z -> (x - 1) > Greeting all! > Now I need a function to transform a polynomial about x to the one about x-1 > eg: x^3+2x^2+3x+4= (x-1)^3+5(x-1)^2+10(x-1)+10 > Does Mathematica supply a function to do this? > === Subject: Drag and drop in the front end Enable drag and drop text editing can be checked on the Interface tab of preferences. (Apparently this feature has been available since version 3 but I did not know about it.) I think that this is useful (and it would be an order of magnitude more useful if it worked across applications [on Windows], e.g. for dragging code to the FE from a browser!), but it has some usability problems that even make it slightly dangerous: First, undo does not work with drag and drop. It removes the dropped object but it does not replace it to its original location (so the object is practically deleted). Second, when dragging something over a graphic, it completely replaces the graphic. Maybe it would be better to disallow dragging objects over graphics. === Subject: Counting nonzeros I want to count the # of NZ entries in an arbitrary multilevel list, say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] === Subject: Re: Counting nonzeros > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] > Count[Flatten[exp],Except[0]] is a bit shorter Peter === Subject: Re: Counting nonzeros I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] Count[Flatten[exp],Except[0]] is a bit shorter Peter try also: Count[exp,Except[0],-1] Robson === Subject: Re: Counting nonzeros > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: > k = Length[Flatten[exp]]-Count[Flatten[exp],0] >> Count[Flatten[exp],Except[0]] is a bit shorter >> Peter try also: Count[exp,Except[0],-1] Beware that as written the above example will count not only the non-zero integer value but also the number of intermediate structures that holds the values. To avoid that, one must use the second argument of Except, in this case setting it to the pattern _Integer. Count[exp, Except[0, _Integer], -1] The following computations should illustrate -- at least I hope! -- what is going on: In[1]:= exp = RandomInteger[{0, 1}, {3, 2, 2}] Out[1]= {{{1, 1}, {1, 1}}, {{1, 0}, {0, 0}}, {{1, 0}, {0, 0}}} In[2]:= Count[exp, Except[0], -1] Out[2]= 15 In[3]:= Count[exp, Except[0, _Integer], -1] Out[3]= 6 In[4]:= Count[Flatten[exp], Except[0]] Out[4]= 6 In[5]:= Level[exp, {-1}] % // Length Out[5]= {1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0} Out[6]= 12 In[7]:= LeafCount@exp Out[7]= 22 In[8]:= Level[exp, {-1}, Heads -> True] % // Length Out[8]= {List, List, List, 1, 1, List, 1, 1, List, List, 1, 0, List, 0, 0, List, List, 1, 0, List, 0, 0} Out[9]= 22 -- === Subject: Re: Counting nonzeros > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] > In Mathematica 6 this: Total[Unitize[expr], Infinity] is both shorter and much faster. Andrzej Kozlowski === Subject: Re: Counting nonzeros > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] The easiest way might be in the eye of the beholder! What about the following? k = Total@Unitize@Flatten@exp (* Fastest Solution *) k = Count[exp, x_Integer /; x != 0, -1] (* Slower Solution *) The first expression uses Unitize to get a list of 0's and 1's only (every non zero entry is set to one). The second expression uses pattern matching and the third parameter of Count (setting level to -1 tells Mathematica to look for numbers, symbols and other objects that do not have subparts) to count the non zero entries. Here are the timings for each approach (we create some arbitrary integer data in the interval [-1, 1] first) In[1]:= exp = RandomInteger[{-1, 1}, {10, 10, 10}]; In[2]:= Timing@Total@Unitize@Flatten@exp Out[2]= {0.000083, 702} In[3]:= Timing@(Length[Flatten[exp]] - Count[Flatten[exp], 0]) Out[3]= {0.000172, 702} In[4]:= Timing@Count[exp, x_Integer /; x != 0, -1] Out[4]= {0.000736, 702} -- === Subject: Re: Counting nonzeros Using Count and Except[0] is surprisingly slow listi = RandomInteger[{0, 100}, 100000]; Length[listi] - Count[listi, 0] // Timing Out[30]= {0.02711, 98995} Count[listi, Except[0]] // Timing Out[31]= {0.063781, 98995} However, I remember reading in a previous post (which I cannot find) about Tally & Clip, perhaps by Carl Woll Tally[Clip[listi]][[1, 2]] // Timing Out[32]= {0.004693, 98995} I suppose there are even faster ways. Tom Dowling > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] === Subject: Re: Counting nonzeros > I want to count the # of NZ entries in an arbitrary multilevel list, > say exp, that contains only integers. Is this the easiest way: k = Length[Flatten[exp]]-Count[Flatten[exp],0] Suppose that we only have integers in the list. Count[expr, Except[0, _Integer], Infinity] Instead of _Integer, we could use _Symbol or _?AtomQ or some other pattern depending on the type of elements that need to be counted. (_Integer was necessary to avoid counting all the compound expressions, such as sublists.) === Subject: Re: Writing variables in strings (opened from text files) To use the value of the variable w rather than the character w use game1 = StringReplace[game, 3, :> ( <> ToString[w] <> ,)]; Check your use of the variable names gametheory and gametheory1 versus the variable names game and game1 Bob Hanlon > Hello everyone, Can someone please help me with the following issue? I am importing a > text file that I want to manipulate (replace some parts) and these > parts shall be variables. Please help. I tried putting more commas for > the variable but it didn't worked. I also tried with the ToString Here is a sample of what I want to do: game = Import[c:textfile.txt, Text]; w = 1500; game1 = StringReplace[gametheory, ( 3,) :> ( w,)]; > game1 = StringReplace[gametheory1, ( 4,) :> ( w,)]; > game1 = StringReplace[gametheory1, ( 5,) :> ( w,)]; > game1 = StringReplace[gametheory1, ( 6,) :> ( w,)]; Export[c:textfile.txt, game1, Text]; === Subject: Re: Saving Packages What use? Different ones, depending on the project. Basically my libraries (as I prefer to call them) contain everything from generic utilities valid for many projects, to project- specific function definitions, which are however too cumbersome to reside in the main notebook. It is simply the usual breaking down of big programs that I'm used to do since the days of plain old C programming. still ignorant about WHY packages exist at all - in a parallel world to the .nb world. And, more to the point, what would change for the outside user if Wolfram would provide a GetNB[] function, performing everything Get does - but for notebooks? wondering... alessandro Jerry ha scritto: > but didnt find so much info - I'll have to dig deeper. Your answers were of course right: setting the cells as init cells did > the right thing. Yet I'd like to explain better what is my larger problem is: > to break down a big project in pieces, it is correct then to save big > chunks of code definitions as packages? > I'm asking because I'd like to still keep on modifying those packages, > as in a standard notebook. But opening the .m file brings up a > different interface, which although it seems useful (drop down boxes > with Functions and Sections - I'd like to have them in the notebook!) > it's not so clear to me if I'm losing something present in the > notebook interface. file, modify it as needed, select all cells and set them to init, and > save as .m file. Correct? Sir, I am very curious: what would you then do with the .m > file? > What use does it have? === Subject: Re: Saving Packages the packages exist for the same reason why your MS-Word has macros/VBasic and you can write letters, and other short text documents with it. The notebooks are text documents with embedded code for teaching/talks .. and the code is typical something that you do *once* and the packages include the code for something that you wish to do on and on. > What use? Different ones, depending on the project. > Basically my libraries (as I prefer to call them) contain > everything from generic utilities valid for many projects, to project- > specific function definitions, which are however too cumbersome to > reside in the main notebook. It is simply the usual breaking down of > big programs that I'm used to do since the days of plain old C > programming. still ignorant about WHY packages exist at all - in a parallel world > to the .nb world. > And, more to the point, what would change for the outside user if > Wolfram would provide a GetNB[] function, performing everything Get > does - but for notebooks? wondering... > alessandro Jerry ha scritto: but didnt find so much info - I'll have to dig deeper. Your answers were of course right: setting the cells as init cells did > the right thing. Yet I'd like to explain better what is my larger problem is: > to break down a big project in pieces, it is correct then to save big > chunks of code definitions as packages? > I'm asking because I'd like to still keep on modifying those packages, > as in a standard notebook. But opening the .m file brings up a > different interface, which although it seems useful (drop down boxes > with Functions and Sections - I'd like to have them in the notebook!) > it's not so clear to me if I'm losing something present in the > notebook interface. file, modify it as needed, select all cells and set them to init, and > save as .m file. Correct? > Sir, I am very curious: what would you then do with the .m >> file? >> What use does it have? > === Subject: Re: Saving Packages > but didnt find so much info - I'll have to dig deeper. Your answers were of course right: setting the cells as init cells did > the right thing. Yet I'd like to explain better what is my larger problem is: > to break down a big project in pieces, it is correct then to save big > chunks of code definitions as packages? > I'm asking because I'd like to still keep on modifying those packages, > as in a standard notebook. But opening the .m file brings up a > different interface, which although it seems useful (drop down boxes > with Functions and Sections - I'd like to have them in the notebook!) > it's not so clear to me if I'm losing something present in the > notebook interface. file, modify it as needed, select all cells and set them to init, and > save as .m file. Correct? > Sir, I am very curious: what would you then do with the .m file? What use does it have? === Subject: Re: Saving Packages > Yet I'd like to explain better what is my larger problem is: > to break down a big project in pieces, it is correct then to save big > chunks of code definitions as packages? Absolutely, that is much better than handle many notebooks which you have to evaluate before starting to work... > I'm asking because I'd like to still keep on modifying those packages, > as in a standard notebook. But opening the .m file brings up a > different interface, which although it seems useful (drop down boxes > with Functions and Sections - I'd like to have them in the notebook!) > it's not so clear to me if I'm losing something present in the > notebook interface. well, what you see in fact is a notebook - with a special style which is trimmed to work on mathematica code and some extras which make possible to save the noncode parts of the notebook within the .m file, too. The main drawback I see is that at this time not too much (none?) information is available wheter and how you can customize this style with an own stylesheet. > file, modify it as needed, select all cells and set them to init, and > save as .m file. Correct? Basically yes, but if you set the Notebooks option AutoSavePackage to Automatic, then the .m file will be generated automatically each time you save the notebook, which makes the whole process very handy. As has been pointed out this is the recommended way to go for versions < 6, for version 6 the recommended way seems to be to edit .m files directly, but the old way still works. It's a matter of taste which way you go. hth, albert === Subject: Re: finding positions of elements in a list > I also tried Position but it wasn't clear to me if a pattern can be = used >> for this. >> Hi. You have answers, but I see you were stuck on using Position. >> Here's one way if you ever need to use it: >> pts = {{20, 109}, {21, 50}, {20, 110}, {22, 60}}; >> Position[pts, {___, n_} /; n > 80] >> {{1}, {3}} >> Extract[pts, %] >> {{20, 109}, {20, 110}} There is one important caveat though, which is not present with Cases = or > Select. Position[] searches the expression at all levels. Suppose = that > we are trying to find those pairs whose second element is not 1. In[1]:= pts = RandomInteger[2, {10, 2}] > Out[1]= {{1, 0}, {0, 0}, {2, 0}, {0, 2}, {2, 0}, {1, 2}, {2, 2}, > {2, 1}, {1, 1}, {0, 1}} In[2]:= Position[pts, {___, n_} /; n =!= 1] > Out[2]= {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {}} Note the {} at the end of the list. It indicates that the complete > expression matches too. There are many little details that can hide this behaviour for most > input lists (e.g. using a different pattern or != instead of = =!=), but > it is good to mention that it is possible to only match against the > elements of the list by using a level specification: Position[pts, {___, n_}, {1}] This might seem like a trivial detail, but I have been bitten by this > type of mistake more than once. Yes. Good point. As another example, to avoid errors with the following method, one should set Heads -> False. pts = {{20, 109}, {21, 50}, {20, 110}, {22, 60}}; Position[pts, v_ /; Last[v] > 80, 1, Heads -> False] {{1}, {3}} Extract[pts, %] {{20, 109}, {20, 110}} === Subject: Match Pairs of Numbers Any help would be appreciated. I am using Mathematica 5.2 & 6.0 I am having trouble finding the correct form of Pattern Matching for pairs of Numbers. I do not know whether to use Select, Cases, Pick, etc. I am also unsure how to set the pattern matching argument. Assume I have the list lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, {4,1}, {4,4}} I would like to match/select pairs that have the same set of numbers only reversed, that is, the selection would find {{1,3}, {3,1}, {1,4}, {4,1} } Andrew C Beveridge MS M888 Los Alamos National Laboratory Los Alamos, NM 87545 505-665-2092 e-mail: acbev@lanl.gov === Subject: Re: Match Pairs of Numbers > Any help would be appreciated. I am using Mathematica 5.2 & 6.0 I am having trouble finding the correct form of Pattern Matching for > pairs of Numbers. I do not know whether to use Select, Cases, Pick, > etc. I am also unsure how to set the pattern matching argument. Assume I have the list lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, {4,1}, {4,4}} > I would like to match/select pairs that have the same set of numbers > only reversed, that is, the selection would find {{1,3}, {3,1}, {1,4}, {4,1} } > Intersection[lst, Reverse /@ lst] Select[%, UnsameQ @@ # &] === Subject: Re: Match Pairs of Numbers > Any help would be appreciated. I am using Mathematica 5.2 & 6.0 I am having trouble finding the correct form of Pattern Matching for > pairs of Numbers. I do not know whether to use Select, Cases, Pick, > etc. I am also unsure how to set the pattern matching argument. Assume I have the list lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, > {4,1}, {4,4}} > I would like to match/select pairs that have the same set of numbers > only reversed, that is, the selection would find {{1,3}, {3,1}, {1,4}, {4,1} } Andrew C Beveridge > MS M888 > Los Alamos National Laboratory > Los Alamos, NM 87545 505-665-2092 > e-mail: acbev@lanl.gov > Here is an algo-rhythmic newbie approach :) > In[2]:= > Last[Reap[While[ > Length[lst] >= 1, > i = Random[Integer, > {1, Length[lst]}]; > c = lst[[i]]; > rc = Reverse[c]; > If[Length[Position[lst, > rc]] > 0 && > c != rc, > Sow[{c, rc}]; , Null]; > lst = Delete[lst, > Position[lst, rc]]; > lst = Delete[lst, > Position[lst, c]]; ]]] > Out[2]= > {{{{4, 1}, {1, 4}}, > {{3, 1}, {1, 3}}}} J=E1nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: Match Pairs of Numbers The following will hopefully do what you want, though the resulting list isn't sorted into the pairs: lst = {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}, {3, 1}, {3, 2}, {3, 3}, {4, 1}, {4, 4}}; In[4]:= Select[ Intersection[lst, Reverse /@ lst], #1[[1]] != #1[[2]] & ] Out[4]= {{1, 3}, {1, 4}, {3, 1}, {4, 1}} This forms the intersection of the list of pairs and the reversed pairs (keeping only those elements which are present both forwards and backwards), and then Select chooses those elements which don't have both numbers the same in each pair (e.g. {1,1} leaves, as does {2,2}, etc.). C.O. > Any help would be appreciated. I am using Mathematica 5.2 & 6.0 I am having trouble finding the correct form of Pattern Matching for > pairs of Numbers. I do not know whether to use Select, Cases, Pick, > etc. I am also unsure how to set the pattern matching argument. Assume I have the list lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, {4,1}, > {4,4}} > I would like to match/select pairs that have the same set of numbers > only reversed, that is, the selection would find {{1,3}, {3,1}, {1,4}, {4,1} } Andrew C Beveridge > MS M888 > Los Alamos National Laboratory > Los Alamos, NM 87545 505-665-2092 > e-mail: acbev@lanl.gov -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Match Pairs of Numbers > I am having trouble finding the correct form of Pattern Matching for > pairs of Numbers. I do not know whether to use Select, Cases, Pick, > etc. I am also unsure how to set the pattern matching argument. Assume I have the list lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, {4,1}, {4,4}} > I would like to match/select pairs that have the same set of numbers > only reversed, that is, the selection would find {{1,3}, {3,1}, {1,4}, {4,1} } The following examples should help you started. Note that they have not been optimized for speed, though the recursive example (myComp) is much faster than the first one (which try to illustrate how to use Pick). Also, note that the best strategy to solve the problem depends on many factors you did not mention, such as the size of the list, possibility of many occurrences of matching pairs (say, several {1,4}'s), whether the order of the matching pairs returned in the solution is important, etc. lst = {{1,1},{1,2},{1,3},{1,4},{2,2},{3,1},{3,2},{3,3},{4,1},{4,4}}; myCheck[lst_List] := Module[{rev = Reverse /@ lst}, Flatten[Table[ Pick[lst, MapThread[SameQ, {lst, RotateLeft[rev, n]}]], {n, Length@lst - 1}] /. {} -> Sequence[], 1]] myCheck[lst] (* ==> {{1, 3}, {1, 4}, {4, 1}, {3, 1}} *) myComp[data_List] := Module[{mySearch}, mySearch[pair_List, lst_List /; Length[lst] > 0] := Union[Cases[Reverse /@ lst, pair], mySearch[First@lst, Rest@lst]]; mySearch[pair_List, lst_List] := {}; Block[{$RecursionLimit = 10 + Length@data}, mySearch[First@lst, Rest@lst] ] ] myComp[lst] (* ==> {{1, 3}, {1, 4}} *) -- === Subject: Re: ListPlot Joined/Filling bug? Alexander ha escrito: > When I try to generate the following plot: ListPlot[{ {15138, 15309, 15341, 15640, 16109, 16675, 16730, 16756, 16797, > 17006, 17412, 17880, 18034, 18081, 18101, 18171, 18390, 18569, > 18821, 18830}, {45373, 45784, 46153, 47525, 48197, 50014, 50141, 50239, 50342, > 50942, 51950, 52198, 52336, 52393, 52450, 52746, 53282, 53861, > 54593, 54624}, {52282, 52487, 52633, 53318, 53766, 57825, 58235, 58333, 58564, > 59470, 60302, 61050, 61238, 61348, 61460, 61752, 62331, 63000, > 63731, 63792}, {11595, 11635, 11663, 11829, 11912, 12704, 12793, 12807, 12845, > 13026, 13226, 13372, 13427, 13459, 13477, 13550, 13692, 13840, > 14023, 14027}, {67539, 68026, 68260, 69793, 70561, 77539, 77729, 77868, 78137, > 80199, 81310, 81882, 82106, 82219, 82302, 82647, 83241, 83960, > 84724, 84785} }, Joined -> True] I consistently hang Mathematica to the point where I have to restart > its kernel in order to restore functionality. Oddly, if Joined->True > is replaced with Filling->Axis, the problem persists, but if either > options is removed (so just the markers are plotted), the plot is > generated as expected. Is anyone else seeing this behavior? I can reproduce the behavior in a simpler example. In[1]:= $Version Out[1]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) In[2]:= myList = {15138, 15309, 15341, 15640, 16109}; In[3]:= ListPlot[myList] Works as expected. However, both ListPlot[myList, Joined -> True] and ListLinePlot[myList] hang Mathematica. This does not happen if myList has only 4 points. Looks like a bug related to the size of the numbers. Everything works fine with myList/100. Juli=E1n === Subject: Re: ListPlot Joined/Filling bug? > Alexander ha escrito: >> When I try to generate the following plot: >> ListPlot[{ >> {15138, 15309, 15341, 15640, 16109, 16675, 16730, 16756, 16797, >> 17006, 17412, 17880, 18034, 18081, 18101, 18171, 18390, 18569, >> 18821, 18830}, >> {45373, 45784, 46153, 47525, 48197, 50014, 50141, 50239, 50342, >> 50942, 51950, 52198, 52336, 52393, 52450, 52746, 53282, 53861, >> 54593, 54624}, >> {52282, 52487, 52633, 53318, 53766, 57825, 58235, 58333, 58564, >> 59470, 60302, 61050, 61238, 61348, 61460, 61752, 62331, 63000, >> 63731, 63792}, >> {11595, 11635, 11663, 11829, 11912, 12704, 12793, 12807, 12845, >> 13026, 13226, 13372, 13427, 13459, 13477, 13550, 13692, 13840, >> 14023, 14027}, >> {67539, 68026, 68260, 69793, 70561, 77539, 77729, 77868, 78137, >> 80199, 81310, 81882, 82106, 82219, 82302, 82647, 83241, 83960, >> 84724, 84785} >> }, Joined -> True] >> I consistently hang Mathematica to the point where I have to restart >> its kernel in order to restore functionality. Oddly, if Joined->True >> is replaced with Filling->Axis, the problem persists, but if either >> options is removed (so just the markers are plotted), the plot is >> generated as expected. >> Is anyone else seeing this behavior? I can reproduce the behavior in a simpler example. In[1]:= $Version Out[1]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) In[2]:= myList = {15138, 15309, 15341, 15640, 16109}; In[3]:= ListPlot[myList] Works as expected. However, both ListPlot[myList, Joined -> True] and ListLinePlot[myList] hang Mathematica. This does not happen if myList has only 4 points. > Looks like a bug related to the size of the numbers. Everything works > fine with myList/100. For what is worth, I can reproduce the bug on the folloiwng system : v6.0.2 on a Mac (Mac OS X 10.5.2) Intel (64-bit); but not on this one : v6.0.2 on a PC (Windows XP SP2) Intel (32-bit). I have used the large list and the shorter one (5 elements) and the variations of the plot command. -- === Subject: Re: ListPlot Joined/Filling bug? For $Version on my PC, I get: 6.0 for Microsoft Windows (32-bit) (February 7, 2008) which is for version 6.0.2.0 using WinXP Pro with SP2. I ran ALL three variations you mentioned with no problems. If you'd like, I'll send you my Notebook file with its output included. Benjamin Tubb brtubb@pdmusic.org > When I try to generate the following plot: ListPlot[{ {15138, 15309, 15341, 15640, 16109, 16675, 16730, 16756, 16797, > 17006, 17412, 17880, 18034, 18081, 18101, 18171, 18390, 18569, > 18821, 18830}, {45373, 45784, 46153, 47525, 48197, 50014, 50141, 50239, 50342, > 50942, 51950, 52198, 52336, 52393, 52450, 52746, 53282, 53861, > 54593, 54624}, {52282, 52487, 52633, 53318, 53766, 57825, 58235, 58333, 58564, > 59470, 60302, 61050, 61238, 61348, 61460, 61752, 62331, 63000, > 63731, 63792}, {11595, 11635, 11663, 11829, 11912, 12704, 12793, 12807, 12845, > 13026, 13226, 13372, 13427, 13459, 13477, 13550, 13692, 13840, > 14023, 14027}, {67539, 68026, 68260, 69793, 70561, 77539, 77729, 77868, 78137, > 80199, 81310, 81882, 82106, 82219, 82302, 82647, 83241, 83960, > 84724, 84785} }, Joined -> True] I consistently hang Mathematica to the point where I have to restart > its kernel in order to restore functionality. Oddly, if Joined->True > is replaced with Filling->Axis, the problem persists, but if either > options is removed (so just the markers are plotted), the plot is > generated as expected. Is anyone else seeing this behavior? Any ideas what might be causing the problem? I'm using 32-bit Mathematica 6.0.2.0 on Mac OS X 10.5. === Subject: Basic plotting of an evaluated function I am trying to do something basic--but I cannot figure it out I have some function in two varaibles f[x_,y_]= some arbitrary polynomial Now I want to minimize the function with respect to y over some compact interval with fixed x NMinimize[{f[x,y],y=995,y=989},y] I want to plot the y's versus the x's. I have tried many things like defining s[x_]=Part[NMinimize[{f[x,y],y=995,y=989},y],2] Plot[s[x],{x,-14, 46}] or variations Plot[tt/.s[x],{x,-14, 46}]. Many error messages or nothing at all results......... I am sure this is easy, and someone can suggest how to do this. However, one more thing would be greatly helpful (give a man a decent and readable Mathematica manual and he can feed himself...) I am baffled by what Mathematica wants when it comes to using a single part of a list and changing it to a scalar. Suppose as above q is a vector with a rule assigning a value to some variable x that is x- >some number, and this assignment is in the third position of the list What is going on with q/.d[[3]] for example: Is q now a scalar? If not why not? === Subject: Re: Basic plotting of an evaluated function it would be helpful a) if you would consider to read the manual b) use correct Mathematica syntax because NMinimize[{f[x,y],y=995,y=989},y] is remarkable nonsense anyway f[x_?NumericQ, y_?NumericQ] := x*(990 - y^2) s[x_?NumericQ] := y /. Last[NMinimize[{f[x, y], y < 995, y > 989}, y]] Plot[s[x], {x, -14, 46}] > I am trying to do something basic--but I cannot figure it out > I have some function in two varaibles f[x_,y_]= some arbitrary polynomial Now I want to minimize the function with respect to y over some > compact interval with fixed x NMinimize[{f[x,y],y=995,y=989},y] I want to plot the y's versus the x's. I have tried many things like defining s[x_]=Part[NMinimize[{f[x,y],y=995,y=989},y],2] Plot[s[x],{x,-14, 46}] or variations Plot[tt/.s[x],{x,-14, 46}]. Many error messages or nothing at all results......... I am sure this is easy, and someone can suggest how to do this. However, one more thing would be greatly helpful (give a man a decent > and readable Mathematica manual and he can feed himself...) I am baffled by what Mathematica wants when it comes to using a single > part of a list and changing it to a scalar. Suppose as above q is a > vector with a rule assigning a value to some variable x that is x- >> some number, and this assignment is in the third position of the list What is going on with q/.d[[3]] for example: Is q now a scalar? If > not why not? === Subject: Re: Basic plotting of an evaluated function > I have some function in two varaibles f[x_,y_]= some arbitrary polynomial Now I want to minimize the function with respect to y over some > compact interval with fixed x NMinimize[{f[x,y],y=995,y=989},y] There are two syntax errors in the above line: First, the expression y = 995 _assigns_ the integer value 995 to the symbol y. What you had in mind was the comparison operator for equality, which is written as a double equal sign == in Mathematica. (See Set, =, Second, NMinimize accepts constraints expressed in the form of inequalities and domain specification. Therefore, your expression should read, Minimize[{f[x, y], 989 <= y <= 995}, y] > I want to plot the y's versus the x's. I have tried many things like defining s[x_]=Part[NMinimize[{f[x,y],y=995,y=989},y],2] Using SetDelayed, :=, and the replacement operator /. should work here. s[x_] := y /. Last@NMinimize[{f[x, y], 989 <= y <= 995}, y] > Plot[s[x],{x,-14, 46}] The following expressions are a working example of what you are looking for. f[x_, y_] := x^2 - 3 y^2 + x y + 10 s[x_] := y /. Last@NMinimize[{f[x, y], 989 <= y <= 995}, y] Plot[s[x], {x, -14, 46}] Hope this helps, -- === Subject: Color Options for PlanarGraphPlot I am interested in applying color options to PlanarGraphPlot. Under Options[PlanarGraphPlot] there is listed the option ColorOutput -> Automatic. Anyone know how to use this option? I have had no luck. Here is some sample data: sampledata = {{0.854, 0.885}, {1.827, 4.126}, {4.255, 2.872}, {0.888, 4.872}, {4.507, 0.721}, {2.978, 1.998}, {3.507, 4.534}} The best I have been able to do is to apply a color directive to the Line primitive- it works but the approach not very pleasing. PlanarGraphPlot[sampledata, Frame -> True, TextStyle -> {FontSize -> 14, FontColor -> Blue}] /. Line[x_] -> {Red, Line[x]} Note: using the option BaseStyle->Red makes everything in the plot Red. Of course, one could undo some of the BaseStyle by then applying LabelStyle, FrameStyle etc as shown below PlanarGraphPlot[bin, Frame -> True, BaseStyle -> {Red, FontSize -> 14}, LabelStyle -> {Black, FontSize -> 12}, FrameStyle -> Black] Brian ps TextStyle is no longer listed as an option but still appears to work === Subject: Re: Color Options for PlanarGraphPlot the ColorOutput option is for B/W or color printers. If you prepare a book and want to use pictures generated by Mathematica than your publisher is not always happy with color images and you need Black/White pictures when the final PostScript or PDF is created. For this run of your Mathematica input, you should set ColorOutput. But As of Version 6.0, ColorOutput has been superseded by ColorFunction, ColorData and related functions. > I am interested in applying color options to PlanarGraphPlot. Under > Options[PlanarGraphPlot] there is listed the option ColorOutput - Automatic. Anyone know how to use this option? I have had no luck. > Here is some sample data: sampledata = {{0.854, 0.885}, {1.827, 4.126}, {4.255, 2.872}, {0.888, > 4.872}, {4.507, 0.721}, {2.978, 1.998}, {3.507, 4.534}} The best I have been able to do is to apply a color directive to the > Line primitive- it works but the approach not very pleasing. PlanarGraphPlot[sampledata, Frame -> True, > TextStyle -> {FontSize -> 14, FontColor -> Blue}] /. Line[x_] - {Red, Line[x]} Note: using the option BaseStyle->Red makes everything in the plot > Red. Of course, one could undo some of the BaseStyle by then > applying LabelStyle, FrameStyle etc as shown below PlanarGraphPlot[bin, Frame -> True, > BaseStyle -> {Red, FontSize -> 14}, > LabelStyle -> {Black, FontSize -> 12}, FrameStyle -> Black] Brian ps TextStyle is no longer listed as an option but still appears to work > === Subject: Re: Color Options for PlanarGraphPlot the ColorOutput option is for B/W or color printers. > If you prepare a book and want to use pictures generated > by Mathematica than your publisher is not always happy with > color images and you need Black/White pictures when the final > PostScript or PDF is created. For this run of your Mathematica > input, you should set ColorOutput. But > As of Version 6.0, ColorOutput has been superseded by ColorFunction, > ColorData and related functions. I wonder why ColorOutput was removed. ColorFunction is used /before/ generating the graphic. ColorOutput could be used to convert to GrayLevel after it has been generated, making it easy to create several versions of the graphic without additional software. But it is true that in v 5.2 ColorOutput -> CMYKColor was far from precise ... Just try Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}] Show[%, ColorOutput -> CMYKColor] === Subject: Re: Bug: symbol recreates itself suddenly There are some things that are not forbidden by the manual, but still, doing them might be a bad idea. For example, making definitions such as the following isn't a good idea: Sign[x]^=1; Instead one should use the assumptions mechanism: $Assumptions = Re[x] > 0 && Im[x] == 0; I agree that the documentation could be improved for such cases. Bhuvanesh, Wolfram Research === Subject: Re: choose elements from list based on elements in different list > I'm trying to choose elements from list based on elements in different > list and I came up with the ideas listed below. It seems to me that > there are a few too many steps involved here, and I need to run this on > larger lists (~20000 entries). > Are there ways to improve this? > Claus Here is the mathematica code: Reihe1={22,33,44,0,0,16,5,0,0,0} > Reihe2={16,27,0,0,5,11,5,0,0,12} {22, 33, 44, 0, 0, 16, 5, 0, 0, 0} {16, 27, 0, 0, 5, 11, 5, 0, 0, 12} (*Find out where in Reihe1 and in Reihe2 are Zeros and notZeros*) Reihe1Is0 = Thread[Reihe1 == 0] > Reihe1Not0 = Thread[Reihe1 != 0] > Reihe2Is0 = Thread[Reihe2 == 0] > Reihe2Not0 = Thread[Reihe2 != 0] {False, False, False, True, True, False, False, True, True, True} {True, True, True, False, False, True, True, False, False, False} {False, False, True, True, False, False, False, True, True, False} {True, True, False, False, True, True, True, False, False, True} (*Select the values of Reihe1 and Reihe2 which are of interest There are 4 Cases (not all of them calculated later) : > Case1 : Reihe1 and Reihe2 are 0 > Case2 : Reihe1 and Reihe2 are NOT 0 > Case3 : (Reihe2 is NOT 0) AND (Reihe1 is 0) > Case4 : (Reihe1 is NOT 0) AND (Reihe2 is 0)*) PreCase3=Pick[Reihe2,Reihe1Is0] > PreCase4=Pick[Reihe1,Reihe2Is0] {0, 5, 0, 0, 12} {44, 0, 0, 0} Case3=Select[PreCase3,#>0&] > Case4=Select[PreCase4,#>0&] {5, 12} {44} Hi. Just another option would be to combine the two lists into an integer.(0,1,2,or 3) Reihe1 = {22, 33, 44, 0, 0, 16, 5, 0, 0, 0}; Reihe2 = {16, 27, 0, 0, 5, 11, 5, 0, 0, 12}; ptn = 2*DiscreteDelta /@ Reihe1 + DiscreteDelta /@ Reihe2 {0, 0, 1, 3, 2, 0, 0, 3, 3, 2} Pick[Reihe2, ptn, 2] {5, 12} Pick[Reihe1, ptn, 1] {44} -- HTH :>) Dana DeLouis Mathematica 6 But reading 5.2 Help. :>( === Subject: Re: Counting nonzeros >I want to count the # of NZ entries in an arbitrary multilevel list, >say exp, that contains only integers. Is this the easiest way: >k = Length[Flatten[exp]]-Count[Flatten[exp],0] There are a number of ways to do what you want. I think using Unitize to convert the non-zero entries to 1 and then summing using Total is likely to be the fastest, i.e., Total[Flatten@Unitize@exp] or Total[Total@Unitize@exp] === Subject: Tally I'm trying the following: *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};* The output is: *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}* instead of *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}* If I remove the last member from DList *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};* then I got a correct answer *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.* Is anything wrong with my original code? Armen === Subject: Re: Tally > I'm trying the following: > *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};* > The output is: *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}* instead of *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}* If I remove the last member from DList *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};* then I got a correct answer *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.* Here is solution to this issue, by writing our own Tally function. Note that code of the function myTally is only one possibility among many and that there has been no attempt to optimize it for speed (though it takes about half a second to process 100,000 pairs of pairs). We assume that the matrix entries are only 0 or 1 (_Integer). The idea is, therefore, to look at en entry of the form {{a, b}, {c, d}} (where a, b, c, and d are in {0, 1}) as if it were, having flatten the matrix, a binary representation of a decimal number. For instance, say we have the entry {{0, 1}, {0, 1)}. We look at it as if it were 0101 (binary), i.e. 5 in decimal. Also, we check the reverse representation of the entry (that is {{b, a}, {d, c}}) and take the minimum value of both representation as the canonical form for this equivalent entries. In our example, the reverse entry of {{0, 1}, {0, 1)} is {{1, 0}, {1, 0)}, that is 1010 in binary or 10 in decimal. So both entries {{0, 1}, {0, 1)} and {{1, 0}, {1, 0)} are going to be encoded as 5 in the code below. When the whole list is processed, Tally is applied, and finally we decode the decimal entries into their pair of pairs equivalent. Well, I hope this makes sense! Here is the code for myTally, followed by some tests. In[1]:= myTally[lst_List] := Module[{l1, l2, l3, l4}, l3 = Min /@ Transpose[{l1, l2}]; l1 =.; l2 =.; l4 = {PadLeft[IntegerDigits[First@#, 2], 4], Last@#} & /@ Tally@l3; l3 =.; {Partition[First@#, 2], Last@#} & /@ l4 ] In[2]:= Dlist = {{{0, 1}, {0, 1}}, {{1, 0}, {1, 0}}, {{1, 0}, {0, 1}}, {{0, 1}, {1, 0}}}; myTally[Dlist] Out[3]= {{{{0, 1}, {0, 1}}, 2}, {{{0, 1}, {1, 0}}, 2}} In[4]:= Dlist = RandomInteger[{0, 1}, {10, 2, 2}] myTally[Dlist] Out[4]= {{{0, 0}, {1, 1}}, {{0, 1}, {1, 0}}, {{0, 1}, {0, 0}}, {{0, 0}, {0, 0}}, {{0, 1}, {1, 1}}, {{1, 0}, {0, 1}}, {{1, 1}, {1, 1}}, {{1, 0}, {1, 0}}, {{0, 0}, {1, 0}}, {{1, 0}, {1, 1}}} Out[5]= {{{{0, 0}, {1, 1}}, 1}, {{{0, 1}, {1, 0}}, 2}, {{{0, 1}, {0, 0}}, 1}, {{{0, 0}, {0, 0}}, 1}, {{{0, 1}, {1, 1}}, 2}, {{{1, 1}, {1, 1}}, 1}, {{{0, 1}, {0, 1}}, 1}, {{{0, 0}, {0, 1}}, 1}} In[6]:= Dlist = RandomInteger[{0, 1}, {10^5, 2, 2}]; myTally[Dlist] // Timing Out[7]= {0.633001, {{{{1, 1}, {0, 0}}, 6366}, {{{0, 0}, {0, 1}}, 12467}, {{{1, 1}, {0, 1}}, 12633}, {{{0, 1}, {0, 1}}, 12484}, {{{0, 1}, {0, 0}}, 12377}, {{{0, 1}, {1, 0}}, 12402}, {{{0, 0}, {1, 1}}, 6278}, {{{0, 1}, {1, 1}}, 12473}, {{{0, 0}, {0, 0}}, 6303}, {{{1, 1}, {1, 1}}, 6217}}} You can find below a step by step evaluation of the code with some extras that should help to understand what is going on. In[8]:= Dlist = {{{0, 1}, {0, 1}}, {{1, 0}, {1, 0}}, {{1, 0}, {0, 1}}, {{0, 1}, {1, 0}}}; In[9]:= Flatten /@ Dlist Out[9]= {{0, 1, 0, 1}, {1, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, 1, 0}} Out[10]= {5, 10, 9, 6} In[11]:= Map[Reverse, Dlist, {2}] Out[11]= {{{1, 0}, {1, 0}}, {{0, 1}, {0, 1}}, {{0, 1}, {1, 0}}, {{1, 0}, {0, 1}}} In[12]:= Flatten /@ Map[Reverse, Dlist, {2}] Out[12]= {{1, 0, 1, 0}, {0, 1, 0, 1}, {0, 1, 1, 0}, {1, 0, 0, 1}} In[13]:= l2 = Out[13]= {10, 5, 6, 9} In[14]:= Transpose[{l1, l2}] Out[14]= {{5, 10}, {10, 5}, {9, 6}, {6, 9}} In[15]:= l3 = Min /@ Transpose[{l1, l2}] Out[15]= {5, 5, 6, 6} In[16]:= Tally@l3 Out[16]= {{5, 2}, {6, 2}} In[17]:= {IntegerDigits[First@#, 2], Last@#} & /@ Tally@l3 Out[17]= {{{1, 0, 1}, 2}, {{1, 1, 0}, 2}} In[18]:= l4 = {PadLeft[IntegerDigits[First@#, 2], 4], Last@#} & /@ Tally@l3 Out[18]= {{{0, 1, 0, 1}, 2}, {{0, 1, 1, 0}, 2}} In[19]:= {Partition[First@#, 2], Last@#} & /@ l4 Out[19]= {{{{0, 1}, {0, 1}}, 2}, {{{0, 1}, {1, 0}}, 2}} -- === Subject: Re: Tally I'm trying the following: > *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};* > The output is: *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}* instead of *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}* If I remove the last member from DList *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};* then I got a correct answer *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.* Is anything wrong with my original code? I really *hope* that I am wrong, but it seems to me that your code is correct. The test function is a good equivalence relation, i.e. it is reflexive, symmetric and transitive, so this cannot be the problem. But something seems to be wrong with Tally: test = dlist = {{{0, 1}, {0, 1}}, {{1, 0}, {1, 0}}, {{1, 0}, {0, 1}}, {{0, 1}, {1, 0}}} test2[p_, q_] := With[{val = test[p, q]}, Print[{Position[dlist, p, {1}], Position[dlist, q, {1}], val}]; val] ( Using Position should work because this specific dlist has no repeating elements ) The output of Tally[dlist, test2] is: {{{1}},{{4}},False} {{{3}},{{2}},False} {{{4}},{{2}},False} {{{4}},{{3}},True} {{{1}},{{3}},False} {{{2}},{{4}},False} {{{4}},{{3}},True} {{{3}},{{1}},False} {{{{0, 1}, {0, 1}}, 1}, {{{1, 0}, {1, 0}}, 1}, {{{1, 0}, {0, 1}}, 2}} It looks like Tally never tests element 1 against element 2, but it does test element 4 against element 3 *twice*, even though this is completely unnecessary. This is the kind of bug that severely undermines one's trust in Mathematica. I do not expect that Integrate or some numerical method should always return a correct answer. I know that this is simply not possible. But the algorithms that could be used by Tally are simple enough that I find this bug quite shocking. === Subject: Re: Tally I dont't think there is anything wrong with your code, but I know that under certain conditions Tally does not work properly. I postet a similar problem re Tally last November to Wolfram support, and I got the answer that Tally is not always working correctly. I suggest you write your own Tally function, e.g. using Sow and Reap. This works fast and perfect in my situations. Michael Weyrauch I'm trying the following: > *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};* > The output is: *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}* instead of *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}* If I remove the last member from DList *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};* then I got a correct answer *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.* Is anything wrong with my original code? > Armen === Subject: Re: Tally > I'm trying the following: > *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};* > The output is: *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}* instead of *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}* If I remove the last member from DList *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};* then I got a correct answer *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.* Is anything wrong with my original code? Although this does not answer your question, writing your expression as follows should help investigating its behavior (assuming, of course, I have correctly understood what you try to achieve). Dlist={{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}}; Tally[Dlist, ==> {{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}} -- === Subject: Re: Tally > I'm trying the following: >> *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}};* >> The output is: >> *{{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}}* >> instead of >> *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},2}}* >> If I remove the last member from DList >> *Dlist = {{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}}};* >> then I got a correct answer >> *{{{{0,1},{0,1}},2},{{{1,0},{0,1}},1}}.* >> Is anything wrong with my original code? > Although this does not answer your question, writing your expression as > follows should help investigating its behavior (assuming, of course, I > have correctly understood what you try to achieve). Dlist={{{0,1},{0,1}},{{1,0},{1,0}},{{1,0},{0,1}},{{0,1},{1,0}}}; Tally[Dlist, ==> {{{{0,1},{0,1}},1},{{{1,0},{1,0}},1},{{{1,0},{0,1}},2}} An even more compact way of writing the test function is as follows, Unfortunately, it still does not solve the issue... -- === Subject: Hide a PopupMenu in Manipulate the rigth email adress. I have just began learning Mathematica. I could not find the solution to the following problem: I have made a circle and the user should decide, whether the circle should have a color. If it should, three PopupMenus should be shown, but when the checkbox is not clicked, they should not be shown: ---------------------------------------------------------------------------- - (*Code: *) Manipulate[ Graphics[ { If[ color, {typ = PopupMenu; color1, Disk[] }, {typ = None; Circle[] } ]} ], {{color, False, Color}, {False, True}}, {{color1, Blue, Color1}, {Blue -> Blue, Green -> Green}, ControlType -> typ} ] --------------------------------------------------------------------------- But as you can see, you have to recompile it in order to see the changes. Is there any way to do so, without recompiling the code? Patrick Klitzke email:philologos14@gmx.de === Subject: Re: Hide a PopupMenu in Manipulate If you like you can skip Manipulate and instead wrap Dynamic around the expression of interest: Dynamic@Row[ { Graphics[If[colored, {color, Disk[]}, Circle[]]], Checkbox[Dynamic[colored]], Color, If[colored, PopupMenu[Dynamic[color], {Blue -> Blue, Green -> Green}]] }, ] > the rigth email adress. I have just began learning Mathematica. I could > not find the solution to the following problem: > I have made a circle and the user should decide, whether the circle > should have a color. If it should, > three PopupMenus should be shown, but when the checkbox is not clicked, > they should not be shown: > ----------------------------------------------------------------------------- > (*Code: *) > Manipulate[ > Graphics[ > { > If[ > color, > {typ = PopupMenu; > color1, Disk[]}, {typ = None; > Circle[] } > ]} > ], > {{color, False, Color}, {False, True}}, > {{color1, Blue, Color1}, > {Blue -> Blue, Green -> Green}, > ControlType -> typ} > ] > --------------------------------------------------------------------------- > But as you can see, you have to recompile it in order to see the changes. > Is there any way to do so, without recompiling the code? > Patrick Klitzke email:philologo...@gmx.de === Subject: Re: Hide a PopupMenu in Manipulate > the rigth email adress. I have just began learning Mathematica. I could > not find the solution to the following problem: > I have made a circle and the user should decide, whether the circle > should have a color. If it should, > three PopupMenus should be shown, but when the checkbox is not clicked, > they should not be shown: How about disabling the popup menu? Manipulate[Graphics[{If[color,{color1,Disk[]},{Circle[]}]}], {{color,False,Color},{False,True}},{{color1,Blue,Color1},{Blue- >Blue,Green->Green},ControlType->PopupMenu,Enabled->color}] -Rob === Subject: Re: Hide a PopupMenu in Manipulate A colleague suggested using PaneSelector to hide the popup menu when it's not in use: Manipulate[ Graphics[{If[color, c, Black], Circle[{0, 0}, 1]}, ImageSize -> {400, 400}], {{color, True, color on}, {True, False}}, Item[ PaneSelector[ {True -> Row[{ select color, PopupMenu[ Dynamic@c, {Red -> red, Blue -> blue, Green -> green}] }, Spacer[3]], False -> }, Dynamic@color ] ], {{c, Red}, {Red, Blue, Green}, ControlType -> None}, ControlPlacement -> Left] -Rob === Subject: Re: Rotation of 3D objects > Here is some code for those who have the Presentations package. For reflection in a mirror: Needs[Presentations`Master`] Module[ > {(* object to reflect *) > gr = ParametricDraw3D[{t, u + t, u t/5}, {t, 0, 2}, {u, -1, 1}, > Mesh -> 5, > BoundaryStyle -> Black], > (* Mirror location and normal *) > p = {1, 1, 2}, > normal = {0, 0, 1}, > vector1, vector2}, > {vector1, vector2} = NullSpace[{normal}]; > Draw3DItems[ > {(* Original object *) > {Opacity[.7, HTML[DarkSeaGreen]], gr}, > (* Reflected object *) > {Opacity[.7, HTML[DodgerBlue]], gr} // > ReflectionTransformOp[normal, p], > (* Draw the mirror *) > {Opacity[0.3, HTML[SkyBlue]], > ParametricDraw3D[ > p + s vector1 + t vector2, {s, -3, 3}, {t, -3, 3}, > Mesh -> None]}}, > NeutralLighting[0, 0.6, .1], > NiceRotation, > ViewPoint -> {2, -2.4, .6}, > Boxed -> False, > ImageSize -> 300] > ] Multiple copies of rotation about an axis: Module[ > {(* object to reflect *) > gr = ParametricDraw3D[{t, u + t, u t/5}, {t, 0, 2}, {u, -1, 1}, > Mesh -> 5, > BoundaryStyle -> Black], > (* axis, location and number of copies *) > axis = {1, 1, 0}, > axislocation = {-1.5, -1.5, 2}, > ncopies = 4, > rotationangle}, > rotationangle = 2 [Pi]/ncopies; > Draw3DItems[ > {(* Rotations *) > {Opacity[.7, HTML[DarkSeaGreen]], > Table[gr // > RotationTransformOp[n rotationangle, axis, axislocation], {n, = 0, > ncopies - 1}]}, > (* Draw the axis *) > Red, Arrow3D[axislocation, axislocation + 5 axis, {.10}]}, > NeutralLighting[0, 0.6, .1], > NiceRotation, > ViewPoint -> {-1, -2.4, .6}, > Boxed -> False, > ImageSize -> 300] > ] A Manipulate statement allowing the rotation about an axis by an adjustabl= e > angle theta. Manipulate[ > Module[ > {(* object to reflect *) > gr = ParametricDraw3D[{t, u + t, u t/5}, {t, 0, 2}, {u, -1, 1}, > Mesh -> 5, > BoundaryStyle -> Black], > (* axis direction and location *) > axis = {1, 1, 0}, > axislocation = {-1.5, -1.5, 2}}, > Draw3DItems[ > {(* Original object *) > {Opacity[.7, HTML[DarkSeaGreen]], gr}, > (* Rotated object *) > {Opacity[.7, HTML[DodgerBlue]], > gr // RotationTransformOp[[Theta], axis, axislocation]}, > (* Draw the axis *) > Red, Arrow3D[axislocation, axislocation + 5 axis, {.10}]}, > NeutralLighting[0, 0.6, .1], > NiceRotation, > PlotRange -> {{-1, 4}, {-1, 4}, {-1, 5}}, > ViewPoint -> {-1, -2.4, .6}, > Boxed -> False, > ImageSize -> 300] > ], > Style[Rotation about axis by angle [Theta], 16], > {[Theta], 0, 2 [Pi], Appearance -> Labeled}] -- > David Park > djmp...@comcast.nethttp://home.comcast.net/~djmpark/ By what command is it possible to create (without writing a code > separately ): 1) Reflections of 3D objects about a plane? 2) Multiple copies equally spaced by rotation around an axis through > two given points? E.g., > surf = ParametricPlot3D[{ t,u+t, u*t/5}, {t,0,2},{u,-1,1}]; > Rotate[surf,Axis->{ {-1,-1,-1},{1,1,1}} , Copies-> 4 ] ; and, 3) A single rotation of given object through a given angle on an axis > through two defined points? > Narasimham- Hide quoted text - - Show quoted text - Actually in engineering drawing software e.g., CATIA, Autocad Pro E &c. such 3D operations are routinely implemented, clicking on a standard GUI...the mathematical basis of which I was sure is well within Mathematica's range of computational capabilities. ( and it also appeared in 200 seconds. ).Mathematica gives the user an advantage to see those steps, or look into the black box.Of course, some minimum code lines have to be written. Narasimham === Subject: Importing text files I'm using Mathematica v6.02 to import a large comma delimited text file (CSV format). The file is about 700,000 records and takes 241 Mb of space according to ByteCount. The file is a mix of real and string characters. I've imported much smaller versions of this using the built-in support for Excel XLS format without any difficulties. For the larger file, the Import appears to work fine except that all of the string elements import with quotation marks, i.e., if you look at the full form, all of the string elements are expressed as {YES,.....} With the character intact. This is the first I've bumped into this particular issue using Import. Two questions: First, is there a way that I can remove the characters as part of the Import command? And second, if these characters cannot be removed during the Import process, can someone offer an efficient way to remove them from the imported list? -Mark === Subject: Re: Importing text files I'm using Mathematica v6.02 to import a large comma delimited text file (CSV > format). The file is about 700,000 records and takes 241 Mb of space > according to ByteCount. The file is a mix of real and string characters. > I've imported much smaller versions of this using the built-in support > for Excel XLS format without any difficulties. For the larger file, the Import appears to work fine except that all of > the string elements import with quotation marks, i.e., if you look at > the full form, all of the string elements are expressed as {YES,.....} With the character intact. This is the first I've bumped into this > particular issue using Import. Two questions: First, is there a way that I can remove the > characters as part of the Import command? And second, if these > characters cannot be removed during the Import process, can someone > offer an efficient way to remove them from the imported list? > -Mark > Something changed between 6.0.1 and 6.0.2 when you import a CSV file containing character strings. The earlier version stripped off the quotation marks, the later one leaves them in. Since a CSV file can contain strings without quotes, the new way of doing things is more consistent, and probably counts as a bug fix. Have you tried just stripping the quotes afterwards: Import[something.csv] /. x_String:>StringReplace[x,->] If you anticipate going to even larger files, you should be aware that because your file contains both real and string types, it will not pack, and therefore occupies much more space and is slower to process than would otherwise be the case. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Importing text files On 25 Mar, 06:19, Coleman, Mark I'm using Mathematica v6.02 to import a large comma delimited text file (CSV > format). The file is about 700,000 records and takes 241 Mb of space > according to ByteCount. The file is a mix of real and string characters. > I've imported much smaller versions of this using the built-in support > for Excel XLS format without any difficulties. For the larger file, the Import appears to work fine except that all of > the string elements import with quotation marks, i.e., if you look at > the full form, all of the string elements are expressed as {YES,.....} With the character intact. This is the first I've bumped into this > particular issue using Import. Two questions: First, is there a way that I can remove the > characters as part of the Import command? And second, if these > characters cannot be removed during the Import process, can someone > offer an efficient way to remove them from the imported list? > -Mark Hi The behavior of Import has changed from 6.0.1 to 6.0.2 regarding csv files. In old versions, a string that is surrounded in quotes such as hello was imported as hello but now it is imported as hello . Say I have a csv file called Book1.csv with the following data hello,1 test,2 bode,3 hehehe,4 oidjaojf,5 cfoiuhsrfipvuh,6 fojewhnfrvo,7 werijfbwpiufv,8 nhjawhb,9 cvijweqbv,10 vwjiebv,11 In[2]:= book = Import[Book1.csv] Out[2]= {{hello, 1}, {test, 2}, {bode, 3}, {hehehe, 4}, {oidjaojf, 5}, {cfoiuhsrfipvuh, 6}, {fojewhnfrvo, 7}, {werijfbwpiufv, 8}, {nhjawhb, 9}, {cvijweqbv, 10}, {vwjiebv, 11}} If you don't want the escaped quotes () you can strip them out as follows: In[3]:=f = If[StringQ[#], StringReplace[#, -> ], #] &; In[4]:= Map[f, book, {2}] Out[4]= {{hello, 1}, {test, 2}, {bode, 3}, {hehehe, 4}, {oidjaojf, 5}, {cfoiuhsrfipvuh, 6}, {fojewhnfrvo, 7}, {werijfbwpiufv, 8}, {nhjawhb, 9}, {cvijweqbv, 10}, {vwjiebv, 11}} I don't know if this is the most efficient way but it does the job. === Subject: Re: (Q: How to copy programmatically?) > The proper structure of Notebook[] is Notebook[{cell1, cell2, etc.}, opts]. > This is documented in the documentation for Notebook[]. Actually the documentation for Notebook[] only contains an example, but it is not clear that this is the /only/ acceptable syntax, so it is natural that one starts experimenting. I tried to achieve an effect similar to simply copying plain text from Notepad, i.e. I did not want any style information to be associated with the copied text. I was not sure what style to use with Notebook[{Cell[abc, style]}], so I tried Notebook[{abc}] which appeared to work. (Most probably the style should be Input.) However, your method of writing to the clipboard isn't going to work robustly. > You can read the values off the clipboard notebook pretty robustly, but writing > to the clipboard notebook doesn't always interact with the clipboard as you > would expect. The most robust way of copying something to the clipboard is to create a > temporary, invisible notebook with what you want and execute the Copy front > end token. This method can also allow you to sidestep the issue of creating > correct cells. E.g., nb = NotebookCreate[Visible -> False]; > NotebookWrite[nb, 2+2]; > SelectionMove[nb, All, Notebook]; > FrontEndTokenExecute[nb, Copy]; > NotebookClose[nb]; How would one use CreateDocument[] instead of NotebookCreate[] and NotebookWrite[]? (According to the documentation, NotebookCreate[] is obsolete, and CreateDocument[] can insert an expression into the notebook right after it is created.) Is the following correct and equivalent to nb = NotebookCreate[]; NotebookWrite[nb, 2+2] ? nb = CreateDocument[Cell[BoxData[2+2], Input]]; There are a few places where Mathematica itself uses this technique to > programmatically deliver something to the clipboard. We're working on a design > for a much easier way to do this in future versions. > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. > > When pasting quoted text from an e-mail, Mathematica will offer to > remove the quoting marks. It says: > > The text you are pasting appears to be from a quoted email. Do you > want Mathematica to remove the quoting marks before pasting it? (Yes|No) > > Here is a quoted expression to try this: > >> {9, >> 0, >> 7, >> 8, >> 7, >> 2, >> 5, >> 0, >> 7, >> 1} > > The dialogue box also comes up when evaluating the following to access > the clipboard programmatically: > > NotebookGet@ClipboardNotebook[] > > This is expected and understandable. But the dialogue box appears when > using NotebookPut[] too if the clipboard contains a quoted expression! > > NotebookPut[Notebook[{abc}], ClipboardNotebook[]] > > Why does this happen? Is it a bug? Also, is this the correct way to > *copy* a string to the clipboard programmatically? It does work, but I > am not sure if Notebook[{abc}] (with no Cells) is a correct Notebook > expression. (Where is the correct syntax documented?) > === Subject: Re: (Q: How to copy programmatically?) Strange, but nothing of this kind happens on my system: In[97]:= $Version Out[97]= 6.0 for Mac OS X x86 (32-bit) (June 19, 2007) The quote marks are removed automatically and no dialog comes up in all the cases you mention below. Andrzej Kozlowski When pasting quoted text from an e-mail, Mathematica will offer to > remove the quoting marks. It says: The text you are pasting appears to be from a quoted email. Do you > want Mathematica to remove the quoting marks before pasting > it? (Yes|No) Here is a quoted expression to try this: > {9, >> 0, >> 7, >> 8, >> 7, >> 2, >> 5, >> 0, >> 7, >> 1} The dialogue box also comes up when evaluating the following to access > the clipboard programmatically: NotebookGet@ClipboardNotebook[] This is expected and understandable. But the dialogue box appears > when > using NotebookPut[] too if the clipboard contains a quoted expression! NotebookPut[Notebook[{abc}], ClipboardNotebook[]] Why does this happen? Is it a bug? Also, is this the correct way to > *copy* a string to the clipboard programmatically? It does work, > but I > am not sure if Notebook[{abc}] (with no Cells) is a correct Notebook > expression. (Where is the correct syntax documented?) > === Subject: Re: Match Pairs of Numbers lst = {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}, {3, 1}, {3, 2}, {3, 3}, {4, 1}, {4, 4}}; Select[lst, MemberQ[DeleteCases[lst, #], Reverse[#]] &] {{1, 3}, {1, 4}, {3, 1}, {4, 1}} Cases[lst, _?(MemberQ[DeleteCases[lst, #], Reverse[#]] &)] {{1, 3}, {1, 4}, {3, 1}, {4, 1}} DeleteCases[lst, _?(FreeQ[DeleteCases[lst, #], Reverse[#]] &)] {{1, 3}, {1, 4}, {3, 1}, {4, 1}} Pick[lst, MemberQ[DeleteCases[lst, #], Reverse[#]] & /@ lst] {{1, 3}, {1, 4}, {3, 1}, {4, 1}} Bob Hanlon > Any help would be appreciated. I am using Mathematica 5.2 & 6.0 I am having trouble finding the correct form of Pattern Matching for > pairs of Numbers. I do not know whether to use Select, Cases, Pick, > etc. I am also unsure how to set the pattern matching argument. Assume I have the list lst = {{1,1}, {1,2}, {1,3}, {1,4}, {2,2}, {3,1}, {3,2}, {3,3}, {4,1}, {4,4}} > I would like to match/select pairs that have the same set of numbers > only reversed, that is, the selection would find {{1,3}, {3,1}, {1,4}, {4,1} } Andrew C Beveridge > MS M888 > Los Alamos National Laboratory > Los Alamos, NM 87545 505-665-2092 > e-mail: acbev@lanl.gov === Subject: Another stylesheet question I went thru the stylesheet tutorial that David Park kindly made available. I was successful in making the new stylesheet he proposed. But I'd like to do something he didn't cover (that I could find). I'd like to simply change the size of the text in the text style (the cell type found in the little box at upper left in a notebook). I can reformat the text cell by cell but I'd like it to just use a proper text size to start with from default.nb. I've given up trying to do this in Options Inspector. I've looked thru it forever and can't find any way to change text size. And if I did, would that change what's in the default.nb stylesheet? So I did Format/ Edit Stylesheet, selected the text style, to modify, then changed it to a new size and color via the Format Menu and then *Save As* default.nb. Well, that didn't work -- Mathematica wouldn't even run on restart. I had to restore default.nb from my backup copy. Even though the Edit Stylesheet window says it is using inherited base definitions from default.nb, the file it makes is tiny and apparently leaves out items needed for Mathematica to run. So I'm missing the big picture -- can someone please tell me how to modify default.nb -- or make Mathematica use a different === Subject: Re: Another stylesheet question I'm not a total expert on this at all and it would still be nice if WRI provided more complete documentation on creating, modifying and using style sheets. A general criticism I have with all the WRI style sheets is that the Text font size is too small. If one looks at textbooks or research papers the text font size is always just as large, if not larger, than the font size used in equations. Mathematica notebooks are the best method there is for technical communications and Text cells are just as important as Input/Output cells. One might even consider making Text cells the default new cell type! Also, Output cells should be unadorned in any way so that if one closed up the Input cells the notebook would look just like a textbook or research paper. I don't think you can, or should, change the Default.nb style sheet. What you should do is modify it and use SaveAs to save it to a new name, say MyDefault.nb, in your personal FrontEnd, StyleSheets folder. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >I went thru the stylesheet tutorial that David Park kindly > made available. I was successful in making the new > stylesheet he proposed. But I'd like to do something he > didn't cover (that I could find). I'd like to simply change the size of the text in the text > style (the cell type found in the little box at upper left > in a notebook). I can reformat the text cell by cell but I'd > like it to just use a proper text size to start with from > default.nb. I've given up trying to do this in Options > Inspector. I've looked thru it forever and can't find any > way to change text size. And if I did, would that change > what's in the default.nb stylesheet? So I did Format/ Edit Stylesheet, selected the text style, > to modify, then changed it to a new size and color via the > Format Menu and then *Save As* default.nb. Well, that > didn't work -- Mathematica wouldn't even run on restart. I had to > restore default.nb from my backup copy. Even though the Edit > Stylesheet window says it is using inherited base > definitions from default.nb, the file it makes is tiny and > apparently leaves out items needed for Mathematica to run. So I'm missing the big picture -- can someone please tell me > how to modify default.nb -- or make Mathematica use a different > === Subject: Re: Mathematica notebooks the best method Of course there IS a time-limited, cheap student version of Mathematica available. In fact, two such: a 6-month version and a 12-month version. > .... A time limited cheap student version > available to any student, whether at an institution that has a site > license or not, would make an enormous contribution to the adoption of > Mathematica, -- 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 === Subject: Re: Mathematica notebooks the best method djvu vs. pdf: no big deal. Tex vs. Mathematica: BIG deal! With djvu and pdf, it's merely a matter of the final format in which the document appears and is disseminated. With (La)TeX and Mathematica, there's a crucial difference in the entire authoring process. Among other things: (1) (La)TeX concentrates upon the logical structure of the document, whereas Mathematica from the start involves the actual appearance of the document. (2) Typing math markup is typically quicker in (La)TeX than in Mathematica, as it avoids Control-key sequences (unless one is using an editor where such sequences are used as shortcuts) or at least uses shorter keystroke-only sequences. (3) Mathematica allows live calculations in the document itself, whereas TeX does not (except of the most primitive kind). Exception: a specialized TeX+CAS system. (4) Mathematica creates graphics of all sorts directly in the document, whereas with the exception of a limited number of native or package add-on graphics types, graphics must be imported into a TeX document from an external source (such as Mathematica)! There are two other another differences: (5) One can have an entire TeX document preparation system -- editor, TeX engine plus packages, viewer, and converter (dvi to ps or pdf, e.g.) -- for free. Needless to say, Mathematica is not free. (6) The source code for TeX and many or most of the supporting utilities is open source; this is certainly not the case for Mathematica. ...I would like to point out that publishing standards are not > set in stone. For several years I have witnessed PDF visibly loosing > ground to djvu in the mathematical preprint area. I like with many > other things I learned about it first form students, who quickly > understood its technical superiority over PDF (most of all, much > smaller file size). Now I see that a number of on-line mathematics > journals are offering djvu as an alternative to pdf. -- 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 === Subject: Re: Mathematica notebooks the best method for technical communications (Was: Another stylesheet question) I agree that the persuading the academic and publishing establishment to add Mathematica to the so called publishing standards is going to be an uphill struggle and probably not worth the effort. But I do not agree about the reasons for this and of course I totally disagree with the final statement. The academic establishment is one of the most conservative establishments there are. The reason for this is clear: it consist mostly of people who are oldish or quite old and thus reluctant to learn ways of doing this different from those that they learned in their youth, particularly if they lie outside their own academic area. In so called research institutions young people are expected and in fact have to, if they are going to stay around, concentrate on research and being concerned with stuff like publishing formats is not going to get one tenure at Stanford. So naturally the people who dominate this area are the older, tenured staff. The publishing world is even worse. The reluctance to adopt technical innovation in academic publishing would be a good subject for a comedy if it wasn't so depressing in its consequences. I have also had quite a lot of contact with this for a number of years. For example I still remember the days when one of the leading mathematical journals started using TeX. Even after they started it, they continued to demand that authors professional typist. I think I must have been one of the earliest Springer authors who used TeX and I remember how none of the editors knew what it was and how much trouble I had when I wanted to modify some of their macros. It was years after TeX had become standard for writing mathematical research. The same thing is happening nowadays with the transfer to electronic publishing. So I agree, the chances of convincing the academic or publishing establishment that they should try to adopt another format are pretty slim. However, there is another way, and I hope WRI is pursuing it. A long time before TeX was adopted by journals and before most senior academics understood how it it suppose to be pronounced, it had become de facto standard among students and young researchers. Being young they learn new things much faster, are much more likely to experiment with them by themselves (so usually they do not care about printed manuals) and appreciate genuine innovation as oppose to hype. What they are mostly concerned with is price and whether the things they learn would be of advantage in their future employment. This suggest an obvious strategy for WRI: ignore the academic establishment and concentrate on the students and their likely future employers. I don't know much about the latter but from the statistics I have seen Mathematica is doing not to badly in this area, at least compared with its major competitors. As for students, what is obviously needed access to cheap copies, other than through piracy (though I hope WRI is not completely blind to the benefits it gets from that latter phenomenon as long as it is restricted to students). By the way, the current system of student versions isn't really sufficient since it requires universities to have site licenses, which in turn requires winning over the establishment. A time limited cheap student version available to any student, whether at an institution that has a site license or not, would make an enormous contribution to the adoption of Mathematica, and would make opinions like that at the end of the OPs post largely irrelevant. Finally, I would like to point out that publishing standards are not set in stone. For several years I have witnessed PDF visibly loosing ground to djvu in the mathematical preprint area. I like with many other things I learned about it first form students, who quickly understood its technical superiority over PDF (most of all, much smaller file size). Now I see that a number of on-line mathematics journals are offering djvu as an alternative to pdf. Andrzej Kozlowski > Mathematica notebooks are the best method there is for >> technical communications Would this were true. It's not. Making Mathematica notebooks become the primary method for both > preparing *and communicating* technical communications (broadly > interpreted to include teaching, writing, presentations, and > publications) in both the academic and professional worlds might be a > laudable goal, and a number of people (David Park very much included) > have put sincere and laudable efforts into trying to make it be the > case. Sorry, it's _not_ goi