A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [programming]

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.

Filter by
Sorted by
Tagged with
2
votes
1answer
34 views

TableView: How to change column headings?

I am not even sure whether it is possible. I would like to change column headings of TableView output to letters such as A, B, C etc instead of 1,2,3. Here is an example: ...
0
votes
1answer
61 views

Assert that prints message and aborts computation?

I'd like to add asserts which check for condition, print useful message and abort computation on failure. IE, ...
4
votes
2answers
69 views

Manipulate lists as function arguments

I am trying to write a Demonstration, which I believe means I must write it as a Manipulate, not a DynamicModule. My question is essentially the same as "Dynamic lists as function arguments", but I ...
8
votes
6answers
303 views

Brute Force for solving Diophantine equation

I'm trying to solve the following Diophantine equation using Mathematica: $$2^x=5^y+3$$ I have a code,but is very slow. Can we speed up ? ...
454
votes
37answers
100k 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 ...
2
votes
0answers
30 views

FindFaces on Raspbery Pi [closed]

I think this is an standard question but I did'nt find any new answer since years. I try to use FindFaces on raspeberry pi. This function leads to an error message : opencv not available for raspberry ...
3
votes
0answers
55 views

Calling custom function from C++

I'm programming a project where I use multivariate symbolic polynomials. At some point I need to perform a PolynomialMod over a prime modulus, but the library GiNaC which I use works only over the ...
7
votes
1answer
215 views

Moving B.C.s in heat diffusion model

I came across the paper Solidification dynamics of an impacted drop regarding a heat equations by Thiévenaz et.al and was interested in knowing how they obtained the graphs presented. From what I ...
3
votes
1answer
76 views

NextKSizePartition, or how to partition a set into subsets of size $k$ but incrementally

This question might seem very much like the linked one below but it differs in a very special way; Mr.Wizard suggested I start a new post: Partition a set into subsets of size $k$ What I want is to ...
2
votes
2answers
71 views

Finding the smallest integer such that a given condition holds with “binary search”

Setup. Suppose we are given a function $$f:\mathbb N\to\{\text{False},\text{True}\}$$ such that $$f(n)=\text{True}\implies f(n+1)=\text{True}$$ and such that $f(n)=\text{True}$ for some $n$ large ...
0
votes
1answer
86 views
1
vote
1answer
36 views

Function and patterns. FixedPointList doesn't work with function [closed]

There is a function: Clear[sort]; sort[{a___, b_, c_, d___}] := {a, c, b, d} /; b > c; It perfectly works with NestList function: ...
-2
votes
1answer
116 views

How to use deep clones in Mathematica [closed]

Is there a way to use deep clones in Mathematica? Maybe by making lots of different kernels. In order to execute multiple notebooks I need more than one kernel, is there a way to make them using C# ...
-4
votes
3answers
87 views

How to print by using For loop? [closed]

For[mu = 0; mu < 6, mu++, mu = -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1]; Print[T1]] I want to get the value of ...
25
votes
2answers
2k views

Using a list of tuples in a pure function

I want to use a list of tuples within a function to make assignments. Say I want to make assignments of the form value[i,j] = val What I have is a list of ...
1
vote
1answer
35 views

How can I find EdgeWeights strongly connected components using Manipulate

Given the following Code: ...
4
votes
4answers
143 views

Is it possible to create lookups on temporary symbols that still allow the symbols to be automatically removed?

Is there some way to create lookups keyed on Temporary symbols that somehow avoid the referencing of the Temporary symbols, ...
17
votes
3answers
787 views

Why use \[FormalN]?

Through a copy of some code from an answer on this site I discovered the existence of: \[FormalN] The documentation describes it as follows: ...
8
votes
1answer
611 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 ...
1
vote
1answer
58 views
12
votes
5answers
310 views

Implement settable properties

I am looking for advice on implementing the following. (It is possible that the answer is that it is simply not a good idea to do this.) I would like to have an object similar to ...
7
votes
2answers
545 views

Distance Time Warp (DTW) function implementation in mathematica

The DTW (Distance time warp) is given here http://en.wikipedia.org/wiki/Dynamic_time_warping There is an implementation of DTW in R as well as MATLAB. However i am unable to find something for DTW in ...
1
vote
1answer
51 views

Hardy Ramanujan Question [duplicate]

I revised the code I asked about earlier, but I am still not getting an output. According to Mathematica it is (mostly) correct syntax. Here is the revised function: ...
2
votes
1answer
100 views

Implement gradient method in functional programming style

I implemented the gm for quadratic function in Mathematica, but it looks like more in an OOP style, as the pic shows. How to rewrite it in Mathematica style? I tried with following code: ...
69
votes
7answers
15k views

Code that generates a mandala

My little brother asked me to print original mandalas for coloring. I would like some idea on how to create them, but without color, so he can color them. examples
1
vote
0answers
35 views

Need help with While loop [closed]

I'm trying to do the iterative jacobian method but I can't get the output. Any other alternatives using iterative jacobian would be highly appreciated. ...
1
vote
1answer
38 views

FindInstance confused by CoprimeQ

For some reason when I type FindInstance[a + b == c && CoprimeQ[a, b, c] == True, {a, b, c}, Integers] Mathematica just immediately returns my input as ...
2
votes
2answers
302 views

How can I solve the Ramanujan problem by using Wolfram language? [closed]

