We’re rewarding the question askers & reputations are being recalculated! Read more.

# 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.

1,359 questions
Filter by
Sorted by
Tagged with
42 views

### How to use deep clones in Mathematica

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# ...
84 views

### How to print by using For loop? [on hold]

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 ...
33 views

### How can I find EdgeWeights strongly connected components using Manipulate

Given the following Code: ...
32 views

### Reference Calculation [closed]

I have database of many references of numbers format L-a-b. for example: L: 76 a: 5 b: 12 (this number is not in database). to get this number I have to do this calculation L: 71.09 ...
23 views

### Problems in understanding the time complexity for a graph [migrated]

I have the following algorithm in a graph G = (V, E). m is the number of edges and n is the number of nodes(vertices). dG'(u) is the number of nodes that are neighbours with u. My problem is that I ...
758 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: ...
57 views

### How can I count the number of edges between connected components of a directed graph

The following code: ...
99 views

### How can I analyze image colors expressed in the CIELAB L-a-b model? [closed]

I have a database of colors in L-a-b format. I want to analyze how many colors there are [in an image (??)], and I want to know the quantity of each color that it contains. For example: I want this ...
49 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: ...
95 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: ...
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 ...
294 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.
29 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? ...
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. ...
49 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? ...
90 views

### Is it possible to make listable ExperimentalNumericalFunction?

I have been playing a bit with the undocumented function ExperimentalCreateNumericalFunction and I wanted to know if somebody found a way to make generated ...
126 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 ...
82 views

### Why did just get “ nope ” ? I want this{ {2, 1}, {1, 2}, {1, 3}, {2, 2}, {3, 1}}. How can I get that with function “Table”? [closed]

How can I get that with function "Table"? Here are my codes ...
220 views

### Writing a program that will filter the integer solutions

I've the following equation: b==(-12 + Sqrt 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)) ...
83 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 ...
49 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] ...
70 views

### Converting a code with for a loop from MATLAB

In MATLAB I have the following for loop: ...
57 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 ...
25 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: ...
76 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 ...
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 ...
309 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 ...
51 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, ...
55 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 ...
79 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.$$
206 views

88 views

### Function with string explanation for its arguments with equal signs [duplicate]

I want to write a function using string as explanation for its arguments so that the function becomes intuitive for new users. For example, I want to write a function to compute BMI (just for ...
95 views

### How to use Module function?

Here is my issue; I want to iterate a fit to this data for a polynomial of degree 2 up till degree 6. However, at each iteration I drop certain data points that have a poor residual value. So each ...
34 views

### How to add a Locator to a Manipulate / ListPlot?

I have the following Manipulate to graphically show the n-th roots of unity: ...
147 views

### Pure functions applied to a two dimensional list

Lets say I have a two dimensional list: list = {{a, b, c}, {aa, bb, cc}, {x, y, z}, {xx, yy, zz}}; and two pure functions: ...
37 views

### how to run a specific cell in a notebook from another notebook

I have a long Mathematica code in a notebook, denoted by NB1. Since it is a very long code, and I need only some of the outputs from NB1 to be used in another ...
81 views

### Delete elements less than the last largest element

Here is my list. The first column contains its index and second column has data. ...
77 views

### Finding Non-Simple Paths of a Given Length on a Graph

For the following graph: ...
99 views

### How to Open, Evaluate and Close the same Notebook 100 times in a row?

I have a Mathematica notebook which I Open and Evaluate by hand. It Exports some data and then Closes. I now wanna Open, Run and Close the exact same Notebook 100 or 1000 times in a row to get a lot ...
54 views

### Open, Evaluate and Close notebooks sequentially

I wanna Open, Evaluate and Close notebooks sequentially. Code from question here ...
49 views

### Wrapping an association with a specialization of the buildin Set (=) function?

I want to wrap some association data into a dedicated symbol (S by example) ...
88 views

### How to make a contextual variable?

I have a question that would be trivial in OOP, but I am a newbie to programming in Mathematica, so I'm wondering how to deal with it. Basically, I want to create a package which basically involves a ...
77 views

### How to decorate data in a matrix for reporting purposes?

I want to create a report from two matrices m1 and m2 (already created, and available) with data. The report should (roughly) look like the output of the following code: ...
47 views

### I need the product of two functions be understood as a function itself (a Dirac delta example):

Define: In:= Dirac /: Dirac[x_, y_] f_[x_] := f[y] This works like Dirac's Delta. For example, In:= h[x] Dirac[x,y] Out:= h[y] perfect! However if I ask: In:= h[x] k[x] Dirac[x,y] Out:= h[y] ...
309 views

### Certain search in list

A list $LL$ of $n$ real numbers is given. For each element $e$ of $LL$ to find the position of the closest to the right element of $LL$ which is at least twice bigger than $e$ and return it. If ...
36 views

### Hierarchically adding {…keys..}->value to an association

Given a list of keys {"a","b","c"} and a value 3 (associated to the last key) I want to define a function that is equivalent to ...
54 views

### Define a function with specific permutation properties

I want to define a function evaluate[f_[x__]] which acts on an arbitrary function f[a,b,c,d]. The function ...
I have $N$ differential equation for each $s \in {1,2,...,N}$ on the domain $x \in [1,2]$ of the form (e.g.) $xf_s'(x) + \log(xs) f_s(x)+1 = 0$, with the boundary condition $f_s(1) = e^{-s}$ Now I ...