# Search Results

Results tagged with Search options user 12
76 results

Questions about the use of built-in Mathematica functions, including pure functions.

Two possible ways: listfun = {Sin, Cos, Tan}; Through[listfun[Pi]] (* {0, -1, 0} *) #[Pi] & /@ listfun (* {0, -1, 0} *)
answered Jul 8 '16 by Szabolcs
The usual term is connected components. You can use Length@WeaklyConnectedComponents[graph]. This will work on directed graphs as well, assuming that you are looking for the components of the underl …
answered Feb 19 by Szabolcs
Like in all other systems I am familiar with, variable and function definitions exist in memory (RAM) only and do not persist across sessions. If you want a definition to persist, you must save it ex …
answered Mar 15 by Szabolcs
As others mentioned, there's the ND function from the NumericalCalculus` package. It's a bit less widely known that Derivative is also able to approximate derivatives purely numerically. Let's creat …
answered Nov 12 '12 by Szabolcs
While While[procedure; test] works, it looks very similar to While[test, procedure]. The only difference is ; vs ,. While is not the most commonly used construct, so when used like this there's a hi …
answered Mar 18 '14 by Szabolcs
[RandomInteger[10000, 300]]] Implementing functions that localize their arguments Functions like Table, Sum, Plot, FindRoot, NIntegrate, etc. use Block to localize their variable. Here's a possible … useful for modifying existing (or built-in) functions temporarily. Here's an example to illustrate: Print does not have the HoldAll attribute: Print[1 + 1] (* ==> 2 *) We can assign HoldAll to Print …
answered Jan 23 '12 by Szabolcs
several locations or when passed to functions. For more information see Share. Number (2) is what you are asking about in your question. To enable a function to modify its argument in Mathematica, it …
answered Feb 14 '14 by Szabolcs
in practice. It only makes sense to use this if you have some sort of requirement to only use documented functions. If you do this, do not forget to also provide a nice OutputForm, which will be …
answered Nov 19 '15 by Szabolcs
Because the latter is equivalent to {1,2,3,4,5}[] = 0 which is invalid. The former stays as listCopy[] = 0 You can't change (i.e. assign to) parts of a literal like this. You can chang …
answered Aug 5 '14 by Szabolcs
You need to use Set instead of SetDelayed. Please see here for an explanation of the difference: What is the difference between Set and SetDelayed? First make sure that x has no value assigned. The …
answered Jan 9 '14 by Szabolcs
The simplest solution is to rescale the data. Suppose we have a distance limit of $r_x = 2$ and $r_y = 1$ and a point set data = {{x1,y1}, {x2,y2}, ...} Instead of working with data and these two …
answered Feb 25 '14 by Szabolcs
The problem is that the definition of CirclePlus is not distributed to parallel kernels. You can test this using DistributeDefinitions[CirclePlus] (* {} *) ParallelEvaluate[Print@Definition[CircleP …
answered Sep 6 '17 by Szabolcs
I can see why this is confusing. Plotting functions try to be too smart, and hide the true way in which they handle their colour functions. Plotting functions typically pass multiple values to their … -> myRainbow[#3])& and will result in an error. The typical way to work with colour functions is to define a function which converts a single number (single argument) to a colour, then build a pure …
answered Nov 24 '17 by Szabolcs
If test is a list of numbers, your code works fine: f[x_] := (If[x > 0, x*n1, 0]) test = {1, 2, 3, -1}; f /@ test (* {n1, 2 n1, 3 n1, 0} *) If you import test from an Excel file, Mathematica migh …
answered Jan 15 '16 by Szabolcs
Use Apply. The following will work: func @@@ list Example: In:= f @@ {1, 2, 3} Out= f[1, 2, 3] In:= f @@@ {{1, 2, 3}, {4, 5, 6}} Out= {f[1, 2, 3], f[4, 5, 6]}
answered Mar 18 '15 by Szabolcs

15 30 50 per page