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
1 vote
1 answer
120 views

Tell mathematica to move on to the next step [closed]

...
  • 3,529
0 votes
0 answers
42 views

How to mimic Expand with Thread?

I want to mimic Expand[(a + b) (c + d)] with Thread. My attempt below does not provide the correct result: ...
1 vote
0 answers
36 views

Efficient construction of a formal polynomial using list manipulations

I have a code which is probably extremely inefficient given my inexperience with Mathematica list manipulation. Take as input data: ...
  • 1,317
2 votes
1 answer
119 views

Introduce formal symbols indexed by natural numbers

I'm going to describe a toy example here which I'm hoping with some help, I can then soup up into the more complex application I have in mind. Suppose the input is a list of lists, and for now take ...
  • 1,317
3 votes
3 answers
152 views

Deleting sublists where an element repeats beyond a repetition threshold

I am looking for some help constructing a function Part[M_,N_] which outputs the list of all integer partitions of positive integers up to $M$ such that in each ...
  • 1,317
0 votes
1 answer
78 views

Create list with integer partitions satisfying some conditions

I want to create a function PartSet[N_,M_] of two positive integer variables which outputs a list of all pairs of integer partitions for all integers up to $M$ ...
  • 1,317
19 votes
12 answers
1k views

Partitioning a list based on a criterion for sublists

