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
3
votes
1answer
106 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) ...
2
votes
2answers
150 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}...
4
votes
2answers
148 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 ...
23
votes
1answer
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.
0
votes
1answer
74 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, ...
0
votes
0answers
51 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
1answer
44 views

Expectation Value of a Potential Using Radial Solution of Hydrogen Atom

I am trying to input $R_{nl}$, which is the radial solution of the hydrogen atom and I would like to obtain an expectation value of particular potential. This is my code: ...
0
votes
1answer
55 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 ...
5
votes
3answers
157 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 ...
1
vote
1answer
53 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 ...
1
vote
0answers
53 views

Define the heat capacity Cp as constant values in the current version of Mathematica (Coupled PDEs)

I am trying to model a 2d heat transfer in fluid flow with nonlinear heat capacity Cp (e.g. Cp=1 + T[t,x,y]). This benchmark problem is described as: the left side of the plate is heated, and the ...
4
votes
2answers
149 views

Modified Heat Transfer in Fluid Flow

I am trying to simulate Modified Heat Transfer in Fluid Flow (based on Buoyancy-Driven Flow in a Square Cavity ). The modified heat transfer takes the form: with the solid volume fraction: The ...
5
votes
3answers
104 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
votes
1answer
251 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 ...
1
vote
1answer
64 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. ...
0
votes
1answer
62 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
0answers
60 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 ...
1
vote
0answers
51 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 ...
0
votes
0answers
57 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 ...
10
votes
4answers
358 views

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

I want to keep the original order of l1: ...
2
votes
1answer
106 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 ...
0
votes
0answers
62 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
1answer
109 views

Classify across ten methods

Mathematica supports ten different methods for Classify. The ten methods are: "ClassDistributions", "DecisionTree", "GradientBoostedTrees", "LogisticRegression&...
0
votes
0answers
35 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 ...
-1
votes
1answer
47 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
0answers
76 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 ...
15
votes
1answer
276 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
1answer
57 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 ...
21
votes
6answers
4k views

Creating the Yin Yang symbol with minimal code

The following code creates the Yin Yang symbol ...
0
votes
2answers
40 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
76 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
52 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
30 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
47 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
105 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
52 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
233 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
63 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
61 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
96 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
1answer
102 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
47 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
135 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
66 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
28 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
53 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
226 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
128 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
124 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 ...

1
2 3 4 5
30