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

7
votes
3answers
863 views

Guidelines on giving readable names to variables [closed]

I know that one cannot use underscore to a variable name, like degree_of_The_First_Polynomial. But for a long variable name, it ...
0
votes
0answers
121 views

The /. syntax in numerical methods [duplicate]

I have an analytical approximation method for solving an ODE and want to compare this to an NDSolve solution, but the syntax is confusing me. To get the solution from NDSolve, I define the ODE as eqn ...
17
votes
3answers
494 views

How is + as an infix operator associated with Plus?

How is + associated with Plus? Suppose I want to define a head FooBar and have it ...
4
votes
2answers
184 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 ...
11
votes
4answers
189 views

Constraint syntax compaction

Is there a more compact way to represent these constraints: NMaximize[{a+b+c,...
10
votes
1answer
184 views

Infix form of PutAppend ( >>> ) does not work with variable

I'm new to Mathematica, so I suspect this question involves either a misunderstanding involving variables or the usage of >>>. On a webMathematica page ...
2
votes
2answers
214 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 ...
7
votes
3answers
439 views

What is the right way to construct DynamicModule

When I'm creating DynamicModules for CDF purposes I'm usualy basing on my experience with that, particular goal and content rather than on deep insight. I want to ...
1
vote
1answer
73 views

Why do two codes give different output?

I have tried the following to get the eigenvalues of several matrices of the type: ...
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 ...
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 ...
5
votes
2answers
216 views

Overlapping pure functions

Let say I need and option for Plot: RegionFunction -> (-6 < #2 < 6 &) But I also want those ...
-5
votes
1answer
171 views

Split dataset based on the first column [duplicate]

I have a dataset which I want to split based on the first column. The data looks like this ...
0
votes
0answers
146 views

Assigning numerical values to constants results in complex coefficients in Equations of Motion

I am using Mathematica to get the Equations of Motion (EOM) for a mechanical system (using Lagrangian Mechanics). While I get the EOM in symbolic form, on introducing the following code for assigning ...
1
vote
3answers
145 views

Equation values into list

Suppose I have a function say $f=x^2$. What I would like is a list (or even better, a list with a grid) which resembles {{1,1},{2,4},{3,9}, ...}. Ideally one should ...
21
votes
2answers
672 views

Why there is no name for #1@#2&?

Why does the pure function #1@#2& have no name? Is it due to the way Mathematica works, or is it "just because"? I'm asking because I find inelegant to write ...
4
votes
1answer
123 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: ...
22
votes
6answers
429 views

Constructing symbol definitions for With

I would like to be able to define two arrays, one containing symbol names and one containing the values of those symbols, for use in constructs such as With. For ...
2
votes
1answer
157 views

How to get 'exact' expression for result

I have a result from Mathematica for which want to have the exact expression, i.e. all of the arguments of type # replaced. It is given by: ...
1
vote
1answer
129 views

Correct usage of GeoPosition

My goal is to trace a ray down to the ground. I have done: ...
3
votes
1answer
151 views

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

I noticed that I often turn out to have a list of substitutions in the form ...
2
votes
2answers
137 views

Extracting counts of contiguous zeros and ones from a binary array

I'm a novice with Mathematica, but you guys have been very helpful to me in the past. I have a binary array [100, J repetitions] consisting of zeroes and ones. I'd like to extract a histogram of the ...
1
vote
1answer
164 views

Bincounting a list

I'm a Mathematica novice here. I'm trying to execute the following code to add random 1's into a zero matrix, repeat this many times, and then bin/histogram the number of nearest neighbor 1s. Can ...
3
votes
1answer
95 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: ...
4
votes
1answer
436 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 ...
5
votes
1answer
190 views

How to convert an image to a compressed string representation equivalent to one copied to clipboard by `CopyToClipboard[image]`?

In my recent question I asked How to embed an image into a string? The suggested solution was ...
8
votes
2answers
366 views

How to create custom Graphics primitive?

How to create custom Graphics primitive? It should have the following properties, resembling properties of built-in geometric figures, like ...
13
votes
2answers
375 views

How to embed an image into a string?

The documentation for String contains the following statements: Strings can contain any sequence of ordinary and special characters: … Strings preserve ...
5
votes
1answer
199 views

What does ` symbol in ClearAll[“Global`*”] mean?

I have found an example for clearing all symbol definition by: ClearAll["Global`*"] But what does the symbol ` mean? It isn't the apostrophe ', yet it is not ...
2
votes
0answers
190 views

NonLinearModelFit with Two Dimensional List of Weights

I'm currently trying to fit Planck's law (B[λ, T]) to measurements, thereby determining Planck's constant. I have a list of triplets containing wavelength, ...
0
votes
1answer
140 views

Pattern match with Table for matrix dimension check

In Mathematica, often an expression involving matrices will encounter dimension mismatch errors, like we are multiplying a 3x2 matrix to a 3x4 matrix. Below we define a new symbol Dim, which can be ...
13
votes
2answers
326 views

What kind of hypergeometric function is it?

I found a formula for an integral of a product of three Bessel functions at The Wolfram Functions Site: I cannot understand what kind of hypergeometric function it is. The Mathematica code given ...
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: ...
29
votes
5answers
875 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 ...
0
votes
1answer
398 views

What is wrong with this Cobweb plot [closed]

Something is wrong with my cobweb plot code but I couldn't figure out where do the mistakes come from. So basically we have the iterative map $x_n == x_{n-1}^{2} - 3 \mu$. I would like to draw a ...
8
votes
1answer
150 views

Different behaviours of Default Argument

I don't really understand the behaviour of Default Argument. If I execute this command in Mathematica: In: {f[a], f[a + b]} /. f[x_ + y_.] -> p[x, y] ...
3
votes
1answer
173 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 ...
1
vote
1answer
200 views

Solve this equation symbolically

I am trying to solve the equation for the quantity r = y/x symbolically: 3/y^4 == 3/x^4 + a/(x + 2 y)^4 with the requirement that we need to perform the ...
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 ...
0
votes
1answer
114 views

How to tell Mathematica to make assumptions? [duplicate]

Say I want to integrate 1/(x^2+a^2) and I want Mathematica to know that $a>0$. What would be the command? Something like: ...
1
vote
2answers
431 views

Translating a “Point-to-Triangle” distance script from MATLAB to Mathematica

Update - Thanks everyone for your responses! After fixing a problem with vector normalization, the code below now works. I'm a new user, and I was attempting to port some Mathematica code from ...
2
votes
2answers
307 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 ...
0
votes
1answer
229 views

Mathematica command for type checking?

I have a program where users can enter mathematica commands that can evaluate to any of the standard numeric types (complex, real, int, etc.), or to boolean values. Moreover the users can enter ...
0
votes
2answers
604 views

Why function cannot be defined inside For loop? [closed]

I have a following code (which is simplified version of what I am doing): For[i = 1, i <= 5, i++, f[x_] := Sin[x]^2 Print[{i, f[i]}] ] And the question ...
2
votes
0answers
234 views

Conditional statements in intial conditions?

This is potentially a daft question, but I thought I'd ask it; I have some material free to diffuse in a boundary between rn and ro; I've been able to get it working nicely for neumann type boundary ...
1
vote
2answers
624 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
106 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
77 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 ...