8,986 reputation
1640
bio website
location
age
visits member for 2 years, 3 months
seen 14 hours ago

Dec
27
awarded  Nice Answer
Dec
23
answered Refering to global variables inside modules
Dec
17
comment Plotting heat equation in a Manipulate expression
@Ajasja: ... here are two examples with a more appropriate usage of Module which show what I am trying to say: Manipulate[Module[{z}, z = a^2; z], {a, 0, 2}] vs. Module[{y}, Manipulate[y = a^2; y, {a, 0, 2}]]. Interestingly by checking with Names["Global*"]` I found that Manipulate itself does leave behind a mess of new symbols for its own local variables, which I honestly do consider a "dirty" job, especially considering that DynamicModule doesn't show the problem...
Dec
17
comment Plotting heat equation in a Manipulate expression
@Ajasja: while it ist true that Module does create a lot of symbols for the local variables if used inside a Manipulate these usually are temporary and removed after the Module finishes (with the usual exceptions as in your examples). A Manipulate inside a Module will, on the other hand, only generate symbols for the local variables once, but these will always leak if used in the Manipulate and remain existing -- which I think is potentially a larger problem...
Dec
13
comment Detecting a collision in n-body simulation with NDSolve
@Silvia: and for n bodies there would be a possibility for an m-body collision with 2<=m<=n. Of course the code I've shown doesn't cover that, but I think it would just mean to provide more sophisticated code for the event-action to cover such cases...
Dec
13
comment Detecting a collision in n-body simulation with NDSolve
@shrx: AFAIK it isn't possible to see the message in the WhenEvent, but I may well be wrong. Even if it would be possible I think waiting for the message to appear wouldn't be a very efficient solution as it might take a lot of very small steps before NDSolve stops. What you could try is to check the step size yourself and react to a small step size in the WhenEvent, probably only then checking the distances as well. Maybe you should add it as a requirement to your question that you explicitly want to avoid the calculation of the euclidian distance.
Dec
12
revised Detecting a collision in n-body simulation with NDSolve
added 464 characters in body
Dec
12
answered Detecting a collision in n-body simulation with NDSolve
Dec
12
comment Detecting a collision in n-body simulation with NDSolve
I think you just can't use the message that NDSolve issues as an event trigger. Presumably the message is only generated after the integration has stopped for that reason. What I'd do is to check for the actual minimal distance between all bodies and if that is smaller than their extents that means collision. This will also be faster as it avoids the very small step sizes which lead to the message...
Dec
7
comment Trouble avoiding computation in DynamicModule when input field is not defined
I agree that this is a duplicate, but the issue seems to be the wrong use of Dynamic, the code will do what is expected when using Dynamic[foo[symbol]] instead of foo[Dynamic[symbol]] and that isn't explained in the linked duplicate question IMO. The best answer I could find seems to be John Fultz's to this question, which I think would be a better duplicate link, but probably someone knows a good candidate on ME...
Dec
7
comment Run kernel script in cygwin without window popping up
Actually I think this is not a duplicate, at least not for the question linked: he is trying to run a Kernel from C++ code and that isn't covered by the linked question. It could be argued that this isn't a Mathematica specific question as any command line programm run in a cygwin terminal would have the same issues. @jorgen: I think you should ask that at a cygwin or c++ specific forum, or do you have any indication that this ONLY happens for a Mathematica kernel but not for other command line programs?
Nov
29
answered List comprehension in Mathematica
Nov
28
revised Nested NDSolve with WhenEvent: setting up new equations and discarding old ones
added two additional approaches, one using a loop the other using recurrence
Nov
28
comment Creating a custom context with a Hold construct
No, you need Verbatim for that one (and everything that is used to make up patterns): testit_ /. Verbatim[Pattern][a_, _] :> a. When a combination of both is needed things become a little hard to read :-)
Nov
28
comment Creating a custom context with a Hold construct
Sorry, have had two very busy days. I tried to explain more clearly what I meant (although I'm not confident that I was successful). The use of Context seems to be a really interesting feature, I'll certainly play with that. It seems to be the key to interesting solutions for these kind of problems...
Nov
28
revised Creating a custom context with a Hold construct
tried to explain better the problem of invisibility of existing symbol definitions
Nov
28
comment Nested NDSolve with WhenEvent: setting up new equations and discarding old ones
@saturasl: while it is in principle possible to switch off equations for certains periods of time by changing their coefficients so that they become trivial (e.g. x'[t]==0) using the WhenEvent mechanism I also think that there are cases where things become easier and probably more efficient if one restarts NDSolve. I would usually use a normal loop for such cases, where the start condition are determined from the last state of the previous run. I'll probably post code for that when I find a little spare time...
Nov
26
answered Nested NDSolve with WhenEvent: setting up new equations and discarding old ones
Nov
24
comment Nested NDSolve with WhenEvent: setting up new equations and discarding old ones
It's not very hard to write code that does what you want, but why do you think you need to nest these NDSolves? As far as I understand you are just stopping at certain conditions and then run another NDSolve with the final point of the previous as initial conditions, stop that at another condition and so on. No need for a recursion at all. In fact as only a parameter changes in your restarted equations you could handle that within the WhenEvent without even restarting...
Nov
24
comment Creating a custom context with a Hold construct
the reason is that you need to prevent the patterns in your rules from evaluation. You can achieve the same thing with using only one ReplaceAll with this rule: HoldPattern[(s : (Set | SetDelayed))[name_Symbol, what_]] :> s[Evaluate@Symbol[context <> SymbolName@name], what]. | is a shortcut for Alternatives. If you need to match symbols used to build patterns, you might sometimes not only have to use HoldPattern but also Verbatim...