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
45 views

Need help to understand the code

Here is the code by P. Valko and J. Abate for finding numerical inverse Laplace transform by trapezoidal's rule. Can someone willing to explain this code? I don't understand this part: ...
0
votes
2answers
44 views

help with performing operations on matrix parts inside a loop

I would like to translate the following code into Mathematica language but am having some trouble doing so: ...
0
votes
2answers
70 views

How to read value from a plot

Let's say I have plot. What is the command for getting the specific value at a point that I choose? Exampe: Plot like --I-. command(1) = 0 command(2) = 0, command(3)=1, command(4)=0
2
votes
1answer
60 views

How to set linear constraints on elements of a long list

I would like to minimize over quite large set of $a_i$ some function $f(a_1,a_2,\dots,a_n)$ subject to a set of $k$ linear constraints: $$ i=1\dots n: \quad a_i\ge0;\quad j=1\dots k:\quad\sum_{i=1}^n ...
2
votes
0answers
19 views

How to abort evaluation when clicking CancelButton in program with Dialog boxes?

If you run the following code you will notice when Cancelbutton is clicked, the output is an $Abort, but it continues running the following cells, I tried different things but no one works. I want to ...
0
votes
0answers
51 views

How to improve the parallelization of the following piece of code?

I'm new to the parallelization of code. I have a code that takes so much time to run and I'm trying to parallelize it. I'm copying below the piece that I need to improve. Can someone help with the ...
18
votes
1answer
187 views

Confirm vs Throw

Version 12.2 brought us Confirm and Enclose. What's the point? Is it just that it's a slightly more convenient syntax than ...
1
vote
2answers
105 views

Plotting Riemann Prime Counting

I want to program the formula in this page. Didn't take me long to get to my code below. But 1) it only plots the prime counting function and 2) evaluation takes incredibly long. How can I fix it? <...
3
votes
2answers
94 views

Best way to write a system of conditions

