# Questions tagged [syntax]

Questions on correct (or improved) formulation of Mathematica code to achieve particular results. Use this tag (not "symbol") for questions about all those odd @@ /@ # & and ~ characters.

742 questions
Filter by
Sorted by
Tagged with
838 views

### Functions that remember their values

Can someone explain what is going on with the following ... func[y_] := func[y] = (Print["Hello world !!!"];) func Hello world !!! ...
2k views

### More than one expression in the Table[] command?

I would like to construct a Matrix using the Table[] command. The issue is that I would like to use more than one expression for it. What I need to obtain is something like this : ...
811 views

### How can I compare the previous value and the current value implemented during NestWhileList?

I am trying to write a part of my code. I am using NestWhileList. However, I couldn't find out the right syntax for testing. It should compare previous result and current result and continue if it is ...
390 views

### Syntax error: newline character interpreted as multiplication

I'm getting this error in Wolfram Workbench, and I don't know where it comes from: "Syntax error: newline character interpreted as multiplication" This error happens around an If[] function, in a ...
2k views

### Problem with Fourier coefficients

I have just started using Mathematica with v9.0. I am trying to follow a computation from a book on Fourier series with the function $f(x)=x$ on the interval $-\pi < x < \pi$. Here is the code ...
923 views

...
1k views

### Using Transpose with a list as the second argument

I'm having difficulty understanding the Transpose function. I know what the transpose of a matrix is, not a problem, and I see that applying the ...
234 views

### Syntax colouring when using Symbolize

I need to use symbols with suffixes in order to make my code readable in relation to the Eurocodes. To do this I use Symbolize from the ...
228 views

### Remove failed Solve[] attempts

I can't figure how to replace a failed evaluation with a null value. I am very new to Mathematica. I have an equation that are being processed using the Solve[] ...
129 views

### Force ellipsis to print an end of an expression

For pedantic reasons I want to display an infinite sum of fractions in fractional form (i.e. as 1/x not as x^(-1)) with an ellipsis at the end of the expression. I have tried a number of ways and ...
157 views

### Working of Date[]

Date[] returns the current date of local system, Date returns {2012, 11, 15, 17, 41, 0.3161629}, ...
302 views

### Difference between Map[f[#] + g[#] &, {a, b, c}] and Map[f[x]+g[x]&, {a, b, c}]

