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

2
votes
1answer
249 views

Fighting Less::nord at the root: Any unintended consequences?

After being plagued too much by Less::nord and companions, I've decided to try to fight it at the root: The comparison operators. I noticed that typically, the bad ...
2
votes
1answer
107 views

Speeding iterative computation

I want to get the following iterative sequence ...
2
votes
1answer
122 views

How does exactly Check work?

Please, consider the following code : ...
2
votes
1answer
70 views

Code optimizations with functions inside Module

I wrote a small code by using functions inside Module: ...
2
votes
1answer
178 views

How to determine whether an expression can act as a “good” function?

It's not easy to see whether an expression can act as a "good" function. A good function refers to an operater that transforms symbolic entities like 1+x^2 or ...
2
votes
1answer
161 views

How to speed up my code about Divisors?

This code is about PE496 In[21]:= ParallelSum[n*Count[Divisors[n^2], a_ /; n < a < 2 n], {n, 1, 10^5}] // AbsoluteTiming Out[21]= {5.987342,10724527832} I ...
2
votes
1answer
90 views

How to package a function for export?

I often post code for functions on Stack-Exchange, and then later find that they are unexecutable - that people can't use them because I mistakenly omitted some private functions or values that are ...
2
votes
1answer
95 views

Probability evaluation fails with equals condition

The following evaluation fails (the result is just the copy of the input) $$\text{Probability}[0<x\leq a | x-y=t,\{x\ {ExponentialDistribution}[\lambda ],y\ {ExponentialDistribution}[\lambda ]\}]$$...
2
votes
1answer
167 views

How can I rewrite my code to make it simpler?

Two months ago,I written a function IRobot to caculate the $I_{xx},I_{yy},I_{zz}$ and $I_{xy},I_{xz},I_{yz}$,shown as below: ...
2
votes
1answer
1k views

Calculate mean square displacements for different particles from a excel file

I have the particle movement data in the following format: ...
2
votes
1answer
325 views

Combining two notebooks

I have a notebook which contain all the variables and defined functions. I want to do two tasks. As an example, I want to find the density and energy which have equations in terms of above mentioned ...
2
votes
1answer
203 views

How do I insert a piece of code in Mathematica?

In Fortran, I can use include "file" to insert a piece of code. Is there a similar method in Mathematica?
2
votes
1answer
104 views

PaneSelector and options in a Module

Consider the following snippet of code: ...
2
votes
2answers
58 views

Substituting within a function definition that includes Simplify

I would like to define a function like myfunc[f_] := Simplify[(f/g)] where g will be substituted/replaced with the current value of g at the time of definition. ...
2
votes
1answer
66 views

Running an entire notebook with different values of an input [closed]

I have about a 20 cell notebook which begins at n=3. By replacing 3 by other natural numbers, I can compute what I want using these values, but I do not understand ...
2
votes
1answer
101 views

Implicit derivatives in one line. How do I do it?

I have this little script to derive implicitly $PrePrint = # /. {D[y_, x_, NonConstants -> {y_}] :> y'[x]} &; Example: ...
2
votes
1answer
86 views
2
votes
1answer
83 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 ...
2
votes
2answers
144 views

Using conditionals to check if LinearSolve found a solution

Is there some way to check if LinearSolve found a solution using conditionals in Mathematica 9? I need to solve a large number of linear equations, but I am only interested in the cases where there ...
2
votes
1answer
325 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} - 3\...
2
votes
1answer
550 views

Cournot Equilibrium

I'm trying to determine reaction functions of a Cournot equilibrium for $n$ firms using the same optimal condition, using the fixed point method. This is the method I'm using: ...
2
votes
1answer
50 views

$Pre and the attribute HoldAll

