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

Programming for a loop and plotting

I am not so familiar with Mathematica programming. Here is my problem. I have defined the parameters in the first step: $G = 0.6, \Gamma = 0.5, r_1 = 1, r_2 = 1, \theta_1 = \pi/4, \theta_2 = \pi/4$,...
3
votes
2answers
126 views

How to define custom differential operator using the arguments of the expression?

This is essentially a follow-up to the question/answer here: How to define a differential operator? Suppose I wish to define an operator DiffOp, e.g., ...
0
votes
1answer
94 views

Declaring global variable in module/ Looping in mathematica [closed]

I'm new and still learning about mathematica. I'm having some trouble with my code. This is my current code that i'm having trouble with: ...
16
votes
3answers
1k views

Could Mathematica solve a differential equation asymptotically?

Is there any possibility that Mathematica could give asymptotic behavior(s) of a differential equation as it independent variable tends to a certain value? Because I didn't know how to decompose this ...
0
votes
0answers
42 views

Symbols in Mathematica (#, & etc) [duplicate]

I am constantly finding a lot of examples of usage of symbols # & etc in the code. But I could not find any information what they actually mean and how to ...
2
votes
2answers
97 views

I want to improve my algorithm of knowing eigenvalues of the matrix H(k)

I want to improve my algorithm. I want to know the eigenvalues of below n-dimensional matrix H. When n=10, the matrix H is like below. Now, $To$ and $M$ are constants and $T1$ and $T2$ are functions ...
4
votes
3answers
727 views

Recursion - Concentric Circles

I'm trying to develop my Wolfram programming skills and set myself an exercise of creating concentric circles using a recursive delayed function: ...
1
vote
1answer
146 views

Use NestList instead of Do loop

I am learning Gibbs sampling and imitating this explanation. Can we use NestList,FoldList or any other iterative function ...
7
votes
3answers
425 views

How can I create an enumeration variable by groups?

I copied the title and concept for this question from here. I have ...
6
votes
1answer
46 views

How to find NextScheduledTaskTime of a scheduled task?

Prior to 11.2 there was a function NextScheduledTaskTime which does what it says on the packet but only for cloud objects and not local scheduled task objects. ...
1
vote
0answers
76 views

Emulating a Scientific Workplace toollbar? [duplicate]

It is possible to have a notebook with the tools of the Basic Math Assistant palette in a toolbar similar to Formatting tool bar it already has? I would like it to work so when I open another notebook ...
4
votes
4answers
262 views

Looking for an effective way of generating integer sequences

I am looking for an effective way of generating all sequences of length $m$ of integer numbers $\{n_1,n_2\dots n_m\}$ such that 1) $0\le n_i\le N$; 2) $n_{i+1}\ge n_i$ for odd $i$; $n_{i+1}\le n_i$ ...
3
votes
1answer
126 views

Testing Head inside a Module [closed]

I hava a Module in which a want to give a single String or a List as a parameter and I want to change a single String to a List containing this String. So I did the ...
0
votes
0answers
146 views

Batch processing of data files

I have a large set of data files containing x-y coordinates. I have written a notebook to extract angles and other relevant lengths from a single data file before exporting the results into a new ...
0
votes
1answer
97 views

Traveling Salesman Problem

Could anybody help me to convert to Mathematica 11.0? ...
5
votes
3answers
340 views

How can I get the unique solution?

The eight queens puzzle has 92 distinct solutions. If solutions that differ only by the symmetry operations of rotation and reflection of the board are counted as one, the puzzle has 12 solutions. My ...
5
votes
0answers
99 views

Techniques in debugging with preview of possibly large expressions + garbage collection issues

First of all, all appreciate all suggestions how to rephrase the title to make it more friendly. Here's the background: Let's say your top level procedure flow is complicated, involves url calls, ...
3
votes
1answer
79 views

Why does AtomQ[y] define y? [duplicate]

Mathematica Version 11.2 desktop / Windows 10 Pro 64-bit ...
2
votes
1answer
114 views

Generalization of the probability of union

hi How can I do for mathematics to expand this equation for any value of the variables i, j, k
3
votes
1answer
201 views

Does anyone know how to speed it up? More efficient way to derive a new graph from a given one

Let us consider a graph1. ...
19
votes
2answers
706 views

Simulation of diffusion in a grid

I want to simulate a diffusive process in a 2D grid, for a central initial value of 1 to the adjacent cells initially at 0. At each time step, the value of the +1 level adjacent cells are increased ...
30
votes
5answers
697 views

Unexpected behaviors in built-in functions

Existence of this topic is discussed in this mathematica.meta post. I'm sure I am not the only non-beginner in WL who from time to time finds themselves not being able to predict an outcome of a ...
0
votes
2answers
261 views

Possible states of a 1-out-of-3

I need to choose one or more cases of three, since $2^3=8$. How to make a program that is possible as shown in the table My attempts TableForm[Tuples[{p, q}, 3]] ...
7
votes
2answers
1k views

Generate white noise in 2D

I am trying to generate a random (white noise) signal, as mentioned in the section Frequency Synthesis of Landscapes (and clouds) on this website. The problem I have is that I do not know if ...
1
vote
1answer
44 views

Looping variables not replaced by their values

Sometimes Table[ ] leaves the looping variable in the output, instead of replacing it by the values. For example ...
5
votes
3answers
544 views

