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

13
votes
2answers
352 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
129 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
937 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
456 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
152 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
205 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
224 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
101 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
121 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
465 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
359 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
317 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
775 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
280 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
887 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
83 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
359 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
84 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
132 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
201 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
199 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
341 views

Why is EigenValues returning Root expressions?

This is the code I have: ...
0
votes
1answer
92 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
331 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 : ...
6
votes
3answers
753 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
109 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
250 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
487 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
101 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
297 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
398 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
196 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
226 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
218 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
694 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
545 views

Explain a Mathematica winning one-liner

...
2
votes
0answers
192 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
175 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
121 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
193 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
177 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
146 views

Problem overloading D[] using UpValues

First I define an entry of UpValues overloading D[] for expressions with head ftest: ...
0
votes
1answer
165 views

How to generalize a formula?

This is a piece of my code: ...
4
votes
1answer
107 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
280 views

local variable naming & symbolic argument

I'm stuck here with my variable assignment in this scenario ...