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
0answers
26 views

Latent Dirichlet Allocation

Are there any references for published or technical papers that have used the Mathematica code given in: How to perform document classification (i.e. extracting topics from text)?
2
votes
1answer
70 views

Function with string explanation for its arguments with equal signs

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 ...
1
vote
0answers
47 views

How to reduce the time of calculation using ParalleDo instead of Do Loop?

I am trying to use ParalleDo function through ParametricNDSolveValue and NIntegrate. The question is pretty similar how to apply ...
1
vote
1answer
88 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 ...
3
votes
1answer
27 views

How to add a Locator to a Manipulate / ListPlot?

I have the following Manipulate to graphically show the n-th roots of unity: ...
5
votes
3answers
132 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: ...
2
votes
1answer
30 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 ...
3
votes
1answer
72 views

Delete elements less than the last largest element

Here is my list. The first column contains its index and second column has data. ...
2
votes
2answers
68 views

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

For the following graph: ...
1
vote
1answer
93 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 ...
2
votes
1answer
49 views

Open, Evaluate and Close notebooks sequentially

I wanna Open, Evaluate and Close notebooks sequentially. Code from question here ...
1
vote
0answers
47 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) ...
2
votes
2answers
77 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 ...
2
votes
1answer
73 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: ...
1
vote
2answers
46 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] ...
6
votes
6answers
301 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 ...
2
votes
1answer
33 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 ...
2
votes
1answer
44 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 ...
2
votes
1answer
57 views

Find critical radius in percolation

I would like to examine the percolation from the left edge to the right edge on random lattice. Suppose I have a rectangle with N random points on it. ...
1
vote
4answers
84 views

How to put solutions of mutiple DEs with NDSolve in table

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 ...
5
votes
1answer
85 views

Mapping a function f[xi_,xj_] over a list {x1, …, xn} with the i < j restriction

I am often facing the situation where I have a list $\{...x_k...\}$ and where I want to compute: $$ \{...f[x_i,x_j]...\}\text{ with }\ i<j $$ Unfortunately, I have not been able to find an ...
0
votes
0answers
51 views

Import and merge PDF files

