Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
11 views

Here is a math game problem, not able to understand why the solution works? [migrated]

Players A and B Rules of the game: The game is played with two piles of matches. Initially, the first pile contains N matches and the second one contains M matches. The players alternate turns; A ...
2
votes
3answers
182 views

Find the 3D region containing the origin bounded by given planes

I'm writing a code to generate the Wigner-Seitz cell of the reciprocal lattice for a given set of lattice translation vectors. For example, consider the Body Centered Cubic (BCC) lattice whose basis ...
0
votes
1answer
34 views

Wrapped Association into a “structure”: how to define Equal[] and what are the good practices for package dev?

Using a nice answer https://mathematica.stackexchange.com/a/197936/42847 I got from a previous question I define: ...
3
votes
3answers
85 views

Efficient manipulation of Associations passed to functions, how-to? [duplicate]

I have some data wrapped into a MyData[data_Association] "structure". My Association contains some big arrays and I do not want ...
0
votes
0answers
37 views

Adding a Cosine function to alter the shape of the initial cosine function

I would like to be able to add a raised cosine to a "standerd" raised cosine. With a timedelay which I could manipulate (so the shape of the standerd cosine function is altered, meaning the function ...
1
vote
0answers
25 views

A newbie question about the use of the FourierSeries functions

Although I have had no previous experience with the Mathematica Fourier Series functions ( or package ), I am writing a tutorial on Fourier Analysis and Transformations in a Mathematica Notebook, ...
9
votes
2answers
214 views

Finding the path in a graph from A to B then back to A with a minimum of shared edges

the problem is to find cycle from A to B back to A, so that the path B-A would use minimum edges from path A-B. The graph is undirected and can have cycles. The paths don't have to be shortest, they ...
0
votes
0answers
30 views

How to use the Mathematica [duplicate]

I am a new learner for Mathematica. I know just some basics of Mathematica, I can plot simple graphs. But, sometimes I have to plot some complicated graphs. Then, I am unable to plot that particular ...
12
votes
1answer
426 views

Pascal records and Mathematica programming

Background: "experienced" Pascal-programmer (DOS-era, never got into OOP) proud owner of Mathematica ver 11.2 have used Mathematica for years to do my share of number crunching and plotting to ...
0
votes
0answers
16 views

CDF and ElasticSearch [duplicate]

I have an large amount of data, in the terabyte range, in an ElasticSearch instance. The data is on an network air gapped from my Mathematica instance and I'd like to have an app to examine the data ...
0
votes
1answer
74 views

How can I use Compile to implement recurrence?

I am trying to make the code for the following recurrence. Here wjoin[[i]] is used for calling values from a data set and a is a ...
12
votes
2answers
266 views

Plot of histogram similar to output from @risk

In order to analyze simulated data, @risk provides a histogram with handle bars, so that we can move these handles to see what proportion of data are on each side. For example, . I am trying to ...
0
votes
0answers
28 views

Custom PopupMenu displays menu items as values instead of labels

I'm trying to create custom appearance for PopupMenu with the below code. The problem I have is with the menu items which are displayed as values instead of labels. ...
0
votes
0answers
28 views

Why is an integration error appearing during this code?

I'm really confused about this to be honest. If i evaluate approx[x,k] for some k, and then input the list into the Plot function, I get a plot. But if I try to use approx[x,k] directly, I get an ...
2
votes
0answers
38 views

Problem with PopupMenu: Its values don't update dynamically

I have a problem with PopupMenu inside DynamicModule, its values don't update dynamically as they supposed to. The example below ...
3
votes
1answer
57 views

How to get Mathematica to loop two functions at once

So I know how to get half of this problem. I am trying to run a loop that combines the following two function at once so I can see from my index i if any number satisfies both conditions. TO get the ...
1
vote
2answers
133 views

MapThread conflicting with DynamicModule

Cross-posted: https://community.wolfram.com/groups/-/m/t/1625808 Answer posted on Wolfram Community I'm creating an interactive UI which allows the user to import data from a spreadsheet, perform ...
0
votes
1answer
62 views

Solving x'[t]+a*x[t]==0, listing all the solutions, trying to get the value -1x<1 and all corresponding value of a

I am Trying to solve x'[t]+a*x[t]==0,x[0]==1, for x with {t,0,10} using NDSolve. ...
0
votes
1answer
54 views

How to make a table for loops?

I have a code given by ...
2
votes
1answer
69 views

a recursive function using memoization

I have looked at a lot of these cases, e.g. Can one identify the design patterns of Mathematica? and the included ones. My trimmed example, here establishing the 'initial conditions' (where the ...
1
vote
1answer
79 views

Complex partial fraction expansion

I would like to have a tool for partial fraction expansion of polynomial quotient $$\frac{P(z)}{Q(z)},$$ where the order of the polynomial $P(z)$ is less than that of $Q(z)$. The output of the ...
3
votes
1answer
48 views

Implementing Dual Unit from Dual Numbers

I'm trying to implement the dual unit $\epsilon$ defined by $\epsilon^2 = 0$ into Mathematica but I'm having trouble defining $\epsilon^n = 0$ for $n\geq 2$. In this answer they simply use ...
1
vote
1answer
41 views

Defining a function that affects indices

I want to define a function, that works like this: f[3v[1,2,3]] = 1/3 v[1,3,2] + 3^2 v[1,2,3] f[2v[2,2,1]] = 1/2 v[2,1,2] + 2^2 v[2,2,1] Basically, it should ...
4
votes
1answer
130 views

How to implement split-complex numbers?

For those who do not know, the split-complex numbers are an analogue to the complex numbers where J is defined such that $J^2=1$ but $J\ne\pm1$, so they are all of the form $a+bJ$. By using ...
2
votes
0answers
67 views

Calling a notebook from a different notebook

Basically I have a notebook (let's call it nb1) that when evaluated yields one number when I specify some parameter $\alpha$ (in nb1). I want to call nb1 in a different notebook (nb2) using for ...
0
votes
1answer
87 views

How to resolve the fail when applying a user-defined solver?

The user-defined function pdetoode and pdetoae, developed by @xzczd, is very useful to deal with a PDE system when there is ...
19
votes
5answers
1k views

Sisyphus Random Walk

A Sisyphus Random Walk evolves as follows: With probability (r) you advance the position of the walker by +1. With probability (1-r) the walker resets at x0 = 0. To simulate the probability of reset ...
1
vote
0answers
68 views

How can we make an algorithm with the A* method in Mathematica with 5 different flight routes? [duplicate]

I need to find the shortest path with the A* algorithm using Mathematica. I have 5 different flight routes with coordinates. They start and end at the same point. Between every point there is a wind ...
1
vote
2answers
110 views

How to print chess board with array? [duplicate]

I am doing n-queen implementation with my own algorithm and I get solutions with Number.But,I want to get output with actual chess board. This is my piece of code. ...
-2
votes
2answers
96 views

What does this code mean? [closed]

Here solutions is array . I need to know why this code is written.Please help me. ...
2
votes
1answer
96 views

How to use external Mathematica Code? [duplicate]

I have a Mathematica Notebook with a function that i would like to be able to access from another Notebook without having to have the first Notebook open. The functions calls other functions in the ...
0
votes
1answer
79 views

Transforming a conic to it's standard form

Suppose a conic is given.I need to transform it to standard form.So i tried like this: ...
1
vote
1answer
70 views

how to sort a list without build-in function

I want to sort a list like below.Without using the build-in function so I tried this: ...
-1
votes
1answer
118 views

Solving two coupled PDEs with the pdetoode function posted on this site [closed]

I want to solve two coupled PDEs with pdetoode function: feq = {D[ϕ, t] + U*D[ϕ, y] - D[ϕ, {y, 2}] - (s0 - 1/20*y^2)*ϕ == 0} and ...
5
votes
0answers
171 views

How to Write Stand-alone Mathematica Projects/Programs

I wish to write several stand-alone projects/programs using Mathematica because of its easy-to-use graphics. I could use Python for this, but Mathematica has built-in graphics that would be better ...
1
vote
0answers
48 views

Making a function $ f(n) $ tangential to another function $ g(n) $ by choosing appropriate constants

I have two functions $ f(n) = 1/(1+n) + b, (n \geq 0,b \geq 0) $ and $ g(n) = pn^2 + qn + r $. Assuming that I know the value of $ p, q $, and $ r $, I am trying to find a value for the constant $ b $ ...
1
vote
3answers
97 views

How to randomly generate Tree or Nested List of Function in Mathematica?

In detail, I want to generate randomly something like Divide[Add[X,Times[X,Y]],Times[X,3]] or {Divide,{Add,X,{Times{X,Y}}},{Times,X,3}} (Specified Function(# of argument is from 2 to 5)) + ...
-2
votes
2answers
168 views

Mathematica is not responding for very large numbers

So, I am having Mathematica 11.3 and trying to evaluate 2^1,000,000,000. When I am trying to show the output in its full form to manipulate the digits, Mathematica stops responding. I am having 32GB ...
0
votes
3answers
90 views

Check if number is in list

I have a nested list, but don't know how long the individual lists are. Sometimes they may be 2 numbers long sometimes 1000, so i need to check if theres is a number at position 6 but i doesn't ...
1
vote
0answers
63 views

Is there packages can help read, analyze or understand MMA codes? [closed]

Sometimes, I think that it's difficult to learn high level codes, or even when looking back on some long lines of codes I myself had written, espectially when lots of pure-functions was used, so I'm ...
2
votes
0answers
42 views

Fold/ NestList/ etc in MCMC loop for optimisation

I am trying to simplify and optimise an old loop code I wrote. Since Fold and NestWhile use the results of the last iteration in the new iteration, I would like to use them in order to get rid of Do ...
9
votes
3answers
1k views

Speed up code to numerically simulate a game of coin tossing

Description I would like to simulate n games in which two players toss one coin each at the same time: If you toss a tail you will receive two tokens, if you toss ...
-1
votes
1answer
158 views

Why can”t I get a smooth curve?

I used "Table" to calculate and plot the following complicated function. First, we choose an initial value for $G$ and other parameters, but at later times $G$ changes with function $I_a$. ...
1
vote
1answer
33 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
144 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
52 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
72 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
246 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
47 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. ...