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
2answers
36 views

Function providing input and integration limits for NIntegrate

I am trying to define some custom function that evaluates the numeric integral of some complicated function. The problem is that I would like to include as an input the integration limits. A MWE ...
1
vote
0answers
65 views

Can we make “applets” with Mathematica?

I've made a very simple photo resizer with Mathematica: It takes some files in a folder, processes them and write them into that folder. Now, I have to open the Mathematica file every time and ...
0
votes
0answers
28 views

Standard way to define a linear operator?

Say I want to define some simple linear operator. I can do this by f[c_?NumericQ x_] := c f[x] f[x_ + y_] := f[x] + f[y] Or let's define a bi-linear operator ...
0
votes
0answers
28 views

Inequality programming involving sum compositions

$n=3$, $m=3$, $B$ - identity matrix $3 \times 3$ Trying to implement it in Mathematica, but can't figure out how to program the second term. The result is an error. ...
0
votes
0answers
45 views

Hi. I'm a beginner so I need help to solve this equations using Regula-Falsi to find root of the equation (which is x)

I've been trying to look for an example but only with one unknown. In my case of studies, I have 4 unknowns. I just want to make sure is it correct the way I'm writing the coding to find the root ...
0
votes
1answer
89 views

Find the Jacobian and Wronskian of 3x3 system [closed]

Can you help me find the code that calculates the matrix Jacobian and Wronskian of 3x3 type. A matrix with the help of the "modlye" commend. I can only write this: ...
0
votes
0answers
46 views

Force WhenEvent and NDSolve to numerical evaluation and Best Practice

I'm trying to perform an hybrid kalman filter for a nonlinear system. The following code works but it is very slow due to the fact that it does symbolic evaluation. What I wish is that for the filter ...
4
votes
1answer
202 views

Programming twisted pyramids based on polygon spirals

I'm interested in polygonal spirals and after reading Filling Space with Pursuit Polygons, I was curious if I could extend the program to create twisted pyramids as 3D-objects. My goal is something ...
1
vote
2answers
55 views

WhenEvent inside Ndsolve how to evaluate actions numerically every time the event happens

I need to force a whenevent action to be evaluated numerically all the times the event happens. The fact is that I use very complicated matrices and I need to invert them so the system requires a lot ...
2
votes
1answer
42 views

In NMinimize, how to incorporate constraints on positive semidefiniteness of a matrix which is not the matrix variable being optimised?

The problem I want to solve the following problem for symmetric matrix $X$: $$ \begin{aligned} \min_{X\succ 0} \; & -\log(\det(X)) & \\ \text{subject to} \; & \begin{pmatrix} X &...
2
votes
1answer
80 views

RLink fails in Mathematica 12.2.0 Mac OS Catalina

Cannot run RLink in mathematica in Catalina. I get a failed error even though the paclet loads. Any pointers?
5
votes
0answers
55 views

Is there a better way to simulate quadratic cost MPC problems?

Question I would like to know if there is a more straightforward or a better way to simulate MPC problems in terms of code length and accuracy as compared to what I am doing. I am looking to know if ...
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
55 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
79 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
64 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
23 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
52 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
193 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
116 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
105 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
168 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
615 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
255 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
69 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 ...
6
votes
1answer
141 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
52 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
42 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
70 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
92 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
61 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
105 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
116 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
289 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
41 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
366 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
347 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
37 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
143 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
54 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
39 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
116 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
2 3 4 5
30