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
1k views

Mutual Information involving two matrix states

I basically retrieved the following technique of evaluating the mutual information involving two matrices from this site at http://bmia.bmt.tue.nl/People/BRomeny/Courses/8C080/default.htm The ...
1
vote
2answers
194 views

How to automatically restart Mathematica kernel after out-of-memory error

I want to run a Mathematica code repeatedly, even after the kernel shuts down when it is out of memory, because I have designed my program to continue appending the data to a file. Currently, I have ...
2
votes
1answer
91 views

Map and Scan ignore HoldFirst

I am trying to write a simple function that takes a list of data and outputs it to a file. I'd like the name of the file to be the same as the variable that holds the list. It seems that giving a ...
2
votes
0answers
205 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 ...
20
votes
1answer
321 views

A fast, robust DropWhile

For reasons that have never been entirely clear to me, Mathematica has had a built-in TakeWhile function since version 6.0, but has no equivalent ...
2
votes
1answer
225 views

Optimal image quality using Rasterize Function

Based on previous posts about plotting two y axes on the same x axis, I wrote this function: ...
0
votes
0answers
94 views

Inconsistent results in fits from NArgMin

EDIT: Just realized I had misspelled "inconsistent." I'm using version 7.0. I'm trying to fit a (noisy) data set to a large-order polynomial. (Just for context: there isn't a model for the ...
3
votes
0answers
232 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 ...
1
vote
1answer
198 views

Making an animated simulation without procedural loops

I'm still new to Mathematica and this is the first time I've wanted to do something more complicated than plotting and changing parameters of mathematical functions. I want to make a simple ...
3
votes
1answer
121 views

Difference between Directory[] and NotebookDirectory[] .. a trailing /?

The following was the code: Directory[] NotebookDirectory[] The output was ...
5
votes
5answers
195 views

On reimplementing the Select function [duplicate]

I am working through the course Programming Paradigms via Mathematica. One of the exercises asks that you construct a function that mimics Select,even with three ...
8
votes
1answer
142 views

Is it possible to write a function immune to symbol redefinitions in any Block surrounding its invocation?

Normally, semantics of symbols used in a function definition can be changed by their redefinitions in Blocks surrounding the function invocation: ...
11
votes
2answers
500 views

Dynamic Programming with delayed evaluation

By using dynamical programming, we can save intermediate steps for recursive relations, as in f[n_]:= f[n] = f[n-1] + f[n-2] However, this only stores ...
8
votes
1answer
124 views

Is it possible to use the global definition of a symbol as part of its new local definition set in a Block?

Consider the following expression: Block[{Print = CopyToClipboard}, doSomething[]] Now all calls to Print from ...
1
vote
1answer
162 views

Handling Overflow

I have a notebook which takes in a user-defined function and starting value and tracks the orbit of the particle under iteration of the function. The problem occurs when the user enters a starting ...
4
votes
2answers
249 views

Adapting “Find and Replace” functionality to work with Patterns

I was thinking if there is something like Find and Replace (Crtl+F) functionality adapted to work with patterns. Probably not, but it seems possible to create this with some effort and skills in ...
1
vote
1answer
99 views

Rounding only reals in an expression containing, reals, integers and symbols

I am trying to make a function that would make rounding real numbers in an expression possibly consisting of real numbers, integer numbers and symbols. An example of such an expression is below: ...
2
votes
1answer
659 views

Mathematica TCP socket client toward Trading Platform

I'd like to connect Mathematica with my Italian electronic trading platform. To connect I need to open a TCP socket client towards the trading platform and send a string command. The high-level ...
3
votes
1answer
222 views

How to determine cluster membership using FindClusters?

I have a 1000 by 3 data matrix in which for each person we have 3 scores. I want to cluster those persons into 8 cluster using Agglomerative method. I did the clusetring by: ...
1
vote
0answers
146 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 ...
3
votes
1answer
99 views

Generating Palindromic_number [duplicate]

I'm trying to construct Palindromic_number, I came up with this code: ...
12
votes
10answers
618 views

How can I generate a nested array like this one?

Well, this is how the array looks like: I came up with this code: n = 10; Nest[ArrayPad[#, 1, 1 - #[[1, 1]]] &, {{1}}, n] /. {1 -> "*"} Any better ...
10
votes
1answer
207 views

Is there a method to enumerate the keys/values of System`Utilities`HashTable

Lacking from the simple API of System`Utilities`HashTable is a method to enumerate the keys/values. ...
5
votes
1answer
170 views

What is the fastest way to maintain a large set of expressions?

In my algorithm I need to maintain a set (an unordered list of distinct elements) of expressions supporting two operations: Test an expression for membership in the set Adding a new expression to ...
2
votes
1answer
125 views

Odd edge-case behavior of Block

In this example, Block is used to localize the variable cache as used in the function g when called from the function ...
1
vote
1answer
811 views

How to linearize an expression automatically?

I would like to automatically linearize some long equations in the scope of variational calculus. Here follows an example of what I need to do : Given two variables $a_1 = q_1 + \delta q_1$ and $a_2 ...
1
vote
1answer
199 views

Calculating mean of multiple stochastic processes and setting a lower threshold

Thanks to “Rod Lm” I got some very nice input for the following problem. My intention is to simulate within a Manipulate function a given number of possible stock ...
4
votes
3answers
190 views

Renaming and indexing list of rules

I have a list of rules that represents a list of parameters to be applied to a circuit model (Wolfram SystemModeler model): ...
30
votes
1answer
1k views

Recommended settings for git when using with Mathematica projects?

Background I'm relatively new to git — currently overseeing an offshore .NET-based development project on GitHub within a private business account, but little experience beyond that. I'd like to set ...
2
votes
1answer
81 views

Fastest way to select the longest cell

I'm trying to learn low-level notebook programming and I have a question. Is there faster way to select the longest cell in a notebook than this: ...
3
votes
1answer
155 views

How to replace a string within a selected region in a notebook?

I want to replace a string in a selected region/cell in mathematica notebook/package. I searched but didn' t get any result. I think it' s a quite common feature for editors/programming environments. ...
0
votes
1answer
166 views

Pattern match with Table for matrix dimension check

In Mathematica, often an expression involving matrices will encounter dimension mismatch errors, like we are multiplying a 3x2 matrix to a 3x4 matrix. Below we define a new symbol Dim, which can be ...
13
votes
1answer
473 views

rule-based implementation of an algorithm

When I first started learning about rule-based programming with Mathematica, I tried to translate this algorithm for computing the convex hull of a set of 2-D points in $O(n \log(n))$ time, to use ...
2
votes
0answers
281 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
2answers
316 views

Mapping multiple functions

This question was part of a course on Mathematica written in 1998. Each of the functions f1, f2, and f3 defined below has a root near x=2. Map an anonymous function involving FindRoot[] onto ...
2
votes
2answers
749 views

Forecast Future Stock Prices - Brownian Motion - Again

excuse me, I think I have here a technical problem with Mathematica yesterday I posted the question with the title: Forecast Future Stock Prices - Brownian Motion I am still not very experienced but ...
39
votes
9answers
4k views

Having used Mathematica as a “gateway” language, where to from here?

I have been using Mathematica for about a year. It is the first language that I have attempted to learn. I'm still very much a newbie, but there are moments I feel more like I am waving than drowning. ...
35
votes
2answers
651 views

How safe is the use of Block and Internal`InheritedBlock

For many questions on this site answers are given which suggest to use Block and, especially for more advanced topics, ...
8
votes
2answers
1k views

Dynamic graph visualisation using JLink/Java and GraphStream

Visualising the addition of new nodes and edges to a graph to 'watch it grow' is to something Mathematica is not suited to by default. However this type of animation really helps convey the emergence ...
1
vote
2answers
151 views

Counting a cardinality of a subset satisfying special property

Suppose that we have a set of 9 2-dimensional vectors $c$ by m=3; n=2; c=Tuples[Range[m],n]; We want to define a subset $S$ of vectors in $c$ by the following: ...
12
votes
3answers
299 views

Notebook vs. DocumentNotebook; display a Notebook inline, like a DocumentNotebook

If you evaluate a DocumentNotebook[] expression in the front-end, it nicely displays inline, inside of an output cell in the current notebook: For my purposes, ...
3
votes
1answer
68 views

Combination of CellPrint and PrintTemporary, or DisplayForm for Cells

I'm programmatically generating some formatted output that generates a cell in the form of a Cell[] expression. For instance, the output might be ...
4
votes
2answers
200 views

How can I write a Do loop that iterates over N iterators when N is not known a-priori?

For any positive integer $n$ which is not specified a priori, I can make $n$-tuple vector $v$ by v = Array[a, 1, n]. Now, given that $n$ is a positive integer which ...
0
votes
1answer
475 views

What is wrong with this Cobweb plot [closed]

Something is wrong with my cobweb plot code but I couldn't figure out where do the mistakes come from. So basically we have the iterative map $x_n == x_{n-1}^{2} - 3 \mu$. I would like to draw a ...
3
votes
1answer
211 views

Using single replacement rule to convert algebraic expression

I have been trying this problems for hours and cannot find any helpful clues. How can I convert $Sinh[3\theta]+Sinh[\theta]$ to a rational function of x given $2Sinh[\theta] = x-x^{-1}$ by using only ...
1
vote
1answer
225 views

Solve this equation symbolically

I am trying to solve the equation for the quantity r = y/x symbolically: 3/y^4 == 3/x^4 + a/(x + 2 y)^4 with the requirement that we need to perform the ...
2
votes
1answer
272 views

Range of stability for iterative map

Using linear stability analysis, I would like to compute the range of stability of the fixed points and the 2-cycles of the following iterative map: $x_n = x_{n-1}^{2} - 3\mu$. Setting $x = x^{2} - ...
1
vote
2answers
289 views

Doing vector manipulations on Mathematica

This is hopefully a simpler version of this previous unanswered question of mine. Let me just focus on the two expressions $F_2^{(s)}$ and $F_3^{(s)}$ given in A.3 and A.4 of page 19 of this paper. ...
4
votes
3answers
189 views

Modify this code using Module and While

I have written a recursive function and would like to re-write the code using Module AND While to compare the timings. Here is my recursive function for f[n], where 6 n f[n] = f[n-1] + n! for n>0 and ...