Quite simply, I am wondering if there is a cleaner (and more easily altered) way to write a system of conditions for an evaluation. For instance, suppose I have something like (I don't think a real ...
0
votes
2answers
34 views

Define-Produce function from a loop?

Consider the following code: ...
4
votes
3answers
165 views

generating lists of integers with constraint

Suppose you have the list $a=(k_1,k_2,k_3, \dots, k_N)$ such that $k_{i}\; (i=1,\ldots, N)$ are non negative integers. How can you get all the lists that satisfy the constraint $\sum_{i=1}^{N} k_{i}=M$...
12
votes
1answer
612 views

Programming a bishop's move on a grid

I am simplifying the question i need too work with, any advice on how to proceed for each step would be appreciated(no answers) I have a square grid of size a by b, inside the cell is an object that ...
5
votes
3answers
245 views

Looking for a notebook with the “glowing gasket” [closed]

I look for an implementation of the "glowing gasket" as described in the book "Indra's Pearls" in Mathematica. Here is a typical image: I did a look at Wolfram Demonstrations and ...
0
votes
1answer
126 views

How to solve following equation with multiple random variables

How can I program the following problem into Mathematica? $X,Y$ are i.i.d. Exponentially distributed random variables. Such that $X\sim\exp(1), \ Y\sim\exp(1)$. All other variables are positive real-...
1
vote
1answer
45 views

How to change the joining code?

I'm trying to combine 4 matrices but I'm getting a matrix of 4x16 not 8x8. A={{1,2},{2,3}}; B={{2,1},{3,3}}; DD={{4,5},{6,37}}; EE={{12,11},{13,14}}; :
1
vote
1answer
61 views

How to know when FindRoot[] fails to find a solution

My problem is very simple. Assume you have this piece of code : FindRoot[{x^2 + 1 == 0}, {x, -1, 1}] Now, this code returns ...
2
votes
0answers
72 views

Mimicking named arguments, a good idea? (programming style)

With respect to code readability I like the possibility to use keyword (named) arguments. I would like to have this under Mathematica, but AFAIK there is no native support for that. By example, to ...
1
vote
1answer
51 views

XOR combination between the bits of a string

Given an integer n, we can construct $2^n$ strings of length n. We can take the first element for each of these strings and create a list. In total 'n' such lists are possible. But now I need to ...
2
votes
1answer
40 views

Simplest way to check if optional parameter is omitted?

Suppose I have a function f[x_,y___]:= (code) and I want my code to check whether the parameter y is omitted. What's the easiest ...
1
vote
1answer
68 views

How avoid to memorize 1 billion useless data

I am a newbie Mathematica user I wanted to know, using brute force, how many non empty triplets $\{A_1,A_2,A_3\}$ of subsets of $$AA=\{1,2,3,4,5,6,7,8,9,10\}$$ satisfy the conditions $A_1\cup A_2\cup ...
0
votes
1answer
84 views

How do I see output for intermediate steps in a program? [closed]

I understand Mathematica programs to be a series of steps enclosed in simple parentheses. Each 'step' ends in a semicolon except for the last. The program output is then the output of the last step ...
0
votes
1answer
53 views

TogglerBar linked to Buttons that override input list

This question is about extending the solution provided here. How do I allow the user to change x outside the TogglerGrid function so that the TogglerBar shows the new values of x? I've set it up ...
3
votes
1answer
99 views

Need help with a linear programming problem

Consider $1\rightarrow{}x+2y\leq{500}$, $2\rightarrow{}2x +y \leq{520}$, $3\rightarrow{}2x+5y \leq{}1200$, $4\rightarrow{}x \geq{}0$, $5\rightarrow{}y \geq{}0$, The above is the set of inequalities ...
4
votes
0answers
114 views

What is the best coding style for performance?

The problem of Mathematica is there are too many ways to perform one task. That leads to confusion for new users because the performances of these methods are so different. I'm learning the best ...
6
votes
4answers
287 views

Converting an equation with units to one without units

I may have a solution but it is not slick! See below Doing numerical calculations with functions that use units can be very slow. I would like to have a function or operator that can turn my functions ...
0
votes
1answer
101 views

Exporting a multi excel files into one file

Suppose a list of students'grades in excel: "excel files" I want to write a program separate student grades to their respective classes and then write them in one excel file. What should I ...
0
votes
1answer
40 views

How to load a function from an external notebook that creates a docked cells toolbar?

I coded a compact toolbar in its own file nbtaskmate.nb for various common notebook tasks which I would like to load onto any notebook I might have open with a ...
5
votes
3answers
351 views

Stacked time series plot

I have multiple time series measured in different units. I want to have a stacked plot of my data with a common x-axis. An example would be here. For illustration, here is my data. ...
3
votes
1answer
46 views

Generating set of equations of varying length and solving them

I am trying to generate a set of equations that describe a change in density for each variable in the form of: $\frac{dX_i}{dt}=X_i(r_i-s_iX_i+\sum_{j=1,j\neq i}^na_{ij}X_j)$ where n is the number of ...
10
votes
2answers
325 views

How can I plot my financial indicator below a trading chart (produced by TradingChart) with the same x-axis?

Since this question was not answered, I would like to ask again with some additional information. I have a trading chart saved as chart1 as follows. ...
1
vote
0answers
51 views

Can Mathematica warn you about mistyped variables?

In other dynamical programming languages like Python, mistyping a variable, e.g. mistyping var1 as bar1 in the example below, immediately results in an error. ...
1
vote
2answers
33 views

Code to Expand Symmetric Laurent Polynomial in Symmetric Basis

Let $F(w,y)$ be a symmetric Laurent polynomial. By this I mean the powers of $w,y$ are bounded above and below, and $F$ is invariant under $y \to y^{-1}, w \to w^{-1}$. Given such an $F$, there are ...
3
votes
3answers
133 views

How to simulate the roll of 3 or more dice and ask for a sum of 3 or more?

How to simulate the throwing of 3 or more dice and ask for the sum of 3 or more and indicate the number of calves, or more that are produced. For example if you throw 3 dice, how many cases will add ...
1
vote
1answer
51 views

How to emulate statistical command choice tab of this widget?-how to do what i ask?

I designed this little program, but I want you to be able to choose what I want to look for by choosing it as you do with the widget tab, please help me. widget Widget of internet my program ...
1
vote
0answers
35 views

Adding a module to teach Mathematica the Laplace transform of particular Mittag-Leffler functions

Mathematica 11.3 is not aware of a useful Laplace transform LaplaceTransform[t^(-a) MittagLefflerE[a, a, t^a], t, s] which for ...
2
votes
2answers
72 views

How to program combinatorics problems about randomly moving cards from $A$ to $B$ to $C$ to $A$?

I have a lot of problems with the following scenario, for example, Given 3 boxes $A$, $B$ and $C$. The box $A$ contains 2 identical cards $x$, 4 identical cards $y$ and 1 card $z$. The box $B$ ...
7
votes
0answers
110 views

Reboot of Maeder's “Programming in Mathematica”, an appeal [closed]

I have been using Mathematica since Version 1, and to me the touchstone for best practices in Mathematica is Roman Maeder's "Programming In Mathematica". It is not fair to say that PIM is ...
0
votes
0answers
23 views

How to terminate NestWhileList when f is applied to a List

I made the following function to demonstrate a Number Theory theorem: ...
1
vote
0answers
44 views

set and set delayed in dynamic programming [closed]

The first one is running Module[{f}, f[1] = f[2] = 1; f[n_] := f[n - 1] + f[n - 2]; f[5] ] But the second one never ends its loop. ...
11
votes
1answer
206 views

Solutions for searching over Mathematica notebooks?

I have hundreds of Mathematica notebooks accumulated over the years, and I'd like to search over them. I've been using various versions of text search (grep, SilverSearcher, Spotlight), but there are ...
0
votes
1answer
117 views

How to show the map of a complex function ( plane z incl the basic square grid to plane w?

I want to make a presentation of the maps of the standard complex functions, as well as some mobius transformations and special complex functions. I want to present it exactly like it is done in the ...
4
votes
3answers
259 views

How to programmatically modify a function definition

I would like to know an efficient method (without converting Mathematica Code to strings and string processing) of modifying a function definition programmatically. For example, I would like to tidy ...
2
votes
3answers
83 views

Strange Behavior of Compile[] inside With[]

Consider, in the examples below, the difference between defining $n$ as a global variable or as an argument to function comp[], which includes a compiled function ...
3
votes
2answers
180 views

How to link Manipulate to specific questions to activate sliders

I have the following multiplication Manipulate: Manipulate[ x*y, {x, 1, 10}, {y, 5, 15} ]; When you run ...
3
votes
1answer
156 views

Using functions instead of lists in physics numerical problems

I'm using the following code for calculation of reflection and transmission coefficients through square well potential: ...
8
votes
1answer
406 views

Why are more highly nested lists often not more memory and time-intensive?

I would expect more highly nested lists, being deeper and more complex than flatter lists, to take up more space (bytecount) and take more time and memory to operate on in general. Consider the ...
1
vote
0answers
18 views

Question about AsymptoticEqual[nChebyshevPsi[x], x, x -> Infinity]

Given the partial sum function nChebyshevPsi[x_] := Sum[MangoldtLambda[y], {y, x}] I would like a True response from ...
1
vote
2answers
32 views

Defining an iterated differential operator with compositions

I'm a bit new to Mathematica so this question might be a bit basic. Still, I could not find an answer. I wish to define a symbolic differential operator. Currently, I do something like the following: <...
2
votes
2answers
125 views

How to program a situation like the following in mathematics and generalize the process to other configurations?

Distribute the numbers from 1 to 10(view image) so that the sum of each row and each column is the same and a) the maximum possible b) the minimum possible (I put it from 1 to 10 for ease) I know it ...
3
votes
1answer
95 views

How can I iteratively add elements to a list

Basically I want to make a histogram with a list of dates by using DateHistogram[]. However I have the data of the dates in nested list format, with elements like ...

1
2 3 4 5
30