I have a folder with several pdf no more than 50, I would like to import them to be disordered and that the output was a single pdf (you can imagine it as a proof of form A and we want to produce form ...
2
votes
3answers
198 views

Find the 3D region containing the origin bounded by given planes

I'm writing a code to generate the Wigner-Seitz cell of the reciprocal lattice for a given set of lattice translation vectors. For example, consider the Body Centered Cubic (BCC) lattice whose basis ...
0
votes
1answer
35 views

Wrapped Association into a “structure”: how to define Equal[] and what are the good practices for package dev?

Using a nice answer https://mathematica.stackexchange.com/a/197936/42847 I got from a previous question I define: ...
3
votes
3answers
90 views

Efficient manipulation of Associations passed to functions, how-to? [duplicate]

I have some data wrapped into a MyData[data_Association] "structure". My Association contains some big arrays and I do not want ...
1
vote
0answers
27 views

A newbie question about the use of the FourierSeries functions

Although I have had no previous experience with the Mathematica Fourier Series functions ( or package ), I am writing a tutorial on Fourier Analysis and Transformations in a Mathematica Notebook, ...
9
votes
2answers
218 views

Finding the path in a graph from A to B then back to A with a minimum of shared edges

the problem is to find cycle from A to B back to A, so that the path B-A would use minimum edges from path A-B. The graph is undirected and can have cycles. The paths don't have to be shortest, they ...
0
votes
0answers
30 views

How to use the Mathematica [duplicate]

I am a new learner for Mathematica. I know just some basics of Mathematica, I can plot simple graphs. But, sometimes I have to plot some complicated graphs. Then, I am unable to plot that particular ...
12
votes
1answer
454 views

Pascal records and Mathematica programming

Background: "experienced" Pascal-programmer (DOS-era, never got into OOP) proud owner of Mathematica ver 11.2 have used Mathematica for years to do my share of number crunching and plotting to ...
0
votes
0answers
16 views

CDF and ElasticSearch [duplicate]

I have an large amount of data, in the terabyte range, in an ElasticSearch instance. The data is on an network air gapped from my Mathematica instance and I'd like to have an app to examine the data ...
0
votes
1answer
76 views

How can I use Compile to implement recurrence?

I am trying to make the code for the following recurrence. Here wjoin[[i]] is used for calling values from a data set and a is a ...
12
votes
2answers
279 views

Plot of histogram similar to output from @risk

In order to analyze simulated data, @risk provides a histogram with handle bars, so that we can move these handles to see what proportion of data are on each side. For example, . I am trying to ...
0
votes
0answers
28 views

Custom PopupMenu displays menu items as values instead of labels

I'm trying to create custom appearance for PopupMenu with the below code. The problem I have is with the menu items which are displayed as values instead of labels. ...
0
votes
0answers
28 views

Why is an integration error appearing during this code?

I'm really confused about this to be honest. If i evaluate approx[x,k] for some k, and then input the list into the Plot function, I get a plot. But if I try to use approx[x,k] directly, I get an ...
2
votes
0answers
39 views

Problem with PopupMenu: Its values don't update dynamically

I have a problem with PopupMenu inside DynamicModule, its values don't update dynamically as they supposed to. The example below ...
3
votes
1answer
58 views

How to get Mathematica to loop two functions at once

So I know how to get half of this problem. I am trying to run a loop that combines the following two function at once so I can see from my index i if any number satisfies both conditions. TO get the ...
1
vote
2answers
133 views

MapThread conflicting with DynamicModule

Cross-posted: https://community.wolfram.com/groups/-/m/t/1625808 Answer posted on Wolfram Community I'm creating an interactive UI which allows the user to import data from a spreadsheet, perform ...
0
votes
1answer
62 views

Solving x'[t]+a*x[t]==0, listing all the solutions, trying to get the value -1x<1 and all corresponding value of a

I am Trying to solve x'[t]+a*x[t]==0,x[0]==1, for x with {t,0,10} using NDSolve. ...
0
votes
1answer
55 views

How to make a table for loops?

I have a code given by ...
2
votes
1answer
76 views

a recursive function using memoization

I have looked at a lot of these cases, e.g. Can one identify the design patterns of Mathematica? and the included ones. My trimmed example, here establishing the 'initial conditions' (where the ...
1
vote
1answer
99 views

Complex partial fraction expansion

I would like to have a tool for partial fraction expansion of polynomial quotient $$\frac{P(z)}{Q(z)},$$ where the order of the polynomial $P(z)$ is less than that of $Q(z)$. The output of the ...
3
votes
1answer
49 views

Implementing Dual Unit from Dual Numbers

I'm trying to implement the dual unit $\epsilon$ defined by $\epsilon^2 = 0$ into Mathematica but I'm having trouble defining $\epsilon^n = 0$ for $n\geq 2$. In this answer they simply use ...
1
vote
1answer
41 views

Defining a function that affects indices

I want to define a function, that works like this: f[3v[1,2,3]] = 1/3 v[1,3,2] + 3^2 v[1,2,3] f[2v[2,2,1]] = 1/2 v[2,1,2] + 2^2 v[2,2,1] Basically, it should ...
4
votes
1answer
133 views

How to implement split-complex numbers?

For those who do not know, the split-complex numbers are an analogue to the complex numbers where J is defined such that $J^2=1$ but $J\ne\pm1$, so they are all of the form $a+bJ$. By using ...
2
votes
0answers
73 views

Calling a notebook from a different notebook

Basically I have a notebook (let's call it nb1) that when evaluated yields one number when I specify some parameter $\alpha$ (in nb1). I want to call nb1 in a different notebook (nb2) using for ...
0
votes
1answer
93 views

How to resolve the fail when applying a user-defined solver?

The user-defined function pdetoode and pdetoae, developed by @xzczd, is very useful to deal with a PDE system when there is ...
19
votes
5answers
1k views

Sisyphus Random Walk

A Sisyphus Random Walk evolves as follows: With probability (r) you advance the position of the walker by +1. With probability (1-r) the walker resets at x0 = 0. To simulate the probability of reset ...
1
vote
0answers
70 views

How can we make an algorithm with the A* method in Mathematica with 5 different flight routes? [duplicate]

I need to find the shortest path with the A* algorithm using Mathematica. I have 5 different flight routes with coordinates. They start and end at the same point. Between every point there is a wind ...
1
vote
2answers
126 views

How to print chess board with array? [duplicate]

I am doing n-queen implementation with my own algorithm and I get solutions with Number.But,I want to get output with actual chess board. This is my piece of code. ...