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

3
votes
1answer
82 views

Error propagation code

I have a code for error propagation :- ...
2
votes
1answer
55 views

Running an entire notebook with different values of an input [on hold]

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 ...
3
votes
0answers
59 views

Programmatic immersion of 2D surfaces in 3D [on hold]

Disclaimer: This may be an open problem, or one that is too large to be amenable to a solution on this site; I'm not sure. Question: I'm looking for a method to programmatically immerse certain ...
-5
votes
0answers
42 views

Conditionals within For Loops [on hold]

The following construct: For[i = 1, i <= Length[a], i++, a[[i]]? If[b[[i]] == a[[i]], p1++, p2++]: If[b[[i]] == a[[i]], p3++, p4++]]; yields the ...
2
votes
0answers
88 views

What is recommended way to define my function option

In Mathematica 5.x days many packages used the following standard mechanism to read option values ...
7
votes
6answers
236 views

Combinations of multiple matching patterns

I wonder if there is any nice way to combine DownValues (or any other suitable rule-/pattern-/function -based Mathematica construct) when multiple patterns match an expression. Let me explain what I ...
0
votes
1answer
71 views

How can I calculate the root of any order of power series

How can I calculate the root of any order of power series with Mathematica. Here I insert every quantity by hand. But I want to give a, ...
0
votes
2answers
71 views

Flipping random elements in a matrix

I'm still a beginner with mathematica so maybe the solution is obvious, but for some reason my code that worked fine earlier doesn't work now. I haven't changed anything about it. I've restarted ...
3
votes
0answers
32 views

How to identify the program that is running my notebook or CDF file [duplicate]

Is there a way to programatically know which Wolfram product is evaluating a notebook or cdf file: Mathematica, CDF Player, or CDF Player Pro, Wolfram Cloud? I'm currently using $InstallationDirectory ...
4
votes
2answers
117 views

Confining/Periodic boundary conditions implementation for 2D Random Walker

I am new to Mathematica, and am having trouble implementing confining boundary conditions for a random walk simulation confining the walker to a pre-defined region (periodic boundary conditions would ...
0
votes
1answer
43 views

Solving simultaneous and determinant given constant value and variable T (temperature) [closed]

How to solve this two simultaneous equations? these two equations got from this free energy equation ...
3
votes
2answers
110 views

Implementation of a matrix formula

For the Bezier surface, which owns the following matrix definition: where, $B_{n,i}$ denotes Bernstein-basis. ...
2
votes
1answer
80 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 ...
0
votes
0answers
27 views

Run mathematica script from python program [duplicate]

Is it possible to run the mathematica code inside the Python program? A simple pseudo-code to describe what I mean: ...
11
votes
1answer
210 views

How to deal with bad arguments when a function's UpValues is a pure-function?

In practice, I needs to define the UpValues of a user-defined function. For instance, the operation of function like differential formula , expansion and so on. ...
4
votes
2answers
77 views

How to Return $Failed symbol in a MakeBoxes context?

Three months ago, I asked a question about How to build a function object like the built-ins? Today, I used a solution proposed by István Zachar ...
0
votes
1answer
46 views

Results of a function are different when the function call and subsequent statements are evaluated one line at a time

I have some code that I am porting from VBA to Mathematica. The original code processes data on an Excel spreadsheet. In Mathematica, I find it convenient to replicate the Excel spreadsheet data ...
0
votes
1answer
88 views

Import Tex's aligned multiline equation into Mathematica

I know there have been answers to similar questions, using either ImportString or ToExpression, however I haven't been able to succeed in importing this. I'm using version 10 Mathematica on Linux by ...
-1
votes
0answers
44 views

Do loop, inconsistent results [duplicate]

Ive been at this problem for a couple of days now and no success. I'm very new to mathematica and hope someone can help. ...
4
votes
1answer
121 views

“Interface” for exam

Is it possible to create a (graphical) interface with Mathematica so that instead of having a Mathematica document where I change definitions and so on, I can just input values and it will use my code ...
0
votes
0answers
32 views

How to transfer the list of parameters values into With [duplicate]

In the following case: With[{x=1,y=2},Print[x+y]] the values of x and y are declared in ...
3
votes
2answers
116 views

Discritizing an analytical 3D-function

I have the following Problem: I need a discretized amount of points in a 3D-volume. These points satisfy a condition to built-up a 3D-geometry. In my example below I selected a helical geometry. The ...
10
votes
8answers
798 views

Best way to emulate MATLAB's bsxfun using Map and similar functions

Given a matrix, we want to subtract the mean of each column, from all entries in that column. So given this matrix: ...
1
vote
1answer
72 views

Help with getting an output from some calculations

I entered the following from @Rahul's answer in "Help with finding the point(s) inside a closed shape with the highest average ray length?" below my post. He told me I should enter his data one input ...
3
votes
2answers
156 views

Merging Financial Time Series

I am trying to merge two or more financial time series. For example, ...
13
votes
1answer
133 views

How to make a dynamic nested menu?

There is no dynamic controller that can represent a hierarchical menu structure: ActionMenu can only handle flat action lists. Thanks to Kuba, we know a lot about ...
4
votes
1answer
91 views

How to efficiently split your code in several pieces [duplicate]

I want to efficiently keep my program in several documents, and initialise pieces of it automatically. I'm pretty sure that there is a manual on the subject, but I'm unable to find it on my own. At ...
6
votes
2answers
133 views

Naming convention for symbols exported from package

I know this is a little opinion based, but so is Mathematica style guide and similar topics. The issue is important so I think this topic will be beneficial for future visitors. Q: So ...
1
vote
0answers
169 views

Help with calculating a complicated integral

Edit: The question is solved : )) Thank you for your attention ! I am sorry for mass questions, but the question bothers me a lot. So I would like to ask this question here. This problem arises when ...
0
votes
1answer
64 views

