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

1
vote
0answers
90 views

Is it possible to 'partially' protect a variabile? [closed]

Please, consider a variable initialized at the beginning of a program: $myVar = {}; Protect[$myVar]; and the only two functions allowed to change it: ...
0
votes
1answer
28 views

How to select bottom three “norm” values and their corresponding matrices? [closed]

I calculated five random matrices of 6x3 (with some code which is already working) having name Subscript[randompop, j].Here is the output ...
6
votes
0answers
104 views

Mimicking Console and Output Matlab/Rstudio-Style Environment in Mathematica?

I am trying to crudely approximate the RStudio or Matlab Workspace environment in Mathematica by having a specific notebook function as the "console notebook" where I execute commands and another ...
0
votes
1answer
133 views

Plotting Graph of Zeno paradoxes

Zeno Paradoxes is about a Greek Heroes Archilles having a race with tortoise. the tortoise given a head start distance. Greek heroes Archilles have constant speed ...
9
votes
1answer
119 views

How to optimize my own BezierFunction?

A few months ago, I asked a question about the implementation of Bezier surface. Please see here for a full detail. I also know that BezierFunction[] is built-in ...
1
vote
1answer
42 views

Question about transforming a list of rules

Consider the following list: ...
5
votes
1answer
81 views

An unexpected match when using Condition, Optional and passing a Sequence

Mathematica is behaving in an expected way when passing a parameter with an Optional and a Sequence. Here is an example: ...
0
votes
1answer
56 views

Graphics is not a primitive or directive- please help! [closed]

I cannot seem to draw a windmill that fits in the photo background. Any help is appreciated! Thank you :)
32
votes
1answer
4k views

++ is dangerous for C programmers

I noticed this fact, that may be misleading for programmers used to C language. In Mathematica, if you have a function f[] and an array v, and you write ...
3
votes
1answer
166 views

How do I use StringReplace to replace repeated characters?

Suppose I have str = "dededekmkmkmvkfjdedemkvmlvdedekfmmdedededemkmkde" And I want to replace the repeated "de"s to one and produce (in a real example, the ...
3
votes
1answer
140 views

Error propagation code

I have a code for error propagation :- ...
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 ...
3
votes
0answers
74 views

Programmatic immersion of 2D surfaces in 3D [closed]

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 ...
3
votes
0answers
104 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 ...
8
votes
6answers
271 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
80 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
79 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
142 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
48 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 ...
9
votes
3answers
299 views

Implementation of a matrix formula

For the Bézier surface, which owns the following matrix definition: $$\begin{align*} S(u,v)&=\sum_{i=0}^m \sum_{j=0}^n P_{i,j} B_{m,i}(u) B_{n,j}(v)\\ &=\small ...
2
votes
1answer
94 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
30 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
215 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
1answer
86 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
102 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 ...
4
votes
1answer
127 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
34 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 ...
4
votes
2answers
131 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
834 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
173 views

Merging Financial Time Series

I am trying to merge two or more financial time series. For example, ...
14
votes
1answer
170 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
95 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
156 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
172 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
66 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
217 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
74 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
113 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
148 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
125 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 ...
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
783 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
141 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
132 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
46 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 ...