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

11
votes
3answers
176 views

Why can't I use Sequence to perform a Select like task?

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. ...
6
votes
1answer
139 views

Problem overloading D[] using UpValues

First I define an entry of UpValues overloading D[] for expressions with head ftest: ...
0
votes
1answer
150 views

How to generalize a formula?

This is a piece of my code: ...
4
votes
1answer
103 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 ...
2
votes
2answers
270 views

local variable naming & symbolic argument

I'm stuck here with my variable assignment in this scenario ...
7
votes
3answers
303 views

Why can't D[] be used in place here? [duplicate]

Possible Duplicate: General::ivar is not a valid variable when plotting - what actually causes this and how to avoid it? Beginner question: Why can't I use ...
1
vote
2answers
230 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 ...
2
votes
2answers
524 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: ...
4
votes
1answer
239 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 ...
1
vote
1answer
374 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"?
2
votes
3answers
176 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 ...
7
votes
1answer
189 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 ...
4
votes
1answer
298 views

Path queries for tree-structured data

Can anyone suggest documentation or tutorials for developing path queries and indices for (XML-like) tree-structured data? Suppose data is organized hierarchically in key->value pairs, eg: ...
5
votes
2answers
483 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: ...
10
votes
1answer
817 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 ...
10
votes
4answers
405 views

Extracting equations from Piecewise expressions

Say I have a PDF: PDF[LogNormalDistribution[1.75, 0.65], x] Calculating it, Mathematica gives me an expression that looks like this: I want to extract the ...
16
votes
3answers
990 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 ...
7
votes
2answers
203 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 ...
20
votes
1answer
500 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 ...
4
votes
3answers
186 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?
1
vote
1answer
202 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 ...
2
votes
3answers
446 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. ...
11
votes
4answers
440 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 ...
15
votes
2answers
373 views

Distributing PlusMinus consistently

I would like to give the built-in function PlusMinus, which is undefined by default, the intuitive meaning: considering all possible combinations of $+$ and $-$. ...
2
votes
4answers
371 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 ...
2
votes
1answer
564 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: ...
11
votes
2answers
256 views

Convert operator to string

How to programmatically convert an operator such as Equilibrium into its displayed form as a string? The conversion should work like this: ...
11
votes
3answers
249 views

Numbers in alternate bases transcend the evaluator?

It looks to me like a number in a base other than base 10 gets evaluated before the evaluator ever gets a chance to be tweaked. For example, FullForm[16^^abcdef] ...
7
votes
2answers
171 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: ...
2
votes
1answer
194 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 ...
8
votes
1answer
337 views

Setting the DifferenceOrder Option

I've been playing around with Method in NDSolve[...] and can't quite seem to figure out how to force ...
4
votes
3answers
515 views

Integrating with multiple indicator functions

I am trying to calculate an integral involving multiple indicator functions, such as: $$ h(u,v,w) = -\int_0^1 J^{\prime\prime}(s) (I_{(0,s]}(u) - s)(I_{(0,s]}(v) - s)(I_{(0,s]}(w) - s)\, ...
7
votes
3answers
1k 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 ...
5
votes
3answers
267 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?
4
votes
4answers
4k 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: ...
1
vote
2answers
230 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 ...
5
votes
1answer
210 views

Why does the Front End group backslashes into pairs?

What is \\ for? Help finds nothing on it. An odd number of backslashes greater than one are grouped by two and the last one is displayed with a different color. ...
10
votes
2answers
103 views

Functions in a different context are replaced with infix forms of their namesake in System`

So, in an attempt to help out Fabian with his question, I did what I often do, and created a new symbol in the Pillsy` package that I could play with. Since it was ...
0
votes
1answer
413 views

What does the slash-colon symbol do?

I came across a bit of code that uses the syntax /: and I don't know what it does. I can't find its documentation, or maybe I'm just not looking properly. The code ...
5
votes
2answers
792 views

Constructing a Summation with a Variable Number of Inner Sums

I have a question regarding multiple sums. And my second index depends on the first index. Here it is: $$ \sum_{d=1}^{P}e^{-d}\sum_{\substack{1\leq k_{1}\leq Q \\ 1\leq k_{2}\leq Q \\... ...
2
votes
3answers
914 views

Orthonormalization of non-hermitian matrix eigenvectors

When using Orthogonalize[] one can specify which definition of "inner product" is to be used. For example, ...
4
votes
1answer
102 views

How do you set an Optional parameter with a global variable on a Function defined in a Package

In a Package I am writing, I'm trying to define a function with an Optional parameter in it that is set to a global variable. ...
9
votes
1answer
155 views

Accept Infinity as an Integer argument

I have the following function, albeit contrived: Foo[x_Integer] := Module[{i}, i = 1; While[i <= x && i <= 10, i++]; i - 1 ]; I am ...
8
votes
2answers
230 views

Cases[data,Colon[key,_]] vs. Cases[data,key:_] toward XPath, XQuery

Exploring methods to index and search tree-structured key:value pairs via named-entity index (key paths) as opposed to Position-based indexing. Using Rule as ...
8
votes
5answers
3k views

Notation of partial derivative

I want to write partial derivatives of functions with many arguments. Why is it that when I type f[x,y] ctrl+6 (0,1) it turns out to be bad syntax? The output of ...
3
votes
1answer
325 views

Explanation on why Compile statement works only if input and output sizes work

I found the following code: Compile[{{m, _Real, 2}}, Fourier[m]][Table[N[i - j], {i, 4}, {j, 4}]] which doesn't work correctly. But the following was posted as a ...
2
votes
2answers
1k views

NMinimize with defined function call getting error NMinimize::nnum

I want to call the NMinimize function for my own defined calculations but I got an error. Below is a simple example. ...
12
votes
7answers
659 views

Equating matrices (or higher order tensors) element-wise

Say I have two matrices (or, as in my case, higher order tensors) $A,B$, and I want to solve the equation $A=B$. To do so , I need a list of equations that equate entry-wise the elements of $A$ and ...
8
votes
4answers
522 views

Error when using rule as a list index - { i, x[[i]] } /. i -> 5

I can't seem to use a rule to index a vector. x = Range[10]; { i, x[[i]] } /. i -> 5 I get the following error when evaluating the above code, even if the ...