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

265
votes
12answers
45k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
-1
votes
0answers
46 views

How to generate all symmetric positive semidefinite 0,1 matrices of a given order [on hold]

The title says it all. There are many instances when we need to check some properties of such matrices. I am looking for an efficient code.
0
votes
1answer
69 views

A problem with set values

The following code is just an example to clearly explain my problem. Assume that : ...
0
votes
0answers
36 views

A problem with functions and Infinite expression 1/0 encountering

Following code (function) makes integrals and then replace f[x] with Cos functions and calculate the definite parametric ...
0
votes
1answer
78 views

How to produce functions [on hold]

I want to produce n functions. For example, assume that by giving n=3, 3 definite integrals will be created, like the following: ...
19
votes
2answers
375 views
+50

How to implement FittedModel like objects

In the course of making some RLink wrappers I want to have some richer containers like Mathematica does with its FittedModel ...
9
votes
2answers
229 views

Create a new infix operator

It is well known that the infix operator @@ is used as a short form of Apply. For example, both ...
0
votes
1answer
74 views

Mathematica Implementation of Householder’s Method

I typed the Householder code in this paper, which starts on page 7. The code is: ...
135
votes
19answers
10k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
2
votes
0answers
48 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 ...
7
votes
1answer
72 views

Equivalence under common permutations

