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.

learn more… | top users | synonyms

6
votes
1answer
53 views

Completion in terminal?

I know that it is possible to run Mathematica in Terminal. But I didn't find a way to get completion work in Terminal. I mean completion by ...
0
votes
1answer
64 views

How do I find the nearest city out of a list of cities?

I am trying to find the next closest city to city 1 and want to use a certain radius to check what is the closest city I'm trying to create an algorithm for a TSP. Does anyone know how to implement ...
1
vote
1answer
60 views

Multiply out product of sums

For a specific quantum mechanical problem I need to multiply out operators in order to calculate a trace by hand. For example I need a Hamiltonian squared with $H^2$. The Hamiltonian contains of a few ...
-1
votes
0answers
39 views

Is there a way to approach the proof of conjecture of Goldbach? [on hold]

An approach to Prove of Goldbach's https://www.academia.edu/11902260/PROOF_OF_GOLDBACHS_CONJECTURE
3
votes
2answers
300 views

How to force Return[] to return from an arbitrary point (like in C++)?

I need to test some complicated conditions to calculate a Return value. But MMa doesn't let you Return[] from anywhere the way C++ does. The structure of my Module is similar to this: ...
-1
votes
1answer
85 views

Implementing the Golden Section Rule

I am attempting to write a code which brackets the minimum of a unimodal function, using the Golden Section Method Below. I am have serious issues debugging my program though, any help will be ...
-1
votes
1answer
71 views

Trying to write my own Greedy/ Nearest Neighbor Algorithm

So I'm trying to write my own function and compare it to the results I have from using FindShortestTour. Does anyone know how to find the distance from each city to each of the others without ...
2
votes
1answer
66 views

Block works when directly used but not when used in a function

I want to calculate a derivative such as: $\delta f=\sum_{i=A,B} \sum_{k=1,2,3} \frac{\partial f}{\partial a_k^i}$. Since $ a_k^i$ are assigned values other places in the code, I have used ...
3
votes
1answer
152 views

How do I create an array by applying a function to the index of each element?

I am looking for something like matrix(m, n, f), but for Mathematica rather than MuPAD, and for arrays rather than matrices. That is, I'm looking for a(n ...
5
votes
4answers
252 views

Efficient way to sum all the primes below $N$ million in Mathematica

Today, I saw a problem described as below: Sum all primes below $N$ million At the beginning, I feel it is rather simple to calculate it in Mathematica ...
0
votes
2answers
155 views

FindShortestTour to solve Traveling Salesman Problem

I'm trying to write my own code to find the shortest route but I'm lost on how or where to start. Does anyone have any idea how the FindShortestTour function works? What type of algorithm or structure ...
0
votes
1answer
67 views

Eigen energies of 2D time independent Schrödinger equation