Please, consider $Pre = If[go, #, Null] &; Now, this go = True; a = 1; b = 1; go = TrueQ @ (b != 0); a/b returns ...
2
votes
1answer
98 views

Clearing a global variable from inside a Module

This is a highly simplified version of a initialization problem I have with a complicated program with many (about 100) modules. If one enters: X=42; Clear[X]; the ...
2
votes
1answer
79 views

ListPlot dynamical problems [closed]

I have Manipulate, where there are FileNameSetter(to load file with data points) ...
2
votes
1answer
118 views

How to keep Mouseover visible while control has focus/cursor?

I have a DateObject and InputField that I am using to collect an inputted date. Mouseover ...
2
votes
1answer
115 views

Program to demonstrate rotation according to quaternion values

On the Wolfram|Alpha website, I type quaternion(1,1,1,1) into the search field. Wolfram|Alpha shows a 3D transformation of the quaternion values representing the orientation of an object. I have 9 ...
2
votes
1answer
63 views

Evaluate recursive funtion as a whole before computing a recursive step

I'll try to make a basic example of my problem with $n$ being an array of elements, ex. $\{1,2,2,3,3,3\}$: If i have a sum which needs a computed value i would like to compute it beforehand and store ...
2
votes
1answer
112 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: ...
2
votes
1answer
76 views

Are there methods to serialize and deserialize large calculation runs? [closed]

I have a fairly large calculation to map an electric field over large areas (square kilometers). This runs for a fairly long time. Are there ways to serialize the current state of a running ...
2
votes
1answer
146 views

How to handle Indeterminate TimeConstrain

I have to use Timeconstrained[aux] first for avoid some bigs calculation that dont need and it use a lot of time of calculate, so i can't do this. ...
2
votes
1answer
146 views

Need help looping a notebook evaluation

I'm a new user and would like to find the minimum value of soln1[30] obtained after repeating the following evaluation (below) for 1000 cycles (for instance). I can obtain sequential values of soln[...
2
votes
1answer
189 views

Discard functions with wrong symmetry?

I have functions of x, where x is the polar angle of spherical coordinates, i.e. ...
2
votes
1answer
290 views

Can Mathematica help a theorem to be alive?

We are used to do limits by means of $\epsilon, \delta$. This is the first step an student encounters limits. Using $\epsilon$ and $\delta$ leads him to be familiar to Logic. I have taught limits and ...
2
votes
1answer
149 views

How to linearize an expression involving derivatives?

I want to linearize the expression involving function $y(x,t)$ $$[y^3(y_x-y_{xxx})]_x$$ by assuming $y(x,t)=y_0(t)+y\prime(x,t)$, where $y\prime(x,t)$ is a small variation. In other words, I will ...
2
votes
1answer
180 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 ...
2
votes
2answers
94 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 ...
2
votes
2answers
211 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 ...
2
votes
1answer
245 views

Piecewise function with user-input interval

I would like define a function g[data,bins,x] which is a piecewise constant function taking value data[[i]] in the range ...
2
votes
1answer
73 views

Evaluate only one from a set of procedures

Let's say I've got a list of procedures: {Print[1];, Print[2];, Print[3];} And I want to only evaluate 3rd one: ...
2
votes
1answer
221 views

Differential operator involving permutations

I would like to construct an operator in Mathematica of the following form, $$D_i=\partial_i +\sum_{i \neq j}^n\frac{1}{x_i-x_j}p_{ij}, \quad i=1,...,n$$ where $p_{ij}$ is a (symmetric) permutation ...
2
votes
1answer
274 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: ...
2
votes
0answers
24 views

How to deal with tensor argument in LibraryLink?

For the Bézier surface, which owns the following matrix definition: $$\begin{align*} \mathbf{S}(u,v)&=\sum_{i=0}^m \sum_{j=0}^n \mathbf{P}_{i,j} B_{i,m}(u) B_{j,n}(v)\\ &=\small \begin{...
2
votes
0answers
48 views

Where can I find tutorials or examples about Internal` packages and other useful packages? [duplicate]

As an intermediate level Mathematica user, I consider one of the greatest barrier on my way to a higher level of programming is the lack of knowledge about extra packages like Internal` package or ...
2
votes
0answers
99 views

How to use Mathematica to help me get highest score in every layout? [closed]

The game is hitting the headline in these day and everyone can click this link to play it.The game have a very simple rule like following: Game Rule It will give you a initial layout when you click ...
2
votes
0answers
50 views

A question regarding shadowed symbols

The more I study, the less I understand. This is the HelloWorld package: ...
2
votes
0answers
101 views

List of amazing things you can do with Mathematica [closed]

What is the coolest (amazing) thing you can do with Mathematica? for instance there are my favorite things Automating xkcd Diagrams Extending Van Gogh’s Starry Night with Inpainting Making ...
2
votes
0answers
145 views

Examples of a large Mathematica construction? [duplicate]

I'm pretty new to Mathematica, and in trying to find examples of good Mathematica programming, it always seems that solutions to a problem can be solved with hardly any lines of code. Of course this ...
2
votes
0answers
82 views

Dynamic array in Mathematica like malloc in C++

I have a table to describe a crossroad. Each traffic line has it own Q(flow), V( speed) and direction. I'm saving data in array, which hardcoded (very simple code data = {{66, 55, 3}, {44, 33, 2}, {...
2
votes
0answers
83 views

Findminimum fails in loops

Introduction to the problem: the function F[x][u,v,w] I'm currently dealing with a very strange minimalization problem. I have a function F[x][u,v,w] which is ...
2
votes
0answers
180 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) ...