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

22
votes
0answers
359 views

What Mathematica features and idioms have $n^2$ complexity or worse

Here are a few: AppendTo[data, elem], Sort[data, test], in some cases use of ___ (as ...
19
votes
0answers
335 views

How to perform document classification (i.e. extracting topics from text)?

I need to build a multi-label text classifier. There are a bunch of techniques for doing this, and it's called automatic document classification. I'm trying to use the EM technique (expectation ...
16
votes
0answers
211 views

Can code optimize code?

Are there functions, programs or packages that deal with optimizing mathematica code i.e. re-writing ineffecive or convoluted code. -This question has haunted me since I joined SE. The background for ...
6
votes
0answers
262 views

How to restrict the mouse cursor to stay within a box?

I'm trying to use Mathematica to write small games, and I find that it would help to restrict the player's mouse into the game window (just like other games do). Is there any way to achieve this? ...
5
votes
0answers
95 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 ...
5
votes
0answers
256 views

How to download and combine S&P 500 stock prices

I want to download historical S&P 500 stock prices and combined them into one big file, having only one column of date referencing all stocks. Here is what I have do so far. ...
5
votes
0answers
232 views

Convert logical relational expression to / from disjunctive and conjunctive forms?

I would like to convert logical relational expressions in disjunctive form, e.g., $$(x \lt -1) \lor (-1 \lt x \lt +1) \lor (x \gt +1)$$ into conjunctive form, e.g., $$(x \ne -1) \land (x \ne +1)$$ ...
4
votes
0answers
124 views

Delete duplicates by a criterion

The description This question came from my recent work. I achieved four groups points by data processing and then visualized them with Mathematica (shown as below) And I know that ...
4
votes
0answers
68 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 ...
4
votes
0answers
145 views

Can I define an axiomatic (Boolean algebra) system and prove theorems using Mathematica?

The general question is Can I define an axiomatic system and prove theorems using Mathematica? The more concrete one is about Boolean algebra. I consider this axiomatic Boolean algebra system ...
4
votes
0answers
92 views

Implement a piecewise function elegantly and efficiently

Given that $$ g(x)= \begin{cases} max(x_{min},x-m) & 0.5x \leq max(x_{min},x-m) \\ 0.5x & max(x_{min},x-m)<0.5x<min(1,x+m) \\ min(1,x+m) & min(1,x+m)\leq 0.5x \end{cases}$$ ...
4
votes
0answers
239 views

Call Haskell from Mathematica and return the results inside Mathematica

I would like to learn Haskell using Mathematica's environment. I know there is the RLink protocol. Is there a similar protocol for Haskell?
4
votes
0answers
91 views

Is there a way to check whether two notebooks share the same variables?

When I code in Mathematica, I often re-use code from old notebooks which fulfilled a specific purpose; for example, one testing for soft matches in strings, or one that identifies outliers on a graph ...
3
votes
0answers
146 views

Distance Time Warp (DTW) function implementation in mathematica

The DTW (Distance time warp) is given here http://en.wikipedia.org/wiki/Dynamic_time_warping There is an implementation of DTW in R as well as MATLAB. However i am unable to find something for DTW in ...
3
votes
0answers
328 views

A* algorithm for finding shortest path in a graph

FindShortestPath finds the shortest path between two vertices in an edge-weighted graph, allowing a choice between the Dijkstra and Bellman-Ford algorithms. In my (limited) understanding, both of ...
3
votes
0answers
177 views

Using NVIDIA 3D Shutter Glasses with Mathematica

Mathematica has great capabilities to display 3D Graphics rendered to the 2D screen. This should make it perfectly suited to use the Graphics3D system together with an NVIDIA Graphics card, a 3D ...
3
votes
0answers
283 views

How to compute the Lovász number for the given graph in Mathematica?

Here is a graph whose adjacency matrix is ...
3
votes
0answers
244 views

Malliavin Derivative with Mathematica is it possible?

Is it possible to define a Malliavin calculus with Mathematica 9? Consider a random variables on the Wiener-space $\Omega=\mathcal{C}([0,1])$ of the form ...
3
votes
0answers
157 views

I am missing a function like HoldPattern

Temporary message: I am planning to edit this question, making the examples less confusing and by moving the things that are confusing to a separate question For any confusion about expressions that ...
2
votes
0answers
91 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: ...
2
votes
0answers
80 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]$ ...
2
votes
0answers
139 views

Maximizing Large Multivariable Function over Region with Parameter Constraints

Brand new Mathematica user here. I have a complicated function to maximize, and thought I would try software like Mathematica instead of taking derivatives by hand. I found some Mathematica ...
2
votes
0answers
75 views

Simulating a system of nonlinear ODEs?

I was trying to simulate a system of ODEs on Mathematica in an effort to try to understand how to muck around with Mathematica but for some reason the following lines of code do not yield any results; ...
2
votes
0answers
57 views

Can BreadthFirstScan be modified?

I would like to obtain a "slick" implementation of A*-search algorithm on Graph objects, using the built-in BreadthFirstScan (if that is possible at all). I noticed that BreadthFirstScan is static in ...
2
votes
0answers
287 views

Lazy evaluation/loading of parts of an expression

Is it possible to have an expression x such that its elements are only evaluated when they are individually accessed, for example when evaluating statements like ...
2
votes
0answers
336 views

Forecasting future Stock Prices II

I intend to do the following: I want to forecast future stock price under the following assumptions: The stock price is governed by the stochastic differential equation: dS = μSdt + σSdWt whereas ...
2
votes
0answers
154 views
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
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 ...
1
vote
0answers
97 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
0answers
72 views

Updating procedural fitting algorithm to more efficient style?

For some time now, I have used this procedural programming approach to fit data in my research that is too cumbersome for the built in Mathematica functions. (Although this simple example works fine ...
1
vote
0answers
72 views

Programming for matrix manipulation

I want to write a programme which operates on nd x nd matrices. The programme looks the matrix as a n x n block matrix where ...
1
vote
0answers
145 views

Expectation Maximization Algorithm

I would like to use the expectation maximization algorithm within Mathematica. The issue is that I am very basic user and progress slowly with understanding functional programming.. I have found this ...
1
vote
0answers
46 views

Settings to disable global scope

I am building a fairly large application in Mathematica, and globally scoped variables are causing issues. I would like globally scoped variables to be out-of-scope for my expressions, except by ...
1
vote
0answers
122 views

How to construct a coordinate system that owns detailed calibration in the 3D enviroment?

Recently,I write a program to demonstrate the forward kinematics of the SCARA robot.The code showed as below: Using this function to construct the BigArm and ...
1
vote
0answers
123 views

Finding Values of All Nine Constants in q-hypergeometric Equation

I suspect that an identity of the form $$\sum_{j=-n}^{j=n}(-1)^jq^{j(5j+1)/2}=\sum_{r=0}^{n}f_{ar+bn+c}(-1)^{n-r}q^{(n-r)(dr+en+f)/2}\frac{(q;q)_{gr+hn+j}}{(q;q)_{n-r}}$$ for $a, \dots , j$ integer ...
1
vote
0answers
94 views

DifferentialEvolution scaling factor randomization

Using NMinimize for finding global minima, one can choose the DifferentialEvolution method. You can find a (not so) detailed ...
1
vote
0answers
92 views

Compiled version of user-defined function

I have a function for parameter estimation with these codes: ...
1
vote
0answers
116 views

Sum slowing down computations

I am trying to compute higher order Casimir invariants for some representations of certain groups. I can get the quadratic, cubic and quartic but beyond that things are taking too long to the point I ...
1
vote
0answers
149 views

Why doesn't ParallelMap improve the performance of FoldList?

This question arose during my analysis of the following problem: filling gaps. (The code used here is Simon Woods's work.) FoldList seems to not cooperate with ...
1
vote
0answers
271 views

Data structure for a list of actions

The idea: I need to generate a sequence of events then run a "propagator" over the list of events where the "propagator" will update the state of the following event. I can then write functions that ...
1
vote
0answers
265 views

Return Functions from parallel execution of module

I wrote a module which numerically solves an ODE using NDSolve. The result from this is e.g. either ...
0
votes
0answers
21 views

Gaussian Elimination with full pivoting

I have some problems with an implementation of the Gaussian elimination with full pivoting. It seems to me that I've programmed it correctly, but nevertheless it throws errors and I can't find my ...
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 ...
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 ...
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
0answers
31 views

$MessageList inside and outside Block[]

Why does 1/0 $MessageList return ComplexInfinity whereas ...
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 ...
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
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 ...