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
26 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
30 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
55 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
128 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
55 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
49 views

How to make a table for loops?

I have a code given by ...
2
votes
1answer
65 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
63 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
45 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
126 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 ...
1
vote
0answers
61 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
84 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
86 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
94 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
92 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
78 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
66 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
105 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
167 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
44 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
87 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
159 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
89 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
62 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
41 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 ...
0
votes
1answer
128 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
32 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
133 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
50 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
70 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
244 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
43 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
46 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
123 views
1
vote
2answers
57 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
42 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
47 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
45 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
0answers
31 views

FormCalc installation error in Mac

I have a Mac and I followed Feyninstall procedure, I have downloaded FeynArts and Looptools successfully. I have a problem with FormCalc. So checking install.log-FormCalc, the error is the following: ...
0
votes
2answers
56 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
217 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
72 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. ...
0
votes
0answers
24 views

Symbol that constrains execution time relative to the computation that is performed

I'm looking for a way to implement a symbol that is like TimeConstrained in that it limits the execution time given to a certain operation, however does so on the ...
3
votes
3answers
129 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
49 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
523 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 ...