SeedRandom[1]; alist = RandomInteger[{1, 10}, 20] {2, 5, 1, 8, 1, 1, 9, 7, 1, 5, 2, 9, 6, 2, 2, 2, 4, 3, 2, 7} I would like to divide this list into sublists (...
  • 28.5k
31 votes
6 answers
1k views

What secrets are hidden away in your init.m and where do you place it? Please help me build the ideal init.m

My init.m Feels Like it's Missing Something Although I am familiar with about a dozen or so programming languages I am only sort of, kind of, halfway competent in about three. MMA with it's boxes, ...
10 votes
1 answer
109 views

How to list all possible string arguments of a specific function?

For example, to learn the function Alphabet, we can read its document. But it's rather ambiguous, like "Some languages have extra properties". How to find ...
0 votes
0 answers
55 views

Algorithm: Permutations & Signature

Theoretical side Simple example: If I have two sets $A_1=\{1,3\} ,A_2=\{2,3\}$ and Permutations[{1, 2, 3}]= $\left( \begin{array}{ccc} 1 & 2 & 3 \\ 1 &...
6 votes
4 answers
349 views

How can I efficiently define functions with different names but doing the same stuff?

Recently I have met with with this interesting question:How can I efficiently define functions with different names but doing the same stuff? Somebody may want to ask me why I want to do things like ...
  • 453
6 votes
4 answers
409 views

Is there a more elegant solution than f[a, b, Sequence@@#3,...]?

I am trying to construct a list of many possible combinations using Outer and Permutations. Something that looks like that: <...
2 votes
1 answer
45 views

How to use another algorithm when the first approach is too slow?

I need to write a program that uses an alternate algorithm when the algorithm first attempted is taking too long. Here is a minimal example. ...
  • 6,914
0 votes
0 answers
42 views

TagSetDelay the Plus[ ] function for direcy use with Datasets

I am trying to define a particular behavior of the function Plus[] when the arguments are $n$ Dataset, with $n\geq 3$. (The goal is to mimic the behavior of Plus[] with Datasets instead of numbers) ...
1 vote
3 answers
133 views

Finding the value of a Fibonacci Polinomial

I need to find the value different to 0 when evaluating Fibonacci[x,2]mod(8417525)=0 How can I set up that with an iterative process, trying subsequent natural numbers till it finds the target value? ...
5 votes
1 answer
297 views

Lazy vs strict evaluation approaches - performance comparison

In general, I think there are two methods of evaluating a variable in Mathematica. My question is about performance of the two methods. Suppose that our final goal is to evaluate ...
  • 3,529
0 votes
1 answer
80 views

Issue with the output of pure functions

I am getting the operator & in outputs of pure functions. e.g. with the following code ...
0 votes
2 answers
104 views

Using FindRoot in a Loop: Updating the value of starting point

Consider the following nonlinear equation for $h[\lambda]$ ...
0 votes
0 answers
38 views

how to delete a variable programmatically in a notebook from another notebook

how to delete a variable programmatically in a notebook from another notebook? c = b; I have already tried Remove[c] but ...
2 votes
2 answers
88 views

Could anyone please help with defining a vector function of tons of variables?

Could anyone please help with effectively defining a vector-valued function of tons of variables so that ...
10 votes
2 answers
524 views

What is the most efficient way to define a Loop until function?

Mathematica has the While function which is very convenient when we need to process some code until the attainment of a certain state (identified with a condition). ...
1 vote
1 answer
110 views

How to convert this Mathematica expression to another, as described here?

I am working on a function of which the core will consist of something like: ...
5 votes
1 answer
82 views

How can I separate expressions in Module without suppressing output?

I want to show a progress indicator while statements in a Module are processed. Outside a Module this ca be done like this: ...
9 votes
0 answers
62 views

Does ArgumentsOptions do anything we couldn't do without it?

ArgumentsOptions was new in version 12.2. I looked at the application on that page, and it makes code very difficult to understand. What if anything does ArgumentsOptions do for us that we couldn't do ...
  • 6,914
0 votes
1 answer
51 views

Program works, but then fails when I write it inside Module [duplicate]

I'm new to Wolfram Language; I'm trying to get used to it by writing a bunch of code and programs, being one of them the algorithm for the bisection method. When I write the algorithm outside of a ...
4 votes
1 answer
199 views

Is it possible to improve a code related with iterative closest point (ICP) algorithm?

I am trying to write a code related with ICP algorithm. The purpose of the code is matching a target data with a reference data by translational operation in XYZ axes (3-degree-of-freedom (DOF) ...
  • 157
3 votes
2 answers
256 views

Numerical solution of the 2D-spatial nonlinear Allen equation

I would like to solve the 2D-spatial Allen equation in rectangular coordinate, which is a nonlinear reaction-diffusion PDE of the type $$\partial_{t}u=\epsilon(\partial_{xx}+\partial_{yy})u + u - u^{3}...
  • 1,238
10 votes
3 answers
432 views

How to programmatically change CellStyle of all Cells from "Input" to "Code"?

I have a special notebook styled for only creating functions and their packages. I often lazily do Evaluate Notebook instead of finding and opening all cells I need ...
  • 2,337
23 votes
1 answer
2k views

What are some approaches to measuring code coverage?

I understand that Mathematica can have some peculiarities in this area, but just in case... I'm talking about things like measuring coverage of MUnit tests to get an idea of code quality.
0 votes
1 answer
179 views

How to use AppendTo in do loop?

list = {1, E, (3/2)*E^2 + (3/8), (5/2) E^3 + (25/8)}; AppendTo[list, 2*E*list[[{x - 1}]] + (2*x - 3) (2*x - 4) (2*x - 5) (1/4)*list[[{x - 2}]]] Let x from 5 to 10, ...
  • 23
0 votes
0 answers
55 views

Block Behavior, but for Function Assignment instead of Variable Assignment

We can define a function using a variable b that does not appear as an argument, and then using Block, change the output of the ...
0 votes
1 answer
135 views

The list of coefficients of the "polynomial", which has the order of derivatives instead of degrees

I have some equation eqn = (A + B).x''[t] + Transpose[x'[t]].(2 A - 3 B + 1).x'[t] +(СС - 5).y'[t]+ Sin[x[t]+y[t]] I need to collect all the coefficients at ...
  • 2,304
5 votes
3 answers
231 views

What is the underlying interpolation in "BrightBands"/"DarkBands" color scheme?

Using the bookmarked conversation mentioned in this answer, I was able to extract the colors (and their parametric positions) of the Mathematica color scheme ...
  • 998
1 vote
1 answer
68 views

generate quadratic functions to evaluate membership of points

How can I make a printable list with different quadratic functions and with points that belong or not to them so that a young person can check whether or not the point belongs to the parabola? my code ...
  • 2,185
5 votes
3 answers
113 views

Plot the lines (nodes) for the given value from NDsolve output

I want to plot lines for a specific single value from the output in Nsolve (we need to find these nodes from the output ufun, then plot them). ...
  • 1,796
-1 votes
1 answer
386 views

Keywords for the Wolfram Language [closed]

For a programming language, certain keywords are reserved; i.e., these tokens can't be used in any other context while programming in that particular language. Here is a list of C language keywords ...
  • 28.5k
1 vote
1 answer
68 views

Appropriate syntax for constructing frequency table and histogram from experiment with three or more dice?

if I say to input 3, how do I get MMA to make me a table with all the cases on the left, in the center their frequency and on the right a histogram,bar chart, or some other way to represent the above. ...
  • 480
0 votes
1 answer
73 views

LocatorPane - restrict to circle

I have cobbled together a solution that does exactly what I need, but I don't fully understand how it works: ...
2 votes
0 answers
68 views

family photo album,how to optimize its realization?

I am Beezy, the eldest daughter of the couple. I have a lot of photos on paper and I want to make a photo album for my parents, but the task is titanic. First I use a scanner, to scan the photos that ...
  • 480
1 vote
0 answers
103 views

Storing python output to variables in Wolfram

Would like to use the external language input in python to save variables I can potentially use in Mathematica. Any chance there is a way to do this? I do understand there might be a solution with ...
10 votes
4 answers
473 views

How to use Intersection[] but keep the original list order

I want to keep the original order of l1: ...
  • 503
3 votes
1 answer
178 views

Extracting values from a Bézier curve in Mathematica

given a list of points I've created a Bézier curve, and now I would like to understand how to extract a "middle point" from a curve or get a list of points (not the input ones, the ...
  • 31
0 votes
0 answers
95 views

Label/GoTo and Compound Expressions

My Mathematica notebooks are often many pages long and, for clarity, I generally write only one expression on any line. In operation, such notebooks need to jump around within the full length of their ...
0 votes
1 answer
125 views

Classify across ten methods

Mathematica supports ten different methods for Classify. The ten methods are: "ClassDistributions", "DecisionTree", "GradientBoostedTrees", "LogisticRegression&...
  • 2,570
0 votes
0 answers
48 views

How to save previous calculation

I want to calculate the longest chain up on million applying repetily the Collatz function until it reach one. I was able to solve this using the following code: This is the definition of the ...
  • 101
-1 votes
1 answer
63 views

Dirichlet theorem [closed]

I'm programming Dirichlet theorem - here(p mod d=a, p is a prime number) via procedural programming and I don't have any idea, how to start. I would like to have function, which gets three numbers (a,...
3 votes
0 answers
82 views

Module inside With, With inside Module, or Just Module?

In general, if one wants to define local variables and local constants, which of the following is the best programming practice in terms of performance and code "safety"? (Assume ...
19 votes
1 answer
411 views

Programming language prototyping in Mathematica

Are you aware of any projects using the Wolfram language resp. Mathematica as an environment to explore the design of programming languages - in particular languages with a focus on mathematics (...
4 votes
1 answer
63 views

Best way to write a function that randomly takes definition from list of functions?

I want to define a function based on a random choice from a list of possible functions. For example, suppose the possible functions are {Sqrt,Log}. Then I want to ...
24 votes
6 answers
4k views

Creating the Yin Yang symbol with minimal code

The following code creates the Yin Yang symbol ...

1
2
3 4 5
32