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

1
vote
2answers
679 views

How does one specify Neumann conditions for NDSolve?

I have a series of functions defined in my notebook, and then want to use this to solve a diffusion-reaction type equation. At the moment, something like this works: ...
6
votes
0answers
108 views

Design considerations behind `O` (a.k.a. BigOh, a.k.a. Landau Order)

This works without any warnings: O[Log[x]]. This raises a warning: O[x^2]. I have a few questions around this: Why is it a ...
0
votes
2answers
78 views

Getting value of clock [duplicate]

I have the following code: a = Dynamic[Floor[Clock[2]]] (*So this basically alternates between 0 and 1*) If[a==1, Print["true"]] But this doesn't work, it ...
4
votes
2answers
353 views

List reversion inspired by Python

In python, if you wish to reverse a list, here is the trick: range(10)[::-1] => [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Note: ...
1
vote
1answer
91 views

How to programmatically comment out multiple source files?

How to programmatically comment out the entire content of multiple .m source files assuming they start with correct Mathematica syntax? I need it to be robust so ...
4
votes
0answers
81 views

Is there a way to check whether two notebooks share the same variables?

When I code in Mathematica, I often re-use code from old notebooks which fulfilled a specific purpose; for example, one testing for soft matches in strings, or one that identifies outliers on a graph ...
2
votes
2answers
131 views

How to make Mathematica returns the exact expression I typed

I'm using Mathematica to compare some constants. Before playing around with those constants, I would like to check that I didn't make any mistake in typing them. So my question is the following: "What ...
1
vote
1answer
173 views

Syntax for integrating over limits specified by a Table

I wish to use NIntegrate to compute multidimensional integrals. However, I don't want to manually input the limits for the dimensions. I want to store the ...
2
votes
1answer
187 views

Transfer of symbols between contexts

As many others (I guess) I'm struggling with the handling of contexts within Mathematica. I'm working on a new package definition with the usual syntaxt specified by the Mathematica documentation: ...
0
votes
1answer
282 views

Why is EigenValues returning Root expressions?

This is the code I have: ...
0
votes
1answer
89 views

Why does Eigenvalues[matrix I defined] not work? [duplicate]

This is the code I have in my mathematica notebook. I want to find the eigenvalues of the matrix I created called Hmatrix as defined below. However when I type Eigenvalues[Hmatrix] I get the Hmatrix ...
3
votes
2answers
313 views

Why does the first derivative of a piecewise continuous function have discontinuities?

I have this piecewise continuous function which is also continuously differentiable over time : ...
5
votes
3answers
564 views

Keep function range as a variable

Plot[2*x^2 - x + 2, {x, -1, 1}] plots a function of x from -1 to 1. As far as I can see, I cannot "save" this range in a variable: ...
4
votes
0answers
108 views

Proper treatment of roots and powers in Series?

I have the following problem in Mathematica 9 on Linux. I let Mathematica compute the Series expansion: ...
5
votes
2answers
224 views

Splicing a list of arguments into a function with Sequence

Not sure if this has been asked, but I have a fairly simple operation that I don't know the syntax for. Say I have an array with some values, and a function f that accepts an arbitrary number of ...
8
votes
1answer
438 views

What is the difference between prefix/postfix notations and map?

I am new to Mathematica and just experimenting with the different programming constructs. I have been looking at Map and how to evaluate a function for a list of ...
9
votes
2answers
3k views

What does # mean in Mathematica?

I asked Mathematica to compute the following Solve[c (1-x)^2-x^(1/4) == 0, x] and it returned this: x = Root[#1^8 c^4 - 8 #1^7 c^4 + 28 #1^6 c^4 - 56 #1^5 ...
1
vote
1answer
98 views

When is Evaluate needed within function arguments? [duplicate]

I'm trying to do a simple variable substitution within a ContourPlot, but it's not working. Here's an example: ...
10
votes
2answers
276 views

Functions that remember their values

Can someone explain what is going on with the following ... func[y_] := func[y] = (Print["Hello world !!!"];) func[1] Hello world !!! ...
1
vote
3answers
348 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 : ...
3
votes
2answers
193 views

How to remove border points from InputForm?

I have this code, and it generates the below ListStreamPlot. The second graph is the ListStreamPlot overlaid with the points ...
4
votes
2answers
204 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 ...
1
vote
1answer
208 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 ...
6
votes
1answer
622 views

Coding mistake? [closed]

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 ...
10
votes
1answer
503 views

Explain a Mathematica winning one-liner

...
2
votes
0answers
181 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 ...
1
vote
1answer
170 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[] ...
3
votes
1answer
106 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 ...
1
vote
1answer
120 views

Working of Date[]

Date[] returns the current date of local system, Date[1] returns {2012, 11, 15, 17, 41, 0.3161629}, ...
2
votes
1answer
191 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? ...
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 ...
28
votes
3answers
631 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 ...
2
votes
2answers
525 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: ...
7
votes
3answers
333 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 ...
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
627 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: ...
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
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 ...
10
votes
1answer
819 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 ...
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: ...
19
votes
2answers
1k 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 ...
6
votes
2answers
324 views
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 ...