Appending array in loop with If statement is not working [closed]

I want to print all non-zero answers to an array so I can then print them to a file. ...
1
vote
2answers
354 views

How to convert from C to Mathematica?

I am trying to understand what is explained in this webpage, in the section entitled "Generating noise with different power spectra laws". After reading that section, I thought I could do it in ...
17
votes
1answer
350 views

Is building an event-based parser possible/reasonable in Mathematica (WL)?

Too long? Go to Problems section Background I like to learn by doing small, sometimes artificial, projects. Among other things I had 'parsers', and 'stream methods / streams in MMA' on my to learn ...
1
vote
1answer
72 views

How to express and solve this minimization problem in Mathematica?

Let $T>0$, $H>0$, $D$, and $No>0$ are known parameter. Let $\{p_1,p_2,\cdots, p_T\}$ are the optimization variables. Let $\{w_1,w_2,\cdots, w_T\}$ are known parameters. Now, I want to ...
0
votes
0answers
54 views

Finding one function from NDSolve of two nonlinear PDE simultaneously!

I want to NDSolve two below partial equations : ...
2
votes
1answer
109 views

How do I set guess constraints for a solution of a linear system of equation?

Let's say I have a linear system of equations $$ Ax = \biggl( \begin{matrix} 1 & 2\\ 0 &1\\ \end{matrix} \biggr) \biggl(\begin{matrix} x_1 \\ x_2 \end{matrix} \biggr) = \biggl( \begin{matrix} ...
2
votes
2answers
125 views

How can I improve my code for visualizing a complex map?

This code visualize a complex map, but it looks rather cumbersome: ...
2
votes
2answers
100 views

Using Append without creating variable

If I use the Append command as follows, Append[foo,1]; I will get an error that says ...
4
votes
1answer
362 views

Loop until no errors

I am doing some numeric computations, involving FindMinimum and FindDistributionParameters. I think these functions have some ...
5
votes
3answers
214 views

Multi-coloured tree plot

I am trying to create a multi-coloured tree plot (Mathematica 9) where each branch is coloured according to its parent node value. For example, for a tree plot with three nodes, n1, n2 and n3, coming ...
24
votes
4answers
1k views

Permanently extending the behaviour of functions (like decorators)

Suppose I have a function, e.g. f[x_] := x^2 It works like this: f[5] (* 25 *) I would like to permanently modify it so ...
2
votes
1answer
172 views

Implement edge contraction function which respects vertex weights

It seems that built-in EdgeContract function doesn't work properly with weighted graphs, to be more precise, I mean that if I'm going to contract edge $e$ which ...
1
vote
1answer
404 views

Allan Deviation Algorithm

I am trying to write my own Allan Deviation calculator in Mathematica using the definition, $$\sigma(\tau)^{2}=\frac{1}{2M-2}\sum_{i=1}^{N-1}(\bar{y}_{i+1} - \bar{y}_{i})^{2}\text{.}$$ Where the $\bar{...
0
votes
1answer
220 views

Code for Factorial Function

Below I have my code that I created for finding the factorial of a number. The output I am getting when I enter MyFact[5] is ...
4
votes
5answers
471 views

Delete all data points of a specific row if any one column has a string or “NA”

I have ...
0
votes
0answers
24 views

a question about cdf player embedable demonstration [duplicate]

I have now my first application to be exportable as a cdf. If I safeguard as a cdf it works. But if I embed it in an html page It proposes to download the cdf player which is already on my computer. ...
6
votes
1answer
158 views

Extracting notebook history programmatically

I know there is a way to open Notebook history dialogbox using Cell > Notebook History, but since there can be a lot of history the dialog box can run very slowly with lags. Is there a way to get a ...
0
votes
1answer
56 views

Some side problem in a manipulate notebook

Sorry for the length of the code but the question is only on the Manipulate part. Here are some functions to evaluate apportionment methods ...
14
votes
2answers
601 views

3D tree in Mathematica?

Searching the web for information about the affine transformation, I found the one page, which called my attention for the tree that show and is this but unfortunately do not give information about ...
3
votes
2answers
144 views

A nice way to fold a non constant recursive function

The following code works exactly as expected. It constructs the Balinski-Young apportionment method. It is composed of two parts 1) the construction of the Balyski-Young function ...
3
votes
2answers
116 views

curious simplification problem

Consider the following expression: If[x==x, 1, 2] This returns 1, as you might guess. However: If[x<x, 1, 2] Returns ...
1
vote
1answer
91 views

Partial floatification - is it possible?

Suppose, I have a system of equations like 2y[Pi] + 3 y[E] == Sqrt[7] 3 y[Pi] + EulerGamma y[E] == Zeta[3] Now, I want a numerical solution to this, but I don't ...
4
votes
1answer
4k views

Principal submatrix and Principal minor of a matrix

A submatrix of a matrix is obtained by deleting any collection of rows and/or columns. For example, from the following 3-by-4 matrix, we can construct a 2-by-3 submatrix by removing row 3 and column ...
0
votes
0answers
37 views

What are the differences between the following two functions, explaining to a MMA novice? [duplicate]

Obviously the following two functions bring the same results: ...
0
votes
0answers
30 views

Why N[…] Function is opperationg on the index [duplicate]

i have following problem. I have an expression with some variables a[i]. When i use the N[] function in Mathematica i want them ...