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
0 votes
0 answers
41 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: ...
user avatar
  • 1,767
1 vote
0 answers
28 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: ...
user avatar
  • 1,287
2 votes
1 answer
102 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 ...
user avatar
  • 1,287
3 votes
3 answers
137 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 ...
user avatar
  • 1,287
0 votes
1 answer
50 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$ ...
user avatar
  • 1,287
14 votes
11 answers
776 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 (...
user avatar
  • 14.9k
23 votes
6 answers
818 views

What secrets are hidden away in your init.m file and where do you place it? Please do share!

Help Build init.m Best Practices By Sharing or Critiquing Code Some of our most essential code is hidden away in a file that we can just drop and forget. Although contents of this infamous file should ...
10 votes
1 answer
97 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 ...
user avatar
0 votes
0 answers
45 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 &...
user avatar
5 votes
4 answers
290 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 ...
user avatar
  • 289
6 votes
4 answers
400 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: <...
user avatar
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. ...
user avatar
  • 6,630
0 votes
0 answers
40 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) ...
user avatar
1 vote
3 answers
109 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? ...
user avatar
5 votes
1 answer
242 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 ...
user avatar
  • 2,451
0 votes
1 answer
69 views

Issue with the output of pure functions

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

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

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

My notebook backup function works fine. I am just asking for your critical review before submitting to FunctionRepository

Why the name and what does it do exactly? Youre probably asking yourselves why I named it NotebookBackupStack. All that is explained in ...
user avatar
  • 1,787
0 votes
0 answers
33 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 ...
user avatar
2 votes
2 answers
75 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 ...
user avatar
10 votes
2 answers
469 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). ...
user avatar
1 vote
1 answer
105 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: ...
user avatar
5 votes
1 answer
77 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: ...
user avatar
8 votes
0 answers
58 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 ...
user avatar
  • 6,630
0 votes
1 answer
45 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 ...
user avatar
3 votes
1 answer
128 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) ...
user avatar
  • 147
3 votes
2 answers
188 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}...
user avatar
  • 1,100
9 votes
3 answers
311 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 ...
user avatar
  • 1,787
23 votes
1 answer
1k 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.
user avatar
0 votes
1 answer
115 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, ...
user avatar
  • 23
0 votes
0 answers
53 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 ...
user avatar
0 votes
1 answer
65 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 ...
user avatar
  • 1,626
5 votes
3 answers
178 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 ...
user avatar
  • 902
1 vote
1 answer
59 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 ...
user avatar
  • 2,145
5 votes
3 answers
108 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). ...
user avatar
  • 1,624
-1 votes
1 answer
296 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 ...
user avatar
  • 14.9k
1 vote
1 answer
67 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. ...
user avatar
  • 480
0 votes
1 answer
69 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: ...
user avatar
2 votes
0 answers
65 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 ...
user avatar
  • 480
1 vote
0 answers
73 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 ...
user avatar
0 votes
0 answers
58 views

Importing n different pdf files and sending them to n different emails

How with MMA could I do to load from a folder called "jobs" "n" different pdf files and send them to "n" different "gmail" emails stored in a mails.txt file in ...
user avatar
  • 2,145
10 votes
4 answers
385 views

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

I want to keep the original order of l1: ...
user avatar
3 votes
1 answer
148 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 ...
user avatar
  • 31
0 votes
0 answers
73 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 ...
user avatar
0 votes
1 answer
114 views

Classify across ten methods

Mathematica supports ten different methods for Classify. The ten methods are: "ClassDistributions", "DecisionTree", "GradientBoostedTrees", "LogisticRegression&...
user avatar
  • 2,036
0 votes
0 answers
38 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 ...
user avatar
  • 101
-1 votes
1 answer
58 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,...
user avatar
3 votes
0 answers
79 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 ...
user avatar
15 votes
1 answer
303 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 (...
user avatar
4 votes
1 answer
59 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 ...
user avatar

1
2 3 4 5
31