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.

learn more… | top users | synonyms

5
votes
1answer
169 views

Should Row be used in place of StringForm?

I've been using Mathematica for a long time, so I have a habit of using some of the older functions even when newer, better ones have been added to replace them. ...
8
votes
3answers
238 views

Grid without lines, but with dots

I want to build a grid to look like the top-left table shown below, but without an outside frame. Here is what I've tried to do: ...
34
votes
1answer
1k views

Once more on object orientation in Mathematica: does it have to be so hard?

Recently I came across a set of problems which would be solved most easily within an object-oriented approach. I first attempted to solve them by other means, but found the complexity of the code ...
5
votes
4answers
1k views

How to find the sum all even numbers of this sequence?

I have a sequence $(u_{n})$ $$u_1= 1, \quad u_2 = 2, \quad u_3 = 3, \quad u_{n}= -u_{n-3} + 3u _{n-2} +2 u_{n-1}, \quad \forall n \geqslant 4.$$ I want to list the first $20$ terms of this sequence ...
14
votes
3answers
527 views

How can I improve my code for drawing a tree?

This code draws a tree, but it's not in the functional style. ...
5
votes
3answers
284 views

More structure in Source Code/Notebooks

Mathematica is great for small and quick projects and has a great syntax. However as soon as a project grows I run into trouble. How do you scale and maintain projects in Mathematica? What is beyond ...
11
votes
8answers
428 views

Any built-in function to generate successive sublists from a list?

Given lst = {a, b, c, d} I'd like to generate {{a}, {a, b}, {a, b, c}, {a, b, c, d}} but using built-in functions only, ...
4
votes
2answers
217 views

About extension fibonacci

I have been trying to solve this problem, it worked slow. I know there is a efficiently way. How do I get it? The following is my code: ...
3
votes
1answer
121 views

How to make a pattern to change x^(2/y) to (x^2)^(1/y) for any x and y?

This might have been asked before. Please let me know if it is. I was looking at an interesting Mathematica question in students forum and trying to solve it, and a chance to learn more about ...
0
votes
1answer
896 views

Loops and subroutines [duplicate]

Possible Duplicate: Alternatives to procedural loops and iterating over lists in Mathematica I am new to Mathematica and not familiar with functional programming. In particular, I have no ...
1
vote
1answer
93 views

Draw from HistogramDistribution with ParallelTable

I wanted to check something, but ran into troubles using HistogramDistribution in combination with ParallelTable. The code does the following: Compute a HistogramDistribution of some sample and use ...
1
vote
3answers
773 views

How to create functions of arbitrary number of variables? [duplicate]

In the following code what would be the simplest way to generalize it to say some $N_f$ number of $z$ instead of just $z_1$ and $z_2$? ...
20
votes
2answers
400 views

How to implement FittedModel like objects

In the course of making some RLink wrappers I want to have some richer containers like Mathematica does with its FittedModel ...
4
votes
4answers
303 views

How to compile the code for generate Pythagorean_triple?

I am finding Pythagorean_triple, it worked slowly. I tried to compile, but it gives some warnings. I also use "Case" or "Do" ,both of them failed.I'm sure my CCompiler has been set correctly. How can ...
6
votes
3answers
467 views

Filtering elements from a list

Suppose that I have a list {{{2, 1}, {4, 3}, {2, 4}}, {{2, 1}, {4, 3}, {3, 1}}, {{2, 1}, {2, 4}, {3, 1}}, {{4, 3}, {2, 4}, {1, 2}}} I want to make a new list ...
7
votes
3answers
417 views

NDSolve and {C, K, Slot} and other built-ins as a variable name

The following problem is an exploration of what causes the error "Input is not an ordinary differential equation" in Mathematica as it seems to have changed from version 8 to version 9. Specifically ...
14
votes
3answers
1k views

Is learning to use Mathematica useful for pure theoretical research in Mathematics and Computer Science?

I am looking for opinions from Mathematica users about Mathematica itself. After reading the faq, I thought that in some sense I "wish to solve a problem using Mathematica" ... although I understand ...
5
votes
2answers
1k views

How to define a differential operator?

I have a linear differential operator, for instance, $L\left (\partial _{t} \right )=\partial _{tt} - 3\partial _{t} + 2$. I use it in 2 different ways: apply the operator to a function: $L\left ...
20
votes
3answers
2k views

Mathematica as a normal programming language

I'm interested in Mathematica's core language for both practical development and as an object of computer science study. Actually, the former is more of a means to the latter. I would like to create ...
2
votes
1answer
180 views

Computing closest set of points to each point in large set — running out of memory (arrays unpacking)

I have a large set of points in 3D and I'm trying to identify all the points that lie within a certain distance of each point. Then using this data store the vector between the pairs of points. I ...
5
votes
1answer
284 views

Progress indicator with shared variables

I'm trying to create a custom progress indicator for a parallelized computation, using Dynamic and SetSharedVariables to display ...
4
votes
1answer
223 views

speed up iteration with conditionals plus optimize memory usage

Given list1 and list2 whose elements are vectors of a certain (fixed) dimension, I am interested in the behaviour of a scalar ...
19
votes
3answers
1k views

Reading periodic elements from a large file

I have a large binary data file (big endian) with 100+ million "rows" of 11 elements, combination of floats and integers. This is the format: ...
4
votes
4answers
184 views

clean functional way to get first n rows that yield maximum rank