errors in simple for loops

Im trying to run the following code, which I have translated from Matlab. I created a for loop nested inside another for loop. mW is a matrix, and ...
5
votes
5answers
204 views

Nested function with an increasing argument

If, for example, I have a nesting function like Nest[1 + x^n (#) &, 1, 3] it gives the result ...
4
votes
2answers
94 views

How to find alignments of interlocking shapes?

I'm searching for the ways to align interlocking shapes, that is, finding the locations and rotations that maximize the arc length at which they touch. For simplicity, I'm assuming 'shapes' are one ...
3
votes
2answers
59 views

how to get the size of a directory(total size of all files under this directory or its subdir or …)

I use Mathematica10 in my Win7 and I want to estimate the amount of disk space occupied by each dirs. I try the code(the code was copied from How do I find the amount of free space on disk?, actually ...
1
vote
1answer
58 views

How to find line error in init.m file?

I have been changing my init.m user file. It runs fine, but I do get this error below. What does it mean by line 55? What constitutes a line? Are lines separated by "," or ";" or both? Or is it ...
3
votes
1answer
99 views

How to check and reset the boolean value of many options one times?

I defined a function which owns many options. In addtion, these options have a common characteristic. Namely, only accepting boolean value True or ...
3
votes
2answers
76 views

union several arrays of same flag(date for example) efficiently

Suppose I have several arrays from data files which look like: arrayi = {{datei1, xi11, xi21, ...}, {datei2, xi12, xi22, ...}, ..., {datein, xi1n, xi2n ,...}} ...
5
votes
4answers
115 views

SubsetQ[] without ignoring duplicates

How could one create a code that checks whether a set is a subset of another, but not ignoring the duplicates? For example, $\{1,1,1\}$ would be a subset of $\{1,1,1,1\}$, but not vice versa. ...
0
votes
1answer
75 views

Mean squared displacement of a single trajectory

I have a single particle trajectory and would like to calculate the mean squared displacement. The particle is moving from blue over yellow, green to red data points. The {x,y} data are available ...
4
votes
1answer
67 views

More efficient method to implement knots instertion algorithm

Knots instertion algorithm of B-spline About the definition of B-spline, please see here. Suppose $\overline u \in [u_{k},u_{k+1})$initially has multiplicity $s$, and suppose it is to be inserted ...
59
votes
10answers
5k views

Is Mathematica worth it for me?

I'm 13 years old and in 7th grade. I'm currently in Algebra 1, and I have fallen in love with both math and programming. When I came upon Mathematica, it was awesome. My two favorite things fused ...
5
votes
2answers
763 views

Line by line code development

One main advantage of Mathematica over several other languages, at least in my view, is that you can create your code line by line. This makes much easier to debug your code during the development ...
3
votes
2answers
89 views

How can I do a Do While loop [duplicate]

Many languages have a Do While loop, how can I do one in Mathematica ?
4
votes
3answers
121 views

Tips to write more readable code [closed]

What are some tips to write a more readable code? For example in C, tab is your friend. You can also declare variables in a way such that you can read the code easily later on. In Mathematica, if ...
0
votes
0answers
45 views

Incorporating sophisticated constraints on the approximating function into NMinimize

Following the approach as given in the answer of Belisarius here I just wonder how one could incorporate some more sophisticated requirements on the approximating function. Suppose the approximating ...
4
votes
2answers
125 views

FindFit and NMinimize to fit a parametric model (minimize the distance of two curves)

I am trying to find a fit to the cumulative distribution of a set of points using FindFit or NMinimize. In particular, I would like to find the parameters of the cdf of the Beta Distribution that ...
8
votes
1answer
224 views

Avoiding copies when modifying lists

Consider the following approach to modifying a list: ...
3
votes
1answer
117 views

Efficiently generating plots from lists of differing lengths

I guess this is more of an informatic question. A quite complicated function of mine generates me a list of valid points, depending on a parameter, like this: ...
2
votes
2answers
67 views

Double For loop problem [closed]

I am not really sure how to post my original data here, because the Tables I am using are rather big - too big to copy them here. I will try to describe what the problem is. I have three separated ...
0
votes
1answer
58 views

How to implement the for loop to replace text strings or texts?

I wonder define a bunch variables named like $X_1$, $X_2$, $...$, $X_n$. Is there some smart way to declare them instead of by pure typing. One trick I can image is to use the for loop,...
3
votes
1answer
110 views

Way to generate all multisets

I have a set $\left\{\{1,2\}, \{3,4\}, \{5,6\}, \{7,8\}\right\}$ (for example) and want to generate all sets of $n$ elements with repetition but without counting the same multiset twice. So I want my ...