Skip to main content
29 votes
Accepted

Visualizing gravity warping the fabric of spacetime

Here my physicist approach to the problem: I consider a cloud/grid of test-particles which get attracted to a reference point by a force. In the following I assume attraction by gravity -- i.e. the ...
N0va's user avatar
  • 3,410
23 votes
Accepted

Mapping function across its arguments

Tuples[expr, 1] (* {f[a], f[b], f[c]} *)
Karl's user avatar
  • 941
14 votes

C++' "do ... while" loop equivalent in Mathematica

Version 13.1 introduced the function Until Until[test,body] evaluates body and then test, repetitively, until test first gives True.
Jason B.'s user avatar
  • 69k
12 votes

Mapping function across its arguments

Using Subsets: expr = f[a, b, c]; Subsets[expr, {1}] (*{f[a], f[b], f[c]}*) Or using ...
E. Chan-López's user avatar
11 votes
Accepted

Apply a function row- and columnwise

If we change dt to: ...
Michael E2's user avatar
  • 238k
11 votes
Accepted

Curve shortening flow

This is roughly the algorithm in the link. Like it says there, it's potentially numerically unstable. The funny curlicue example in the OP was not provided, so I can't check that. In fact, most of the ...
Goofy's user avatar
  • 3,405
11 votes

Mapping function across its arguments

Operate[Map[#]@*List &, expr]
lericr's user avatar
  • 30.3k
11 votes
Accepted

Why doesn't b = a; f[a_] := b; f[2] return 2?

Caution The post is long. If you just want to know how to fix the code, please search "fix the code in title in 10 ways" in the page. If you want to read discussions about global/local ...
xzczd's user avatar
  • 67k
10 votes
Accepted

How can I change elements in a matrix to a combination of other elements?

A simple way would be to define a function to transform a single triple: transform[{x_, y_, z_}] := {x + Cos[z/x], y, z - Sin[z/x]} and then map it over your list: ...
lericr's user avatar
  • 30.3k
10 votes

How can I change elements in a matrix to a combination of other elements?

...
user1066's user avatar
  • 20.3k
9 votes

Mapping function across its arguments

Some alternatives: f[a, b, c] // #[[0]] /@ Level[#, 1] & (* {f[a], f[b], f[c]} *) f[a, b, c] // #[[0]] /@ List @@ # & (* {f[a], f[b], f[c]} *) Sharper, ...
Goofy's user avatar
  • 3,405
9 votes

Create n random points on [0,1] with minimum distance

If you want to generate independent random samples under the stated restrictions and $s<1/(n+1)$, then consider the following: ...
JimB's user avatar
  • 41.9k
9 votes
Accepted

Functions, Speed, and Evaluate[]

It's the automatic simplification of the expression that spends the additional time. Compare the following two definitions of a function: ...
Domen's user avatar
  • 27.4k
9 votes
Accepted

Can Mathematica return the closed forms of 'arbitrary' function compositions?

...
Bob Hanlon's user avatar
  • 160k
8 votes
Accepted

Trick to apply function on a variable and store output in the same variable

Yes, there is ApplyTo with a shorthand notation //=. var //= AnyFunction
Domen's user avatar
  • 27.4k
8 votes

How can I change elements in a matrix to a combination of other elements?

Equivalent to @lericr`s answer except a pure function is used rather than defining a helper function ...
Bob Hanlon's user avatar
  • 160k
8 votes

How can I change elements in a matrix to a combination of other elements?

Another way using Cases: ...
E. Chan-López's user avatar
8 votes

Mapping function across its arguments

expr[[0]]/@{Delete[0][expr]} (* {f[a],f[b],f[c]} *) or ...
user1066's user avatar
  • 20.3k
8 votes

Mapping function across its arguments

expr = f[a, b, c]; Using BlockMap BlockMap[# &, expr, 1] Using ...
vindobona's user avatar
  • 4,961
8 votes

Create n random points on [0,1] with minimum distance

Thanks to the comment from Izaak van Dongen, it can be solved with straightly : umd[n_, s_] := Sort[RandomReal[{0, 1 - (n + 1) s}, n]] + s Range[n]; Pick ...
imida k's user avatar
  • 4,315
8 votes
Accepted

How to use || as a function name and apply it to calculate the equivalent resistance of parallel resistors as we typically write?

It won't work with || for reasons described in the comments. However, you can use a unicode character or ...
flinty's user avatar
  • 25.6k
7 votes

Module that finds the sum of digits of any given positive integer

Mathematical v14.0 introduced DigitSum. For example: DigitSum[2525] (* 14 *) DigitSum ...
creidhne's user avatar
  • 5,235
7 votes

Visualizing gravity warping the fabric of spacetime

Related posts:In general relativity vizualizations what are the equations of grids? How exactly does curved space-time describe the force of gravity? Solving the physics equation makes the problem ...
miss's user avatar
  • 874
7 votes
Accepted

Evaluation control in function definition: Total interferes with Evaluate

...
Bob Hanlon's user avatar
  • 160k
7 votes

Plotting multiple parametric 3D curves without using the Show command

To get different colors automatically for a plot, the idea is to do this data=.... (*generate list of data*) Plot[Evaluate[data],.....] What you did is generate ...
Nasser's user avatar
  • 146k
7 votes

How to stop mapping on true results for large lists?

The AllTrue function will short circuit. AllTrue[list, EvenQ] But I may have misunderstood, because you said you want short-...
lericr's user avatar
  • 30.3k
7 votes

How to stop mapping on true results for large lists?

You can use AnyTrue. AnyTrue short-circuits on first True result and returns ...
Edmund's user avatar
  • 42.4k
7 votes

Given two functions, generate all nested applications of the functions to a given order

First level a = {f[x], g[x]}; Second level b = Flatten @ Transpose @ Query[All, {f, g}] @ a {f[f[x]], f[g[x]], g[f[x]], g[g[x]...
eldo's user avatar
  • 78.8k
7 votes
Accepted

Given two functions, generate all nested applications of the functions to a given order

Using Composition: ...
Syed's user avatar
  • 55.7k
7 votes

Reverse association and map through its values/keys

AssociationMap[Thread[#, List, 1] & @* Reverse] @ asoc ...
kglr's user avatar
  • 398k

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