A58 == I output 3D objects to DXF files in Mathematica, then import those DXFfiles into another raytracing 3D program....works quit well gievn thelimitations of DXF files. ==== I find the Timing results below a little curious. Is there a simpleexplanation why I shouldnÕt?Chris GrantIn[1]:= x = Table[2.,{i,100000}];In[2]:= y = Table[If[i<1000000,2.,i],{i,100000}];In[3]:= SameQ[x,y]Out[3]= TrueIn[4]:= Timing[Inner[Divide,x,x]]Out[4]= {0.44 Second,100000.}In[5]:= Timing[Inner[Divide,y,y]]Out[5]= {0.321 Second,100000.} ==== Wolfram Research is working on a product that integrates Mathematica with .NET, similar to what J/Link does for Java. You will be able to use .NET/Link to call C# and any other .NET languages from Mathematica, and also call Mathematica from .NET.The project is well underway, but we have not yet established a schedule for its release. We will make sure that this group is informed when further details are available.Todd GayleyWolfram Research ==== has anyone in the general user community ever implemented Elliptic CurveCryptography (ECC) using Mathematica and would be willing to share it?I tried MathSource with no apparent luck. ==== The answer is very,very simple.As I have repeatedly explained in this forum, almost everything inMathematica is ultimately made up of symbols...and all symbols have afull name that contains a context. Heads of expressions are definitelyNOT an exception.Hence an expression of the form:f[args___] is usually in realityGlobal`f[args] if f is user-defined, orSystem`f[args] if f is built-in.In your case SerObject is a symbol in a context not in $ContextPath,hence the appearance of its full name oo`Priv`SerObject.Hope that helped,Orestis ==== Well, if you executed Apply[SerObject, liste] in a Mathematica session after loading your oo package, it basically means that you didnÕt put a usage message for SerObject. If you put a usage message for SerObject in your package, e.g. SerObject::usage = (*the usage message*) your problem is solved. An alternative would be to execute Begin[oo`Priv`] before executing Apply[SerObject, liste] . Hope this helps!! Jan M. (^_^) in my oo package, I have a list:liste = {p1, p2,...}I execute:Apply[SerObject, liste]and get:oo`Priv`SerObject[p1, p2,..]I am astonished, that I get a head with context.Is this correct and how can I avoid the context?Hermann Schmitt ==== LC,Did you mean this?DSolve[{A1 x^2 yÕÕ[x]+A2 x^2 yÕ[x]^2+A3 x y[x] y[x]== A4 x^3 y[x]^4+A5 x^2 y[x]^3,yÕ[0]==0,y[a]==A6},y[x],x]Todd ==== A series of OOP experiments in Mathematica.msg#2 - The Stack, part#2: a simple Eiffel implementation of a stack.Discussion:IÕm not sure how useful this is to anyone not familiar with Eiffel -without a lengthy explanation.But in general, Eiffel is closest to the features I desire,so I expect to show a fair number of Eiffel examples.IÕll try to show each example in Java as well -though that wonÕt always be possible.Important features of the Eiffel code:1. The functions and the preconditions are specified in a deferred class,Z_STACK.This would be an abstract class in C++; an interface in Java.The Eiffel compiler guarantees that any implementing class correctly matchesthis specification.(Any violation of preconditions is caught at run-time.)If a client only refers to the deferred class, then a different implementingclass can easily be substituted.Well, some code somewhere has to know the implementing class, to create newobjects.But that code can be localized (Factory Pattern), then all other code isindependent of chosen implementation.For example, HELLO has the declaration s1: Z_STACKwhich is referring to the abstract deferred class.2. The implementing class APPEND_STACK stores items in a LINKED_LIST.Each pushed item is appended to the end of the list.3. Eiffel Base class library already has a STACK class, which I amdeliberately not using in this example.4. HELLO.make is the entry point to this example. It produces the outputshown way below.------------------------------------------------------- ----------indexing description: Abstract Protocol for all stacks (elements not typed) author: ToolmakerSteve@ShawStudio.com date: 31-Dec-2002 revision: 1.0.0deferred class Z_STACKfeature -- Access-- NO, donÕt actually have this feature.-- Instead, client (HELLO) will use EiffelÕs syntax for creating anobject. --new: Z_STACK is -- -- create empty instance -- deferred -- end is_empty: BOOLEAN is deferred end top: ANY is -- most recently pushed item require not is_empty deferred endfeature -- Element change push( item: ANY ) is -- store item without forgetting previous items deferred end drop is require not is_empty deferred endfeature -- Compound Action pop: ANY is -- return top, and drop it from stack. require not is_empty do result := top drop endinvariant invariant_clause: True -- Your invariant hereend -- class Z_STACK------------------------------------------------------ -----------indexing description: Concrete Implementation of stack (elements not typed) author: ToolmakerSteve@ShawStudio.com date: 31-Dec-2002 revision: 1.0.0class APPEND_STACKinherit Z_STACK redefine default_create end;feature {NONE} -- Initialization default_create is -- Initialize `CurrentÕ. do -- TBD: Suppose client wants different concrete type, -- for different performance characteristics? !!items.make() endfeature -- Access --new: Z_STACK is -- -- create empty instance of this type. -- do -- !APPEND_STACK!result -- end top: ANY is -- most recently pushed item do --result := items.first -- deliberate mistake to test axioms result := items.last endfeature -- Status report is_empty: BOOLEAN is do result := items.is_empty endfeature -- Element change push( item: ANY ) is -- store item without forgetting previous items do items.force( item ); end drop is do -- YUK. Have to do cursor movement just to delete last item. items.finish -- points TO last item, not past it! items.remove endfeature {NONE} -- Implementation items: LINKED_LIST [ANY] -- holds pushed itemsinvariant items_not_void: items /= Voidend -- class APPEND_STACK------------------------------------------------- ----------------indexing description : SystemÕs root classclass HELLOcreation makefeature -- Initialization make is -- Creation procedure. local s1: Z_STACK do !APPEND_STACK!s1 print( new stack s1%N ); print_top_or_empty( s1 ); s1.push( x1 ); print( push x1.%N ); print_top_or_empty( s1 ); s1.push( x2 ); print( push x2.%N ); print_top_or_empty( s1 ); s1.drop; -- drop x2 print( drop.%N ); print_top_or_empty( s1 ); --s1.drop; -- drop x1 --print( drop.%N ); print( pop: ); print( s1.pop ); print( %N ); print_top_or_empty( s1 ); print( Goodbye.%N ); endfeature {NONE} -- Implementation print_top_or_empty( s1: Z_STACK ) is -- if s1 empty then say so else print its top item. do if s1.is_empty then print( --s1 is empty--%N ); else print( --s1.top: ); print( s1.top ); print( %N ); end endend -- class HELLO-------------------------------------------------------- -------------- Output from running HELLO -----new stack s1--s1 is empty--push x1.--s1.top: x1push x2.--s1.top: x2drop.--s1.top: x1pop: x1--s1 is empty--Goodbye. ==== A series of OOP experiments in Mathematica.msg#2 - The Stack, part#3: a simple Java implementation of a stack.Important features of the Java code:1. A Java interface is used to represent the specification.P: There is no (compilable) way to represent the PRECONDITIONS in aninterface.I have simply stuck them in as comments.COMMENTARY: A severe lack on JavaÕs part, for development of large-scalesystems.2. I have used asserts within the implementation, to catch thepre-conditions.IÕve just read that this is incorrect Java style.Any publicly visible constraints on the incoming parameters are supposed toThis is as close as Java comes to representing preconditions visibly - byshowing what exception gets thrown if something is wrong.3. Those asserts wonÕt compile on JavaÕs older than Java 2, version 1.4.Comment them out if your compiler doesnÕt accept them.4. MainTest.main() is the entry point to this example. It produces theoutputshown way below.------------------------------------------------------- ----------/* IStack.java * Created on January 1, 2003 * @author ToolmakerSteve@ShawStudio.com */// Protocol for all stacks (elements not typed).public interface IStack { //--- Query Actions. --- boolean isEmpty(); Object top(); // REQUIRE: !isEmpty() //--- Change Actions. --- void push( Object ob ); void drop(); // REQUIRE: !isEmpty() // --- Compound Actions. --- Object pop(); // REQUIRE: !isEmpty()}-------------------------------------------------- ---------------/* AppendStack.java * Created on January 1, 2003 * @author ToolmakerSteve@ShawStudio.com */// Concrete stack (elements not typed), by appending to a list.// TO DO: put inside a package, so can enable assertions on that package.import java.util.LinkedList;public class AppendStack implements IStack { // ==== =========================================== //--- Initialization Actions. --- /** Creates a new instance of AppendStack */ public AppendStack() { } // ==== =========================================== //--- Query Actions. --- public boolean isEmpty() { return items.isEmpty(); } // REQUIRE: !isEmpty() public Object top() { assert (isEmpty()); return items.getLast(); } // ==== =========================================== //--- Change Actions. --- public void push(Object ob) { items.addLast( ob ); } // REQUIRE: !isEmpty() public void drop() { assert (isEmpty()); items.removeLast(); } // ==== =========================================== // --- Compound Actions. --- // REQUIRE: !isEmpty() // Equivalent: hold=top(); drop(); return hold. public Object pop() { assert (isEmpty()); return items.removeLast(); } // ==== =========================================== // --- Implementation Details. --- private LinkedList items = new LinkedList();}----------------------------------------------- ------------------/* MainTest.java * Created on December 28, 2002 * @author ToolmakerSteve@ShawStudio.com */// Here is a class to test the implementation.public class MainTest { public MainTest() { } public static void main( String[] args ) { System.out.println( new stack s1 ); IStack s1 = new AppendStack(); print_top_or_empty( s1 ); s1.push( x1 ); System.out.println( push x1. ); print_top_or_empty( s1 ); s1.push( x2 ); System.out.println( push x2. ); print_top_or_empty( s1 ); s1.drop(); System.out.println( drop. ); print_top_or_empty( s1 ); System.out.print( pop: ); System.out.println( s1.pop() ); print_top_or_empty( s1 ); // Deliberate errors (on an empty stack). //s1.top(); //s1.drop(); System.out.println( Goodbye. ); } // ==== =========================================== // --- Implementation Details. --- // if s1 empty then say so else print its top item. private static void print_top_or_empty( IStack s1 ) { if (s1.isEmpty()) { System.out.println( --s1 is empty-- ); } else { System.out.print( --s1.top: ); System.out.println( s1.top() ); } }}----------------------------------------------------------- ------new stack s1--s1 is empty--push x1.--s1.top: x1push x2.--s1.top: x2drop.--s1.top: x1pop: x1--s1 is empty--Goodbye.---------------------------------------------- --------------------- Steve S. ==== A series of OOP experiments in Mathematica.msg#2 - The Stack, part#4: two simple Mathematica implementations of astack.Finally :-)This message contains a Notebook expression.Select all the text after the ------ lines of dashes,then copy / paste that into a Mathematica notebook.The result should be my original notebook, complete with output.The NEXT message (part#5) has a plain-text version of the input lines,for your perusal, if Mathematica is not handy.Important features of the Mathematica code:1. TWO different implementations are shown.One appends to the end of a list, the other prepends to the start of a list.The same tests are run with each, to show that the results are identical.2. MathematicaÕs symbolic nature allows result1 to be shown as anexpression containing tops, pushs, etc.Perhaps some mathematician can tell me how to use the axioms shown toreduce this expression,without any implementation of the functions themselves.The axioms should reduce result1 to x4.3. Note the deliberate errors, and how they spit out Error messages via mydefinition of assert.Presumably, this should instead be using an Exception mechanism.If Mathematica has such a mechanism.As it stands, I let the Mathematica code keep running, so each error message4. No inheritance is required by this example. Hence I simply used a headSTACK to identify a stack.This will not be a sufficient solution for examples after this one.5. This mimics an OOP solution to implementing a stack.(Minus the lack of inheritance.)Therefore, it is a PROCEDURAL (or STATE-FUL) implementation,not a PURE FUNCTIONAL (or side-effect-free) implementation.That is, the functions manipulate the state of an object - the listrepresenting a stack.No doubt Mathematica could do some elegant pure functional implementation ofthis specification.Anyone want to take a stab at doing such?As I understand it, this would mean that instead of modifying the existinglist, a new list would be constructed at each step. But wouldnÕt that behorribly inefficient for large problems?---------------------------------------------------- -------------Notebook[{Cell[BoxData[ ((( (* Quiet the warnings about similarly spelled ((variables)(.)) *) )(n)(Off[General::spell]; Off[ General::spell1];)))], Input],Cell[BoxData[ ((( (*(===)(===)(===)(===)(===)(===)(== =)(===)(===)(===)(===)(===)(===) ([Equal])*) )([IndentingNewLine])( (*(-- AXIOMS) - True for all stacks . --*) )([IndentingNewLine])((axiom1[] := empty[ new[] ];)[IndentingNewLine] (axiom2[ s_STACK, x_ ] := (! empty[ push[ s, x ] ]);)[IndentingNewLine] (axiom3[ s_STACK, x_ ] := ((top[ push[ s, x ] ] == x));)[IndentingNewLine] (axiom4[ s_STACK, x_ ] := ((drop[ push[ s, x ] ] == s));)[IndentingNewLine] (allAxioms[ s_STACK, x_ ] := (([IndentingNewLine]axiom1[] && axiom2[ s, x ] && axiom3[ s, x ] && axiom4[ s, x ]));))))], Input],Cell[CellGroupData[{Cell[BoxData[ ((( (*(===)(===)(===)(===)(===)(===)(= ==)(===)(===)(===)(===)(===)(===) ([Equal])*) )([IndentingNewLine])( (*(-- an) example of stack (usage --)*) )([IndentingNewLine])((s1 = new[];)[IndentingNewLine] (s2 = push[ push[ push[ s1, x1 ], x2], x3 ];)[IndentingNewLine] (s3 = drop[ s2 ];)[IndentingNewLine] (s4 = new[];)[IndentingNewLine] (s5 = push[ push[ s4, x4 ], x5 ];)[IndentingNewLine] (s6 = drop[ s5 ];)[IndentingNewLine] (v1 = top[ s6 ];)[IndentingNewLine] (s7 = push[ s3, v1 ];)[IndentingNewLine] (s8 = push[ s7, x6 ];)[IndentingNewLine] (s9 = drop[ s8 ];)[IndentingNewLine] (s10 = push[ s9, x7 ];)[IndentingNewLine] (s11 = drop[ s10 ];)[IndentingNewLine] (result1 = top[ s11 ];)[IndentingNewLine] result1[IndentingNewLine] (* MUST BE TRUE for any implementation of STACK *) [IndentingNewLine] (stackVerify = ((result1 [Equal] x4));))))], Input],Cell[BoxData[ (top[ drop[push[ drop[push[ push[drop[push[push[push[new[], x1], x2], x3]], top[drop[push[push[new[], x4], x5]]]], x6]], x7]]])], Output]}, Open ]],Cell[BoxData[ ((( (* TBD - True, report ((error)(.))[IndentingNewLine]*) )([IndentingNewLine])(assert[ test_, message_ ] := If[ (! TrueQ[ ToString[ message ] // Print ];)))], Input],Cell[BoxData[ ((( (*(===)(===)(===)(===)(===)(===)(= ==)(===)(===)(===)(===)(===)(===) ([Equal])*) )((Stack --)*) )([IndentingNewLine])((Clear[ empty, top, new, push, drop ];)[IndentingNewLine] (*(-- (Queries --))*) [IndentingNewLine] (empty[ s_STACK ] := ((Length[ s ] [Equal] 0));)[IndentingNewLine] (top[ s_STACK ] := (([IndentingNewLine]assert[ (! empty[[IndentingNewLine]First[ s ][IndentingNewLine]));)[IndentingNewLine] (*(-- (Changes --))*) [IndentingNewLine] (new[] := STACK[];)[IndentingNewLine] (push[ s_STACK, x_ ] := Prepend[ s, x ];)[IndentingNewLine] (drop[ s_STACK ] := (([IndentingNewLine]assert[ (! empty[[IndentingNewLine]Drop[ s, 1 ][IndentingNewLine]));))))], Input],Cell[CellGroupData[{Cell[BoxData[{ (s1), [IndentingNewLine], (s2), [IndentingNewLine], (result1), [IndentingNewLine], ((assert[[IndentingNewLine], (allAxioms[ new[], xx ]), [IndentingNewLine], (allAxioms[ s1, xx ]), [IndentingNewLine], (allAxioms[ s11, xx ])}], Input],Cell[BoxData[ (STACK[])], Output],Cell[BoxData[ (STACK[x3, x2, x1])], Output],Cell[BoxData[ (x4)], Output],Cell[BoxData[ (True)], Output],Cell[BoxData[ (True)], Output],Cell[BoxData[ (True)], Output]}, Open ]],Cell[CellGroupData[{Cell[BoxData[ ((( (* Deliberate errors *) )([IndentingNewLine])(top[ s1 ][IndentingNewLine] drop[ s1 ])))], Input],Cell[BoxData[ (***Error: stack.top- empty)], Print],Cell[BoxData[ (First::first ((:)( )) !(STACK[]) has a length of zero and no first element.)], Message],Cell[BoxData[ (First[STACK[]])], Output],Cell[BoxData[ (***Error: stack.drop- empty)], Print],Cell[BoxData[ (Drop::drop ((:)( )) Cannot drop positions !(1) through !(1) in !(STACK[]).)], Message],Cell[BoxData[ (Drop[STACK[], 1])], Output]}, Open ]],Cell[BoxData[ ((( (*(===)(===)(===)(===)(===)(===)(= ==)(===)(===)(===)(===)(===)(===) ([Equal])*) )((Stack --)*) )([IndentingNewLine])((Clear[ empty, top, new, push, drop ];)[IndentingNewLine] (*(-- (Queries --))*) [IndentingNewLine] (empty[ s_STACK ] := ((Length[ s ] [Equal] 0));)[IndentingNewLine] (top[ s_STACK ] := (([IndentingNewLine]assert[ (! empty[[IndentingNewLine]Last[ s ][IndentingNewLine]));)[IndentingNewLine] (*(-- (Changes --))*) [IndentingNewLine] (new[] := STACK[];)[IndentingNewLine] (push[ s_STACK, x_ ] := Append[ s, x ];)[IndentingNewLine] (drop[ s_STACK ] := (([IndentingNewLine]assert[ (! empty[[IndentingNewLine]Drop[ s, (-1) ][IndentingNewLine]));))))], Input],Cell[CellGroupData[{Cell[BoxData[{ (s1), [IndentingNewLine], (s2), [IndentingNewLine], (result1), [IndentingNewLine], ((assert[[IndentingNewLine], (allAxioms[ new[], xx ]), [IndentingNewLine], (allAxioms[ s1, xx ]), [IndentingNewLine], (allAxioms[ s11, xx ])}], Input],Cell[BoxData[ (STACK[])], Output],Cell[BoxData[ (STACK[x1, x2, x3])], Output],Cell[BoxData[ (x4)], Output],Cell[BoxData[ (True)], Output],Cell[BoxData[ (True)], Output],Cell[BoxData[ (True)], Output]}, Open ]],Cell[CellGroupData[{Cell[BoxData[ ((( (* Deliberate errors *) )([IndentingNewLine])(top[ s1 ][IndentingNewLine] drop[ s1 ])))], Input],Cell[BoxData[ (***Error: stack.top- empty)], Print],Cell[BoxData[ (Last::nolast ((:)( )) !(STACK[]) has a length of zero and no last element.)], Message],Cell[BoxData[ (Last[STACK[]])], Output],Cell[BoxData[ (***Error: stack.drop- empty)], Print],Cell[BoxData[ (Drop::drop ((:)( )) Cannot drop positions !(-1) through !(-1) in !(STACK[]).)], Message],Cell[BoxData[ (Drop[STACK[], (-1)])], Output]}, Open ]]},] ==== A series of OOP experiments in Mathematica.msg#2 - The Stack, part#5: plain text version of the input lines of thenotebook in message part#4.For your perusal, if Mathematica is not handy.------------------------------------------------------- ----------(* Quiet the warnings about similarly spelled variables. *)Off[General::spell]; Off[General::spell1];(* ==== ================================== =[Equal]*)(*-- AXIOMS- True for all stacks. --*)axiom1[]:=empty[ new[] ];axiom2[ s_STACK, x_ ]:=!empty[ push[ s, x ] ];axiom3[ s_STACK, x_ ]:=(top[ push[ s,x ] ]==x);axiom4[ s_STACK, x_ ]:=(drop[ push[ s,x ] ]==s);allAxioms[ s_STACK, x_ ]:=( axiom1[] && axiom2[ s,x ] && axiom3[ s,x ] && axiom4[ s,x ]);(* ==== ===================================[Equal]*)(*-- an example of stack usage --*)s1=new[];s2=push[ push[ push[ s1,x1 ],x2],x3 ];s3=drop[ s2 ];s4=new[];s5=push[ push[ s4,x4 ],x5 ];s6=drop[ s5 ];v1=top[ s6 ];s7=push[ s3,v1 ];s8=push[ s7,x6 ];s9=drop[ s8 ];s10=push[ s9,x7 ];s11=drop[ s10 ];result1=top[ s11 ];result1(* MUST BE TRUE for any implementation of STACK *)stackVerify=(result1[Equal]x4);(* TBD - throw exception? Unless test is True, report error. *)assert[ test_,message_ ]:=If[ !TrueQ[ test ],(* ==== ===================================[Equal]*)(*-- Prepend Implementation of Stack --*)Clear[ empty, top, new, push, drop ];(*-- Queries --*)empty[ s_STACK ]:=(Length[ s ][Equal]0);top[ s_STACK ]:=( assert[ !empty[ s ],stack.top- empty ]; First[ s ] );(*-- Changes --*)new[]:=STACK[];push[ s_STACK,x_ ]:=Prepend[ s,x ];drop[ s_STACK ]:=( assert[ !empty[ s ],stack.drop- empty ]; Drop[ s,1 ] );s1s2result1assert[ stackVerify,Bad Stack Implementation ];allAxioms[ new[], xx ]allAxioms[ s1, xx ]allAxioms[ s11, xx ](* Deliberate errors *)top[ s1 ]drop[ s1 ](* ==== ===================================[Equal]*)(*-- Append Implementation of Stack --*)Clear[ empty, top, new, push, drop ];(*-- Queries --*)empty[ s_STACK ]:=(Length[ s ][Equal]0);top[ s_STACK ]:=( assert[ !empty[ s ],stack.top- empty ]; Last[ s ] );(*-- Changes --*)new[]:=STACK[];push[ s_STACK,x_ ]:=Append[ s,x ];drop[ s_STACK ]:=( assert[ !empty[ s ],stack.drop- empty ]; Drop[ s,-1 ] );s1s2result1assert[ stackVerify,Bad Stack Implementation ];allAxioms[ new[], xx ]allAxioms[ s1, xx ]allAxioms[ s11, xx ](* Deliberate errors *)top[ s1 ]drop[ s1 ] ==== A series of OOP experiments in Mathematica.msg#2 - The Stack, part#1: Mathematics of a stack.Having listed Goals and References in msg#1,(post 4 of thread Re: Re: OOP in Mathematica on 30-Dec-2002),now consider one small example using OOP.--------------------------------------------------------- ------------- A classic programming task - a stack ------------------------------------------------------------- ---------Mathematics of a stack, based on:[Meyer-97] Ch. 6. Abstract data types.sec. 6.1-6.4 gives an abstract data type prescription for a stack.- - - - -Brief explanation of syntax:* STACK -- type names are all-capitals.* ANY -- like Object in Java and returns a stack. takes two parameters: (a stack) and (any object), and returns astack.NOTE: this doesnÕt explain what push does, it just declares what objecttypes come in and out of the function. This is a pure-functional(no-side-effect) mathematical specification - so any change is shown bycreating a new object, rather than modifying an existing object.In the OO languages, for a mutable type Stack,STACK in and STACK out will be turned into a single STACK that is changingstate.The actual behavior of the functions is determined implicitly from theaxioms that come later. drop( s ) require not empty( s ) -- function named ÔdropÕ, takes a stack and returns a stack. This will become an action thatchanges the state of a stack. The require part is a condition - this function must only be calledwith a non-empty stack.-------------------------------------- Mathematics of a stack ---For any x of type ANY and s of type STACK...Type: STACKType-signatures of FUNCTIONS with PRECONDITIONS: top( s ) require not isEmpty( s ) drop( s ) require not isEmpty( s )Axioms:A1. isEmpty( new() ) = TrueA2. isEmpty( push( s, x ) ) = FalseA3. top( push( s, x ) ) = xA4. drop( push( s, x ) ) = s-----------------------------------Informally, this is saying:A1. new() creates an empty stack.A2. After push, a stack is not empty.A3. push( s, x ) causes Ôx' to now be top of stack.A4. push followed by drop returns the stack as it was before the push.Combining these axioms, produces all the desired behavior of a stack.For example: top( push( new(), x1 ) ) = x1 top( push( push( new(), x1 ), x2 ) = x2 top( drop( push( push( new(), x1 ), x2 ) ) ) ) = x1Because PRECONDITIONS are specified,we can also discover ILLEGAL operations on a stack: top( new() ) drop( drop( push ( new(), x1 ) ) )NOTE: wondering where pop() is?That is a compound action.pop( s ) is equivalent to: temp = top( s ) drop( s ) return temp-------------------------------------------------------- ---------Here is that mathematical spec, as it might be shown in Mathematica:NOTE: Since this example doesnÕt involve inheritance, it can be modeledusing a simple type. That is, by having the head of an expression beSTACK.NOTE: conditions arenÕt yet shown.(*-- Functions of a stack --*)new[]isEmpty[ s_STACK ]push[ s_STACK, x_ ]top[ s_STACK ]drop[ s_STACK ](*-- Axioms of a stack. True for any s & x. --*)axiom1[]:=isEmpty[ new[] ];axiom2[ s_STACK, x_ ]:=!isEmpty[ push[ s, x ] ];axiom3[ s_STACK, x_ ]:=(top[ push[ s,x ] ]==x);axiom4[ s_STACK, x_ ]:=(drop[ push[ s,x ] ]==s);allAxioms[ s_STACK, x_ ]:=( axiom1[] && axiom2[ s,x ] && axiom3[ s,x ] && axiom4[ s,x ]);---------------------------------------------------------- -------WhatÕs Next:Showing implementations in Eiffel, then Java.Then finally, Mathematica implementations.(The above Mathematica code isnÕt an implementation, as I donÕt show definitions for the 5 functions of a stack. The idea is that many different implementations should be possible. But all a client should know, is what I have shown above. Plus the pre-conditions, that I havenÕt yet shown in Mathematica.)Since I am coming from an OO background, I may not be showing the mostnatural Mathematica implementations. Though in this simple case (beforegetting into inheritance), hopefully I will be close to the mark.-- Steve S. Shaw (ToolmakerSteve) ==== I think, that Orestis has a different conception of OO than I. I want todraw the attention to an aspect of OO, which is apparently ignored byOrestis:OO may be seen as a medium to make code available in an efficient way.My kind of class definition (see www.schmitther.de) is based on the sameintention as the Mathemica package concept and is similar to this. MostMathematica packages could be even replaced by class definitions. The classconcept apparently includes the package concept.Hermann Schmitt.----- Original Message ----- ==== see my comments in your text.Please, do not take my comments personally. I appreciate your work, but Ihave not understood it fully till now.Hermann Schmitt----- Original Message -----I cannot see, why packages are natural, you only are accustomed to them!My classes are much more powerful, the functionality of the Matheamticapackages is only a small part of the functionality of the classes.My classes are part of my oo support. I think, it is very easy to work withmy oo system.I would be very interested to see, how you program my small example in yourway of OO, I think, you would need several pages.it ==== Well, for one thing, if ListPlot had the HoldAll attribute, the following wouldnÕt work: In[1]:= pts=Table[Sin[u], {u,0,2 Pi, Pi/0}]; In[2]:= ListPlot[pts]; YouÕd have to wrap Evaluate[] around pts if you donÕt want to get a bunch of error messages . If you want first-hand experience of how it would be if ListPlot had the HoldAll attribute, execute this: In[3]:= Unprotect[ListPlot]; SetAttributes[ListPlot, HoldAll]; Protect[ListPlot]; and try to execute the commands I gave previously. Jan M. (^_^) Attributes[ListPlot]{Protected}Attributes[Plot]{HoldAll, Protected}I do not know why Mathematica is inconsistent here.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Plot[x^ 2,{x,0,5}, optionB]Plot[x^2,{x,0,5}, Evaluate[optionB]]??? why is this so????Why must I wrap Evaluate around my options in Plot?thanksMikeps. This is with version 4.0.2 on a G4 power Mac. ==== David,One reason for Plot being HoldAll is to localize the variable: x=3; Plot[x,{x,0,1}] - Graphics - ClearAttributes[Plot,HoldAll] Plot[x,{x,0,1}] Plot::itraw:Raw object 3 cannot be used as an iterator. Plot[3,{3,0,1}] SetAttributes[Plot, HoldAll]HoldAll is not needed in ListPlot since no working variable is used.--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198 ==== I have received a number of replies pointing out that there are perfectlygood reasons why ListPlot does not have HoldAll and some other plots do. SoI completely agree that WRI is not being inconsistent here.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/For appearance reasons I usually place all my Plot and ListPlot options in alist eg.When I plot a list everything is fine:ListPlot[list, optionA]but when I use options in Plot I get an error message unless I wrap Evaluatearound the options.For examplePlot[x^2,{x,0,5}, optionB]Plot[x^2,{x,0,5}, Evaluate[optionB]]??? why is this so????Why must I wrap Evaluate around my options in Plot?thanksMikeps. This is with version 4.0.2 on a G4 power Mac. ==== Diana,Did you do this?<< DiscreteMath`Combinatorica`A5 = AlternatingGroup[5]mult[x_?PermutationQ, y_?PermutationQ] := Permute[x, y]MultiplicationTable[A5, mult] // TableFormExport[C:tableDELETETHISLATER.csv, MultiplicationTable[A5, mult], CSV]It works fine for me. I hope you didnÕt type all that other stuff with thequotes in by hand, as it appears from your posting.Do you know thatdummy = MultiplicationTable[A5, mult] // TableFormExport[C:tableDELETETHISLATER.csv, dummy], CSV]wonÕt work, but(dummy = MultiplicationTable[A5, mult] )// TableFormExport[C:tableDELETETHISLATER.csv, dummy], CSV]will?Todd Rosefrom9,read:12,6,8,9,10, ==== When I first say this question I did the following:< NDSolve seems to have difficulties with solving integral equation.> n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0}*[Sigma]norm[z,> t], {z, 0.01, 1}, {t, 0.01, 2}]> Mathematica returns a message> NDSolve::deql: The first argument must have both an equation and an > initial condition.> which I cannot understand.> Can anybody tell whatÕs wrong with my attempt?> > -Toshi> I am not really sure that your question isnÕt a joke.NDSolve solves differential equations, not integral equations.Although there are relations between these topics, they are certainlynot the same.Alois-- Vienna University of Technology, ==== evaluating the following gives you a sample x=x+1 button:NotebookPut@Notebook[{Cell[BoxData[ ButtonBox[(x = (x + 1)), RuleDelayed[ButtonFunction, CompoundExpression[If[Not[ ValueQ[x]], Set[x, 0]], Set[x, Plus[x, 1]]]], Rule[ButtonEvaluator, Automatic]] ], NotebookDefault, PageBreakAbove -> True, CellTags -> GeneratedButtonBoxx=x+1]}, ClosingAutoSave -> True, Editable -> False, WindowToolbars -> {}, PageWidth -> 299.5, WindowSize -> {89., 29.}, WindowMargins -> {{92., Automatic}, {Automatic, 56.}}, WindowFrame -> Palette, WindowElements -> {}, WindowFrameElements -> CloseBox, WindowClickSelect -> False, ScrollingOptions -> {PagewiseScrolling -> True}, ShowCellBracket -> False, CellMargins -> {{0., 0.}, {Inherited, 0.}}, Active -> True, CellOpen -> True, ShowCellLabel -> False, ShowCellTags -> False, ImageMargins -> {{0., Inherited}, {Inherited, 0.}}, Magnification -> 1.5](* ********************************* *)Now, how do you create such a button in less than a minute? ... :One way is to just create a section cell and the underlying ButtonFunction code as input cells, i.e., type interactively such that you get something like:NotebookPut[Notebook[ {Cell[CellGroupData[ {Cell[x=x+1, Section], Cell[If[!ValueQ[x], x=0], Input], Cell[x=x+1, Input]}, Open]]}]]Then hit the F2B (function to Button) button in ButtonTools.nb ( my freewarebutton tools from http://www.mertig.com/mathdepot ) and you get the button.With the HP and VP you can easily and quickly generate (horizontally orverically) palettes. Check out the Help button, or also the source code.It basically is all straightforward and there is actually documentation about all those ButtonFunction features somewhere. I agree that the whole Button-design could have been made better, but up to a point is quite useful. Of course the world is used to better GUIÕs these days but if you really need nice GUIÕs and buttons, use Java and JLink ( and there are also simple examples in the JLink manual of how to do this ).If you donÕt like Java, go with VBA and use the nice Mahematica for Active Xproduct from http://www.episoft.comRolf MertigMertig Consultinghttp://www.mertig.com ==== tryIn[1]:=Clear[a,b,c,d,x, y]x= {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};y = {a,b,c,d}; LinearSolve[x,y]s01= LinearSolve[x,y][[1]]Out[4]={-a+b,-a+c,a-b-c+d,a}Out[5]=-a+ bIn[6]:=g[a_,b_] =s01Out[6]=-a+bIn[7]:=g[1,3]Out[7]=2*NEVER* use capital letters at the beginning of a variableÕs name! Never!Matthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de-----Ursprí.b9ngliche Nachricht-----Gesendet: Freitag, 23. August 2002 06:25An: mathgroup@smc.vnet.netBetreff: := Does not assign variables properly.Why?HereÕs a piece of a conversion I had with Mathematica.Why is a[A_,B_] := LinearSolve[X,Y][[1]] not givingme the function I expect?In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};In[262]:= Y = {A,B,C,D};In[263]:= LinearSolve[X,Y]Out[263]= {-A+B,-A+C,A-B-C+D,A}In[264]:= LinearSolve[X,Y][[1]]Out[264]= -A+BIn[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]In[266]:= a[1,3]Out[266]= -A+BThe output above is not what I want. I want 2. HereÕswhat I expect:In[267]:= a[A_,B_] := -A+B;In[268]:= a[1,3]Out[268]= 2This output is what I expect. What is the difference betweenthe two? ==== First of all, just look at your own posting below. You clearly have a *(Times) where a , (comma) should be. Presumably your input ought to be:n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z,t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n, [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0},[Sigma]norm[z,t], {z, 0.01, 1}, {t, 0.01, 2}]However, even in the corrected version the equation canÕt be solved. First of all you will get the complaint:NDSolve::bcedge: Boundary conditions must be specified at the edge of the spatial domain.In other words Mathematica wants a boundary condition for [Sigma]norm[z, 0.1] or alternatively you should use {z,0,1} in NDSolve. But actually I do not think this equation is solvable by any numerical scheme even if you could provide the initial conditions at the edge of the boundary that Mathematica requests. To evaluate the integral in your equation NDSolve needs to know the values of [Sigma]norm[z, t] for all z between 0 and 1 and a given t, but this knowledge is not available at any stage of the evaluation. I am not really an expert, but this seems to me a clear example of an equation that is not solvable by any numerical means.By the way, the fact that you know a solution to a differential equation, and even the fact that the solution is very simple does not imply that the equation can be solved by any known method, except of course guessing, which computer programs generally do not use. Andrzej KozlowskiToyama International UniversityJAPANOn Friday, August 23, 2002, at 05:25 AM, Toshiyuki ((Toshi)) Meshii >> NDSolve seems to have difficulties with solving integral equation.>> n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == > 3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == > 0}*[Sigma]norm[z,> t], {z, 0.01, 1}, {t, 0.01, 2}]>> Mathematica returns a message>> NDSolve::deql: The first argument must have both an equation and an > initial condition.>> which I cannot understand.> Can anybody tell whatÕs wrong with my attempt?-Toshi> ==== >HereÕs a piece of a conversion I had with Mathematica.>Why is a[A_,B_] := LinearSolve[X,Y][[1]] not giving>me the function I expect?>>In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};>In[262]:= Y = {A,B,C,D};>In[263]:= LinearSolve[X,Y]>Out[263]= {-A+B,-A+C,A-B-C+D,A}>In[264]:= LinearSolve[X,Y][[1]]>Out[264]= -A+B>In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]>In[266]:= a[1,3]>Out[266]= -A+B>>The output above is not what I want. I want 2. HereÕs>what I expect:>>In[267]:= a[A_,B_] := -A+B;>In[268]:= a[1,3]>Out[268]= 2>>This output is what I expect. What is the difference between>the two?X={{0,0,0,1},{1,0,0,1}, {0,1,0,1},{1,1,1,1}};Y={A,B,C,D};a[A_,B_]:= LinearSolve[X,Y][[1]];?aGlobal`aa[A_, B_] := LinearSolve[X,Y][[1]]Note that the RHS of the stored definition is not a function of the arguments. Now add Evaluate to RHSa[A_,B_]:= Evaluate[LinearSolve[X,Y][[1]]];?aGlobal`aa[A_, B_] := -A + Ba[1,3]2Bob HanlonChantilly, VA USA ==== All of this looks like a mistake to me because it seems far too easy. But anyway, here is the solution that makes almost no use of Mathematica. First of all, your equation is not a differential equation so there is no point using DSolve.Secondly the use of z in Integrate[[Sigma]norm[z]^n*z, {z, 0, d}] is deceptive, since you are integrating over z, so letÕs replace it by something else, say s. So your equation is:(3*z)/d^3)*Integrate[[Sigma]norm[s]^n*s, {s, 0, d}] ==[Sigma]norm[z]^nwhich is supposed to hold true for every z>0. Re-write it asIntegrate[[Sigma]norm[s]^n*s, {s, 0, d}]/d^3 =[Sigma]norm[z]^n/3zfor all z. However, the left hand side is a function of d, independent of z, so we can write:[Sigma]norm[z_]:=(3z*g[d])^(1/n)LetÕs take this as a definition and substitute in the original equationIn[2]:=Simplify[((3*z)*Integrate[[Sigma]norm[s]^n*s , {s, 0, d}])/d^3 == [Sigma]norm[z]^n, {d > 0, n > 0, z > 0}]Out[2]=TrueThat means you can take g to be an arbitrary function of d.Andrzej KozlowskiToyama International UniversityJAPANOn Friday, August 23, 2002, at 05:25 AM, Toshiyuki ((Toshi)) Meshii > How can I solve the following integral equation?> Mathematica seems not to work.> Is there any way?>> DSolve[((3*z)/d^3)*Integrate[[Sigma]norm[z]^n*z, {z, 0, d}] ==> [Sigma]norm[z]^n, [Sigma]norm[z], z]>> note: z>0 & n>1>> I know that the answer is simple and> $B&R(Bnorm[z_] = (1 + 1/(2*n))*(z/d)^(1/n)-Toshi> ==== But suddenly the following Errormessage appears:/usr/bin/local/mathematica: file or directory not found(Maybe its more a UNIX-Problem or has to do withMandrake-updates ... but so far everything exceptof Mathematica seems to work fine.)Of course I checked for the File (it is indeed there) and (a hint from a Unix-usegroup) the needed libs libc.so.5, libm.so.5 are in /lib/ too.Had anyone had, ore better solved, a similar problem?greetings Detlef ==== How can I create a Mathematica thing (function? program?) that wouldautomatically open a browser page, and give my username and pwd to log meinto a https:.... site? The serverÕs login page has a script resettingfields: and the relevant input cells areNicholas ==== Howdy,IÕm trying to figure out the correct syntax to do the following. I havesome function with three arguments, and I want to syntactically describe thesingle-argument function that holds two of those arguments constant (i.e.without creating that single-argument function).More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s}, c = Floor[state/base]; s = Mod[state,base]; multiplier*s + c ]where I have a generalize ÔmachineÕ, defined by the radix and multiplier,which converts one state into another state. So IÕd like to be able to dosomething like this: NestList[Machine[10,7,#], 3, 22]to get the series of states that the radix-10 multiplier-7 machine runsthrough (starting with state 3). However, this syntax doesnÕt seem to dowhat I want.I hope that description makes sense. It seems like there must be a syntaxto describe the function Machine[10,7,#].Anyone have any ideas?Bob H ==== >>There is a following problem with Mathematica 4.2:>when i try to load Help Browser, i get a message:>building help browser index (first time only)>scanning index file>and Mathematica stops responding: you have to>kill process. There was no such a problem with>version 4.1.>>Is there is a solution to that?IÕd start with the following FAQ.http://support.wolfram.com/mathematica/interface/ helpbrowser/howrebuildindex.html-Dale ==== >IÕd start with the following FAQ.>>http://support.wolfram.com/mathematica/interface/ helpbrowser/howrebuildindex.html>>-DaleSorry that i failed say it immediately in a first place, but of coursei did try it FAQ at first, and both tried to delete cache and rebuildindex, but results where the same - whenever i try to invoke help browser (or rebuild index, for that matter), mathematica stops responding (i did read your answer to the same question asked a week ago before - actually that is why i turned to the FAQ). ==== People encounter this all the time. It is because SelectionEvaluate does not do what you think. It does not work like ToExpression, which causes immediate kernel evaluation. Instead it works like when you press Shift-Enter, which selects a cell for evaluation after all current evaluations have finished.See http://support.wolfram.com/mathematica/kernel/interface/ selectionevaluate.html-Dale>>Trying to manipulate notebooks from the kernel I found>an unexpected bahavior with Mathematica. First I tried>>the following commands one by one (they are not int>the same cell, and they are not selected at same time>for evaluation)>>nb = NotebookCreate[];>i = 0;>(* Purpose is a Do loop here *)>NotebookDelete[nb] (*1*)>NotebookWrite[nb, ++i, All] (*2*)>SelectionEvaluate[nb] (*3*)>SelectionMove[nb, All, Cell] (*4*)>>If I repeat evaluating coomands (*1,2,3,4*) one by one>what is shown in the created notebook is an animation>of the index i in the same cell.>Naturally a loop must do the job. However when I>intent to collect (*1,2,3,4*) in the same cell the>result is not the same even whitout the Do loop (I>mean just evaluating this cell several times)>>I would be grateful if some can explain whatÕs going>on here or if there is something wrong with my>machine.>>Cesar>__________________________________ ________________>Do You Yahoo!?>Yahoo! Finance - Get real-time stock quotes>http://finance.yahoo.com ==== >HereÕs a piece of a conversion I had with Mathematica.>Why is a[A_,B_] := LinearSolve[X,Y][[1]] not giving>me the function I expect?>>In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};>In[262]:= Y = {A,B,C,D};>In[263]:= LinearSolve[X,Y]>Out[263]= {-A+B,-A+C,A-B-C+D,A}>In[264]:= LinearSolve[X,Y][[1]]>Out[264]= -A+B>In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]>In[266]:= a[1,3]>Out[266]= -A+B>>The output above is not what I want. I want 2. HereÕs>what I expect:>>In[267]:= a[A_,B_] := -A+B;>In[268]:= a[1,3]>Out[268]= 2>>This output is what I expect. What is the difference between>the two?This is a common misconception about what := does. What it does is set up a variable replacement for the unevaluated expression, not the evaluated expression. Soa[A_,B_] := LinearSolve[X,Y][[1]]a[1,3]is similar to doingReleaseHold[ Hold[ LinearSolve[X,Y][[1]] ] /. {A->1, B->3}]which means that only explicit instances of A and B are replaced. What you are attempting is done with =. This assigns the function to the evaluated expression.In[5]:=a[A_,B_] = LinearSolve[X,Y][[1]]Out[5]=-A+BIn[6]:=a[1,3]Out[6]=2There are certain situations where you get a different result if you evaluate with the values or replace the values in the symbolic evaluation. (This example is not one of them.) Using = does the later. If you want to do the former, you should use := and have the right hand side use A and B explicitly or you could use a Block.In[7]:=a[b_,c_] := Block[{A=b, B=c}, LinearSolve[X,Y][[1]] ]In[8]:=a[1,3]Out[8]=2--------------------------------------- -----------------------Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== > Normally I donÕt feel so stupid, but IÕm trying to create an interactive>Mathematica notebook, and IÕm stuck at square one.>>Specifically, how do I do something like create a button to add a number (or>perform other mathematical functions) and then display or otherwise>manipulate the result (eventually I want to be able to click a button that>increments/decrements an angle and animate the resulting transformation of a>vector, with an eye to finally simulating a simple robotic arm complete with>simple controls to manipulate the arm).>>I want to have a variable (or matrix or whatever) defined as a global>variable x, and then perform x = x+1 when a button is clicked. IÕve been>using and programming computers for almost 25 years and I canÕt follow>WolframÕs documentation. Is it just me, or is he always this obtuse when>explaining things? I mean, given the amazing power of the Mathematica>system, a sample list of buttons in a notebook that you could select and>examine how they were implemented, would have been nice. I canÕt find such a>list, and this seems to be par for the course for the rest of the>documentation as well.Button programming can be very confusing at first. It has a whole series of quirks that make it in many ways unique to Mathematica and programming in general. This causes a lot of head-scratching, but once you understand whatÕs going on things get easier.The key is to create a button that uses the kernel (by default it only uses the front end). HereÕs a simple example to help you get started.In[1]:= x=1;In[2]:=ButtonBox[Increment x,Active->True, ButtonEvaluator->Automatic, ButtonFunction:>Print[x = ,++x] ]//DisplayFormSome random things to note:- ButtonEvaluator->Automatic. This says use the kernel to implement the ButtonFunction.- Buttons only create side-effects. They generate no output. What you see when you press the button is the result of 2 side effects. One from ++, which changes the value of x. The other from Print, which creates a cell.- Print is, in general, a poor side-effect to use in a button. ItÕs difficult to control where the Print cell is placed. It is worth your while to learn how to use other front end side-effect functions (such as NotebookRead and NotebookWrite) when using buttons.Here are some further resources you might find helpful:http://support.wolfram.com/mathematica/interface/ buttons/http://library.wolfram.com/conferences/devconf99/ hinton/Buttons19991022.nbhttp://library.wolfram.com/ conferences/devconf2001/horton2/horton2.nb------------------- -------------------------------------------Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== How do I change format used for tick mark labels in a 2D plot? I wouldlike to use DigitBlock->3 option of NumberForm to format large numbersappearing as tick mark labels on a histogram.Alexander ==== As Daniel Lichtblau pointed out, the statement below about vertices is nonsense. Consider two overlapping rectangles arranged as a cross. You need to compute intersections and test them instead of vertices.Begin forwarded message:>> Begin forwarded message:>> Dear colleagues,>> any hints on how to implement a very fast routine in Mathematica for> testing if two rectangles have an intersection area?> Frank Brand> Here is one approach.>> Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then> Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as> you walk along the line though b and c in the direction from b to c.> ( If the result is zero, then a lies on the line.)>> The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the algorithm depends essentially on how fast this quantity can> be computed. Suppose we write a function LeftSide[a,{b,c}] that computes> the sign of the determinant.>> Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a> convex polygon traced counterclockwise. Then a lies within or on the> boundary of the polygon if and only if none of the numbers> LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1].>> Now use the fact that if two convex polynomials overlap, then some> vertex of one of them must lie inside or on the boundary of the other.>> If an overlap of positive area is required, then the check is that only> +1 appears--not that -1 does not appear.>> For two rectangles ( or parallelograms) this approach requires the> evaluation of 16 determinants, so it may be a bit expensive. If the> points have rational coordinates, then (positive) denominators may be> cleared in the homogeneous coordinates and the computations can be done> in integer arithmetic, at the cost of at least three more> multiplications per determinant.>>Garry HelzerDepartment of MathematicsUniversity of MarylandCollege Park, MD 20742301-405-5176gah@math.umd.edu>> ==== While playing arounf with patterns and substitutions, I came across thefollowing behavior which I didnÕt expect:z := SomeHead[{{1, 2}, {3, 4}}]z /. {SomeHead[q_] -> Flatten[q]}While this _does_ yield the desired result {1,2,3,4}, Mathematica complains:Flatten::normal: Nonatomic expression expected at position 1 inFlatten[q].........as if it is trying to evaluate Flatten[q], with q not bound to{{1,2},{3,4}}.Could anybody explain why this happens? Sidney Cadot ==== > While playing arounf with patterns and substitutions, I came across the> following behavior which I didnÕt expect:> z := SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] -> Flatten[q]}> While this _does_ yield the desired result {1,2,3,4}, Mathematica complains:> Flatten::normal: Nonatomic expression expected at position 1 in> Flatten[q].> > ........as if it is trying to evaluate Flatten[q], with q not bound to> {{1,2},{3,4}}.> Could anybody explain why this happens?> Sidney Cadotduring the Replaceall (/.) Mathematica first evaluate the ruleSomeHead[q_] -> Flatten[q] . q is stilla symbol then and will bereplaces when /. is used.You can avoid this Problem by using a delayed rule SomeHead[q_] :>Flatten[q] or using thr Rule Somehead->Flatten.Yours, Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== > ............... I came across the> following behavior which I didnÕt expect:>> z := SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] -> Flatten[q]}>> While this _does_ yield the desired result {1,2,3,4}, Mathematicacomplains:>> Flatten::normal: Nonatomic expression expected at position 1 in> Flatten[q].>............> Could anybody explain why this happens?Sidney,The clue is that, before any replacing is done, z is evaluated to SomeHead[{{1, 2}, {3, 4}}]; SomeHead[q_] is evaluated to SomeHead[q_] Flatten[q] is evaluated to Flatten[q] and the message is generatedsaying essentially nothing to ßatten.*Then* the replacement SomeHead[{{1, 2}, {3, 4}}] /. {SomeHead[q_] -> Flatten[q]}is performed.It would be better here to use RuleDelayed, :>, instead of Rule, ->, sinceFlatten[q] would not then be evaluated. z:=SomeHead[{{1,2},{3,4}}] z/.{SomeHead[q_]:>Flatten[q]} {1,2,3,4}--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198 ==== Never mind my question, I should have used a delayed rule there (:> insteadof ->).Bit silly of me. ==== Suppose f is a function of n real variables, and returns avector of n real variables. What is the correct syntax to find a rootof f using FindRoot?For instance, the following works with n=7, but I would need to changethe code if I changed the value of n:f[p_] := Table[fk[p, k], {k,n}];pn = {p1,p2,p3,p4,p5,p6,p7};f1 := f[pn] [[1]];f2 := f[pn] [[2]];f3 := f[pn] [[3]];f4 := f[pn] [[4]];f5 := f[pn] [[5]];f6 := f[pn] [[6]];f7 := f[pn] [[7]];theRoot = FindRoot[{f1==0,f2==0,f3==0,f4==0,f5==0,f6==0,f7==0}, {p1, 1/n},{p2, 1/n},{p3, 1/n},{p4, 1/n},{p5, 1/n}, {p6, 1/n},{p7, 1/n}];-- John MacCormick Systems Research Center, HP Labs, 1501 Page Mill Road, ==== On 8/23/02 at 12:25 AM, meshii@mech.fukui-u.ac.jp (Toshiyuki (Toshi)>NDSolve seems to have difficulties with solving integral equation.>n = 5; NDSolve[{D[[Sigma]norm[z, t], t] ==>3*z*Integrate[[Sigma]norm[z, t]^n*z, {z, 0, 1}] - [Sigma]norm[z,>t]^n, [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] ==>0}*[Sigma]norm[z, t], {z, 0.01, 1}, {t, 0.01, 2}]>Mathematica returns a message>>NDSolve::deql: The first argument must have both an equation and an> initial condition.A general solution to a differential equation includes a constant of integration. It isnÕt possible to arrive a numerical solution without providing sufficient information to determine this constant. Specifying the initial condition provides this information.Look at the examples using the help browser to see what NDSolve needs. ==== >IÕm trying to figure out the correct syntax to do the following. I have>some function with three arguments, and I want to syntactically describe>the>single-argument function that holds two of those arguments constant (i.e.>without creating that single-argument function).>>More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s},> c = Floor[state/base]; s = Mod[state,base];> multiplier*s + c> ]>>where I have a generalize ÔmachineÕ, defined by the radix and multiplier,>which converts one state into another state. So IÕd like to be able to>do>something like this: NestList[Machine[10,7,#], 3, 22]>>to get the series of states that the radix-10 multiplier-7 machine runs>through (starting with state 3). However, this syntax doesnÕt seem to>do>what I want.>>I hope that description makes sense. It seems like there must be a syntax>to describe the function Machine[10,7,#].>I assume that you want base rather than radix in the definition (or vice versa).Machine[base_, multiplier_, state_]:= Module[{c, s}, c=Floor[state/base]; s=Mod[state, base]; multiplier*s+c];NestList[Function[Machine[10,7,#]],3,22]{3, 21, 9, 63, 27, 51, 12, 15, 36, 45, 39, 66, 48, 60, 6, 42, 18, 57, 54, 33, 24, 30, 3}The abbreviation for Function[body] is body&%==NestList[Machine[10, 7, #]&, 3, 22]TrueBob HanlonChantilly, VA USA ==== >While playing arounf with patterns and substitutions, I came across the>following behavior which I didnÕt expect:>>z := SomeHead[{{1, 2}, {3, 4}}]>z /. {SomeHead[q_] -> Flatten[q]}>>While this _does_ yield the desired result {1,2,3,4}, Mathematica complains:>>Flatten::normal: Nonatomic expression expected at position 1 in>Flatten[q].>>........as if it is trying to evaluate Flatten[q], with q not bound to>{{1,2},{3,4}}.>>Could anybody explain why this happens?z:=SomeHead[{{1,2},{3,4}}]The error is associated with defining the Rule not executing it. Note that you get the error with{SomeHead[q_]->Flatten[q]};Use RuleDelayedz/.{SomeHead[q_]:>Flatten[q]}{1, 2, 3, 4}Bob HanlonChantilly, VA USA ==== Can anyone help me with this problem. If I have an n-element list, (say where each element is itself alist), such as {{a,b}, {a,b}, {a,b}}is there a way to strip off the outermost nesting of the list toobtain just a sequence of of these n elements, that is{a,b},{a,b},{a,b} so that I can use this for input for some function.I would like to do something likeOuter[SomeFunction, Table[{a,b},{N} ]] where I can enter Ndynamically.The problem, of course, is that the output of the Table command is onebig listand Outer is expecting a sequence of N separate lists afterSomeFunction. ==== Bob, Apply[Sequence,{{a,b},{c,d}}] Sequence[{a,b},{c,d}] Outer[F,Apply[Sequence,Table[{a,b},{3}]]] {{{F[a,a,a],F[a,a,b]},{F[a,b,a],F[a,b,b]}},{{F[b,a,a],F[b,a,b ]},{F [b,b,a],F[b,b,b]}}}---Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Can anyone help me with this problem.>> If I have an n-element list, (say where each element is itself a> list), such as {{a,b}, {a,b}, {a,b}}> is there a way to strip off the outermost nesting of the list to> obtain just a sequence of of these n elements, that is> {a,b},{a,b},{a,b} so that I can use this for input for some function.>> I would like to do something like> Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N> dynamically.> The problem, of course, is that the output of the Table command is one> big list> and Outer is expecting a sequence of N separate lists after> SomeFunction.>> ==== > Can anyone help me with this problem.> > If I have an n-element list, (say where each element is itself a> list), such as {{a,b}, {a,b}, {a,b}}> is there a way to strip off the outermost nesting of the list to> obtain just a sequence of of these n elements, that is> {a,b},{a,b},{a,b} so that I can use this for input for some function.> I would like to do something like> Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N> dynamically.> The problem, of course, is that the output of the Table command is one> big list> and Outer is expecting a sequence of N separate lists after> SomeFunction.> Sequence@@{{a,b}, {a,b}, {a,b}}resp. Apply[Sequence, {{a,b}, {a,b}, {a,b}}]will do it.CU, Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== some function with three arguments, and I want to syntactically describe thesingle-argument function that holds two of those arguments constant (i.e.without creating that single-argument function).More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s}, c = Floor[state/base]; s = Mod[state,base]; multiplier*s + c ]where I have a generalize ÔmachineÕ, defined by the radix and multiplier,which converts one state into another state. So IÕd like to be able to dosomething like this: NestList[Machine[10,7,#], 3, 22]to get the series of states that the radix-10 multiplier-7 machine runsthrough (starting with state 3). However, this syntax doesnÕt seem to dowhat I want.I hope that description makes sense. It seems like there must be a syntaxto describe the function Machine[10,7,#].Anyone have any ideas?Bob H ==== Sidney,With a direct rule Mathematica tries to Flatten the symbol q immediately.You want a delayed rule to avoid the error message.z /. SomeHead[q_] :> Flatten[q]David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/{{1,2}, {3,4}}.Could anybody explain why this happens? Sidney Cadot ==== Lucas,I hope that your question will provoke a number of replies because I thinkit is an interesting topic.First, it would be nice if Mathematica had a ShowPrecedence statement toquickly retrieve a precedence number for any command. It is a bit timeconsuming to search through the table in Section A.2.7.Next, it would be nice if the user could set the precedence for operatorsthat donÕt have built-in definitions.Since it appears that you canÕt do that, is it possible to switch themeanings of Plus and CirclePlus in your theory? Are you depending on thenumerical behavior of Plus? Go with the precedence that Mathematica givesyou. Or you could use something like VerticalBar or RightTee which havelower precedence than Plus, but perhaps donÕt have the look that you want.You could try to use the Notation package for your CirclePlus sum. But Ialways find the Notation package difficult to use and like to useStandardForm as much as possible. One possibility is...!((([Sum]+(i = 1)%5 x[i])) /. Plus -> CirclePlus)These are weak answers to your question, but maybe they will bring in morediscussion.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/desired effect.Also, I would like to introduce a notation like N[BigCirclePlus] x[[i]] --> x[[1]] [CirclePlus] x[[2]] [CirclePlus].... i=0analagous to summation, but mathematica does not appear to offer theCirclePlus in a large format. to relate this to the case above, x[1]= (a + b) andx[2] = (c + d), so each indexed element is a subexpression.Finally, I would like to be able to set up the CirclePlus operatorsuch that the following algebraic relations hold:Sum BigCirclePlus E = BigCirclePlus Sum E i j ij j i ijd d-- BigCirclePlus E = BigCirclePlus -- Edx j j j dx j-Lucas Scharenbroich-MLS Group / JPL ==== You are quite right, Mathematica does evaluate Flatten[q] before substituting {{1, 2}, {3, 4}}. It then issues the error message and returns Flatten[q]. Only now {{1, 2}, {3, 4}} is substituted for q, Flatten[{{1, 2}, {3, 4}}] is evaluated and you get the right answer. To avoid all this just use RuleDelayed instead of Rule:In[1]:=z := SomeHead[{{1, 2}, {3, 4}}];In[2]:=z /. {SomeHead[q_] :> Flatten[q]}Out[2]={1,2,3,4} Andrzej KozlowskiToyama International UniversityJAPAN>> While playing arounf with patterns and substitutions, I came across the> following behavior which I didnÕt expect:>> z := SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] -> Flatten[q]}>> While this _does_ yield the desired result {1,2,3,4}, Mathematica > complains:>> Flatten::normal: Nonatomic expression expected at position 1 in> Flatten[q].........as if it is trying to evaluate Flatten[q], with q not bound to> {{1,2},{3,4}}.>> Could anybody explain why this happens?> Sidney Cadot>> ==== > [...] Y = {A,B,C,D}; [...]> In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]> In[266]:= a[1,3]> Out[266]= -A+B> The output above is not what I want. I want 2.> [...]You are mixing the (global (*)) symbols A and B with the (local (*)) patterns A_ and B_. If you want to replace the (global) solution with local values you should writeIn[4]:= a[AA_, BB_] := LinearSolve[X, Y][[1]] /. {A -> AA, B -> BB}; a[1, 3]Out[5]= 2________________(*) as far we can say that in Mathematica-- Rainer Gruber ==== > NestList[Machine[10,7,#], 3, 22]You almost have it:NestList[Machine[10,7,#]&, 3, 22]More elegantly, you can defined Machine this way:Machine[radix_,multiplier_][state_] := ...Then you can writeNestList[Machine[10,7], 3, 22]Tom Burton ==== > z := SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] -> Flatten[q]}> While this _does_ yield the desired result {1,2,3,4}, Mathematica complains:> Flatten::normal: Nonatomic expression expected at position 1 in> Flatten[q].The -> operator is prompt: It permits evaluation of the RHS Flatten[q]immediately, before it is used in the substitution. Evidently, q wasundefined before you tried this, so Flatten[q]Õs evaluation yielded itself.Later, in the process of substitution, with q set as you intended, Flattenevaluated again, this time yielding the desired result.Try it again after setting q to something. Then you get not only thecomplaint but also the wrong answer.To avoid these issues, use the delayed operator :> instead of the promptoperator ->. A rule of thumb is: Use delayed operators := and :> when theLHS (SomeHead[q_] in your case) contains a blank (_).Tom Burton ==== Mark:In: ?KOut: K is a default generic name for a summation index in a symbolic sum.Turns out that there are seven single-letter symbols.In: ClearAll[Global`*]; Select[Names[*], (StringLength[#] == 1) &]Out: {C, D, E, I, K, N, O}K is a little weird, because itÕs not Protected.In: Attributes[{C, D, E, I, K, N, O}]Out: {{NHoldAll, Protected}, {Protected, ReadProtected}, {Constant, Protected, ReadProtected}, {Locked, Protected, ReadProtected}, {}, {Protected}, {Protected, ReadProtected}}----Selwyn Hollis> I just learned that K is a System` Symbol:> Information[K]> Context[K]> I learned this due to an error message:> Block[{K = 1}, Sum[j, {j, i}]]> The same message can be generated by the following:> > K := 1> Sum[j, {j, i}]> The message can be eliminated by Removing K:> Remove[K]> Block[{K = 1}, Sum[j, {j, i}]]> K := 1> Sum[j, {j, i}]> Surely, this is not intentional.> --Mark.> ==== Dear MathgroupI have convert pde to ode like thisdu_i/dt = 1-4 u_i + .02 (u_i-1 .9a 2 u_i + u i+1)/(delta (x))^3 + (u_i)^3 v_idv_i /dt = 3 u_i + .02 (v_i-1 .9a 2 v_i + u i+1)/(delta (x))^3 - (u_I)^3 v_idelta(x)=(i)/(N+1)x_i= (i)/(N+1)Boundary conditionu_0 (t) = 1 = u_N+1(t)v_0(t) = 3 = v_N+1(t),Initial conditiou_i(0) = 1+sin (2 pi x_i )v_i = 3For i = 1,á., NTime Interval =[t_o, t_end] = [0,10]Could i get code in Mathematica (by using Euler of 4 Runge - Kutta..)to solve this ordinary differential equation.I am very happy if you give me helpKhaled___________________________________________________ ______________MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx ==== > Dear Mathgroup> I have convert pde to ode like this> du_i/dt = 1-4 u_i + .02 (u_i-1 ? 2 u_i + u i+1)/(delta (x))^3 + (u_i)^3 > v_i> dv_i /dt = 3 u_i + .02 (v_i-1 ? 2 v_i + u i+1)/(delta (x))^3 - (u_I)^3 > v_i> delta(x)=(i)/(N+1)> x_i= (i)/(N+1)> Boundary condition> u_0 (t) = 1 = u_N+1(t)> v_0(t) = 3 = v_N+1(t),> Initial conditio> u_i(0) = 1+sin (2 pi x_i )> v_i = 3> For i = 1,?., N> Time Interval =[t_o, t_end] = [0,10]Since this is 1+1 dimensional initial value problem, Mathematica can do the discretization for you automatically. Just useNDSolve[{ D[u[t, x], t] == 1 - 4 u[t, x] + 0.02 D[u[t, x], x, x] + u[t, x]^3 v[t, x], D[v[t, x], t] == 3u[t, x] + 0.02 D[v[t, x], x, x] + u[t, x] ^3v[t, x], u[t, 0] == u[t, 1] == 1, u[0, x] == 1 + Sin[2 Pi x], v[t, 0] == v[t, 1] == 3, v[0, x] == 3}, {u, v}, {t, 0, 10}, {x, 0, 1}]Mathematica by default uses fourth order differences instead of the second order you specified above. If you really want second order spatial differences with the exact spacing you defined, you can useNDSolve[{D[u[t, x], t] == 1 - 4 u[t, x] + 0.02 D[u[t, x], x, x] + u[t, x]^3 v[t, x], D[v[t, x], t] == 3u[t, x] + 0.02 D[v[t, x], x, x] + u[t, x] ^3v[t, x], u[t, 0] == u[t, 1] == 1, u[0, x] == 1 + Sin[2 Pi x], v[t, 0] == v[t, 1] == 3, v[0, x] == 3}, {u, v}, {t, 0, 10}, {x, 0, 1}, StartingStepSize -> 1./206, MaxSteps -> {1000, 300}, DifferenceOrder -> 2]Interestingly enough, either way you do it, Mathematica is only able to carry out the solution out to about t == 0.035 or so. This appears to be because the nonlinearity is causing the solution to form a nonsingularity which appears as a cusp with rapidly rising height.is because of the (delta (x))^3 in .02 (u_i-1 ? 2 u_i + u i+1)/(delta (x))^3 Any finite difference formula for the second derivative on a uniform grid will involve (delta (x))^2 -- i.e. squared, not cubed. At a fixed grid space, the extra power will have the effect of making the diffusion coefficient larger by a factor of n (which for your range of interest effectively removes to formation of the discontinuity). Presumably the (delta (x))^3 was a typo as was the u_i+1 instead of v_i+1 in .02 (v_i-1 ? 2 v_i + u i+1)However, if you really wanted the cubed power, here is how you could manually do the discretization with Mathematica:n = 205;X = N[Range[1, n]/(n + 1)];U[t_] = Map[u[#][t] &, Range[1, n]];V[t_] = Map[v[#][t] &, Range[1, n]];eqns = Join[ Thread[D[U[t], t] == 1 - 4 U[t] + 0.02 ListCorrelate[N[{1, -2, 1} n^3], U[t], {2, 2}, 1] + U[t]^3 V[t]], Thread[ D[V[t], t] == 3 U[t] + 0.02 ListCorrelate[N[{1, -2, 1} n^3], V[t], {2, 2}, 3] + U[t]^3 V[t]], Thread[U[0] == 1 + Sin[X]], Thread[V[0] == 3 + 0. X]];NDSolve[eqns, Join[U[t], V[t]], {t, 0, 10}]> Could i get code in Mathematica (by using Euler of 4 Runge - Kutta..)to > solve this ordinary differential equation.I do not recommend solving this with either an Euler method or a RungeKutta method for the reason that the potential formation of discontinuities could make the ODEs stiff. The default method Mathematica uses automatically switches to methods appropriate for stiff ODEs when needed. If you want to use a RungeKutta method, you can useNDSolve[eqns, Join[U[t], V[t]], {t, 0, 10}, Method->RungeKutta]This uses the Runge-Kutta-Fehlberg 4(5) method.> I am very happy if you give me help> Khaled> _____________________________________________________________ ____> MSN Photos is the easiest way to share and print your photos: > http://photos.msn.com/support/worldwide.aspx> ==== I am a newbie to mathematica. I have a 14 functions which are thefunction of r,theta and phi. I want to do some mathematical operationover them. How can I do? Can it be possible to call them in Do or Forloop with some index? Please suggest. Raj ==== Is there an easy (elegant?) way to generate the set of all k-tuplestaking values from some set (list) S? I want the arguments of thefunction to be k (the length of the tuples) and the set S. That is,KTuples[3,{a,b}] should produce{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b, a},{b,b,b}}. ==== Bob, KTuples[n_,lst_]:= Distribute[Table[{a,b},{n}],List] KTuples[3,{a,b}] {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b ,b}}--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Is there an easy (elegant?) way to generate the set of all k-tuples> taking values from some set (list) S? I want the arguments of the> function to be k (the length of the tuples) and the set S. That is,> KTuples[3,{a,b}] should produce> {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b ,b}}.> ==== HereÕs my contestant:< Is there an easy (elegant?) way to generate the set of all k-tuples> taking values from some set (list) S? I want the arguments of the> function to be k (the length of the tuples) and the set S. That is,> KTuples[3,{a,b}] should produce> {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b ,b}}.> ==== > Is there an easy (elegant?) way to generate the set of all k-tuples> taking values from some set (list) S? I want the arguments of the> function to be k (the length of the tuples) and the set S. That is,> KTuples[3,{a,b}] should produce> {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b ,b}}.HereÕs a first implementation:ktuples[k_, set_List] := Map[ set[[#]] &, Flatten[ Array[ List, Table[ Length[set], {k}]], k - 1]]In[31]:= ktuples[3,{a,b}]Out[31]={{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a ,a},{b,a,b},{b,b,a},{b,b,b}}-Nevin ==== Does anyone know if there are any publications that describe theintegration of above?In particular I am working with a 4 gaussian process with joint pdfp(x1,y1,x2,y2) transformed to-> p(r1,r2,theta1,theta2), the processeshave non-zero mean and I would like to integrate the joint pdf twice(over r1 and r2) and obtain an expression for the pdf of the phaseangles between p(theta1,theta2). I could assume that the means are thesame (to make life easier). Has anyone come accross this - it doesnÕtseem that unusual to me. I am asking because the integrals arebecoming ÔinterestingÕ.thankyou for any tips. ==== Start Excel and go to Tools -> Macro -> Security..., then on the SecurityLevel tab click on Medium and then click OK.----- Original Message -----> My original version of MathLink for Excel (MLX.xla) was for Excel 97,and> It worked fine. Then I upgraded the package to Excel 2000 by unloadingthe> macro from the Wolfram site. It continued working perfectly on my old> environment (Windows 98 + Mathematica 4.1).> But I recently upgraded to Mathematica 4.2 under Windows 2000; and when> trying to load the macro (MLX.xla) for Excel2000, I got (in Excel 2000)> the> following message: This workbook contains a type of macro (Microsoft> Excel> version 4.0 macro) that cannot be disable nor signed. Therefore, this> workbook cannot be opened under high security level.> Does any one have any experience on this?> Emilio Martin-Serrano> > ==== Download the newest patch from wolfram research - this should theoreticallyhelp.> Group,>> My original version of MathLink for Excel (MLX.xla) was for Excel 97, and> It worked fine. Then I upgraded the package to Excel 2000 by unloading the> macro from the Wolfram site. It continued working perfectly on my old> environment (Windows 98 + Mathematica 4.1).>> But I recently upgraded to Mathematica 4.2 under Windows 2000; and when> trying to load the macro (MLX.xla) for Excel2000, I got (in Excel 2000)the> following message: This workbook contains a type of macro (MicrosoftExcel> version 4.0 macro) that cannot be disable nor signed. Therefore, this> workbook cannot be opened under high security level.>> Does any one have any experience on this?> Emilio Martin-Serrano> ==== >IÕm sorry for that my question is not clear,I have correct below.> I have a very interesting math problem:If I have a scales,and I>> have 40 things that their mass range from 1~40 which each is a nature>> number,and now I can only make 4 counterweights to measure out each>> mass of those things.Question:What mass should the counterweights>> be???>> The answer is that 1,3,9,27 and I wnat to use mathematica to solve>> this problem.>> In fact,I think that this physical problem has various>> answer,ex.2,4,10,28>> this way also work,because if I have a thing which weight 3 , and I>> can measure out by comparing 2<3<4 . But,If I want to solve this math>> problem:>> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature numbers.>> and {k1,k2,k3,k4}={1,0,-1}>> How to solve it ?? >> mathematica solving method. appreciate any idea sharing>> sincerely >> bryan>Just use brute force.Needs[DiscreteMath`Combinatorica`];var = {a, b, c, d}; n = Length[var];s = Outer[Times, var, {-1, 0, 1} ];f = Flatten[Outer[Plus, Sequence@@s]];Since the length of f is just 3^n then the range of numbersto be covered should be {-(3^n-1)/2, (3^n-1)/2}.Consequently, the largest of the weights can not exceed(3^n-1)/2 - (1+2+...+(n-1)) or ((3^n-1) - n(n-1))/234Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ KSubsets[Range[((3^n-1) - n(n-1))/2], n], Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&]){{a -> 1, b -> 3, c -> 9, d -> 27}}Bob HanlonChantilly, VA USA ==== Can we please get a response from WRI?i.e. regarding:In[1]:= Limit[ (Log[x]^Log[Log[x]])/ x , x->Infinity]Out[2]:= InfinityIt should be 0Jonathan Rockmannmtheory@msn.com ==== IÕm finding that the ImageSize option in Export has no effect when exporting Cell or Notebook objects. For instance, the following two commands produce precisely the same graphic: Export[image1.jpg, Cell[Some cell contents, Text, FontSize -> 100]] Export[image2.jpg, Cell[Some cell contents, Text, FontSize -> 100], ImageSize -> {576, 288}]Has anyone encountered this problem before?(This is with Mathematica 4.1.5 and Mac OS X.)----Selwyn Hollisslhollis@mac.com ==== Does anyone know how to get the JavaPlot window (or any windows of this type)which can be seen at http://www.wolfram.com/products/mathematica/newin42/ java.htmlthat WRI advertises comes with 4.2?Jonathanmtheory@msn.com ==== How can I get mathematica to display the inverse of functions like:f(x) = x^2 - 7*x + 10orf(x) = cos(3*x + 1/2*pi)orf(x) = (x - 3) / (x + 2)IÕm having trouble getting the syntax right. ==== GÕday,Looks like you forgot to define base in your Machine function and whenusing pure functions, donÕt forget the ampersand.ThusNestList[Machine[10,7,#]&, 3, 22]returns{3, 8, 4, 2, 1, 7, 10, 5, 9, 11, 12, 6, 3, 8, 4, 2, 1, 7, 10, 5, 9, 11,12}with base = 2.Yas> Howdy,>> IÕm trying to figure out the correct syntax to do the following. I have> some function with three arguments, and I want to syntactically describe the> single-argument function that holds two of those arguments constant (i.e.> without creating that single-argument function).>> More specifically, I have defined Machine[radix_,multiplier_,state_] := Module [{c,s},> c = Floor[state/base]; s = Mod[state,base];> multiplier*s + c> ]>> where I have a generalize ÔmachineÕ, defined by the radix and multiplier,> which converts one state into another state. So IÕd like to be able to do> something like this: NestList[Machine[10,7,#], 3, 22]>> to get the series of states that the radix-10 multiplier-7 machine runs> through (starting with state 3). However, this syntax doesnÕt seem to do> what I want.>> I hope that description makes sense. It seems like there must be a syntax> to describe the function Machine[10,7,#].>> Anyone have any ideas?>> Bob H> ==== >IÕm sorry for that my question is not clear,I have correct below.>>ajvp7h$ibk$1@smc.vnet.net>...> I have a very interesting math problem:If I have a scales,and I> have 40 things that their mass range from 1~40 which each is a nature> number,and now I can only make 4 counterweights to measure out each> mass of those things.Question:What mass should the counterweights> be???> The answer is that 1,3,9,27 and I wnat to use mathematica to solve> this problem.> In fact,I think that this physical problem has various> answer,ex.2,4,10,28> this way also work,because if I have a thing which weight 3 , and I> can measure out by comparing 2<3<4 . But,If I want to solve this math> problem:> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature>numbers.> and {k1,k2,k3,k4}={1,0,-1}> How to solve it ?? > mathematica solving method. appreciate any idea sharing> sincerely > bryan>>Just use brute force.>>Needs[DiscreteMath`Combinatorica`];>var = {a, b, c, d}; n = Length[var];>s = Outer[Times, var, {-1, 0, 1} ];>f = Flatten[Outer[Plus, Sequence@@s]];>Since the length of f is just 3^n then the range of numbers>to be covered should be {-(3^n-1)/2, (3^n-1)/2}.>Consequently, the largest of the weights can not exceed>(3^n-1)/2 - (1+2+...+(n-1)) or >>((3^n-1) - n(n-1))/2>34>Thread[var->#]& /@> (First /@ Select[{var,f} /. Thread[var->#]& /@> KSubsets[Range[((3^n-1) - n(n-1))/2], n],> Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&])>{{a -> 1, b -> 3, c -> 9, d -> 27}}>A modification to my earlier response. Since you are try to cover all of the values up to (3^n-1)/2 then you can speed up the brute force method by requiring that a+b+c+d == (3^n-1)/2Needs[DiscreteMath`Combinatorica`];var = {a,b,c,d}; n = Length[var]; m = (3^n-1)/2;s = Outer[Times, var, {-1,0,1} ];f = Flatten[Outer[Plus, Sequence@@s]];k= Select[KSubsets[Range[m - n(n-1)/2], n], (Plus @@ #) == m&];Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ k, Sort[#[[2]]] == Range[-m,m]&]){{a -> 1, b -> 3, c -> 9, d -> 27}}Bob HanlonChantilly, VA USA ==== Some functions with vector arguments work as expected and some giveerrors. I would appreciate if someone can clarify why.First an example of a function definition that works fine :f[u_,v_] := u.vCalling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +y1 y2.Now an example that does not work :g[u_,v_] := u-vCalling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,y1-y2} but instead one gets error messages.Why ? And how do I fix g (i.e write a function that outputs thedifference of 2 vectors). ==== I do not know why you are getting a message, using your own code I get theresult you expect.> Some functions with vector arguments work as expected and some give> errors. I would appreciate if someone can clarify why.>> First an example of a function definition that works fine :> f[u_,v_] := u.v> Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +> y1 y2.>> Now an example that does not work :> g[u_,v_] := u-v> Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,> y1-y2} but instead one gets error messages.>> Why ? And how do I fix g (i.e write a function that outputs the> difference of 2 vectors).>> ==== > Now an example that does not work :> g[u_,v_] := u-v> Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,> y1-y2} but instead one gets error messagesWorks fine for me.Please check that you have no existing definitions for the symbols used. Clear[g,x1,x2,y1,y2]; g[u_,v_]:=u-v g[{x1,y1},{x2,y2}] {x1-x2,y1-y2}--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Some functions with vector arguments work as expected and some give> errors. I would appreciate if someone can clarify why.>> First an example of a function definition that works fine :> f[u_,v_] := u.v> Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +> y1 y2.>> Now an example that does not work :> g[u_,v_] := u-v> Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,> y1-y2} but instead one gets error messages.>> Why ? And how do I fix g (i.e write a function that outputs the> difference of 2 vectors).>> ==== > Some functions with vector arguments work as expected and some give> errors. I would appreciate if someone can clarify why.> First an example of a function definition that works fine :> f[u_,v_] := u.v> Calling it with f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +> y1 y2.> Now an example that does not work :> g[u_,v_] := u-v> Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,> y1-y2} but instead one gets error messages.> Why ? And how do I fix g (i.e write a function that outputs the> difference of 2 vectors).> in fact this call works fine on my Mathematicas (3.0 up to 4.1). Did Youreally use the minus character? Maybe some erroneous code was assignedto g before. Restart Mathematica or use Remove[g] to really start upfrom the beginning.Sincerly Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== Garry, HereÕs a solution using your LeftSide concept; it works perfectly but takes twice as much time as my solution. Both solutions look at every vertex of both rectangles, but mine uses two sides from each and yours requires looking at all four sides of each rectangle. IÕd think yours should be a triße faster than this, though. There may be efficiencies IÕm missing (in both solutions). ClearAll[cis, rect, pickRect, extent, cannotIntersect, intersects, daveRect] cis[t_] := {Cos@t, Sin@t} rect[{pt : {_, _}, angle_, {len1_, len2_}}] := Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2 cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}] daveRect := {{Random[], Random[]}, Random[] + Pi/2, {Random[], Random[]}} pickRect := rect@daveRect extent[r1_, r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] - r1[[{2, 3}]]).Transpose@r2) cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 < min1 || min2 > max1 intersects[r1_, r2_] := Catch[ If[cannotIntersect[#], Throw[False]] & /@ Flatten[Transpose[Outer[extent, {r1}, {r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}], 1]; Throw[True]] ClearAll[leftSide,leftIntersects,sides] sides[a_List]:=Partition[Join[a,{First@a}],2,1] leftSide[{a_,b_},{{c_,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c f>0 leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&! Or@@(And@@#&/@leftSide[b,sides@a]) davePairs={daveRect,daveRect}&/@Range[10000]; rectanglePairs=Map[Reverse@rect[#]&,davePairs,{2}]; Timing[right=intersects[Sequence@@#]&/@rectanglePairs;] Timing[test=leftIntersects[Sequence@@#]&/@rectanglePairs;] right[Equal]test {3.187999999999999*Second, Null} {6.765000000000001*Second, Null} True Bobby Treat -----Original Message----- intersection > Begin forwarded message: > Dear colleagues, > any hints on how to implement a very fast routine in Mathematica for > testing if two rectangles have an intersection area? > Frank Brand > Here is one approach. > Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then > Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your left as > you walk along the line though b and c in the direction from b to c. > ( If the result is zero, then a lies on the line.) > The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the algorithm depends essentially on how fast this quantity can > be computed. Suppose we write a function LeftSide[a,{b,c}] that computes > the sign of the determinant. > Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a > convex polygon traced counterclockwise. Then a lies within or on the > boundary of the polygon if and only if none of the numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1]. > Now use the fact that if two convex polynomials overlap, then some > vertex of one of them must lie inside or on the boundary of the other. > If an overlap of positive area is required, then the check is that only > +1 appears--not that -1 does not appear. > For two rectangles ( or parallelograms) this approach requires the > evaluation of 16 determinants, so it may be a bit expensive. If the > points have rational coordinates, then (positive) denominators may be > cleared in the homogeneous coordinates and the computations can be done > in integer arithmetic, at the cost of at least three more > multiplications per determinant. > Garry Helzer Department of Mathematics University of Maryland College Park, MD 20742 301-405-5176 gah@math.umd.edu ==== I would like to have a list of all the directives that can be used forcommand in the Windows Start Menu). I am especially interested in adirective with which you can appoint a file which has to be evaluated by thekernel after it has been launched. I imagine that such a directive lookslike -f filename, but I can not find a list of the correct directives.The Mathematica version I have is 4.1 on a Windows NT system.Rene Klaver ==== > 1) Get data from excel into a coordinate > list {x,y,z}> e.g. Node 1, {x1,y1,z1}> Node 2, {x2,y2,z2}> etc...Why not just use data = ReadList[filename, Table[Number, {4}]];Alternatively, data = ReadList[filename, Number, RecordLists->True]; data = Partition[data, 4]; cord = {#[[1]], #[[2]], #[[3]]}& /@ data;> 2) Convert from Rectangular to > Cylindrical (maybe)Coordinate tranforms live in Calculus`VectorAnalysis`. ItÕs straightforwardto write a function that uses > 3) Plot3D the dataThis will be tricky -- ListSurfacePlot3D plots f[x, y]. ListContourPlot3Dwhich plots f[x, y, z] can be quite slow.> 4) Generate a harmonic bessel function for that > plot3D/graph> 5) Find the equation(s) that spits out > these harmonic > bessel functions (which I think might be in the general form > of Hankel > Function solutions to the Helmholtz equation which shows > cylinder harmonics > of order v)Maybe I misunderstand ... isnÕt this the same as fitting a bessel functionto your data? For this, you can use Statistics`NonlinearFit`. > I can figure out step 5 if I can get steps 1 through 4 > figured out. If > anyone can write a recipe for me to follow that would be > great, or even some > tips and clues...Anything!!!Dave. ==== YouÕve gotten some very helpful responses so IÕm just going to add a coupleof comments. The following is an example of yet another type of button that you can useas a model. Copy and paste the following code into a notebook. When youevaluate it, it will create a button within the same notebook which whenpressed evaluates the entire notebook. Sort of like selecting from the menuis something in the notebook already to evaluate. So input 1+2 (and donÕthit enter) somewhere in the notebook so that you can see whatthe effect of the button is.DisplayForm[Button[Evaluate*Notebook,ButtonFunction:> FrontEndExecute[FrontEndToken[EvaluateNotebook]], ButtonEvaluator->None,Active->True]]It has the nice feature that it doesnÕt get stuck in a loop creating the button over and over again. However, with some enthusiasm you can make thishappen too.Personally, I am fascinated by the Java integration in version 4.2. But I wouldnÕt recommend it to anyone who is just starting to program in Mathematica.Further, there is hardly enough material contained in the Help Browser to make sense of much of it.It is always a good idea to have several basic constructs of efficient, usefulprograms that can serve as models when programming. If you look atsome of the MathGroup archived threads you will find similar complaints that the Mathematica documentation is confusing.Jonathan Rockmannmtheory@msn.com----- Original Message -----I want to have a variable (or matrix or whatever) defined as a globalvariable x, and then perform x = x+1 when a button is clicked. IÕve beenusing and programming computers for almost 25 years and I canÕt followWolframÕs documentation. Is it just me, or is he always this obtuse whenexplaining things? I mean, given the amazing power of the Mathematicasystem, a sample list of buttons in a notebook that you could select andexamine how they were implemented, would have been nice. I canÕt find such alist, and this seems to be par for the course for the rest of thedocumentation as well. ==== This was REALLY interesting. HereÕs a solution that looks only at the7,560 relevant combinations. It first chooses three numerators. Thenit chooses two denominators for the first fraction. Then twodenominators for the second fraction. The last fraction is determinedat that point.<< DiscreteMath`Combinatorica`ClearAll[f, g, h, j]r = Range[1, 9];f = KSubsets[#1, #2] &;g[r_List, n_Integer, {}] := f[r, n]g[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@ f[Complement[r, e],n]g[r_List, n_Integer, e : {__?VectorQ}] := Flatten[g[r, n, #] & /@ e, 1]h[r_List, e : {__?VectorQ}] := Join[#, Complement[r, #]] & /@ ej[{a_, b_, c_, d_, e_, f_, g_, h_, i_}] := a/(d e) + b/(f g) + c/(h i)Timing[Select[h[r, Fold[g[r, #2, #1] &, {}, {3, 2, 2}]], j@# == 1 &]]{0.532 Second, {{1, 5, 7, 3, 6, 8, 9, 2, 4}}}Hence the only solution is1/(3*6)+5/(8*9)+7/(2*4)Bobby Treat-----Original Message-----University Professor of Philanthropy and the LawDirector, National Center on Philanthropy and the LawNew York University School of LawRoom 206A110 West 3rd StreetNew York, N.Y. 10012-1074-----Original Message-----byran____________________________________________ ____________________________service. For more information on a proactive anti-virus service workingaround the clock, around the globe, visit http://www.messagelabs.com___________________________________ _____________________________________ ==== Garry,HereÕs a solution using your LeftSide concept; it works perfectly buttakes twice as much time as my solution. Both solutions look at everyvertex of both rectangles, but mine uses two sides from each and yoursrequires looking at all four sides of each rectangle. IÕd think yoursshould be a triße faster than this, though. There may be efficienciesIÕm missing (in both solutions).ClearAll[cis, rect, pickRect, extent, cannotIntersect, intersects,daveRect]cis[t_] := {Cos@t, Sin@t}rect[{pt : {_, _}, angle_, {len1_, len2_}}] := Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2 cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}]daveRect := {{Random[], Random[]}, Random[] + Pi/2, {Random[],Random[]}}pickRect := rect@daveRectextent[r1_, r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] - r1[[{2,3}]]).Transpose@r2)cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 < min1 || min2 > max1intersects[r1_, r2_] := Catch[ If[cannotIntersect[#], Throw[False]] & /@Flatten[Transpose[Outer[extent, {r1}, {r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}],1]; Throw[True]]ClearAll[leftSide,leftIntersects,sides]sides[a_ List]:=Partition[Join[a,{First@a}],2,1]leftSide[{a_,b_},{{c_, d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c f>0leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@ aleftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@ bleftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&& ! Or@@(And@@#&/@leftSide[b,sides@a])davePairs={daveRect, daveRect}&/@Range[10000];rectanglePairs=Map[Reverse@rect[#]&, davePairs,{2}];Timing[right=intersects[Sequence@@#]&/@ rectanglePairs;]Timing[test=leftIntersects[Sequence@@#]&/@ rectanglePairs;]right[Equal]test{3.187999999999999*Second, Null}{6.765000000000001*Second, Null}TrueBobby Treat-----Original Message-----intersection>> Begin forwarded message:>> Dear colleagues,>> any hints on how to implement a very fast routine in Mathematica for> testing if two rectangles have an intersection area?> Frank Brand> Here is one approach.>> Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then> Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your leftas> you walk along the line though b and c in the direction from b to c.> ( If the result is zero, then a lies on the line.)>> The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the algorithm depends essentially on how fast this quantitycan> be computed. Suppose we write a function LeftSide[a,{b,c}] thatcomputes> the sign of the determinant.>> Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a> convex polygon traced counterclockwise. Then a lies within or on the> boundary of the polygon if and only if none of the numbers> LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1].>> Now use the fact that if two convex polynomials overlap, then some> vertex of one of them must lie inside or on the boundary of the other.>> If an overlap of positive area is required, then the check is thatonly> +1 appears--not that -1 does not appear.>> For two rectangles ( or parallelograms) this approach requires the> evaluation of 16 determinants, so it may be a bit expensive. If the> points have rational coordinates, then (positive) denominators may be> cleared in the homogeneous coordinates and the computations can bedone> in integer arithmetic, at the cost of at least three more> multiplications per determinant.>>Garry HelzerDepartment of MathematicsUniversity of MarylandCollege Park, MD 20742301-405-5176gah@math.umd.edu>> ==== Garry,Also note your solution requires rectangle points to be in clockwiseorder (mine doesnÕt), but yours works for arbitrary convex polygons aswritten.Bobby-----Original Message-----ClearAll[cis, rect, pickRect, extent, cannotIntersect, intersects,daveRect]cis[t_] := {Cos@t, Sin@t}rect[{pt : {_, _}, angle_, {len1_, len2_}}] := Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2 cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}]daveRect := {{Random[], Random[]}, Random[] + Pi/2, {Random[],Random[]}}pickRect := rect@daveRectextent[r1_, r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] - r1[[{2,3}]]).Transpose@r2)cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 < min1 || min2 > max1intersects[r1_, r2_] := Catch[ If[cannotIntersect[#], Throw[False]] & /@Flatten[Transpose[Outer[extent, {r1}, {r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}],1]; Throw[True]]ClearAll[leftSide,leftIntersects,sides]sides[a_ List]:=Partition[Join[a,{First@a}],2,1]leftSide[{a_,b_},{{c_, d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c f>0leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@ aleftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@ bleftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&& ! Or@@(And@@#&/@leftSide[b,sides@a])davePairs={daveRect, daveRect}&/@Range[10000];rectanglePairs=Map[Reverse@rect[#]&, davePairs,{2}];Timing[right=intersects[Sequence@@#]&/@ rectanglePairs;]Timing[test=leftIntersects[Sequence@@#]&/@ rectanglePairs;]right[Equal]test{3.187999999999999*Second, Null}{6.765000000000001*Second, Null}TrueBobby Treat-----Original Message-----intersection>> Begin forwarded message:>> Dear colleagues,>> any hints on how to implement a very fast routine in Mathematica for> testing if two rectangles have an intersection area?> Frank Brand> Here is one approach.>> Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then> Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your leftas> you walk along the line though b and c in the direction from b to c.> ( If the result is zero, then a lies on the line.)>> The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the algorithm depends essentially on how fast this quantitycan> be computed. Suppose we write a function LeftSide[a,{b,c}] thatcomputes> the sign of the determinant.>> Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a> convex polygon traced counterclockwise. Then a lies within or on the> boundary of the polygon if and only if none of the numbers> LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1].>> Now use the fact that if two convex polynomials overlap, then some> vertex of one of them must lie inside or on the boundary of the other.>> If an overlap of positive area is required, then the check is thatonly> +1 appears--not that -1 does not appear.>> For two rectangles ( or parallelograms) this approach requires the> evaluation of 16 determinants, so it may be a bit expensive. If the> points have rational coordinates, then (positive) denominators may be> cleared in the homogeneous coordinates and the computations can bedone> in integer arithmetic, at the cost of at least three more> multiplications per determinant.>>Garry HelzerDepartment of MathematicsUniversity of MarylandCollege Park, MD 20742301-405-5176gah@math.umd.edu>> ==== Try this:Off[Remove::rmnsm]Remove[Global`p@, Global`p@@]n = 7;pn = Unique[p] & /@ Range[10]f[p_] = Array[fk[p, #] &, n]f[p]fEq[p_] = MapThread[Equal, {f[p], Array[0 &, n]}]Bobby Treat-----Original Message-----f2 := f[pn] [[2]];f3 := f[pn] [[3]];f4 := f[pn] [[4]];f5 := f[pn] [[5]];f6 := f[pn] [[6]];f7 := f[pn] [[7]];theRoot = FindRoot[{f1==0,f2==0,f3==0,f4==0,f5==0,f6==0,f7==0}, {p1, 1/n},{p2, 1/n},{p3, 1/n},{p4, 1/n},{p5, 1/n}, {p6, 1/n},{p7, 1/n}];-- John MacCormick Systems Research Center, HP Labs, 1501 Page Mill Road, ==== the problem, but I duplicated it just now, so IÕm puzzled. IÕm usingWindows XP Home, and System`Private`$BuildNumber is 168634.4.2 for Microsoft Windows (June 5, 2002)f[n_] := Log[n]^Log[Log[n]]Limit[f[n]/n, n -> Infinity]InfinityBobby Treat -----Original Message----- By the way, Mathematica gets the following limit wrong:f[n_] := Log[n]^Log[Log[n]]Limit[f[n]/n, n -> Infinity]InfinityThat limit is zero. For the Sieve to be polynomial, we only need thesequence to be BOUNDED (for some power of n in the denominator).Bobby Treat ==== Garry,No, you donÕt have to compute intersections, and yes, you can testvertices only. I havenÕt coded it yet, but the LeftSide idea seemslike a good one.It is sufficient to test whether all vertices of one convex polygon areon the left (out) side of some side of the second polygon (both polygonsin clockwise order). If that happens for any side of either polygon,the polygons donÕt intersect. In the cross example, some vertices areto the right for every side you try.Bobby Treat-----Original Message-----intersection>> Begin forwarded message:>> Dear colleagues,>> any hints on how to implement a very fast routine in Mathematica for> testing if two rectangles have an intersection area?> Frank Brand> Here is one approach.>> Given three points {x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then> Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on your leftas> you walk along the line though b and c in the direction from b to c.> ( If the result is zero, then a lies on the line.)>> The value of the determinant is x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the algorithm depends essentially on how fast this quantitycan> be computed. Suppose we write a function LeftSide[a,{b,c}] thatcomputes> the sign of the determinant.>> Now let {p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a> convex polygon traced counterclockwise. Then a lies within or on the> boundary of the polygon if and only if none of the numbers> LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. . .,pn,p1},2,1].>> Now use the fact that if two convex polynomials overlap, then some> vertex of one of them must lie inside or on the boundary of the other.>> If an overlap of positive area is required, then the check is thatonly> +1 appears--not that -1 does not appear.>> For two rectangles ( or parallelograms) this approach requires the> evaluation of 16 determinants, so it may be a bit expensive. If the> points have rational coordinates, then (positive) denominators may be> cleared in the homogeneous coordinates and the computations can bedone> in integer arithmetic, at the cost of at least three more> multiplications per determinant.>>Garry HelzerDepartment of MathematicsUniversity of MarylandCollege Park, MD 20742301-405-5176gah@math.umd.edu>> ==== > Dear All:> I want to make an animation that simulate the Doppler Effect, just 2D> circles travel out one by one, and at the same time,the origin of the> wave also moves toward one direction. I have no idea to make the speed> of the wave origin and the speed of traveling wave independent.Is> sincerely bryancircles, but the second one includes two lines which approximate theshock waves, I believe. The arguments of the functions are vx & vy(velocities in x & y directions) and tstart, tend, tstep whichdetermine how many circles to draw and the spacing of the circles. Ijust used the Do loop to make the pictures, & then you can select thecells & pick Animate.dopp[vx_,vy_,tstart_,tend_,tstep_]:=Show[Graphics[ Table[{Hue[t/tend],Circle[{vx*t,vy*t},tend-t]},{t,tstart, tend,tstep}]],AspectRatio->Automatic,Axes->True,PlotLabel-> Mach Sqrt(vx^2+vy^2)];doppcone[vx_,vy_,tend_,tstep_]:=Show[ Graphics[Table[{Hue[t/tend],Circle[{vx*t,vy*t},tend-t]},{t,0, tend,tstep}]],Graphics[Line[{{-tend*Sin[If[vx==0,0,ArcTan[vy /vx]]],tend*Cos[If[vx==0,0,ArcTan[vy/vx]]]},{Sign[vx]*Cos[If[ vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^2+vy^2]- tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sin[If[vx==0,0,ArcTan[ vy/vx]]]*Sign[vx]*(tend-tstep)*sqrt[vx^2+vy^2]+tstep*Cos[If[ vx==0,0,ArcTan[vy/vx]]]}}]],Graphics[Line[{{tend*Sin[If[vx== 0,0,ArcTan[vy/vx]]],-tend*Cos[If[vx==0,0,ArcTan[vy/vx]]]},{ Sign[vx]*Cos[If[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^ 2+vy^2]+tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sign[vx]*Sin[If [vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*srt[vx^2+vy^2]-tstep* Cos[If[vx==0,0,ArcTan[vy/vx]]]}}]],AspectRatio->Automatic, Axes->True];Do[dopp[i,0,0,10,1],{i,0,1.4,0.2}];Hope I did that without typos - I canÕt see how to post the notebook ==== It would take me a lot of time to understand howfunctions like SelectionEvaluate works...Cesar.> People encounter this all the time. It is because> SelectionEvaluate does > not do what you think. It does not work like> ToExpression, which causes > immediate kernel evaluation. Instead it works like> when you press > Shift-Enter, which selects a cell for evaluation> after all current > evaluations have finished.> See >http://support.wolfram.com/mathematica/kernel/interface/ selectionevaluate.html> __________________________________________________Do You Yahoo!?Yahoo! Finance - Get real-time stock quoteshttp://finance.yahoo.com ==== > How can I get mathematica to display the inverse of functions like:> f(x) = x^2 - 7*x + 10> or> f(x) = cos(3*x + 1/2*pi)> or> f(x) = (x - 3) / (x + 2)> IÕm having trouble getting the syntax right.> Solve[y==x^2-7*x+10, x]{{x -> (1/2)*(7 - Sqrt[9 + 4*y])}, {x -> (1/2)*(7 + Sqrt[9 + 4*y])}}x^2-7*x+10 /. % // ExpandAll{y, y}Solve[y == Cos[3*x+1/2*Pi], x]{{x -> -(ArcSin[y]/3)}}Cos[3*x+1/2*Pi] /. %{y}Solve[y == (x-3)/(x+2), x]{{x -> (-3 - 2*y)/(-1 + y)}}(x-3)/(x+2) /. % // Simplify{y}Bob HanlonChantilly, VA USA ==== > I am a newbie to mathematica. I have a 14 functions which are the> function of r,theta and phi. I want to do some mathematical operation> over them. How can I do? Can it be possible to call them in Do or For> loop with some index?> As a general rule avoid Do and For loops and just operate on Lists or Map (/@) onto lists.g /@ {f1[r,theta,phi], f2[r,theta,phi], f3[r,theta,phi]}{g[f1[r, theta, phi]], g[f2[r, theta, phi]], g[f3[r, theta, phi]]}This can be written more compactly asg /@ (#[r,theta,phi]& /@ {f1,f2,f3}){g[f1[r, theta, phi]], g[f2[r, theta, phi]], g[f3[r, theta, phi]]}Bob HanlonChantilly, VA USA ==== > Is there an easy (elegant?) way to generate the set of all k-tuples> taking values from some set (list) S? I want the arguments of the> function to be k (the length of the tuples) and the set S. That is,> KTuples[3,{a,b}] should produce> {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b ,b}}.> kTuples[n_Integer?Positive, s_List] := Flatten[Outer[List, Sequence@@Table[s,{n}]],n-1];s = {a,b};kTuples[3, {a,b}]{{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}}Length[kTuples[10, {a,b}]]1024Bob HanlonChantilly, VA USA ==== > If I have an n-element list, (say where each element is itself a> list), such as {{a,b}, {a,b}, {a,b}}> is there a way to strip off the outermost nesting of the list to> obtain just a sequence of of these n elements, that is> {a,b},{a,b},{a,b} so that I can use this for input for some function.> I would like to do something like> Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N> dynamically.> The problem, of course, is that the output of the Table command is one> big list> and Outer is expecting a sequence of N separate lists after> SomeFunction.> Use SequencekTuples[n_Integer?Positive,s_List]:= Flatten[Outer[List,Sequence@@Table[s,{n}]],n-1];s = {a,b,c,d,e}; n =3;Length[kTuples[n,s]] == Length[s]^nTrueBob HanlonChantilly, VA USA ==== f[Sequence@@{{a,b}, {a,b}, {a,b}}]f[{a, b}, {a, b}, {a, b}]Bobby Treat-----Original Message-----dynamically.The problem, of course, is that the output of the Table command is onebig listand Outer is expecting a sequence of N separate lists afterSomeFunction. ==== f[x_] = x^2 - 7*x + 10g[x_] = Cos[3*x + 1/2*Pi]h[x_] = (x - 3)/(x + 2)Off[Solve::ifun]Solve[f[x] == y, x]Solve[g[x] == y, x]Solve[h[x] == y, x]Bobby Treat-----Original Message----- ==== f[x_] = x^2 - 7*x + 10;g[x_] = Cos[3*x + 1/2*Pi];h[x_] = (x - 3)/(x + 2);#[x] & /@ {f, g, h}{10 - 7*x + x^2, -Sin[3*x], (-3 + x)/(2 + x)}Bobby Treat-----Original Message----- ==== I get the expected results. I suspect g was already defined at thetime. For instance you might have set g={a,b} previously. ClearAll[g]goes before defining the function g.Bobby Treat-----Original Message-----Calling it with g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,y1-y2} but instead one gets error messages.Why ? And how do I fix g (i.e write a function that outputs thedifference of 2 vectors). ==== In[1]:=ktuples[n_Integer, d_List] := Flatten[Outer[List, Sequence @@ Table[d, {n}]], 2]In[2]:=ktuples[3, {a, b}]Out[2]={{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}}Tomas GarzaMexico City----- Original Message ----- ==== kTuples[k_Integer?Positive, s_List] := Partition[Flatten@Outer[List,Sequence @@ (s & /@ Range[k])], k]kTuples[3, {a, b}]Bobby Treat-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== The trick is to use the Sequence Function. Try the following code and youwill see how it works.abcd = CharacterRange[a, d]abcd1 = Flatten[Outer[{#1, #2} &, abcd, abcd], 1]abcd2 = Outer[First[#]*Last[#] &, Sequence[abcd1], 1]abcd2 uses the list of lists you have created to load as a sequence ofarguments to outer. You need the third argument to operate on the parts ofthe list if this is your goal.Read the description of Sequence. It also works in contexts other thanOuter.Richard Palmer> Can anyone help me with this problem.> If I have an n-element list, (say where each element is itself a> list), such as {{a,b}, {a,b}, {a,b}}> is there a way to strip off the outermost nesting of the list to> obtain just a sequence of of these n elements, that is> {a,b},{a,b},{a,b} so that I can use this for input for some function.> I would like to do something like> Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N> dynamically.> The problem, of course, is that the output of the Table command is one> big list> and Outer is expecting a sequence of N separate lists after> SomeFunction.> ==== Dear GroupI would like to know, if is possible to solveIntegrate[(exp[-a/x])/(x^2-b^2),{x,0,infinity}] witha and b constant ( Real )using Mathematica.Valdeci Mariano****************************************************** ***************Valdeci Mariano de SouzaMasterÇs Degree of Applied Physics - Unesp/Rio Claro - State of S.8boPaulo - BrazilLaboratory of Electrical Measurementsphone : ( 0XX19 ) 526 - 2237********************************************************* ************ ==== > Is there an easy (elegant?) way to generate the set of all k-tuples> taking values from some set (list) S? I want the arguments of the> function to be k (the length of the tuples) and the set S. That is,> KTuples[3,{a,b}] should produce> {{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b ,b}}.Method 1:Distribute[Table[{a,b},{3}],List]Method 2:Needs[DiscreteMath`Combinatorica`];Strings[{a,b},3]Rob PrattDepartment of Operations Researchhttp://www.unc.edu/~rpratt/ ==== > Does anyone know how to get the JavaPlot window (or any windows of this type)> which can be seen at > http://www.wolfram.com/products/mathematica/newin42/java.html > that WRI advertises comes with 4.2?Well, I donÕt know if any tools (like that Window/Palette) written in Java are in the M_4.2 box, but if you know a little Java Programming, you can easily write something like that yourself; eg. using the MathGraphicsJPanel which allows you to display Mathematica GraphicsExpressions in a Java Component, simply by calling its setCommand()Method (I hope thatÕs correct, I am writing that from memory); eg. a simple JFrame with a MathGraphicsJPanel would be programmed likethis: (* This code is necessary for setting up J/Link *)< {NumberPoint -> ,}] ;However, Import is not the function IÕd like to use, because it is realyslow over large files.I wonder if someone knows a way to use something faster than Import (I namely think of ReadList) with coma-numbers? ==== IÕm a poor physicist trying to figure out how to sort out thephysical from the non-physical solutions to a problem. To dothat, I need to be able to look at an expression and pick out asubexpression, the part under the radical.For example, say IÕve got the expression a b x^2 + 5 x^3 + 5 Sqrt[4 - x^2]IÕd like to pick out 4 - x^2, which would then tell me that x isbetween +/- 2. I know there has got to be an easy way to do it, but IcanÕt find it. Any help would be appreciated.Steve Beachasb4@psu.eduhttp://www.thebeachfamily.org ==== Bob, Mathematica has commands to do exactly what you wish and their use is fairlycommon. The first command is Apply (@@ in prefix form) and the secondcommand is Sequence.If you have a list of arguments such as...arglist = {{a, b}, c, {d, e}, 3, Report -> True};you can insert them into a function, f, simply by applying f to the list.f @@ arglistf[{a, b}, c, {d, e}, 3, Report -> True]If you want to insert them into another function, h, that also has otherarguments, then you can use Sequence and Apply.h[firstarg, Sequence @@ arglist, Compile -> False]h[firstarg, {a, b}, c, {d, e}, 3, Report -> True, Compile -> False]David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/The problem, of course, is that the output of the Table command is onebig listand Outer is expecting a sequence of N separate lists afterSomeFunction. ==== Bob,KTuples[n_Integer?Positive, elements_List] := Flatten[Outer[List, Sequence @@ Table[elements, {n}]], n - 1]KTuples[3, {a, b}]{{a, a, a}, {a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b, b}}Outer produces an array of all the elements but we have to ßatten it to getit down to a two-level array.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== Raj,You could include an index for the function in the argument list, or make aclear separation between parameters and variables as follows (I just usetwo functions).f[1][r_, t_, p_] := 2r Sin[t]f[2][r_, t_, p_] := r Cos[t]Sin[p]You could then sum them, for example, bySum[f[i][r, t, p], {i, 1, 2}]r Cos[t] Sin[p] + 2 r Sin[t]Or perhaps you wish to sum the derivatives of the functions with respect tothe second argument, t.Sum[Derivative[0, 1, 0][f[i]][r, t, p], {i, 1, 2}]2 r Cos[t] - r Sin[p] Sin[t]Perhaps you can define all your functions in terms of integer parameters.g[n_, m_][r_, t_, p_] := r^(m - n)Sin[m t]Cos[n p]You could then sum as follows.Sum[g[n, m][r, t, p], {m, 1, 3}, {n, 1, 3}]Cos[p]*Sin[t] + (Cos[2*p]*Sin[t])/r + (Cos[3*p]*Sin[t])/r^2 + r*Cos[p]*Sin[2*t] + Cos[2*p]*Sin[2*t] + (Cos[3*p]*Sin[2*t])/r + r^2*Cos[p]*Sin[3*t] + r*Cos[2*p]*Sin[3*t] + Cos[3*p]*Sin[3*t]Or perhaps you want to take the square of the derivatives of the functionswith respect to the first argument, r...Sum[(Derivative[1, 0, 0][g[n, m]][r, t, p])^2, {m, 1, 3}, {n, 1, 3}](Cos[2*p]^2*Sin[t]^2)/r^4 + (4*Cos[3*p]^2*Sin[t]^2)/ r^6 + Cos[p]^2*Sin[2*t]^2 + (Cos[3*p]^2*Sin[2*t]^2)/ r^4 + 4*r^2*Cos[p]^2*Sin[3*t]^2 + Cos[2*p]^2*Sin[3*t]^2If possible, try to steer away from For and Do loops and use functionalprogramming as much as you can. At first it may seem strange, but it is muchmore powerful and easier once you get used to it. Ask further questions toMathGroup with SPECIFIC examples and you will get a lot of help on how touse functional programming.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== David,Except in a few cases, Mathematica will not automatically generate theinverse function for you. You will have to Solve the equations and constructthe inverse function yourself. In two of your three cases there are actuallymultiple inverse functions.Taking the easy one first.Clear[x];Solve[f[x] == f, x][[1, 1]] // Simplifyx[f_] = x /. %x -> (3 + 2*f)/(1 - f)(3 + 2*f)/(1 - f)So we now have the inverse function.x[f](3 + 2*f)/(1 - f)For the quadratic equation there are two solution.Clear[x]sols = Solve[f[x] == f, x]{{x -> (1/2)*(7 - Sqrt[9 + 4*f])}, {x -> (1/2)*(7 + Sqrt[9 + 4*f])}}We define the two solutions and identify them by an index.x[1][f_] = x /. sols[[1, 1]]x[2][f_] = x /. sols[[2, 1]](1/2)*(7 - Sqrt[9 + 4*f])(1/2)*(7 + Sqrt[9 + 4*f])For the third example there is a double infinity of solutions.Clear[x]sols = Solve[f[x] == f, x]Solve::ifun: Inverse functions are being used by !(Solve), so some solutions may not be found.{{x -> -(ArcSin[f]/3)}}Using some trigonometry we can define the solutions as (I hope I got thisright)Clear[x];x[1, n_][f_] = (-ArcSin[f] + 2 Pi n)/3x[2, n_][f_] = (-Pi + ArcSin[f] + 2Pi n)/3Here are some of the solutions for f = 1/2.Table[x[1, n][1/2], {n, -5, 5}]~Join~Table[x[1, n][1/2], {n, -5, 5}] // Sortf /@ %{-((61*Pi)/18), -((61*Pi)/18), -((49*Pi)/18), -((49*Pi)/18), -((37*Pi)/18), -((37*Pi)/18), -((25*Pi)/18), -((25*Pi)/18), -((13*Pi)/18), -((13*Pi)/18), -(Pi/18), -(Pi/18), (11*Pi)/18, (11*Pi)/18, (23*Pi)/18, (23*Pi)/18, (35*Pi)/18, (35*Pi)/18, (47*Pi)/18, (47*Pi)/18, (59*Pi)/18, (59*Pi)/18}{1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2}Generally, when you want inverse functions you are going have to do somework.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== g[u_, v_] := u - vg[{x1, y1}, {x2, y2}]{x1 - x2, y1 - y2}David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ y1-y2} but instead one gets error messages.Why ? And how do I fix g (i.e write a function that outputs thedifference of 2 vectors). ==== >If I have an n-element list, (say where each element is itself a>list), such as {{a,b}, {a,b}, {a,b}} is there a way to strip off the>outermost nesting of the list to obtain just a sequence of of these n>elements, that is {a,b},{a,b},{a,b} so that I can use this for input>for some function.Try Sequence@@ as in the following:In[1]:=x={{a,b},{a,b},{a,b}};In[2]:=g[x_,y_,z_]:=x( y.z)In[3]:=g[Sequence@@x]Out[3]=!({a ((a^2 + b^2)), b ((a^2 + b^2))}) ==== Why is it that when I type, say, Table[ Plot[ Sin[n x],{x,0,Pi}], {n, 1,5}]my output is marked in the righthand column with 3 cell ``markers,withthe middle marker encompassing the output (and *only* the output).However, when I try something like Table[Show[Graphics[ etc., etc]], {n, 1,5}]the middle cell marker on the righthand side of the notebook alsoincludes the input command?The reason that this is important for me is that I am doing ananimation; and after the animation I would like to delete all thegraphic images; but when I use Show[Graphics[ this would mean deletingthe input command as well.Could someone explain this to me and also make a suggestion so how Icould use Show[Graphics[ ] and have the middle cell marker *only*encompass the output. ==== > Because it depends on how you get there. For instance,> Limit[(1-x)^(1/x), x->0] gives 1/E, while Limit[(1-x)^(1/x^2), x->0]> gives 0.You are correct. However, that last limit claim is somewhat deceptive.Based on it, one might conclude, incorrectly, that the direction ofapproach to 0 is immaterial. Note that, althoughLimit[(1-x)^(1/x^2), x->0, Direction-> -1] yields 0,Limit[(1-x)^(1/x^2), x->0, Direction-> +1] yields Infinity.Thus, when Mathematica says that Limit[(1-x)^(1/x^2), x->0] is 0, it ismaking a hidden assumption of direction of approach.> In fact, you can construct similar examples in which> 1^Infinity = anything you like.Well, yes, as long as you donÕt like negative values. David> 1^[Infinity] => Indeterminate, unexpected. Naively expected: 1.> For which reason(s) is 1^[Infinity] defined as Indeterminate?-- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service ==== >>Because it depends on how you get there. For instance,>>Limit[(1-x)^(1/x), x->0] gives 1/E, while Limit[(1-x)^(1/x^2), x->0]>>gives 0.> You are correct. However, that last limit claim is somewhat deceptive.> Based on it, one might conclude, incorrectly, that the direction of> approach to 0 is immaterial. Note that, although> Limit[(1-x)^(1/x^2), x->0, Direction-> -1] yields 0,> Limit[(1-x)^(1/x^2), x->0, Direction-> +1] yields Infinity.> Thus, when Mathematica says that Limit[(1-x)^(1/x^2), x->0] is 0, it is> making a hidden assumption of direction of approach.Actually it seems youÕve discovered a bug in Limit. If we allow complex values, then Limit[(1-x)^(1/x^2), x->0, Direction-> +1] should be 0, which is evident from the graph of Abs[(1-x)^(1/x^2)]. Mathematica gives Infinity for Limit[Abs[(1-x)^(1/x^2)], x->0, Direction-> +1] as well. If we donÕt allow complex values, then Limit[(1-x)^(1/x^2), x->0, Direction-> +1] canÕt exist at all (even as Infinity or -Infinity).>>In fact, you can construct similar examples in which>>1^Infinity = anything you like.> Well, yes, as long as you donÕt like negative values.> DavidSome of my favorite numbers are negative, such as (1 + x I)^(I Pi/Log[1 + x I]) = -1Note that this has the form 1^Infinity as x->0.> >1^[Infinity] => Indeterminate, unexpected. Naively expected: 1.>>For which reason(s) is 1^[Infinity] defined as Indeterminate?> ==== Dear members,There is an equivalent of Or (||) to be used with patterns: Alternative (|). I couldnÕt find an equivalent for And (&&) and Not (!). I donÕt know if they donÕt exist, or it is just that I can`t find them.Julio ==== Is there a possibility that Mathematica gives me a function to givenpairs of values?In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And Iwhat like to know the corresponding function (what is in this exampleobviously f[x]=x^2).TIASven ==== Ok, I thank you for your help. The values {1,2},{2,4},{3,9} were only anexample. And the 2 in the first pair should actually be an 1.... Butthis doesnÕt matter since you understood the problem. I also knew theproblem, that I have to give something like a model for thefunction... Unfortunatly, I have no idea, how the function looks like. Ithought, that Matematica is maybe able to compare these values withknown functions (and combinings of them). But it looks like there is noway...Anyway, the real pairs of values are:{{0.5,3.45058},{1,5.3352},{1.5,6.9328},{1.8,7.306},{ 1.9,7.2962},{2,7.2163},{2.5,5.8877},{3,3.7307},{3.4464,2.0000 },{4,0.6928},{5,0.04575}}At first, I thougt that the function is something like the densityfunction of the standard normal distribution... Thus, I tried thefollowing function (and lots of modifications):(a + e*x)(2[Pi] Exp[0.5 (c*x^d + b)^2])Unfortunatly, the result wasnÕt very accurate...I know, that this is not longer a problem a Mathematica, but I justwanted to let you know...Anyway, I thank you all for your help.Sven ==== SvenIt may be obvious to you that 1^2=2 (surely not ?), 2^2=4 and 3^2=9, butto me your pairs look like they were derived from the function f[x]=x+x!(that is Factorial[x], not an x followed by an expression of surprise). But I could not find a Mathematica function to support my argument - orto support yours for that matter.I guess you could try Fit and its related functions ...Mark Westwood> Is there a possibility that Mathematica gives me a function to given> pairs of values?> In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And I> what like to know the corresponding function (what is in this example> obviously f[x]=x^2).> TIA> Sven ==== I have a lot of different files, containing data (already formatted for mathematica) which is supposed to be imported as tables with names derived from the original file name. Problem being: Scan[(StringDrop[#,-4]=Import[#];DeleteFile[#])&,FileNameList ] only gives StringDrop protected..... What I also do not like about the above command is, that the data files are deleted. How can I get what I would like to have?Bettina ==== Does anybody know how to install Postscript Fonts Type 1, using Mathematica 4.2 under Mac OSX 10.1.5?-- Daniel AMIGUET Avenue du L.8eman 59 CH 1005 Lausanne +41 21/728 0730 ==== Not sure what youÕre asking here. Installation of type 1 fonts has nothing to do with Mathematica. You put them in your Library:Fonts folder.A shot in the dark: I have a feeling your difficulty might be related to the FontType option. Open the Option Inspector, show option values for Global, and look under Formatting Options > Font Options > PrivateFontOptions. Change the setting of FontType to Outline.---Selwyn Hollisslhollis@mac.com> Does anybody know how to install Postscript Fonts Type 1, using > Mathematica 4.2 under Mac OSX 10.1.5? ==== Dear members,For long calculations, sometimes a message appears, telling the program is out of disk space. The kernel shuts down.I searched the archives for the list, and found a number of postings on this issue, but none of them solved my problem.I have 1.7 G of free space in my internal hard disk, but also have 22 G free in my Buslink USB external hard drive. I would like to use this space for the calculations.In Windows98 (control panel, system, performance, advanced, virtual memory) there is an option to use this space, but it seems like its either internal disk or external disk. I didnÕt dare to change it to the external disk, because I received a scary message from W98 (you may not be able to restart your computer).If I change the settings, will I be able to restart the PC? Is there a way to use both disks succesively? Is there a way to use the external one, but without restarting the computer? Is it possible to do this directly from Mathematica?Julio ==== Why does Mod[3.5,0.1] gives 0.1?However,3.5 - 0.1 Quotient[3.5,0.1] gives 0-Souvik ==== I have a problem with DigitQ and letterQ I would like for a string toyeild True when run with DigitQ if the the string looks like this:{1,2} and false if it looks like this:Right now both strings return False because of { , }. So, if therewere anyway to include the charecters {, }, and , into theDigitQ 0-9 list temperarelly that would work, but I am sure there isCharles ==== CharlesDoes Apply[And, Map[DigitQ, list]]do what you want ? Mark Westwood> I have a problem with DigitQ and letterQ I would like for a string to> yeild True when run with DigitQ if the the string looks like this:> {1,2}> and false if it looks like this:> Right now both strings return False because of { , }. So, if there> were anyway to include the charecters {, }, and , into the> DigitQ 0-9 list temperarelly that would work, but I am sure there is> Charles ==== I have been having difficulty using the distribution packages. In apackage I created, I canÕt get the CDF function to evaluate, and IcanÕt figure out the problem. Below I have included a very simple (anduseless) package I created that runs in to the same problem. I wantto use the numerical value of the CDF for a normal distribution. WhenI call TestFunction, this is the output:Global`glibb`Private`CDF[Global`glibb`Private` NormalDistribution[0,1], -1]Global`glibb`Private`CDF[Global`glibb`Private` NormalDistribution[0.,1.], -1.]Calls to CDF return similar outputs in my useful packages. Thepackage I am currently working with was originally written forMathematica 2.0, and I am trying to update it to work with 4.0. I wastold that all the functions were tested thoroughly in the 2.0implementation and worked fine.TEST PACKAGE: file glibb.m---------------------------------------------------- --------BeginPackage[`glibb`, {Statistics`ContinuousDistributions`}]glibb::usage = glibb is a test package.TestFunction::usage = TestFunction[].Begin[`Private`]TestFunction[] := Module[{alpha,alpha2}, alpha = CDF[NormalDistribution[0,1], -1]; Print[alpha]; alpha2 = N[CDF[NormalDistribution[0,1],-1]]; Print[alpha2];]; End[ ]EndPackage[ ]------------------------------------------------------------ -Aaron ==== HereÕs a start:pairs = {{1, 1}, {2, 4}, {3, 9},{4,16}}ClearAll[f, g]g[{a_, b_}] := (f[a] = b)g /@ pairs?? fThat defines f only at the points in your list of ordered pairs.If you want to identify a polynomial (or other) fit, you could use Fit,if you have in mind what the functional form might be. Unfortunately,it might not do what you expect! You can also use Interpolation todefine f on the range of values you have.expr1 = Fit[pairs, {1, x}, x]expr3 = Fit[pairs, {1, x, x^2}, x]expr4 = Fit[pairs, {1, x, x^2, x^3}, x]expr5 = Fit[pairs, {1, x, x^2, x^3, x^4}, x]expr6 = Interpolation[pairs]Plot[Evaluate[# -