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
1
vote
1answer
36 views

How to perform a set of commands specific amout of time?

I have 3 lines of code that does the Collatz Conjecture in mathematica. the code is the following: ...
2
votes
4answers
169 views

Subdivision of a line into n intervals of linearly changing length

This question is separate, but connected to my previous question on this site, that can be found here. Let's say that we have a line of length X (in this case X=5), defined by a list ...
1
vote
0answers
55 views

ConditionalExpression still resulting from Assuming a Module's local variables

I have a memoizing, recursive function whose MWE looks like this (the two fake inputs/ICs are from 'K' and 'Bfun2', the latter just a quick way to check the results coming out of the Residue.: ...
5
votes
1answer
76 views

Ignore message in `Check` without silencing

Check[expr,failexpr,checkedMessages] will evaluate expr and if it encounters any of the messages in ...
2
votes
2answers
252 views

How do I write this matrix?

The following code gives 20 data as output. How can I make a 5*4 matrix by that data list?
2
votes
1answer
79 views

How to select Input|Output Cell Groups in the Notebook?

I am trying to convert a Cell expression to an image. I created a new notebook and copied the cells that need to be rendered. ...
0
votes
0answers
61 views

magic square with prime numbers of any order

how could you create a script in Mathematica that generates magic squares of order n, but that the numbers that form the square are all primes I've looked at what's in other answers but I can not ...
1
vote
2answers
174 views

Error propagation in finding full width at half maximum

I have an equation given by: ...
1
vote
2answers
71 views

How can I construct a matrix by programming in mathematica?

I want to write a matrix in Mathematica by programming. How can I write it? The matrix is : $ M= \begin{bmatrix} 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & ...
0
votes
2answers
50 views

An Alternative Solution to a List Manipulation Example

Is there any way to write a code that has a function include Block[ ] and Do[ ] loop instead of my code? Here is my code: ...
2
votes
1answer
52 views

How to define a function that can transform integrands to the unit hypercube?

We know most integrands can easily be transformed to the unit hypercube: $$\int_{a_1}^{b_1}\cdots\int_{a_d}^{b_d}{\rm d}^{d}x\, f(\vec{x})=\int_0^1{\rm d}^dx\,f(\vec{x})\prod_{i=1}^{d}(b_i-a_i)\ ,$$ ...
1
vote
1answer
47 views

How can I print only the lines for a file that contain consecutive digits?

I have a text file containing a list of numbers. I want to print only the lines that contain a number, the digits of which are consecutive digits. The input list: 123 321 567 765 124 568 The output ...
0
votes
2answers
57 views

Total does not give the output expected

Using the three matrices given below, I like to perform the operation stated in Quiet[...]/.{Interderminate->0}. ...
3
votes
3answers
220 views

What is wrong with Module? or me? [closed]

The following code does not give me an answer. It looks all is working when each command inside Module is individually run. But ...
2
votes
1answer
80 views

Recall the names of functions used in a long MMA code

Suppose you have a very long code in which many new functions are created. For efficient programming, very short and easily iterated function names are preferred. ...
3
votes
3answers
162 views

Infinite While loop

I have an exercise where I need to input a multi-digit number and evaluate the square of the sum of its digits. I am new to Mathematica and I can't figure out why I'm getting an infinite loop. This is ...
3
votes
1answer
57 views

What is a good way to implement a versatile folder structure checking system?

I'm writing an 'application' (set of *.wl and *.wls files) that requires a given folder structure to function; I am not sure how this structure will eventually look like, because it changes as I ...
29
votes
3answers
601 views

Analogies to Help New Users

In many of the classes that I teach, I require students to learn the basics of Mathematica which we use throughout the semester to do computations and to submit homeworks (in notebook form). Some ...
3
votes
1answer
74 views

FindShortestTour finds very long tour

The documentation claims FindShortestTour works extremely well for hundreds or thousands of cities. I show an example set of 5 cities where it does an abominable job. I also show a couple of absurd ...
4
votes
1answer
259 views

Pythagorean quadruples

I am very interested in the problem that deals with the Pythagorean quadrruples, which are listed in rosettacode. Unfortunately, I have not been able to find any way to compute them with Mathematica. ...
10
votes
3answers
629 views

Can I use Compile to speed up InverseCDF?

I'm repeatedly issuing the command P = InverseCDF[NormalDistribution[0, 1], T] where T is either a 36- or 64-vector of real numbers (points in the unit ...
3
votes
3answers
616 views

How to create a fractal tree?

I want to create a fractal tree, using translation and rotation. Code below is working for one level, but when I try loop, it is not giving output. Code is given below: ...
4
votes
1answer
60 views

FindShortestTour shows erratic behaviour wrt 2nd argument

FindShortestTour behaves erratically. It should return a {distance, ordering} pair, and it does this for most values of its ...
0
votes
0answers
22 views

Why does the contour plot shows blank part? [duplicate]

when I try to plot some complicated functions coming from chi-square distribution, the plot gives me a result with a blank part. I try to narrow the spaced vertical bin using Log for multiple times ...
1
vote
1answer
79 views

What resources can I use to become familiar with high level syntax?

I was reading a question about dropping higher order terms and realized that I have a serous gap in knowledge when it comes to the finer points of mathematica computational programming. Are there any ...
3
votes
1answer
139 views

Taking a long time to produce output

In the following, I want to know b[1000], but it is taking a very long time even for b[30]. Please help ...
3
votes
1answer
304 views

How to calculate all possible resistances made from 5 distinct resistors in series and/or parallel? [closed]

Five distinct resistors resistors={1,2,3,4,5} are given. The objective is to find a list of all possible resistances obtained by configuring all these resistors in ...
1
vote
1answer
69 views

How to randomly generate a list of function calls from a list of args and a list of functions?

I want to generate a list of simple trigonometric questions in TeXForm, for example, as follows. ...
2
votes
2answers
76 views

Compound Statements and returning earlier results in () parentheses

I am trying to debug some script and need to Print[] out some results, sometimes before, and sometimes after, certain executions. These 3 trials exemplify my ...
4
votes
1answer
129 views

Jaro distance in MMA

I'm trying to program Jaro distance as requested by this page I've done the following code that works well for the next two pairs ("MARTHA", "MARHTA") and ("DIXON", "DICKSONX") but when I try with ("...
0
votes
2answers
200 views

Delay operator and Apply used when for applying function of a function

I define my own function like that: DelayL1t[(q_: 1) a_[t_]] := q Apply[a, {t - L1[t]/c}] DelayL2t[(q_: 1) a_[t_]] := q Apply[a, {t - L2[t]/c}] if I just do : ...
1
vote
2answers
175 views

Integration of a function that oscillates rapidly (apparently)

I would like to know if you could help me solve some doubts about the integration of a function that oscillates rapidly (apparently) that depends on time and two angular variables. The parameters S ...
2
votes
1answer
254 views

How to calculate linear conflicts on a board?

Thanks to your help to solve previous problems, I have been able to advance in the learning of mathematica. It seems that this project to make a solver for the 8-puzzle has surpassed my abilities in ...
0
votes
0answers
98 views

Help! SystemException[“MemoryAllocationFailure”]

I am trying to run this code: ...
6
votes
1answer
91 views

What is a compact way to generate the list of $n^m$ composite functions, given a list of n functions and a composition depth of m?

Introduction. An image says more than a thousand words. The functions sym4ref (pmm) and sym4rot (p4) create symmetries of a geometric object in the 2D Euclidean Space. ( pmm, p4 refer to the list of ...
5
votes
0answers
98 views

Use Mathematica with Go Language

I would like to know if I can use Go and Wolfram Language? Example C ...
4
votes
5answers
303 views

How to build these functions without nested For loops?

I am trying to solve the 8-puzzle using two heuristics, which are: Pieces out of place and Distance Manhattan. After consulting several websites for example see and some books, I'm with some doubts, ...
2
votes
1answer
159 views

Overlap two images and give movement and the result record it in an animated gif

I need to put the circular image 1 in the image with the hole 2 (and cover the gap) the idea is to create an animated gif that shows the image 1 turning to the right and image 2 to the left in a size ...
5
votes
1answer
94 views

The reason behind ControlToBoxes (DynamicDump`)

Background I'm trying to establish best practices for custom controllers programming. This question is about one top level aspect of it. WRI suggested (few talks I don't remember right now) to ...
6
votes
3answers
242 views

How to create a variable List

I need, given "n", create a list {a1,a2,...,an}. For example: Given n=3, the list that must be created is composed by the symbolic variables {a1,a2,a3}. Sorry if this question is simple. Does anybody ...
3
votes
1answer
77 views

Speeding up filling a matrix when approximating a double integral

I want to approximate a double integral in the process of solving a partial-integro differential equation, to then put it, next to the differential part. The integral is (after some simplifications): \...
1
vote
1answer
217 views

How to compare two datasets having almost the same y-axis but different x-axis

I have plots of two datasets that have almost the same values on the y-axis but different values on the x-axis. lets suppose p1={x1,y1} and ...
1
vote
3answers
141 views

Computation performance involving multiple numeric integrals

I have the following code that has been running for more than three days without an answer, unfortunately. Now, my institution provides us with a computer with Intel Xeon CPU E-52650 v3 @ 20 CPU, 2....
2
votes
1answer
85 views

using functions with the same name doing different stuff

I am trying to use functions with the same name, but which do different stuff. Let me show an example. ...
0
votes
1answer
59 views

about matrix manipulation

I have a large matrix and I want to extract different sub-matrices that actually have elements on different positions. Using Extract and mention the position of ...
0
votes
1answer
390 views

Bellman-Kalaba algorithm optimization

I wrote a Bellman-Kalaba algorithm which finds the shortest paths between all vertices in graph (for now only distances). It works correctly but it is written iteration by iteration and I have a ...
1
vote
0answers
106 views

Will my procedure be correct?

I am facing a problem when trying to solve the exercise of page 210 of the book GRAPHICS with MATHEMATICA, FRACTALS, JULIA SETS, PATTERNS and NATURAL FORMS of the authors CHONAT GETZ and JANET ...
0
votes
1answer
64 views

How can I define a derivation in Mathematica?

I would like to define a derivation in Mathematica. As an example something like this: for an operator O and operators $A,B$ in a two dimensional vector space with $$ O \times A = a \\ O \times B = b \...
4
votes
2answers
154 views

Function on a block matrix

I am trying to write a program of the following nature. Let $A = [[a_{ij}]]$ be a $4 \times 4$ matrix. I have to divide it in the form $$ A = \begin{bmatrix} P & Q \\ R & S\end{bmatrix}$$ ...
0
votes
0answers
39 views

MakeExpression[BoxData[“1”], StandardForm]

I am a new user. After clearing all the variables and functions from the "memory", the answer format have changed. For example an input of 1 provides an ...