Questions tagged [syntax]
Questions on the correct (or improved) formulation of Mathematica code to achieve particular results. Use this tag (not "symbol") for questions about all those odd @@ /@ # & and _ characters, which are keyboard shortcuts for the Wolfram Language named functions Apply, Map, Slot, Function, and Blank.
1,047 questions
3
votes
0
answers
135
views
Timing inside a compiled function?
I want to have multiple timings inside a compiled code. However, it turns our that AbsoluteTime[] does not work:
...
12
votes
4
answers
559
views
Recursive anonymous functions with |-> notation
We can define anonymous functions like this:
#^2+#+1 &
or like this
x |-> x^2+x+1
When we want to define a recursive ...
0
votes
1
answer
77
views
What is the sense of the {x, xmin, xmax) form when used with NMaximize?
I mainly use the {x,xmin,xmax} form in plotting functions, and I probably assume, if forced to think about it, that it's a hard restriction. Someone recently asked ...
0
votes
0
answers
95
views
Understanding an error message
I was wondering if you could help me with an error message. The message is:
[<<19>>,{<<1>>},{a53,-Infinity,Infinity}]is incomplete; more input is needed.
The expression ...
3
votes
2
answers
245
views
How to code a recursive algorithm to exponentiate $e^{1/e}$ to itself indefinitely and hence show that this sequence converges to $e$?
I seek help coding an algorithm that shows when $e^{1/e}$ is repeatedly raised to itself it will eventually converge to $e$. The context for this post comes from this same question on M.SE:
What ...
2
votes
0
answers
122
views
Most efficient way to store set of numbers and manipulate them
I have a set of pairs of numbers {id, quantity}, which I store in the table tab; id takes discrete values, and ...
2
votes
3
answers
371
views
Why does importing a .dot graph file cause \l and \r to become \n?
When I import a DOT file (or a string in that format) with labels containing the exact characters \\l or \\r, they are displayed ...
0
votes
0
answers
110
views
Alternative to RandomSample?
Consider the following simple routines:
...
0
votes
0
answers
168
views
The most efficient way of working with updating tables: particular routine
I have a large table for which I need to do the following:
Split it into many smaller tables.
For each smaller table, iteratively perform some action. Within each iteration, I have either to (a) ...
2
votes
2
answers
174
views
Returning row's index and row itself after making weighted selection
I have a 2D table tab, each row is {type, weight}. I want to iteratively sample a few rows with probability proportional to <...
2
votes
1
answer
137
views
Cannot evaluate functions defined by derivatives of other functions
I defined a function of two variables H[x, t] in my code, and then attempted to define a second function G[x, t] through the ...
1
vote
0
answers
86
views
Smart simplification of an analytic expression
Consider the following expression:
...
0
votes
0
answers
46
views
How to define custom derivative rules for multiple symbolic fields in a loop without copy‐pasting?
Consider this code defining the "fields" field and their "derivatives" dfield for some list ...
2
votes
2
answers
335
views
Replacing complex numbers in expressions [duplicate]
Consider the following expression:
expr = -((I G8 d\[Eta]pr[x, \[Mu]]^2 K0[x] f\[Pi])/Sqrt[2]) + (
I G8 d\[Pi]0[x, \[Mu]]^2 K0[x] f\[Pi])/Sqrt[2]
I want to ...
0
votes
0
answers
134
views
Syntax error "Has no closing"
In this code
...
2
votes
2
answers
312
views
Map /@ with two arguments in which the first argument depends on the second argument
I have a question regarding the syntax of the /@ command.
I start with some list, say testlist = {{a, b}, {c, d}, {e, f}}. I also have a function ...
2
votes
1
answer
123
views
The arrow inside string [closed]
In Mathematica, if using ->, it gets automatically replaced with a nicely looking arrow. However, if using "->", ...
1
vote
0
answers
181
views
ParallelMap vs ParallelTable: issues and performance for Mathematica 13.2 vs 14.1
Consider the following test code:
...
5
votes
1
answer
144
views
Different speed of RandomInteger depending on syntax?
Consider the two commands:
RandomInteger[3, 10^7]; // RepeatedTiming
RandomInteger[{1, 3}, 10^7]; // RepeatedTiming
The first executes by a factor of 3 faster than ...
2
votes
1
answer
139
views
Can I make missing semicolons in Module more obvious in the front end?
I use Module a lot to localize symbols. Occasionally I will forget a semicolon on one of the lines in the middle, and don't notice until I get flooded with Tag ...
0
votes
2
answers
112
views
How to make the specific filling in the plot
Consider the following curves:
...
1
vote
0
answers
44
views
How to inactivate Print when launching a notebook from another notebook? [duplicate]
I am launching a notebook from another notebook:
NotebookEvaluate[
FileNameJoin[{NotebookDirectory[], "path-to-notebook"}]]];
The latter contains ...
3
votes
1
answer
154
views
Cursor caret symbol or red curly brackets in the code
There are situations that the caret cursor symbol ^ remains in the code like if the code is not finished and something has to be added in its position yet the code ...
0
votes
0
answers
63
views
How to align the colors of contours and legend bar in ContourPlot
Consider the following plot:
...
1
vote
1
answer
82
views
1
vote
1
answer
68
views
Alert in Resource Definition Notebook for Packet
I recently discovered the "Resource Definition Notebook" which helps considerably with the development of paclets. It enables you to check the coding of the various files associated and also ...
1
vote
0
answers
166
views
How to use the tedious definitional results to make a next definition for FindRoot?
I am trying to use a designed function to find the quasi-normal modes.
...
0
votes
0
answers
74
views
Weird problem with ParallelTable: assigning variables does not work
Consider the following three codes:
...
4
votes
5
answers
732
views
How can I check whether a long rational expression contains a minus?
I have some monster expressions, but for simplicity, consider
m = -(-3 + a+3 b-5 c)/(-d -5);
How can I check if "undisplayable" expressions contain ...
4
votes
1
answer
182
views
How to convert the legend bar to scientific form? [duplicate]
Consider the following data and corresponding ListDensityPlot:
...
2
votes
3
answers
406
views
Styling histograms
Consider this code:
...
1
vote
2
answers
123
views
How to find the nearest point using RegionNearest for this case?
Consider the following region:
...
6
votes
3
answers
324
views
Composition of vectorvalued functions
Suppose I have two functions $f,g:\mathbb{R}^2 \to \mathbb{R}^2$ and that I want to compute $g(f(x,y))$. As an example, let's take $f(x,y)=(x+y, x-y)$ and $g(x,y)=(y^2,x^2)$. Then, $g(f(1,2))=(1,9)$.
...
1
vote
1
answer
124
views
How to solve the following system?
Consider the system
...
1
vote
2
answers
155
views
How to transform a list in the following way?
Consider the following list:
...
3
votes
1
answer
187
views
Nested integration of the list of functions returns error
I have a list of expressions which I would like to integrate by nested integration. For any element from the list it works without issues (see end of the post), however, when I apply nested ...
0
votes
0
answers
96
views
NIntegrate: variable is not a valid limit of integration
I have a function $F(z_h)$ given by,
$$F(z_h) = \int^{\infty}_{z_h} s(y) T'(y) dy$$
where $T \equiv T(z_h), T' \equiv T'(z_h), s \equiv s(z_h)$, which means they're all functions of $z_h$. Their ...
2
votes
1
answer
165
views
Outer function for nested list
I have the following routine where I build a pair of function name lists {Flist, Klist} and 1D argument list {a1,a2,a3,a4,a5}:
<...
1
vote
1
answer
183
views
Define certain argument in functions which depend on several arguments and built in a list
I got confused working with list of functions of two variables.
I construct few lists of functions, one is vector of functions List1 and another is 2D list of ...
2
votes
1
answer
176
views
Expression cannot begin with [duplicate]
What is the problem with the following syntax:
(5^^ # &) /@ {2, 3}
The following error message is produced:
...
5
votes
2
answers
332
views
Syntax error when running file created with Save which contains backslashes
I am doing a nested integration. So far the result was successfully saved with Save["filename.wl", IntOutput] and looked as following:
...
1
vote
1
answer
125
views
Why using compiled code inside compiled code may slow things down?
I made some code that I compiled. The snippet looks as follows:
...
0
votes
1
answer
97
views
Build 2D lists of functions and variables in different combinations
Can someone give examples on how to build 2D Lists of function and expressions by the given vectors? I have the following:
V1={a,b,c}; V2={1,2,3}; V3={x1,x2,x3};
...
0
votes
1
answer
99
views
Syntax regarding Manipulate plot with multiple functions
I am facing the following issue; I have the solution of a ParametricNDSolveValue and would like to plot several solutions with varying parameter in the same Manipulate to see qualitative differences. ...
2
votes
1
answer
192
views
Fast sampling from Fermi-Dirac distribution under specific conditions
This question is a continuation of the following one.
Let us assume a Fermi-Dirac (FD) distribution (times $p^{2}$):
...
1
vote
0
answers
79
views
How to quickly check if compiled code calls MainEvaluate?
Consider the following test compiled code:
...
0
votes
0
answers
33
views
Question about rule syntax/format for CellularAutomaton function [duplicate]
I am trying to understand how to use CellularAutomaton function. For example, I am interested in the Game life and I found a working example here. However I cannot understand or find a detailed ...
4
votes
2
answers
229
views
How to speed up the following algorithm?
I have some random combinations of numbers pairs (where numbers range from 1 to some ntest) ...
6
votes
2
answers
220
views
Is there a system option to make Mathematica generate syntax error when reading code from file which has red syntax warning in frontend?
I type some equations from text books into database, which later read from Mathematica to solve.
Since I do this manually, sometimes I make mistakes where I type ...
0
votes
1
answer
166
views
How to select non-repeating pair of numbers?
Consider the following combinations of integers comb, where the integers range from 1 to n ...