Tag Info

New answers tagged

0

My concerns have been mostly addressed here. The correct answer that works is given by: colorQ = Quiet @ Check[Blend @ {#, Red}; True, False] &; which can be implement in either of the following methods: colorQ /@ {Red,Hue[0.5],GrayLevel[0.5],CMYKColor[0,1,1,1/2],Opacity[0.5,Purple],blah} {True, True, True, True, True, False} colorQ[Red] True


1

You have to use SameQ (===): test[lcolor_: Red] := Module[{}, Red === lcolor] test /@ {RGBColor[1, 0, 0], Red, Blue} {True, True, False} For a full explanation read the Details sections for Equal and SameQ


1

You can do it like this, but your system is Stiff: p[t] = {p1[t], p2[t]}; p'[t] = {p1'[t], p2'[t]}; A[t_] = {{p1[t], 1}, {1, p2[t]}}; NDSolve[Flatten@{Thread[p'[t] == A[t].p[t]], Thread[p[t] == {1, 0}] /. t -> 0}, {p1, p2}, {t, 0, 1}] NDSolve::ndsz: At t == 0.9040861047003397`, step size is effectively zero; singularity or stiff ...


4

I suggest that you use local rules for your fixed values. Then, the following seems to do what you ask for: ClearAll[dotQ, init, vars]; dotQ[s_String, MSymbol_Symbol] := StringMatchQ[s, ToString[MSymbol] ~~ LetterCharacter]; vars[MSymbol_] := Select[Not@*(dotQ[#, MSymbol] &)@*ToString]@*Variables; init[expr_, MSymbol_Symbol] := Thread[#, Hold] ...


1

Based on comments, I came to the following approach: DynamicModule[ {nn, tn, dist, dataAll, data, dx, func, wave, f}, ColumnForm[{ Button["New data", dataAll = RandomVariate[dist, 2000]; data = Take[dataAll, nn]; func = CalcG1[wave, data, 0, Ceiling[Log2[nn] - Log2[Log2[nn]]]]; f = func[tn]; ], PopupMenu[Dynamic[wave, ...


5

This bug is fixed in V10.0.1.0 but the behavior is different based on evaluation sequence. If both expressions are in a single cell you get the expected empty list: Do[Module[{foo}, foo[x_] := 1; foo[0]], {100}]; Names["foo$*"] {} If they are evaluated one at a time in different cells you get a single foo$ symbol regardless of how many times the Do ...


2

This will probably be closed as a duplicate of either: What are the use cases for different scoping constructs? Passing function as argument In the meantime the simple answer is that you need Module rather than Block, because the former creates a new Symbol whereas the latter merely temporarily changes the value of Symbol. myf = Module[{f}, f[3] = 33; ...


2

When Mathematica parses the definition LocalTestModule[]=Module[{localX, localY}, localX=1; localY=2;] the parser finds the following symbol names: LocalTestModule, Module, localX, localY. While Module is found in the System` context, LocalTestModule, localX and localY are not found, and are therefore created in the current context (which in ...


1

I've simplified your example a bit (the package doesn't seem to be relevant): Module[{localX, localY}, localX = 1; localY = 2;] My expectation is that I should not be able to set the value of the localX variable from the notebook because it is local to LocalTestModule. If it is truly local to LocalTestModule[], it should not be visible outside of ...


0

Are you certain that a and b in the first example are Global? In version 10 they do not appear to be: (The sliders of one Manipulate do not affect those of the other.) A look at the Cell Expression for one of these shows: . . . DynamicModuleBox[{$CellContext`a$$ = -3.3999999999999995`, $CellContext`b$$ = 0.21999999999999997`, . . .] . . . It would ...



Top 50 recent answers are included