# Tagged Questions

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.

145 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}] ...
2k 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: ...
1k 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.
725 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 ...
117 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. ...
677 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 ...
2k 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 ...
806 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 ...
190 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 ...
2k views

### Find the minima and maxima of a list

I have a list, such as: ...
238 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. ...
420 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 ...
583 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 ...
126 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 ...
396 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 ...
25k 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 ...
1k 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: <...
4k 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 ...
454 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 ...
680 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 ...
742 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 ...
1k 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 ...
864 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 ...
144 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. ...
678 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 ...
216 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 ...
207 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 ...
319 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 ...
189 views

### Discard functions with wrong symmetry?

I have functions of x, where x is the polar angle of spherical coordinates, i.e. ...
307 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 ...
494 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: ...
951 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. ...
138 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 a ...
2k 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 ...
818 views

### Is there a Break[] equivalent for short-circuiting in Table?

I am running Mathematica 7. The following is admittedly a silly example, but suppose that I have a list list whose entries are either ...
3k views

917 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 ...
661 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: ...
1k 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 ...
298 views

### How could I implement the equivalent of NextPrime

I would like to know what an implementation of the function NextPrime would look like if it were implemented in Mathematica's core language.
173 views

### Rookie mistake in defining a function with Modules?

I can't figure out what's wrong with this piece of code. I'm trying to define a function that counts the occurrences of x, y and ...
400 views

### Finding resolution of an optical system using Rayleigh criterion

I want to use the Rayleigh criterion to find the resolution of an optical system. I have two functions f1 = Sinc[x]^2 and ...
470 views

### How can I find minimum and maximum of a region?

I have a regionplot like the following: ...
417 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 ...