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
236 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
163 views
Is it possible to define custom compound assignment operators like ⊕= similar to built-ins +=, *= etc?
I would like to do something like this:
...
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 ...
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, ...
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 ...
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 ...
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 ...
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:
...
21
votes
4answers
511 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
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 ...
8
votes
1answer
115 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
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
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 ...
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 ...
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:
...
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
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 ...
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 ...
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 ...
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
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
84 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
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
1answer
103 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 ...
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 :
...
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:
...
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 ...
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 ...
6
votes
2answers
556 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
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
153 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
132 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
125 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
144 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
316 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 ...
9
votes
1answer
335 views
2
votes
0answers
122 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
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[] ...