I have a matrix A and want the matrix consisting of the first n rows of A, having the same rank as A, where n is minimal. More generally, I want the shortest "start piece" of a list, such that some ...
4
votes
3answers
203 views

Creating Multi-Tabbed Grid with Preserved Contents and Overview Grid

I am in the process of creating an application/panel that will aide me in scheduling hours for my staff of ten or more. I am hoping to create a multi-tabbed grid within which I may collect data about ...
1
vote
1answer
187 views

Problem with function as an argument

I want to write a function like the following: s[u_, v_, x_, val_] := u[val]/NIntegrate[u'[x] v[x] + u'[x] v'[x], {x, 0, 1}] So I can evaluate something like ...
4
votes
2answers
499 views

Optimize inner loops

I'm Mathematica newbie so please be gentle :) I have this, heavily non-optimized part of code, which I would like to speed up. I have put all matrices to be RandomReal, but in my code they take ...
0
votes
1answer
277 views

How can I make many runs of a simulation and plot all the results with one expression evaluation?

I have many cells, starting with this first cell: ...
1
vote
0answers
167 views

Return Functions from parallel execution of module

I wrote a module which numerically solves an ODE using NDSolve. The result from this is e.g. either ...
6
votes
1answer
220 views

Why is MapIndexed better than mapping over a range?

Background I'm working on an application in which I need to create and control two sets of locators. I know from reading the Mathematica documentation and certain posts on Mathematica.SE that this ...
2
votes
1answer
301 views

Cournot Equilibrium

I'm trying to determine reaction functions of a Cournot equilibrium for $n$ firms using the same optimal condition, using the fixed point method. This is the method I'm using: ...
9
votes
5answers
400 views

Incrementing a number where each digit has a different base

Let's say I have a list, for instance {10,5,3}, indicating the bases for each digit of my 3-digit number. Using this basis, if I wanted to increment {8,4,1} a couple of times, here's what I would get: ...
2
votes
0answers
140 views
4
votes
3answers
427 views

How to make brute force coding more efficient?

Hi guys and guysettes, The little Mathematica I've been using/seen so far, it seems to be all about neat "one-liners" using the underlying functions and working with lists & maps to solve issues, ...
5
votes
1answer
151 views

How to create a Hyperlink within the current Notebook?

Using “Create Hyperlink” dialog window I can create a link to a tagged cell in my notebook (it's “Destination notebook: Current notebook” radio button). Now, I can't figure it out how to create such ...
7
votes
3answers
413 views

Rewriting For loop to FoldList or similar

In CrossValidated, the answer to a question on prediction of number of viewers of Gangnam Style is given in R. I have mapped the answer directly to Mathematica: ...
7
votes
3answers
239 views

Restricted accumulation of values

Please consider the following list data. I was trying to accumulate data until the result turns positive the first time and ...
7
votes
4answers
446 views

How to implement dual numbers in Mathematica?

I wonder how can I implement dual numbers in Mathematica, so that all functions work well with them (as with complex numbers). Particularly, for each function $f$, ...
12
votes
5answers
663 views

How to improve this code for solving the “Mr.S and Mr.P” puzzle?

Mr.S and Mr. P puzzle — "Formalization of two Puzzles Involving Knowledge", McCarthy, John (1987) We pick two numbers $a$ and $b$, such that $a\geq b$ and both numbers are within the range ...
4
votes
1answer
201 views

Maximizing functions with Which statements

I'd like to be able to find the maximum value that my Capex function (see below) generates. This is a fairly simple function so I could just add it up but I have more complex functions of a similar ...
2
votes
5answers
368 views

How to leave function unevaluated programmatically?

Is it possible to write a function in such manner, that it can be either evaluated or left unevaluated? This is a general question. Sample below is just a sample. No need to find solution for this ...
2
votes
1answer
749 views

Using triangulation

I have been presented with 3 known points and the power densities at those points. I need to use those points to find the location of the actual antenna which is generating the signals. Power ...
6
votes
1answer
224 views

Return a Part by Reference? (For accessing hierarchical / structured data)

Is there a way to return a part of a list by reference, for reading and writing? I want to do this so I can easily manipulate "rule-styled structured", i.e., hierarchical data that is loaded from a ...
4
votes
3answers
338 views

Generate a Combination of letters by a number

I'm trying to write a function f. example: ...
7
votes
1answer
304 views

Guides for programming CDFs

Are there any tutorials for programming high-quality CDFs, like the interactive calculus textbook presented at wolfram.com? Mathematica's Help is extremely impressive but it really does not help much ...
1
vote
2answers
236 views

Inputting two arrays for a module in Mathematica

I am relatively new to the Mathematica enviroment and not sure where I am going wrong. I have evaluated the question and understand it, but dont know how to exactly create a module for it. The ...
1
vote
1answer
395 views

Equivalent of Python's “all” function in Mathematica

The Python function def isPrime(n): return all(n % i for i in xrange(2, n)) checks if a number is a prime number by using ...
18
votes
2answers
329 views

When to use Get vs Needs

When should I use << vs Needs? I just always use Needs as ...
3
votes
2answers
124 views

Localizing Pattern Names

When I want to define a function that uses a pattern, how should I localize the pattern name (i.e., x_ localizing the symbol x)? ...
4
votes
2answers
233 views

How can I use Max[] in a function that is passed a list not find the max of the list

For most functions in Mathematica, passing them a list will call the function on each element of the list. For example: ...