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

9
votes
2answers
187 views

Built-in symbols that support operator form

In version 10 some built-in symbols are updated to support operator form like the Derivative. For example, Select, ...
0
votes
0answers
32 views

Calling a custom function in slave kernel process connected through mathlink

I am performing a small experiment to check if we can call/execute a custom package function in slave kernel launched from master using mathLink. I have created a dummy application called ...
5
votes
1answer
267 views

Only `Break` from innermost loop

How could I Break from only the innermost loop in a Do[stuff,{i1,i1min,i1max},{i2,i2min,i2max},...] ? I get the desired ...
0
votes
1answer
70 views

`Do` structures - listing iterated values

Please excuse the crudity / simplicity of this question, hbut I have never really got on too well with Do structures - perhaps I don't use them enough - perhaps I ...
2
votes
2answers
78 views

Creating a Cayley's table of square

I'm interested in creating a Cayley's table of square using Mathematica. I'm not a programmer but occasionally resort to using Mathematica to simplify my work insofar as the programming doesn't take ...
1
vote
0answers
42 views

How can I launch kernels in series using mathlink

I have written below code to launch n kernels connected to one another in series using mathlinks. Before you read the code allow me to be more precise what i want to achieve: Source kernel(k1) ...
1
vote
1answer
44 views

Is it possible to use FormObjects and FormFunction in a stand-alone notebook?

I have been looking at the FormObject and FormFunction. Can FormObject and ...
0
votes
0answers
20 views

Solving (one variable) Linear Equation by Dividing Slope by Constants Accumulation? [migrated]

I've been Google searching for this, and apparently my Googlefu is not strong today, or I'm doing something wrong. I have been told that it is possible to solve a one variable linear equation by first ...
0
votes
0answers
30 views

Evaluate notebook using text-based interface

I am trying to evaluate a notebook using a text based interface so that it can be submitted to a computing cluster. I have seen this stackexchange page and attempted to use ...
1
vote
1answer
39 views
1
vote
2answers
91 views

How to find total distance covered when I have a list of GeoPositions?

So I have a list of GeoPositions and I need to find the distance covered in that order? I know I can find the distance from each city and then add them all up but I was wondering if there is any ...
1
vote
1answer
66 views

Can I use Switch with an inequality? [closed]

I'd like to have something like: Switch[x, 10, a = 3; b = 7, >10, a = 5; c = 6, _, a = 7; d = 12, b = 1]; I can't seem to get this to work.
0
votes
0answers
30 views

Debug package with command line arguments

I'm creating a package that takes as arguments input from the command line using $ScriptCommandLine. What's unclear to me is how to best debug this package. How do others perform these tasks? I ...
0
votes
1answer
52 views

How to properly use conditionals inside NDSolve

Currently I am working with Mathematica to learn the program, and I'm confused what exactly is wrong with this code. ...
6
votes
1answer
66 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
73 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
75 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 ...
3
votes
2answers
313 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
102 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
76 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
67 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
157 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
276 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
171 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
75 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
63 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 ...
5
votes
1answer
135 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 ...
3
votes
1answer
108 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
62 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}?
2
votes
1answer
99 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
204 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
31 views

$MessageList inside and outside Block[]

Why does 1/0 $MessageList return ComplexInfinity whereas ...
0
votes
1answer
28 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
46 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
105 views

Delete duplicates by a criteria

Given that I have a set of points as below ...
8
votes
2answers
170 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
61 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
275 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
144 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
216 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
37 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
136 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
110 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
195 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
68 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
351 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
45 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
84 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
99 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: ...