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.

922 views

757 views

How can I improve my code for drawing a tree?

This code draws a tree, but it's not in the functional style. ...
347 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 ...
622 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, ...
240 views

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: ...
132 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 ...
2k 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 idea ...
115 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 ...
2k 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$? ...
520 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 ...
652 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 ...
1k 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 ...
571 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 ...
2k 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 ...
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 (\... 3answers 3k 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 ... 1answer 283 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 ... 1answer 536 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 ... 1answer 260 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 ... 3answers 2k 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: ... 4answers 195 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 ... 3answers 336 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 ... 1answer 307 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 <... 2answers 595 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 ... 1answer 484 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: ... 0answers 325 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 ... 1answer 472 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 ... 1answer 550 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: ... 5answers 519 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: ... 0answers 167 views Why is Compile[] failing with message Compile::extscalar? [closed] ... 3answers 704 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, ... 1answer 344 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 ... 3answers 564 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: ... 3answers 305 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 ... 4answers 707 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$,$f(\varepsilon)=f^\prime(0)\...
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 \$(2,...