Firstly, I am aware that a similar question of this type was asked, but it was not helpful as it was only one dimensional (so please don't mark my question as a duplicate) The trouble I am having is ...
0
votes
2answers
60 views

Diophantine and odd

need to resolve this Diophantine equation, but with the condition that a, b, c belong to the set of odd numbers from 1-51, as I write this condition in the code ...
-1
votes
0answers
24 views

How could I speed up a code including a Module with many functions

I have implemented a big formula through the mathematica function Module. Within this module a lot of definitions are made (i.e. function[x_]:=). The code are working well but it is too slow. I am ...
5
votes
1answer
123 views

How is LHS = RHS; … ; RHS (nontrivially) different from … ; RHS

I'm trying to understand how Mathematica thinks about the results of Set. Suppose we perform LHS = RHS. I'm focusing on when ...
2
votes
1answer
101 views

How to define the Bernstein function like the built-in BernsteinBasis?

We know the Bernstein function defined as below: $$B_{n,i}(u)=\binom n i u^i(1-u)^{n-i}$$ And we define $B_{n,i}(u)=0$ when $i<0 $ or $i>n$ In addition, the first derivative of $B_{n,i}(u)$ ...
0
votes
1answer
58 views

cross point of intersecting lines [closed]

What is the easiest way to find the crossing point of two intersecting lines passing lets say through points line1 = {p1,p2}, line2 = {p3,p4}?
1
vote
1answer
93 views

Separate output screen; clearing (cleaning) output screen

Is there a way to split the screen so that the code is on top visible, and execution of code look at the bottom? Is there any way to clean the screen from previous runs, so that the result of ...
7
votes
3answers
200 views

How to speed up auxilary DoolittleDecomposite function?

The Doolittle Decomposition algorithm as below: $$A=LU$$ where $A= \begin{bmatrix} a_{11} & a_{12} & \cdots a_{1n}\\ a_{21} & a_{22} & \cdots a_{2n}\\ \vdots & \vdots & \vdots ...
0
votes
0answers
29 views

$MessageList inside and outside Block[]

Why does 1/0 $MessageList return ComplexInfinity whereas ...
0
votes
1answer
25 views

How to combine two or more groups while selecting form the unbalanced panel data if the number of obs is less than a scalar in certain groups

I have an unbalanced panel data. I want to calculate group statistics for each group. However, if ith group has less than K obs, then I want to combine ith and (i+1)th groups to calculate group ...
1
vote
0answers
37 views

How to use RunProcess to run python interpreter

In a related question How to use RunProcess to import external function? @taliesin provides a very nice answer illustrating using RunProcess to launch a GO http server. Has anyone, or does anyone ...
4
votes
0answers
100 views

Delete duplicates by a criteria

Given that I have a set of points as below ...
7
votes
1answer
136 views

Relaxation of Mass-Spring System with Pinned Masses

Problem Assume that four masses are connected to each other by springs while two of them are pinned down at their initial positions. Find the position of masses when system is at its minimum ...
4
votes
1answer
58 views

subtleties about variable shadowing in Block[]

Let' s consider this packege : BeginPackage["myProgram`"]; myProgramF::usage = "arg + 1"; Begin["`Private`"]; myProgramF[arg_: 0] := arg + 1; End[]; EndPackage[]; ...
4
votes
4answers
253 views

Spiral roots, how?

I found this picture on the net, as I can play in mathematica
1
vote
1answer
35 views

Implicit region is not “valid” in ParamatricNDSolveValue function?

I am trying to solve a geometric problem with relation to my Schrodinger equation and its boundaries. Here is my code: ...
3
votes
2answers
139 views

How can I create a 3D representation of an object with known coordinates and adjacency table in mathematica?

Basically I want to create an object with specified coordinates and adjacency table, like in page two of this article. I'm completely new to using Mathematica, any help would be great! EDIT: So I ...
3
votes
1answer
203 views

How to download pictures from webpage automatically?

Today, I read a good web page about love which owns many beautiful pictures. It is fussy for me to download every picture hand-by-hand, so I'd like to use Mathematica to do this case automatically. I ...
0
votes
0answers
31 views

Retrieve rendered graphics via WSTP

I am planning on using Mathematica as calculation- and rendering backend for an application, i.e.: Call Mathematica via WSTP and by using EvaluatePacket have it ...
2
votes
3answers
135 views

How to extract both first and last rows of each group from unbalanced panel data

This is a follow up question form my last question click here. I have unbalanced panel data such as : ...
3
votes
1answer
106 views

How can I overload a function with multiple bracket-slots so f[a][b] and f[a] can coexist?

Maybe this is not even possible: I want to create a function f that can have two input brackets like: f[a_][b_:1]:= a*b and ...
6
votes
1answer
193 views

How can a function know in which function it was evaluated?

Hello my second question here might be very hard. I am asking for something "magical", if i define a function g and i call it inside a function f, how can g have information about the outer function ...
2
votes
2answers
61 views

Need help updating an old Mathematica worksheet

I found a notebook that symbolically applies the multiple time scales method to any differential equations. I don't like just using other people's code so I am going through the author's work line by ...
5
votes
2answers
336 views

Find permutations with constraints without using Permutations

EDIT: To clarify, the bottleneck right now is available RAM, so any answer should keep that in mind (I cannot store all T! lists of length ...
0
votes
0answers
42 views

Trying to write a program to find an approximate harmonic function on a given graph using relation method

So given an undirected graph with two vertices that have fixed values assigned to them, a harmonic function is a function that assigns values to all other vertices such that the value assigned to each ...
0
votes
1answer
81 views

How to improve this function that selects parameters from arbitrary distribution using Recursion?

Below, I have defined a function using Which to select model parameters based upon various conditions. My questions are: Is there any danger in writing this function using Recursion? Is there a more ...
1
vote
1answer
98 views

Perceptron: Do loop not returning a value

I am trying to write a function that finds a simple best fit line for some data (Perceptron algorithm). Sadly it returns no output at all. Here's the code below: ...
2
votes
2answers
114 views

How to plot points with error circles on map with latitude/longitude grid

I am currently working on a project to model the location of icebergs in the northwest atlantic. When an iceberg is sighted, an error circle is plotted around it (with a bivariate normal probability ...
4
votes
0answers
57 views

Using mathlink/WSTP with fortran

I would like to access Mathematica functions from within a Fortran program. I am unsure how to start (which is probably related to my lack of up-to-date Fortran knowledge). Is it necessary to write a ...
1
vote
1answer
75 views

Hypothesis Testing and Formatting Output

I am trying to write a function that tests hypotheses and gives me a nice table but I can't. I need forum's help. For example, I have the following data ...
5
votes
0answers
91 views

How to construct custom operators with precedence?

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of ...
2
votes
1answer
110 views

How can I invoke the solution of NDSolve to determine a parameter in my equation just inside NDSlove?

I am trying to solve a differential equation by NDSlove for $h(x,t)$. It reads $$h_t=h_{xx}-V_h-\lambda(t)$$ where $V_h$ is a given function of $h(x,t)$ denoted by ...
1
vote
1answer
49 views

Ways to protect certain parts of expressions

I am currently working on a quantum mechanics problem where I try to find equations that relate different states of a many-body system. The states are described by sets of pairs of integers, like ...
0
votes
0answers
25 views

Iterating a model with 2nd order difference equations using Manipulate [duplicate]

I have a model including first and second order difference equations. It works for the case of first difference equation, which is below: ...
4
votes
2answers
127 views

Nested mapping of a function

If I use the construct f[#] & /@ f[#] & /@ f[#] & /@ {a, b, c} my function works, but if I use ...
4
votes
2answers
103 views

Finding column-wise ranks of values in a multidimensional list

I often have to find ranks of values in a list. However, Mathematica does not have built-in functions for that, or may be I'm just not aware of them. I can easily find ranks of a row/column vector. ...
0
votes
1answer
41 views

Why does this cause an error? [closed]

In[73]:= f[x_] := Save["C:\\Users\\user\\Desktop\\file", x <> x] f["###"] During evaluation of In[73]:= Save::sym: Argument ...
5
votes
3answers
347 views

Easiest way to create a binary variable

Binary variable is often used in applied statistics. However, I had a hard time to figure out how to create it. Somebody might have better idea how to do it. I have two variables say x and y as ...
1
vote
0answers
91 views

Simulations using alternative initial conditions

With help from some of you guys here in this forum, I have developed the following code, which works perfectly. My questions are: how to automate the simulations with varying initial conditions. In ...