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

0
votes
2answers
85 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
58 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
23 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
117 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
54 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
196 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
24 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
36 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
99 views

Delete duplicates by a criteria

Given that I have a set of points as below ...
7
votes
1answer
132 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[]; ...
0
votes
2answers
129 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: ...
-1
votes
0answers
24 views

Feasability question about object tracking in 3d space

Is it possible to use 3 different webcams to track an object in an xyz axis. If so, how would one do it?
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
200 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
104 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
333 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
96 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
112 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
54 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
73 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
90 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
105 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
126 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
102 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
346 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 ...
1
vote
1answer
105 views

Using FindMinimum with matrix input

I define the following function which spits out a number S when I feed it a dxd square matrix: ...
0
votes
0answers
70 views

Stringing functions together

My professor introduced Mathematica to my class for the first time this week and gave us the following assignment. Also a disclosure that this is the first computer science class I have taken and the ...
2
votes
0answers
88 views

How to efficiently find parts of a string with beginning and ending specified?

I'm trying to find specific URL addresses from a html document. The addresses can be found between the strings "href=\"" and "\" class=\"listing". The problem is not including strings like this: ...
0
votes
1answer
82 views

converting DO loop into NestList form

I would like to rewrite this Do loop using NestList. Can you help me? ** DO loop ...
0
votes
0answers
54 views

Modifying Game of Life code so that the lattice can be seeded with life forms

I want to modify Game of Life code so that the lattice can be seeded with one or two new life forms like: ...
10
votes
1answer
166 views

Copy Built-in function to new name

It is know that some built-in functions are system function and changing their properties may cause trouble. Suppose for example I want to change features of Cases: ...
2
votes
0answers
75 views

How can I do multiple (double) integral with periodic boundary conditions?

I am trying to do a simple double integral $\int_0^l \left[\int_0^l h^3 h_{xxx}dx\right]dx$ with periodic boundary conditions $h[0,\tau]=h[l,\tau]$ $h_x[0,\tau]=h_x[l,\tau]$ ...
0
votes
1answer
104 views

NDSolve with initial condition: initial conditions did not evaluate to an array of numbers of depth 1(for 1D) or 2 (for 2D) on spatial grid

I have the following naive code to solve a PDE in two spatial dimensions (x,y) with periodic boundary conditions: ...
7
votes
3answers
371 views

Mathematica style guide?

I encountered this site today https://code.google.com/p/google-styleguide/ regarding the programming style in some languages. What would be best programming practices in Mathematica, for small and ...