The problem like this: find all integers n, 1 ≤ n ≤ 10, 000 such that n is the sum of two cubes of positive integers in two different ways. I want to solve the problem as a procedure in mathematica.
0
votes
1answer
30 views

Subtraction of vectors subtracts whole vector with individual elements

When I'm trying to calculate the value of DP, it subtracts the PCurrent matrix from each element of PGoal. What am I doing wrong? ...
1
vote
1answer
52 views

How to save matrices from each iteration of i? [closed]

I am trying to get the transformation matrices from DH parameter table and would like to save each matrix (Ai) getting after each iteration of i. How can I do that? ...
6
votes
1answer
97 views

Is it possible to make listable Experimental`NumericalFunction?

I have been playing a bit with the undocumented function Experimental`CreateNumericalFunction and I wanted to know if somebody found a way to make generated ...
4
votes
3answers
110 views

Function for converting to base b, taking derivative with respect to b and evaluating at b

I am relatively new to Mathematica and I would like to program a function taking 2 variables in and giving 1 output. I think the best way to describe the function is like so: Given a base 10 number x ...
3
votes
2answers
133 views

Is there any command similar to Delaunay of matlab?

After finding this webpage where they mention the generation of land using matlab, In its section how it works, explain its operation in detail, I started trying to do it in MMA but I am doubtful of ...
0
votes
1answer
82 views
23
votes
5answers
7k views

How can I implement object oriented programming in Mathematica?

Roman Maeder's object oriented programming package is nice, but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.
16
votes
1answer
421 views

Confused by the opts : OptionsPattern[ ] pattern

I'm trying to make sense of the syntax in the clause opts:OptionsPattern[], as found in this standard "rule-based" (pseudo-)function definition pattern: ...
4
votes
3answers
229 views

Writing a program that will filter the integer solutions

I've the following equation: b==(-12 + Sqrt[3] Sqrt[ 3 (-4 + r)^2 + 12 a^2 (-2 + r) - 4 a (-5 + r) (-2 + r) + 4 a^3 (-2 + r)^2] + 3 r)/(6 (-2 + r)) ...
4
votes
1answer
85 views

Is it possible to make Decompose work with coefficients containing radicals?

It appears that Decompose works reliably only on polynomials with integer coefficients, although it seems to be not mentioned in the docs. Can I make it work (or ...
0
votes
1answer
50 views

Getting unexpected results form If expressions [closed]

I'm mystified by this: g[a_, b_, c_] := Module[{d}, d = If[(b < 1), b, b + 1]; If[a < b, d = 0.]; d*c] g[a, 20, 40] ...
4
votes
2answers
66 views

Turning Lists of Formulas Into Lists of Ordered Pairs

I'm working with a finite list of linear equations in some amount of variables. Say, {2kx-3y,3y+2kz-x,2x+2y+2z,ky} Is it possible for Mathematica to take this list and output a list of pairs where ...
0
votes
0answers
74 views

Converting a code with for a loop from MATLAB

In MATLAB I have the following for loop: ...
121
votes
3answers
26k views

Is there an open source implementation of Mathematica-the-language?

I've seen questions before such as "What is the best open-source equivalent for Mathematica?", but that specific question (and that line of inquiry in general) cares more about the computer algebra ...
2
votes
0answers
78 views

How can I make this “Pick” inside a “Table” run faster?

I am working on becoming more and more familiar with MMA and on a scale from one to ten, I would rate myself as a four or a five. I understand vectorization and that loops-are-very-bad. I have ...
0
votes
0answers
26 views

Question about converting Mma expressions to TeX

When I want to convert the following expression Integrate[1/(1 + t (-I - 1)) (-I - 1), {t, 0, 1}] to TeX, I do: ...
91
votes
4answers
8k views

What are the recommended settings for git when using with Mathematica projects?

Background I'm relatively new to git — currently overseeing an offshore .NET-based development project on GitHub within a private business account, but little experience beyond that. I'd like to set ...
0
votes
1answer
69 views

Change a formula [closed]

have a program consisting of a database of colors in L-a-b format. I want a formula to obtain the desired color by mixing different amounts of colors that are in the database. For example: I want ...
16
votes
2answers
314 views

Improving Performance of an XY Monte Carlo

I normally write my Monte Carlo codes in Fortran for speed, but I was doing some quick and dirty work and wrote one in Mathematica for the XY model on a square lattice (see Kosterlitz-Thouless ...
2
votes
1answer
57 views

Operate on functions with arbitrarily many arguments

Is it possible to define a function that can operate on another function with arbitrarily many arguments? For example, I want to do error propagation using partial derivatives. It is not clear to me ...
2
votes
2answers
81 views

How to generate vectors with programming

I want to generate all possible vectors programicaly with entrys in $\Bbb Z_4$: $$A_j:=\begin{bmatrix}x_1\\ x_2\end{bmatrix}, \qquad x_i\in \{0,1,2,3\}, j=1,2,\cdots 16.$$
4
votes
4answers
215 views

Programming a recursive formula into Mathematica and find the nth position in the sequence

Well, I have the following recursive formula (where $\text{n}$ gives the position in the sequence): $$\text{P}_\text{n}=\alpha\cdot\text{P}_{\text{n}-1}+\text{P}_{\text{n}-2}\tag1$$ For arbitrary $\...