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

4
votes
3answers
381 views

What is the right way to write a function that includes other functions?

I want to include multiple sub functions: $b(x) = 10x$ $w(x) = s + b(x)$ $c(x) = x^2$ into two main functions: $ua(x) = w(x)-c(x)$ $ub(x) = w(x)-c(x)^2$ As a reaction to this answer, I wrote ...
4
votes
3answers
250 views

Brackets in output make unable to use output to identify matrix element

I'm trying to write a code where each matrix element swaps with a randomly selected neighbor (cardinal directions only) to redistribute the matrix. So far I've been able to replace an element with its ...
4
votes
2answers
172 views

How can I avoid getting the error message Goto::nolabel in my code?

If anyone could suggest a reason why Label[begin] ... Goto[begin] would return Hold[Goto[Begin]], and (better) how can I avoid ...
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)\, ...
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 ...
4
votes
1answer
68 views

Dot when used in a pattern becomes Times… Why?

In[1] := Hold[a.b] // FullForm Out[1] := Hold[Dot[a,b]] So far so good. ...
4
votes
2answers
193 views

Can someone explain this code for joining two lists by the first element of each sublist?

Background (which may be skipped, unless context is needed) I've recently begun learning Mathematica (and only up to chapter 3 of Wellin), but wanted to write some code to get a better feel for ...
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 ...
4
votes
2answers
73 views

Why can't I pass in a product of matrices in my modified matrixform? [duplicate]

In attempt to build a function that would work like MatrixForm but would wrap a matrix with brackets, I tried the following function: ...
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 ...
4
votes
1answer
299 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: ...
4
votes
2answers
105 views

Scalar product operator of complex vectors

What is the scalar product operator for complex vectors (or matrices) in Mathematica? The usual $Dot[]$ doesn't work. E.g. here is what the Mathematica gives $$\{1,0\}.\{I,0\}=I$$ but the answer ...
4
votes
2answers
89 views

Limit won't compute

Does anyone know why the limit: ...
4
votes
1answer
70 views

Constructing an Array from typed expression

I want to produce an array from expressions given by test[one][1] = 3; . . test[one][5] = 7; etc. Normally would use ...
4
votes
1answer
473 views

What do the hashtags represent in the result of Solve, and how should I use them? [duplicate]

There is a function that I'm trying to get the inverse of. My function is a simple polynomial: Tn[T_] := 4/9 T^3/Tc^2 + 5/9 T Now I tried to find ...
4
votes
1answer
127 views

DeleteCases vs. DeleteDuplicates for removing points within a critical Euclidean distance

I'm attempting to remove all points in an array which are within a Euclidean distance "ThresDist" of one-another. Using the command: ...
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. ...
4
votes
2answers
123 views

Replacing a function in defined expressions

I'm having a little trouble with substituting functions into an expression. A minimal example is as follows: ...
4
votes
0answers
116 views

Syntax error for optional pattern, but only in debugger

This expression (explained here by Leonid) evaluates fine unless Evaluation->Debugger is enabled: h[x : (_Integer) : 1] := x Syntax::sntxf: "x:" cannot be ...
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 ...
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: ...
3
votes
5answers
416 views

Using variables in function names

I want to make a list of plots and my functions are named C1, C2... Cn. The command I wish ...
3
votes
3answers
134 views

Is it possible to use infix notation ~ for functions with one argument or more than 2 arguments?

According to a Mathematica textbook, we can write N[x,n] by using infix notation as x ~ N ~ n. How about other functions with ...
3
votes
1answer
96 views

Export file with semicolon at the end of line

Is there a rule that tells Mathematica to set a semicolon at the end of each line (except of the last one)? My MWE is: ...
3
votes
1answer
86 views

Syntax Coloring for “Possible Unwanted Assignment” Issue

Apparently Mathematica's syntax coloring engine believes that the second assignment in the following code excerpt (concocted for illustration purposes only) is a "Possible Unwanted Assignment" since ...
3
votes
1answer
155 views

Shortening the syntax {var1, var2} /. # & /@ list

I noticed that I often turn out to have a list of substitutions in the form ...
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 : ...
3
votes
2answers
126 views

How to define the irrational domain or any other arbitrary domain?

I have found no way to define the domain of Irrational numbers. I can easily define a test to see if a number is irrational by defining: ...
3
votes
2answers
109 views

Why does the iterator index in Table not work here?

I type the following command line Table[D[#1,varx[[i]]] &,{i,3}] where varx is a vector of dummy variables ...
3
votes
1answer
179 views

Using single replacement rule to convert algebraic expression

I have been trying this problems for hours and cannot find any helpful clues. How can I convert $Sinh[3\theta]+Sinh[\theta]$ to a rational function of x given $2Sinh[\theta] = x-x^{-1}$ by using only ...
3
votes
1answer
71 views

Highlight the same symbol throughout notebook

Once I saw people using Matlab use a keystroke shortcut that made all the same symbols as a selected symbol become blue. I am wondering is there is a function in Mathematica that is similar. If so, ...
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 ...
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 ...
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 ...
3
votes
1answer
99 views

Differentiating a Dot Product

I apologize if this type of question has been asked before, but a preliminary search turned up nothing. I would like to differentiate dot products. For example, consider taking a derivative with ...
3
votes
1answer
94 views

Dt acting on symbolic notational forms

This one must be simple, but I can't figure out a decent solution. Suppose, I have a symbol with a notational form applied to it, say OverHat[A]. Now, if I didn't ...
3
votes
1answer
61 views

Pathological behaviour when evaluating a sum

When I declare the function $f$ as follows: f[n_] := Sum[x/Sum[Sqrt[y], {y, 1, x}], {x, 1, n}]/n the input ...
3
votes
1answer
166 views

Levels and slots

I am struggling with levels and #, if I understand this I think I will be able to grasp the entire concept. ...
3
votes
1answer
127 views

Filtering the elements of an array to split them into two categories

So, I am new to Mathematica, and I am trying to write something that involves taking values from one array and separating them into two different arrays. My code for doing this is: ...
3
votes
1answer
94 views

Why is ^^ff not the same as ^^ToExpression[“ff”]?

I want to convert a hexadecimal string to a decimal (base 10) number: 16^^ff 16^^ToExpression["ff"] The 1st line returns the correct answer of 255, while the 2nd ...
3
votes
1answer
104 views

How to make InverseFunction work on function defined with restriction on arguments

This example works to define InverseFunction on the first argument of a function ...
3
votes
0answers
151 views

Do any mainstream text editors support Wolfram Language syntax for highlighting?

Syntax Highlighting for Mathematica on a Blog There is the above, but I'm not terribly excited to install rogue packages. For example on github, I share lots of Mathematica code. I see no way to ...
2
votes
2answers
559 views

Single dot textual form

How do I render a letter with a single dot above it? I see \[DoubleDot] and \[TripleDot] are readily available, but what about ...
2
votes
4answers
373 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
3answers
915 views

Orthonormalization of non-hermitian matrix eigenvectors

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

Where did I go wrong with my implementation of finding a plane tangent to a surface?

I am working on finding the plane tangent to a paraboloid at a given point. My code: ...
2
votes
2answers
313 views

Write a function that returns the logarithmic derivative

How can we write a function that if we input an expression f, it returns the log derivative $\frac{1}{f} \frac{df}{dx}$. We have to use a conditional or pattern test so that the function accepts any ...
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 ...
2
votes
3answers
449 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. ...
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: ...