Map[f[#] + g[#] &, {a, b, c}] vs Map[f[x]+g[x]&, {a, b, c}] My question is: why is the output different? ...
217 views

### Why can't I use Sequence to perform a Select like task? [duplicate]

Suppose I wanted to write down a list of $p^2$, for $p$ a prime between $1$ and $20$. I would expect Table[If[PrimeQ[k], k^2, Sequence[]], {k, 1, 20}] to work. ...
215 views

511 views

### How to generalize a formula?

This is a piece of my code: ...
174 views

### Setting a binary operator Flat

I defined a binary operator in as the first statement in a new Mathematica notebook. {x1_, y1_} ⊕ {x2_, y2_} := Module[{}, Print["do anything"];] where the code ...
429 views

### local variable naming & symbolic argument

I'm stuck here with my variable assignment in this scenario ...
959 views

### Parentheses in pure functions: # & vs. ( # &)

I've been using Mathematica for years, and over time I have developed the habit of using: Select[data, (# == 1 &)] instead of ...
34k views

### How do I identify the source of a “Tag times protected” error?

I have some code that looks like Table[ a = 1; b = {2, 3} c = i;, {i, 2} ] which gives an error: Set::write: Tag Times in c {2,3} is Protected....
7k views

### Superscript prime symbol

x\[Prime] looks like $x_{'}$, ugly right? Is there a way to make a symbol with prime to look like $x'$? That's what I'm trying right now: ...
2k views

### how to read in a file in the same directory?

Now I am writing a small package. I have written several files and put them in the same directory. And some files need to read in or include another file in the same directory. But when I simply write ...
282 views

### How to insert an expression in a Mathematica program?

I need to insert a very large expression in a Mathematica program. So I first Put[large expression,"file"] and then use Block[{}, Get["file"];...] to ...
1k views

### Several functions in one RegionPlot with different grayscale

I try to plot the following, but something seems to be wrong in my code and I can't figure out how to fix it: ...
1k views

### Why is Euler's number an uppercase “E” and not a lowercase “e”?

Why is Euler's number an uppercase "E" and not a lowercase "e"? Isn't Euler's Number normally expressed with a lowercase "e"?
245 views

### How do I interpret the following syntax?

I have been given some code with the following line PeriodicExtension[g_, x_] := If[Abs[x] < Pi, g[x], PeriodicExtension[g, x - 2 Sign[x] Pi]] I do not ...
215 views

### How can I specify a numerical order for variables?

I need to specify that a variable is less than another, and greater than yet another, in a Mathematica program, because I will later apply a test to them that will determine what functional form to ...
338 views

### Upon opening my notebook, I must evaluate cell for code to work properly

I am new to Mathematica. Once I evaluate the cell containing the code, my Manipulate works as desired; however, if I open the file and do not evaluate the cell, the Manipulate goes haywire. Can ...
6k views

### What is the difference between Set and SetDelayed?

I have a problem with defining a function and most of time I get confused by Set or = and ...
2k views

### Code Readability and Object-Oriented Code

The basic problem I have been running into is making readable code, where in other languages I am more familiar with I might have been using class or struct like objects. For example, you can imagine ...
792 views

### Extracting parts of nested lists of rules using a syntax similar to JsonPath or Xpath

Given an example data set: ...
327 views

### Internal Representation of ?name and ??name

Code FullForm[Hold[?name]] Syntax::bktmcp: Expression "Hold[?name]]" has no closing "]". Syntax::sntxi: Incomplete expression; more input is needed . Question ...
3k views

### Why does Mathematica use [[ ]] notation for array indexing?

I am confused by why Mathematica uses [] to get the 3rd element, or [[i,j] to get the i,j-th element of a 2D array. This ...
965 views

### Is it possible to make the Button execute two or more actions?

According to the help: Button[label,action] Is it possible to make the button execute two actions?
361 views

### Can I use Table without the appropriate bounds?

I'd like to use the Table command without defining n, so that I can have a list of n ...
2k views

### Output of plots from within Do[ ] Command

I am wondering why the following does not plot the way it's written and exactly how does the Do[] function operate? I think I could be using it incorrectly. ...
672 views

### Is it possible to insert arguments into functions when they're used like Function@ or //Function?

Is it possible to insert arguments into functions when they're used like Function@ or //Function? Sometimes I need to do this, but then I have to return to the standard function usage: Function[] ...
1k views

### Calling Table with custom iterator

I often find myself in situations where I, for example, need to build a table for some expression, but want to set the number of points rather then the step size, so the code ends up looking like this ...
2k views

### can the color in MeshStyle be specified by a ColorFunction, such as “SunsetColors” for example. If so, what is the correct syntax?

This is an example given in Help: Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, MeshStyle -> Gray] Could this be changed to something like ...
1k views

### Using the result of Solve in subsequent calculations

I'd like to know how to use the results of Solve in later calculations. Here's what I'm doing now: This is my expression ...
2k views

### Indices and variable definitions in Mathematica

Does anyone know how I can do this in Mathematica? Just an example.. Defining indices and variables (defined over indices), "mapping" variables and indices: ...
2k views

### How can one define an infix operator with an arbitrary unicode character?

You can setup "UsefulFunction[a, b]" to use custom infix notation "a ↔ b" as follows: ...
1k views

### Prefix operator with low precedence

The question is simple, but I will elaborate on the background as well for those interested in the idea: How to define a new operator with specified precedence value? Background Mathematica was ...
255 views

### What is an alternative to using backticks in separating namespaces from function names?

What is an alternative to the backtick () in separating the namespace from the function name? Can the function be called without using this symbol? I think in ...
226 views

### “A number in base b” and pure functions: why doesn't b^^# & work?

Why do the following not work (in Mathematica 7)? 2^^ # & /@ {1000, 1101} and 2^^ # & @ 1101 This does work: <...
5k views

### Using D to find a symbolic derivative

I need to do the following: Define a function Take the derivative of this function and have a look at the symoblic representation Substitute in some values With the bonus that I want to use the ...
1k views

### Syntax for prefix mode with multiple arguments using @ shorthand

Is it possible to use the @ symbol with multiple arguments? The Prefix command suggested not. If so, why?
11k views

### Mapping multiple parameters of a function to specific values

I am a little bit confused by the documentation for Apply (@@). I want to define a list of parameters, for instance: ...
326 views

### Finding the position of a specific value in a list

Is it possible to easily find the position of a specific value in a list? For example, if the list is {{x1,y1},{x2,y2},...,{xn,yn}} I would like to know the ...