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.
12
votes
2answers
215 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 ...
7
votes
3answers
159 views
Is it possible to define custom compound assignment operators like ⊕= similar to built-ins +=, *= etc?
I would like to do something like this:
...
24
votes
3answers
464 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
...
5
votes
1answer
98 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 ...
0
votes
1answer
64 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 ...
3
votes
0answers
62 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, ...
3
votes
2answers
227 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 :
...
2
votes
1answer
100 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
0answers
29 views
Redefining Function inside function [duplicate]
I'm really newbie to Mathematica, but I'm trynig to figure out what does means things like:
splus[s_][ k_] := splus[s][k] = (s1[s][k] + I*s2[s][k])/2
I cant' get ...
1
vote
1answer
92 views
Longest string of special characters [closed]
I was answering a question the other day and my answer had several special characters in a row -- it was something like FindRoot[#, {2}] & /@ {f1, f2, f3} which ...
21
votes
4answers
510 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 ...
11
votes
2answers
209 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
112 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:
...
8
votes
1answer
114 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]
...
15
votes
4answers
936 views
Is there a syntax for single-line comments for notebooks?
I'm aware that I can use (* ... *) to comment out stuff in a notebook. Many languages have a syntax for single-line comments, such as
...
0
votes
1answer
124 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 ...
3
votes
1answer
117 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
2answers
165 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 ...
1
vote
1answer
141 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 ...
0
votes
1answer
85 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:
...
3
votes
1answer
73 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 ...
1
vote
2answers
159 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 ...
6
votes
2answers
555 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 ...
0
votes
1answer
81 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
168 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
82 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
1answer
106 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
93 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 ...
5
votes
1answer
242 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 ...
4
votes
2answers
282 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: ...
0
votes
1answer
104 views
0
votes
0answers
84 views
Why doesn't Dot work on typeset vectors?
When I try to do scalar product of vectors I get the following message:
Is there a specific way to input the vectors? I'm doing it as the Basic Math Assistant palette suggests, typing {, Ctrl+,, } ...
0
votes
2answers
60 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 ...
33
votes
2answers
708 views
Head and everything except Head?
I have been working on picking expressions apart using Head and Part and encountered a little mystery. Consider the canonical ...
1
vote
1answer
145 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[] ...
0
votes
0answers
51 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
55 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
102 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
83 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 ...
0
votes
1answer
102 views
0
votes
1answer
65 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 ...
4
votes
3answers
143 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
79 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:
...
8
votes
5answers
319 views
can the color in MeshStyle be specified by a ColorFunction, such as “SunsetColors” for example. If so, what is the correct syntax?
This is an example given in Help:
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, MeshStyle -> Gray]
Could this be changed to something like
...
7
votes
3answers
201 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 ...
5
votes
2answers
136 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 ...
1
vote
1answer
62 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
204 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
152 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 :
...
6
votes
2answers
197 views
What's the purpose of the Unique function?
As the title says: What's the purpose of Unique?
I understand that it generates some unique symbol, but when and for what is it to be used? Are there applications ...