I have lists which consists of sublists of equal length. The outer list is regarded as a multiset (that is, permutations of the sublists don't matter, but repetitions do), but the order in the ...
1
vote
1answer
87 views

Help to solve the equation with RungeKutta method [closed]

I need to solve this equation. v'[t] + v[t] == 1/(1 + Exp[-v[t]]) I tried to solve it using RungeKutta method described in Wolfram ...
0
votes
0answers
26 views

Determine if a point is inside two planes [closed]

If I have a point and two planes defined by three vertex each how can I know if the point is inside the two planes? note: I need to code the solution in java.
0
votes
0answers
21 views

Does RuleDelayed work inside MessageName?

using : Mathematica 9.0.1.0 Hello ! Does RuleDelayed work inside MessageName ? This code: ...
4
votes
1answer
68 views

How to set the position of the palette when use CreatePalette[]

When using CreatePalette[], the palette created always shows up on the upper left corner. Is there a way to make it show up at the center of the screen, just like ...
1
vote
1answer
100 views

How to replace a list with the result list after each iteration [closed]

I have some initial values such as L1 list: L1={10,20,30,40,50}; I want to use the L1 ...
2
votes
0answers
86 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? ...
16
votes
4answers
467 views

Accessing list elements by name

First, a bit of a long introduction to my problem: I only have a few weeks of Mathematica experience. I am creating a mathematica application that calculates some material properties of steel based ...
0
votes
1answer
39 views

Problem with Label in a Do loop, “nolabel” [closed]

Can someone tell me why this code doesn't work and how to fix it ? Thanks. ...
1
vote
3answers
163 views

How to update a list in a function in each iteration

There is a list with numbers 1 to 8 ( p1 ) and another list (j) which contains 4 numbers which shows different 4 positions of ...
-1
votes
1answer
80 views

Transformation of a simple logic statement

I'm designing a logic circuit and I was wondering if the following two things are equivalent: (x <= y) and (x < (y + 1)) I can't think of any set of numbers that would make these two things ...
1
vote
3answers
156 views

How to replace identical positions in two different lists

Assume that I have two lists like : list1={1,2,3,4,5}; list2={a,b,c,d,e}; I want to replace some elements from list1 into ...
1
vote
1answer
99 views

Requesting explanation of FitModel code

I am struggling with understanding the code given in this original post I understand how the tests are conducted, both of them. However, I do not understand this part: ...
0
votes
1answer
64 views

Defining a new matrix product of matrix function

Suppose I have two matrices A, B, whose entries are functions of x. Suppose they are 2*2. In the product, each entry is of the form $\sum_k A_ik B_kj$. There are two summands corresponding to k=1,k=2. ...
0
votes
1answer
41 views

How to put some values from a list into a function in a Do loop

I want to program a code in MATHEMATICA in order to calculate some values in different iteration. For example, assume this list: list={1,2,3,4,5} Now assume that ...
1
vote
2answers
64 views

Avoid making repeated Random Integer in different iterations

Assume following code : Do[ i1 = RandomInteger[{1, 5}]; i2 = RandomInteger[{1, 5}]; While[i1 == i2, i2 = RandomInteger[{1, 5}]] , {k, 1, 4}];` This ...
1
vote
1answer
113 views

How can I import sound from within a Manipulate expression?

I want to import sound from a file, record, and import sound. ...
0
votes
1answer
154 views

Heat Transfer equation by numerical methods

I want to solve the following heat conduction equation using numerical methods: D[u[x, t], t] -alpha*D[u[x, t], {x, 2}] == 0 u[x, 0] == 1/(1 + x^2)^0.25, u[-10, t] == u[10, t] == 0, ...
25
votes
2answers
882 views

when is f@g not the same as f[g]?

I have always thought that f@g will give the same result as f[g] in all cases, and it is just a matter of style which one to use ...
11
votes
5answers
1k views

What is the fastest way to extract a substring from a huge string?

I develop an algorithm to find the most common substrings of a given length n up to a certain distance l in front of a pattern p in a huge sequence S. E.g. I want to find the most common hexamers ...
11
votes
5answers
748 views

How can I get exactly 5 logarithmic divisions of an interval?

I'd like to get exactly 5 divisions from x to y on a log scale. Can FindDivisions do this?
0
votes
2answers
82 views

Finding lags of time series with `Do`

I have generated two time series, S[t] and P[t] as follows: ...
15
votes
1answer
372 views

List manipulation to build a functional expression

Since Mathematica deals with Head[a, b] as an expression in this way The first Part of Head[a, b] is ...
1
vote
1answer
48 views

Hide MathKernel Tab on Taskbar when using C++ [duplicate]

I am connecting to MathKernel.exe using C++ via MathLink on Windows. Hence, to create the link, this is what I use: ...
0
votes
0answers
67 views

Integrate double definite integral [duplicate]

I am trying to evaluate an integral numerically and plot its result. My mathematica code is: ...
0
votes
0answers
17 views

NDSolve_ODESolve_Plotsolution [duplicate]

I am trying to use mathematica to solve this problem. Thank you! Given the ODE $$ -\frac{a^2 V_0}{2} f''(x)-V_0\cos\big(\frac{2\pi x}{a}\big) f(x)=E f(x) $$ (a,V_0) are positive real constants. Find ...
13
votes
2answers
389 views

Most influential and/or disrupting features introduced with new versions of Mathematica

This is something that has been bugging me for ages. With every upgrade, Mathematica has added new functionalities and amendend some of its bugs. In the process, though, some older functionality has ...
4
votes
1answer
131 views

Selecting expressions from a sequence that are not subexpressions of earlier elements

I have a While loop that generates and prints an expression on each iteration (there can be thousands of iterations). UPDATE: Some expressions are generated in ...
1
vote
1answer
195 views

Euler's method for system of differential equation

I need to program Euler's method to solve a system of two diffferential equations of first order. Fist, I have programmed the Euler's method for just one differential equation: ...
2
votes
2answers
118 views

Solving a dynamic program via recursion

I'm trying to use recursion to solve a joint inventory/ dynamic pricing problem as in monahan, petruzzi and zhao 2004. I tried to solve for y[t] and ...
9
votes
7answers
358 views

How to efficiently Append a result of an operation on each element of a list to itself

I'm looking for the best function to apply the product of the last two elements of sublist elements to each element: Example: ...
1
vote
0answers
64 views

Read expression from Mathematica via Mathlink C++

This is a simple C++ program to send an expression to the_Mathematica_ Kernel and get its response. ...
3
votes
2answers
63 views

Defining an anonymous function using another function but with fewer arguments

In MATLAB you can use an anonymous function with another function to define a new function with fewer arguments as long you define the excluded argument before, e.g. ...
0
votes
1answer
59 views

Evaluate function of two variables using nested Do loops

Is there a more efficient way of evaluating a function of two variables on a rectangular grid the the following nested Do loops? ...
1
vote
1answer
43 views

MLEvaluate() Function Gives Error

I am trying to link my C++ program to Mathematica Kernel. I am trying to use the MLEvaluate() evaluate but I receive an error while compilation. My codes are as below: ...
3
votes
0answers
132 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 ...
11
votes
1answer
310 views

Generating Gelfand-Tsetlin patterns

I am doing some research on some combinatorial object called GT-patterns. They are generated from three parts of data. Two integer, partitions (sequences of weakly decreasing numbers), $\lambda = ...
2
votes
0answers
83 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 ...
7
votes
1answer
740 views

Efficient backtracking with Mathematica

Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ...
4
votes
1answer
129 views

Using Mathematica in Conjunction with LyX. Path Issues?

I am attempting make life easier, and, instead of using Mathematica at the same time that I'm using LyX (a front end for LaTeX), I was hoping that I could just use LyX and use the CAS option to do ...