Tag Info

Hot answers tagged

6

I believe the simplest change to your code is to replace the Return[$Failed] expressions with Sets that restore the default values of the options: ClearAll[func] Options[func] = {Method -> Automatic, WorkingPrecision -> MachinePrecision, Order -> 2}; func::badval = "`1` is not a valid value of option `2`"; func[arg1_, arg2_, opts : ...


6

It may suit your purpose to use the Windows API function IsUserAnAdmin. It can be accessed through NETLink like this: Needs["NETLink`"] isUserAnAdmin = DefineDLLFunction["IsUserAnAdmin", "shell32.dll", "bool", {}]; isUserAnAdmin[] (* True if Mathematica was launched elevated, False otherwise *) It is also possible to to use the shell command whoami to ...


5

Following belisarius's interpretation of your question, and if the total number of terms is not too large, I might write: Total /@ (1.0/GroupBy[Array[Sqrt, 2003], IntegerQ]) <|True -> 4.37273, False -> 83.6879|> Another formulation: fn[x_Integer] := {1.0/x, 0}; fn[x_] := {0, 1.0/x} Sum[fn @ Sqrt[k], {k, 1, 2003}] {4.37273, 83.6879} ...


5

list1 = {a, b, c, d}; Rest[FoldList[Times, 1, list1]] Scan[Print, %] a a b a b c a b c d


4

You need to define how you expect this special object to interact with functions, and which functions should handle it. Based on your example I think you want the label to be stripped from the object when an operation is performed? You can generally use UpSet or TagSet (or more frequently their Delayed counterparts) to provide handling rules as needed. ...


4

In short: there's no reliable way, so don't bother. Leave it to the users of your function to pass correct arguments to it which are actually functions. I think there was a question about this before, but I can't find it. Why is this not possible? There are many, many very different types of expressions in Mathematica that can act as functions, and ...


4

Misunderstanding Dynamic Although this FAQ is to "focus on non-advanced uses" and Dynamic functionality is arguably advanced it seems simple and is one of the more important pitfalls of which I am aware. I have observed two primary misunderstandings which may be countered in two statements: It does not provide continuous independent evaluation; it works ...


4

I haven't followed your logic carefully, but you probably want something like Fcoord[coord : {_?NumericQ, _String}] := Module[{x, y}, If[(Mod[coord[[1]], 30]) != 0, y = (Quotient[coord[[1]], 30] + 1)*100; x = Mod[coord[[1]], 30]*100, y = (Quotient[coord[[1]], 30])*100; x = 3000.]; Switch[coord[[2]], "I", { x, y}, "II", {-x, y}, ...


4

I am going to demonstrate this with a smaller matrix to enable us to more readily view the results. A0 = Table[Subscript[a, i, j], {i, 8}, {j, 8}]; A0//MatrixForm Step 1. Partition A0 into 4x4 blocks A0byBlock = Partition[A0, {4, 4}]; A0byBlock // MatrixForm Step 2. Map f onto A0 at level 2 A0out = Map[f, A0byBlock, {2}]; A0out // MatrixForm ...


3

My comment in Manipulate form: func = {x^2 + x y + y^2}; Manipulate[ D[func, variable], {variable, {x, y}} ] The control that Manipulate uses is the SetterBar[Dynamic[variable], {x, y}] of my comment.


3

Your problem is the Set. Set means you're assigning something to a variable (=), x2 Sin[x2] is not a variable. Try Equal[] instead, this is equivalent to ==. Vars = {{(x1) Cos[x2], Sin[x2], 0, (x3) (Sin[x2])}, {(Cos[x2]) (Sin[x4]), (x3) Cos[x4], 1, x1}}; Const = {{1, 0, 0, 1}, {0, 1, 1, 2}}; MapThread[Equal, {Vars, Const}, 2] yields the output: {{x1 ...


3

My version of Bob Hanlon's comment solution: list1 = {a, b, c, d}; FoldList[Times, list1] % // Column {a, a b, a b c, a b c d} a a b a b c a b c d Reference: Shorter syntax for Fold and FoldList?


3

You can also use Accumulate list1 = {a, b, c, d}; Times @@@ Accumulate[list1] (* or Accumulate[list1] /. Plus -> Times *) {a, a b, a b c, a b c d} ... or ReplaceList: ReplaceList[list1, {x__, ___} :> Times[x]] {a, a b, a b c, a b c d}


3

I think that in the simplification of your sum, Mathematica is assuming that $n - k + 1\geq1$. But that is not true, if you include a Sow: f[k_, n_] := Sum[2*(1 +Sum[Sow[{n - k + 1}]; f[k - j, n - m - j], {j, 1, k - 1}]), {m,1, n - k + 1}] Then the issue probably starts at $n=4$, as that includes a negative endpoint. Reap[f[4, n]] /. m -> (n - 4 + ...


2

I was able to generate one instance (the all-zeros solution) but FindInstance refuses to generate 2 or more for me (v10.1) using the final argument, despite copious solutions existing. Horrible hack incoming in 3... 2... 1: (* N.B I removed your greek and the sphere constraint is now `Ball`. If you only want the surface of the sphere, then `Sphere` is ...


2

Sum[If[IntegerQ[#], {1, 0}, {0, 1}]*1/# &@Sqrt[k], {k, 1, 2003}] // N or Sum[If[# ∈ Rationals, {1, 0}, {0, 1}]*# &[1/Sqrt[k]], {k, 1, 2003}] // N both return {4.37273, 83.6879}


1

This should produce the desired dialog loop pdGUIstyled[func_, outputList_: {}] := Setting@DynamicModule[{variable}, Module[{symboles = Cases[func, _Symbol, Infinity] // DeleteDuplicates, lastRes}, lastRes = DialogInput[ Column[{ Row[{"the function is: ", Panel[func, Background -> White]}], "", Row[{"the current list of ...


1

ContinuousMarkovProcess provides a general mechanism for creating a Markovian (i.e. memoryless) random process with continuous index (e.g. time) and countably finite states. A Poisson process has countably infinite states, so you can't quite get there from here. You can specify alot of states to study the process before it hits some maximum. Your two ...



Only top voted, non community-wiki answers of a minimum length are eligible