Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.
5
votes
2answers
639 views
Solving a tridiagonal system of linear equations using the Thomas algorithm
I'm trying to write a function that can solve a tridiagonal system of linear equations using the Thomas algorithm. It basically solves the following equation. (Details can be found at the Wiki page ...
2
votes
0answers
73 views
SetDelayed and avoiding function calls through memoization [duplicate]
I am fairly new to Mathematica. I am working my way through a number of books. I have been looking at the use of SetDelayed and want to confirm that my ...
0
votes
0answers
63 views
-8
votes
1answer
200 views
Plotting Energies vs. m for all values of R with the colors of the levels indexed by R [closed]
I have two lists like this:
...
0
votes
1answer
62 views
Collecting roots of different equations and create a list
I solve two equations and have two solutions one by each equation. I want to create list of these roots. Could anyone please help me? Appreciate it.
m02R150 = FindRoot[P1 == 0, {E1, 0.07, 0.1}]
...
4
votes
3answers
138 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:
...
18
votes
5answers
593 views
Voronoi diagrams for generators other than points
Any suggestions how to determine Voronoi diagram for sites other than points, as e.g. in the picture below? Input is a raster image.
0
votes
1answer
128 views
The built-in function If behaves strangely in a procedure/function [closed]
Inside a procedure or user-defined function, If doesn't do as it should. Long ago, I found out that I should use === instead of == in a procedure in order to make ...
13
votes
1answer
161 views
List manipulation to build a functional expression
Since Mathematica deals with Head[a, b] as an expression in this way
The first Part of Head[a, b] is ...
1
vote
1answer
79 views
Avoiding unnecessary computations within loops
Consider the following data:
test = RandomReal[{1, 2}, {10, 5, 3, 3}];
How can I do the following without the For loops, e.g. ...
6
votes
2answers
206 views
CorrelationFunction for vectors
Mathematica 9 has a new CorrelationFunction. Sadly the joy does not last long, as I can't get it to work with vectors. I would like to make a velocity correlation ...
2
votes
1answer
82 views
Executing a .m file from the Linux command line
I have some code in a file named Demo-3.m, It can be evaluated in Mathematica 9. The final expression in the file is
...
4
votes
2answers
138 views
Finding all/most roots of a discontinuous function more consistently?
I have the equation:
f[x_]:=α Tan[α*a] - Sqrt[c - α^2]
and ideally I want to find all of its positive zeros, given a and c, with variable alpha. The problem is ...
-3
votes
1answer
73 views
Why won't an expression run inside a function? [closed]
Given that f is defined as
f[x_] := 1/(1 + x)
the Do expression
...
2
votes
2answers
112 views
How to achieve Set+Part like behaviour in custom Set function?
So I've been toiling away on my DataFrame package. I've been trying to get Set to work with it, but it seems it either can't be done (ie via ...
9
votes
4answers
624 views
0
votes
1answer
195 views
Why does memory run out when adding same-sized matrices in a loop?
I have written a module that it generates a 101x101x51 zero matrix at first. At every iteration, it generates a list by funct1 and based on this list, if list is empty it gives the previous result. ...
13
votes
1answer
181 views
Is the sharing of variables in Module/Block within Compile documented behavior?
Today I noticed something, I think for the first time.
When used inside Compile variable values within Module (and ...
6
votes
4answers
187 views
How to set Block local variables by code?
I need to create a user defined Block function where the Block variables values are defined by code. For example, imagine I have:
...
0
votes
1answer
99 views
Where do those nulls come from? [closed]
I have seen discussions of unwanted nulls in the output in the context of building lists with conditions on the elements, but that is not involved here. I would like to know where the nulls come from ...
7
votes
3answers
210 views
Patternmatching sets
How to match set-patterns against sets?
A set (in the mathematical sense) is a list of elements without repetition and order of elements does not matter. For example, we have a pattern set ...
81
votes
1answer
12k views
Mathematica Minecraft
Some time ago I asked myself: with all these great graphics and interactive capabilities of Mathematica, what kinds of 3D games can be implemented in it? And the answer which came to mind is ...
1
vote
3answers
354 views
Finding the square root of a random number with Newton's method, using While/Do/For loops?
I am trying to construct a program that will find the square root of a number, using Newton's method, which is
$$x(n+1) = x_n- f(x) / f'(x_n)$$
The number, will be a random number, generated by: ...
2
votes
2answers
426 views
Product of Fibonacci numbers using For/Do/While loops
I want to find the product of the first 20 Fibonacci numbers (the fibonorial). I want implementations using While, Do, and ...
4
votes
2answers
199 views
Improve performance and style of solution to Project Euler #32
Since I'm fairly new to Mathematica, I'm trying to learn better ways to improve my coding skills so I've turned to Project Euler and this site to speed up my learning pace. Anyways, I was trying to ...
8
votes
4answers
272 views
Best way to modify values in a list of rules?
Recently I had to solve a problem similar to this:
Let's say I have a list of list of rules
...
2
votes
0answers
239 views
Why is Mathematica limiting the execution time of my calculation? [duplicate]
Is there a Front End option (or programming option) in Mathematica 9 that limits the amount of time that functions take to execute? I have a function (as part of a Mathematica Application) that shows ...
8
votes
4answers
291 views
Passing large list by reference
I have the following problem: I would like to control evaluation of a variable that points to a list. For example, frequently in the code I have functions of the form that are supposed to work on ...
0
votes
1answer
134 views
Find Roots in Do loop
Task: Finding roots in loop
t = List[1, 2, 3, 4, 5]
fx[x_] := a*x^2 - 5
List[Do[Print[FindRoot[fx[k] == 1, {a, 1}]], {k, 0, 5}]]
Output: Currently the output is ...
4
votes
1answer
92 views
Determining End of Notebook with Mathematica 9
The application package I had working in Mathematica 8 no longer works in Mathematica 9. I believe the problem lies in how I cycle through cells and test for reaching the last cell of the notebook. ...
3
votes
3answers
354 views
Is Table the only functional way to construct nested loops in Mathematica?
Suppose you have a cubic box containing identical particles and you want to compute the distances between each particle and every other particle in the box without double-counting (i.e., if you've ...
1
vote
3answers
112 views
Using Outer with Compiled functions that accept more than 2 arguments
How does one use Outer with a compiled function that accepts 3 or more arguments. Alternatively, how does one create a compiled function with 3 or more arguments ...
1
vote
0answers
84 views
Search & Replace Other Languages
Mathematica allows you to pattern match based on type and operate on itself because of it's list nature.
For example:
a[b] /. a -> d returns ...
2
votes
3answers
97 views
How can I find the points of B Spline functions for a specific range?
Based on this question:
I have a list of bspline functions (nearly 1000) provided by applying BSplineFunction to a list of points. I want to get the points each of ...
1
vote
2answers
72 views
Checking equality with ComplexInfinity and testing whether a function is (mathematically) undefined
This seems ridiculously basic, but I cannot find anywhere explaining how to do it.
If you evaluate certain undefined functions like 1/0 or ...
2
votes
1answer
105 views
Discard functions with wrong symmetry?
I have functions of x, where x is the polar angle of spherical coordinates, i.e. ...
10
votes
1answer
90 views
Are formal characters like \[FormalA] to be used differently than other symbols?
I noticed that Mathematica has a set of special 'Formal' characters such as \[FormalA], \[FormalB] , etc.. In the front end, it ...
5
votes
3answers
226 views
Delete elements from a list really fast
I have this bit of code that works, but it's very slow when there are 600k elements in the list:
...
1
vote
1answer
137 views
pointer like operations in mathematica and evaluation control
I would like to create a data structure of the type "header[pointer]" where pointer would point to a list. I will shown on an example how I'd like this to work, and where the problems are.
...
2
votes
0answers
85 views
Programming Mathematica - Introduction by Paul Wellin [duplicate]
Possible Duplicate:
Where can I find examples of good Mathematica programming practice?
Can anyone recommend a decent book on programming mathematica ? I came across this which looks to be ...
0
votes
1answer
95 views
Stubborn Output: Returning the value from the wrong subroutine [closed]
Problem:
I wanted to program these 2 subroutines shown below and each was to return a function expression:
AnIntegrand[n0_] :=
Module[{n = N[n0]},
Return[6 t^2 Cos[2*n*t*Pi]];];
...
6
votes
1answer
339 views
Use Mathematica as a terminal
I love how notebooks work in Mathematica.
You can edit code in real time and hit Ctrl+Shift to run it.
Additionally you copy and paste different cells around to organize and test ideas.
Search ...
6
votes
2answers
367 views
Easier program for period of Fibonacci sequence modulo p
For a little project I need to calculate the period of a Fibonacci sequence modulo p, for which p is a prime number. For example, the Fibonacci sequence modulo 19 would be:
$$0, 1, 1, 2, 3, 5, 8, 13, ...
1
vote
1answer
105 views
What is the new command for AffineMap?
AffineMap was present in Mathematica version 4. What is the equivalent command in the current version of Mathematica?
63
votes
14answers
2k views
What are the most common pitfalls awaiting new users?
As you may already know, Mathematica is a wonderful piece of software.
However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
7
votes
1answer
62 views
Aborting from inside a Dialog
Suppose I got in a Dialog and wanted to not Return but Abort the computation. How could I do ...
4
votes
1answer
155 views
Simplification of double symbolic sums containing a DiscreteDelta without explicit summation range
I am trying to get Mathematica to automatically do simplifications like the following:
$$\sum\limits_{q}^{q\in qV}\sum\limits_{q'}^{q'\in q'V}{f(q)g(q')\delta(q-q')}=\sum_{q}^{q\in qV}{f(q)g(q)}.$$
...
10
votes
3answers
376 views
1D Random Walk variant
I am making a notebook that is a variation to the traditional 1d random walk problem.
The normal 1D random walk can be simulated easily by
...
1
vote
1answer
142 views
Nested Sums to multiple sum
I would like to automatically "move nested sums to the left". I mean, just take out of an expression all the summations and go from a nested Sum to a multiple sum. Something like starting with:
...
18
votes
4answers
497 views
Efficient circular buffer?
I wish to create an efficient circular buffer. That is, I wish to keep a fixed length list while appending a new value and dropping the oldest, repeatedly.
As we know lists in Mathematica are ...






