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

0
votes
0answers
34 views
2
votes
1answer
50 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
56 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 ...
1
vote
1answer
79 views

How to Minimize an NIntegral

My problem is to minimize in Mathematica a numerical integral. The command FindMinimum[With[{R=2.5},NIntegrate[(R*r1*a)*Sin[r1*a],{r1,1,R}]],a] does calculate ...
41
votes
5answers
4k views

Are there any cases when For[] loops are reasonable?

To my mind the only reason for the existence of For[] loops in Mathematica is to allow new users with some experience in procedural programming languages to write ...
3
votes
1answer
371 views

How can I invoke the solution of NDSolve to determine a parameter in my equation just inside NDSlove?

I am trying to solve a differential equation by NDSlove for $h(x,t)$. It reads $$h_t=h_{xx}-V_h-\lambda(t)$$ where $V_h$ is a given function of $h(x,t)$ denoted by ...
-5
votes
0answers
41 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 ...
7
votes
6answers
234 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 ...
395
votes
15answers
88k 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 ...
2
votes
0answers
85 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 ...
295
votes
26answers
46k 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 ...
10
votes
2answers
253 views

Is there a method to enumerate the keys/values of System`Utilities`HashTable

Lacking from the simple API of System`Utilities`HashTable is a method to enumerate the keys/values. ...
7
votes
1answer
265 views

How is LHS = RHS; … ; LHS (nontrivially) different from … ; RHS

I'm trying to understand how Mathematica thinks about the results of Set. Suppose we perform LHS = RHS. I'm focusing on when ...
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
70 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
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. ...
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 ...
27
votes
4answers
2k views

What is a type in Wolfram Mathematica programming language?

"Everything is an expression" is a popular citation from many Mathematica guidebooks. So, what is type in Mathematica? How does it relate to common types from Haskell, for example? I did some ...
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 ...
11
votes
1answer
125 views

Preventing Keys from appearing in Query Output (+ the casting of Ascending/Descending operators)

One of the challenges of coming to grips with Query's on Association's and Datasets is ...
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
1answer
118 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 ...
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 ...
8
votes
7answers
1k views

Better code to find Narcissistic number

My code finding Narcissistic numbers is not that slow, but it's not in functional style and lacks flexibility: if $n \neq 7$, I have to rewrite my code. Could you give some good advice? ...
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: ...
0
votes
1answer
87 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
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 ...
4
votes
1answer
240 views

Help with Permutations

I am currently trying to generate a list of permutations of length 2 of elements of a list of strings. For example: ...
1
vote
2answers
119 views

how to generate repeatable Unique streams?

I need to label some data in arbitrarily nested ragged lists, with a stream of unique labels. It's very convenient if the labels are consecutive integers, starting at ...
-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. ...
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 ...
11
votes
2answers
921 views

Morphing a “sheet of paper” into a torus

How can I visualize the standard topological "rubber-sheet" construction of a torus, that is, morphing a square into a torus? How can I start or are there any examples in the Mathematica ...
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
797 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 ...
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 ...
8
votes
2answers
418 views

Association and rudimentary object-oriented programming

Doesn't Association provide us rudimentary object oriented programming via constructs like ...
10
votes
2answers
522 views

Abort not aborting

I have a relatively simple bit of code that looks like the following: ---some code here--- If[statement, Abort[]]; ---more code following--- However, while ...
3
votes
2answers
155 views

Merging Financial Time Series

I am trying to merge two or more financial time series. For example, ...
5
votes
2answers
131 views

A pre-parsed HoldForm

HoldForm holds an expression's parsed form not its actual "inputted form" e.g. ...
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 ...
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
90 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
281 views
6
votes
2answers
132 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 ...
0
votes
0answers
87 views

Evaluate notebook using text-based interface

I am trying to evaluate a notebook using a text based interface so that it can be submitted to a computing cluster. I have seen this stackexchange page and attempted to use ...
1
vote
0answers
436 views

Interpolating function as a model in Mathematica's procedures for fitting

Is it possible to use interpolating function with parameters as a model for NonLinearModelFit (and other integrated methods for fitting)? Similar question was ...
16
votes
3answers
1k views

Reading from STDIN, or: how to pipe data into Mathematica

Today I tried using Mathematica's plotting capabilities to display the output of a C++ program. This made me wonder whether it is possible to somehow tell a Mathematica script to read from STDIN and ...