15
votes
Accepted
Association vs Pair - Creation performance, Selection performance
Simply use
keys = Range[1000000];
vals = Range[1000000]^2;
result = Pick[vals, PrimeQ[keys]];
to get the best of both worlds (zero construction cost and even ...
11
votes
Accepted
11
votes
How can I use variables instead of slots in DeleteCases?
Pick could also be useful:
Pick[tuples, Function[{a, b, c}, a + 2 b + c == 0] @@@ tuples, False]
11
votes
How can I apply a function only to even-index elements of a list?
I changed D to Dd:
MapAt[Dd, A, 2 ;; ;; 2]
11
votes
Accepted
Why does this Fourier transform not match the formula?
I think the confusion is between frequency in cycles per second or Hz and frequency in radians per second. In the page you link to the frequency is in Hz. Thus to match this convention the ...
10
votes
How can I apply a function only to even-index elements of a list?
You can use the new ApplyTo:
A = {1, 2, 3, 4, 5};
Dd[P_] := P + 1
A[[2 ;; ;; 2]] //= Dd;
A
(* {1, 3, 3, 5, 5} *)
9
votes
Find shortest distance between two functions
Assuming that you mean the shortest distance between their graphs, the following does the job.
...
9
votes
Accepted
How to use PlusMinus properly?
Per the documentation, you could define the function for PlusMinus:
...
8
votes
How can I apply a function only to even-index elements of a list?
alist = {1, 2, 3, 4, 5}
Using MapIndexed:
...
8
votes
How can I use variables instead of slots in DeleteCases?
g[{a_, b_, c_}] := a + 2 b + c == 0
Using the operator form:
DeleteCases[x_ /; g[x]][tuples]
8
votes
How can I use variables instead of slots in DeleteCases?
Perhaps (Thanks to comment/correction @BenIzd )
DeleteCases[tuples, _?(Apply@Function[{a, b, c}, a + 2 b + c == 0])]
is what you are looking for?
6
votes
Accepted
While inside a function body does not work as expected
You may wish to disambiguate your description as it seems you're creating rational functions made up of polynomials. Below I modularized CreateDiscontinuityPoly ...
6
votes
How to simplify function with Abs?
Try this:
Refine[Simplify[mylist], Assumptions -> x \[Element] Reals]
6
votes
6
votes
How can I apply a function only to even-index elements of a list?
SubsetMap[dd, arr, 2 ;; -1 ;; 2]
(* {1, 3, 3, 5, 5} *)
where:
arr = {1, 2, 3, 4, 5};
dd[p_] := p + 1
Just for fun
...
6
votes
Accepted
How to simplify function with Abs?
PiecewiseExpand does it.
Edit and // ComplexExpand // Simplify does it
...
6
votes
Why Mathematica does not return explicit output
You need to be careful about the precedence of each operation. Here's your original:
A = ({{a11, a12}, {a21, a22}}) // Transpose[A] // MatrixForm
Here is how the ...
6
votes
Accepted
Introduce formal symbols indexed by natural numbers
It is often useful to avoid Subscript, Superscript, and Subsuperscript and instead to just ...
5
votes
How to simplify function with Abs?
Here's the ComplexityFunction way I referred to in my comment just to illustrate the alternative:
...
5
votes
Find shortest distance between two functions
Assuming that you mean by "shortest distance" the x value and y values where both functions differ by a minimal amount. In this case the distance is given by the difference of the two ...
5
votes
Accepted
Classifying elements, by the value of a fixed function, using Replace
L = Table[ConstantArray[1, RandomInteger[999]], 100000];
m = Replace[L, {x_List :> Quotient[Length@x, 100]}, {1}];
$$\{7,2,8,8,6,5,1,5,2,1,1,3,6,7,2,4,7,2,1,8,...
5
votes
Accepted
Replacement, PatternTest, Module related Question
The reason your attempt fails is that at the time the Function is applied to its arguments, m has not yet been replaced by ...
5
votes
Accepted
Tropical Operation Conversions: Multiple Operations
I assume that you want to replace Addition by "Max" and Multiplication by addition. It is not clear how a negative term should be treated. For the time being I assume that it will be ...
4
votes
Accepted
Module returns multiple functions
The correct syntax is:
prep[p1_, p2_] := Module[{},
f1[x_, y_] := (p1 + p2)*x + y;
f2[x_, y_] := (p1 - p2)*x - y;
{f1, f2}];
Then:
...
4
votes
Accepted
How to get a function from a string?
Welcome to the community.
With little generalization (be applied to any variable name), Here is how you can achieve your goal:
Since Function has ...
4
votes
Tropical Operation Conversions: Multiple Operations
I'm not entirely sure if this is what you're looking for, but it seems you would just need to replace your x_ with x__
...
3
votes
Accepted
RunProcess : Save directly to Mathematica Variable
It might be possible to do what you say, if myprogram.exe can output the image data directly to stdout. But I wouldn't lose any sleep over having to create a ...
3
votes
3
votes
3
votes
Find global maximum of InterpolatingFunction in interval but not maximum value
Here is an example.
data = Table[{x, Exp[x]*Sin[2*x] + 1}, {x, 0, 10, 0.2}];
ListPlot[data, PlotRange -> All]
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
functions × 3309function-construction × 440
plotting × 365
list-manipulation × 354
calculus-and-analysis × 196
equation-solving × 175
evaluation × 125
matrix × 111
programming × 105
performance-tuning × 86
syntax × 79
differential-equations × 70
replacement × 68
variable-definitions × 67
simplifying-expressions × 66
functional-style × 65
graphics × 63
complex × 62
pattern-matching × 59
numerical-integration × 58
core-language × 58
numerics × 56
symbolic × 56
probability-or-statistics × 55
table × 52