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

10
votes
8answers
850 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
73 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
183 views

Merging Financial Time Series

I am trying to merge two or more financial time series. For example, ...
14
votes
1answer
177 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
102 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
164 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
175 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
68 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
220 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 ...
5
votes
2answers
99 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 ...
1
vote
1answer
84 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 ...
4
votes
1answer
194 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
78 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
153 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
140 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 ...
61
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
796 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
174 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
148 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
48 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
195 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
229 views

Avoiding copies when modifying lists

Consider the following approach to modifying a list: ...
3
votes
1answer
126 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
99 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
82 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
127 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 ...
2
votes
0answers
146 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 ...
1
vote
1answer
105 views

How to write or extend operators like $*\!\!*$

I'm stuck on trying to define simplification rules for NonCommutativeMultiply, much like ExpandNCM found in Documentation Center, under Applications. For example, I'd like ...
5
votes
1answer
181 views

Average positions in a 1D random walk

I wrote this to simulate m random walks of n steps ...
1
vote
2answers
172 views

Code for Newton's Method [closed]

I'm trying to write a program for finding the root of f(x)=e^x+sin(x)-4 by Newton's Method but I'm instructed to not use the built in function and write the code from scratch. I'm pretty new to this ...
3
votes
1answer
146 views

How can I plot the normalized distribution of the Riemann zeta zeros?

Given a list of eigenvalues or a list of Riemann zeta zeros, how can I plot this famous plot found here: On the page referred to, You need to click on "Programs", "The Riemann zeta function" and "...
1
vote
1answer
219 views

What is the equivalent of FORTRAN 77 COMMON BLOCK in Mathematica?

I am in the process of converting a FORTRAN 77 program to Wolfram Language. I have several COMMON BLOCK statements in FORTRAN 77. My question is how to deal with them in Wolfram Language? My ...
0
votes
1answer
92 views

Formulate an equation to find a fixed point [closed]

I have the following equation: Subscript[x, n + 1] = Subscript[x, n]^2 + c with Subscript[x, 0] = 0. This equation is restricted ...
-7
votes
1answer
83 views

My program to model exterior ballistics doesn't doesn't produce the plot I expect

Here is my program to model exterior ballistics. It doesn't doesn't produce the plot I expect. How can I fix it? ...
2
votes
0answers
83 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}, {...
1
vote
1answer
36 views

ReplaceAll - Position of list arguments not displayed properly [closed]

This code A[1, 2, 4, 5] /. A[a___] -> Position[{a}, 4] return {} Why this code not return 3 (a position of number 4) ? I ...
0
votes
1answer
66 views

How do I get the last three vectors to complete this cube?

Looking at this file, what vectors do I need to add to the cube:={...} in order to get a full cube?
2
votes
0answers
84 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 ...
8
votes
2answers
189 views

Name rewriting for Function fails in closure

At its heart, Mathematica is a dynamically scoped language. While the choice of dynamic scope for Mathematica is very much a defensible one, lexical scope is too useful to do without, and Mathematica ...
0
votes
0answers
40 views

Could not access a specific element of ConstantArray, why ? partw error [duplicate]

I could not access a specific element of ConstantArray, why ? The following is piece of my code: ...
12
votes
1answer
121 views

How to remove a LocalSymbol (or CloudSymbol)?

In version 10.2 LocalSymbol can be used to create a persistent store of a variable. Once this is created I don't see a method to remove it. How are are they ...
0
votes
0answers
102 views

Best practices, tools, and snippets for manipulating notebooks, cells, packages, and help access? [duplicate]

Where is the best place to find/submit lists of Wolfram Language/Mathematica best practices, idioms, and patterns, perhaps grouped by topics? I'm personally interested in those that involve using ...
0
votes
0answers
49 views

system.dllnotfoundexception unable to load DLL“ .dll”: can not find corresponding module

There are two computers. One of them works correctly, whereas the second one writes an error system.dllnotfoundexception unable to load DLL" .dll": can not find corresponding module in Wolfream....
1
vote
1answer
204 views

How can we accommodate arbitrary Unicode characters in symbol names?

I understand why Mathematica doesn't the support the [ character in symbol names, but it should be escapable in some way, like non-printable characters are in ...
2
votes
1answer
80 views

ListPlot dynamical problems [closed]

I have Manipulate, where there are FileNameSetter(to load file with data points) ...
6
votes
4answers
349 views

Plot[f,{x, xmin, xmax}], where xmax is not a const

I have a graph of the function, as in the picture. Function can be set manually, but after a certain value, it is 0. Could I find this value to put it instead of xmax=1 in Plot in order to avoid ...
0
votes
1answer
164 views

Iterating FindRoot to solve a differential equation

I am new to Mathematica style programming, better at traditional programming. I would like to know if I can create a table of results using FindRoot, where the ...
2
votes
1answer
171 views

Translate C++ in Mathematica 10.0.2 [closed]

By translating the following program written in C ++ ...
7
votes
1answer
145 views

How would one return from a place of a pure function's body using Return?

From previous answers, replies and discussions it is known, while not formally documented (even in the most recent Wolfram Language Documentation Center), that Return can be used in a two-argument ...
1
vote
2answers
76 views

How would one set up a conditional to evaluate at the last output value (wondrous numbers) [duplicate]

I know this is pretty fundamental, but I'm trying to learn Mathematica on my own and this is stumping me. I know 5 is wondrous and it takes 5 steps to reach one, but I can't figure out the input to ...