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.

learn more… | top users | synonyms

5
votes
3answers
215 views

How to imitate list comprehensions for constant arrays?

In Python, ['a'] * 10 generates ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] and ...
6
votes
2answers
768 views

Evaluating an If condition to yield True/False

I would like to decide whether an option passed to my custom function has the value Automatic or something else. This is my attempt: ...
1
vote
0answers
84 views

How can I solve the 2D Laplace equation with Neumann boundary conditions? [closed]

I would like to solve the following boundary value problem for $u(x,y)$: PDE $\quad \quad \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} = 0$ Domain $\quad \quad 0 \le x \le ...
1
vote
2answers
91 views

How to define a sequence of piecewise functions and then plot them altogether?

The following is the piecewise functions I want to define ${f_k(x)} = \left\{ {\begin{array}{*{20}{c}} {\frac{{j - 1}}{{{2^k}}}}&{\frac{{j - 1}}{{{2^k}}} \le f(x) \le \frac{j}{{{2^k}}}}\\ ...
19
votes
0answers
317 views

A documented syntax of FileNames doesn't work?

Documentation discrepancy present through 10.2 According to the documentation for FileNames under Details: However when I attempt to use this syntax I get an ...
18
votes
0answers
156 views

New AssociationThread forms in 10.2?

Is this another case of "documented" but "not implemented" ? or at least it is not explained clearly as I cannot make it work: Two new forms appears in the new 10.2 doc. of ...
3
votes
0answers
46 views

String option names for Cells

They seem to be correctly interpreted. I'm asking because of some minor reasons and a major one: NotebookWrite a Cell with WholeCellGroupOpener option I don't know any official confirmation so let ...
2
votes
2answers
54 views

Simplify set-theoretic expressions [duplicate]

As I can get set-theoretic simplifications of expressions and corresponding Venn diagram for example ...
1
vote
0answers
40 views

Mathematica Workflow [duplicate]

What methods/tools/tips have you found that dramatically improved your Mathematica workflow? I have a love/hate relationship with Mathematica. It is useful no doubt, but defies my intuition at every ...
47
votes
1answer
1k views

Incompatible Changes since Mathematica Version 7?

There is documentation of the incompatible changes made to Mathematica with each major release: Incompatible Changes since Mathematica Version 1 Unfortunately that documentation simply stopped ...
0
votes
1answer
87 views

How to enter piecewise functions into Mathematica [closed]

I'm trying to enter a piecewise function (named eq30) into Mathematica. However, it seems not to work. The expression I entered is ...
2
votes
2answers
294 views

Writing a function that returns a (usable) function

I am trying to create a function that returns Arnold's Cat Map of size n iterated k times. I can get something out of the Function command, but I can't figure out ...
21
votes
1answer
510 views

Shorter syntax for Fold and FoldList?

I find it tedious to write out the following: a = {1, 2, 3, 4}; Fold[f, First @ a, Rest @ a] f[f[f[1, 2], 3], 4] It ...
17
votes
3answers
1k views

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

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

A question about the syntax [closed]

I have $3$ elementary questions to ask and I thank you in advance. Question N°1. What is the right syntax for $$y\equiv0\pmod {2}$$ in the code below? ...
5
votes
2answers
158 views

How to Write Partition with Infix?

The documentation says that using Infix ~, the following input f[e1,e2,e3,...] can be rewritten as ...
7
votes
0answers
147 views

What is a good way to code long, complex, compilable algorithms?

The functional paradigm of the Wolfram Language used in Mathematica is all around wonderful. For intense numerics, Mathematica comes with the ability to Compile ...
2
votes
2answers
84 views

Using Table with arbitrary number of variables [duplicate]

Let $P=\{p_1,...p_n\}$. I would like a way to implent Table[Expression,{$p_1$,lim},{$p_2$,lim},...,{$p_n$,lim}] where n and lim are parameters defined by the user. Any ideas?
6
votes
1answer
78 views

What is the role of _ in this expression?

I'm fairly familiar with basic Mathematica, but some of its more advanced syntax (especially certain special characters) eludes me. In the Scope section in the documentation of ...
1
vote
1answer
52 views

How to set the values into some variables from different lists [duplicate]

I have a list of Values and a list of variables. I want to set the Values into Variables. Assume the following code: ...
4
votes
1answer
65 views

How to define an expression which is differently evaluated in calculations and printed

Let's say, we have a list: values = {1.2, 0.04, 0.9}; Is it possible to replace 0.04 by some expression, which displays as ...
0
votes
1answer
80 views

Can't get a plot from piecewise parametric function [closed]

I can't seem get a 3D plot from r[t]. Any suggestions? ...
1
vote
1answer
74 views

How to make a StreamPlot with three variables and two expressions

I'm trying to make a StreamPlot in Mathematica with three variables. I already have two variables, x and y, that make an ellipse via StreamPlot[{-y,x}] but I ...
1
vote
2answers
68 views

What is the meaning of Range[10] /. {x_ /; PrimeQ[x] -> x^2}? [closed]

I'm currently doing a unit at university that touched briefly on Mathematica, but the final exam will feature multiple choice questions from Mathematica (along with excel and matlab). This leads to ...
0
votes
1answer
35 views

Testing Conditions in For Loops

I am attempting to create a set of coefficients that satisfy a set of conditions using the Do function and If statements. I did this successfully with a basic set of conditions: ...
2
votes
1answer
63 views

Failure in the use of FullSimplify

My question is about an apparent failure of the function "FullSimplify" to simplify an easy algebraic expression. This is the expression that I ask Mathematica to evaluate: ...
2
votes
1answer
100 views

Mathematica and special functions

How is it possible that Mathematica doesn't recognize it's own definitions of special functions ? I tried as input: ...
-2
votes
1answer
63 views

Sign of a symbolic expression as a function of parameter values

I need to know the sign of the following expression for p[t] = z/(1-a), as a function of the parameters {a, b, c, z}: ...
1
vote
1answer
83 views

How to evaluate sum with different coefficient in each term?

I would like to know if there is a syntax that allows me to enter a sum that has coefficients that vary for every term? I have no interest in evaluating them numerically, but rather to keep them as ...
1
vote
2answers
84 views

Matrix with infinity on main diagonal

The question is trivial, however, there might be unexpected solutions. What would be nice way to create a square matrix with $\infty$ on main diagonal, and some arbitrary constant everywhere else? My ...
2
votes
3answers
782 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. ...
32
votes
5answers
1k views

Why is there no PositionFunction in Mathematica?

Too often I have seen the programs of inexperienced users greatly slowed by using Position in an iterative fashion, when far faster would have been to compute a ...
1
vote
1answer
46 views

GCD of Table entries

This question is from a newbie, so please be gentle in thrashing if I'm missing something very basic. How can I use GCD on a matrix/vector entries stored as Table. For example, if ...
20
votes
5answers
951 views

How do you programatically load data into symbols?

I am trying to convert a list of string names into symbols, which will then be used to store data. I have 24 files (where the name of each file is a member of the list mentioned above) that I need to ...
2
votes
1answer
46 views

how to manipulate indices in a table/vector

Perhaps I'm missing something very basic. Could somebody guide me how to manipulate indices of a list. For example, if I've u = Table[Subscript[u, i], {i, 1, lp + 1}]. I've these u in an expression, ...
0
votes
0answers
42 views

Treating expressions as symbols [duplicate]

I'm trying to do something like this: test = {x, y}; With[{test[[1]] = 3}, x/y] However, the following error is printed: With::lvset: "Local variable ...
12
votes
2answers
522 views

Why aren't parentheses ( ) an expression in Mathematica?

Why aren't parentheses ( ) an expression in Mathematica? Can I get an expression in a form where parentheses are represented by an expression?
50
votes
7answers
2k views

Functions vs. patterns

Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are ...
4
votes
1answer
74 views
3
votes
1answer
75 views

Why minimization does not work with symbolic array as arguments

If I try to minimize with constraints a function of several variables, with Gamma regularized function involved in the constraints it seems to works, as shown below (this is just a dummy example ...
6
votes
0answers
62 views

Negative accuracy numerics ( 0``-128 notation )

What does it mean to have a negative accuracy number? I understand 0``128 to mean "the number zero to 128 decimal points". Mathematica corroborates this: ...
-1
votes
2answers
92 views

How to make sure input is an ODE

I'm having trouble wrapping my head around why this isn't an ordinary differential equation. ...
0
votes
1answer
164 views

How To Use D[ ] to Define a System of PDEs

We have two variables $u_{1}$ and $u_{2}$ which are functions of $x,t$. That is, $u_{1}=u_{1}(x,t)$ and $u_{2}=u_{2}(x,t)$. Consider the the system of partial differential equations $$\frac{\partial ...
3
votes
2answers
138 views

Integrate using \[Esc] int \[Esc]

I like writing integrals symbolically instead of using Integrate[]. I suddenly seem to not be able to do this and am confused. I type \[Esc] int \[Esc] then ...
1
vote
1answer
54 views

Partial derivative of defined function with vector input

Background: Have written a formula for the refractive index for a glass slab (n) that depends on the variables t,a and d. Now I want to calculate for example some sort of error and I'll be needing to ...
1
vote
1answer
52 views

What is the correct idiom for mapping a 0 value in a modulo n expression back to n?

What is the correct idiom for mapping the $0$ value in a modulo $n$ expression back to $n$. For example if I want to be sure that any integer value maps back to the index for a character in the ...
0
votes
0answers
33 views
5
votes
1answer
87 views

Syntax for FrontEnd`SelectionSetStyle

I know FrontEnd`SelectionSetStyle is undocumented, but its name suggests it does what I need. What is its syntax? I have already tried several variations of the ...
0
votes
1answer
49 views

Block Matrix Multiplication [closed]

I have a = {{-1}, {0}, {0}} b = IdentityMatrix[3] c = {a, b} d = {{7}, {2}, {0}, {0}} and would like to compute e = c.d ...
19
votes
2answers
549 views

What is the difference between Composition (@*) and sequential applications (@)?

What is the difference between f@*g@*h@x and f@g@h@x Both evaluate to f[g[h[x]]] ...