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
24 views

Bezier curves function in mathematica [on hold]

I need help urgently, for next monday I need to write the name ALAN using BEZIER CURVES programming it on mathematica, but I'm not allowed to use the bezier curves function that mathematica already ...
-1
votes
1answer
48 views

CompiledFunction::cfsa Argument x at position1 should be a machine-size real number [on hold]

I have a compiled function: g:=Compile[{{x, _Real}},...] and call g through an interim function: g2[x_?NumericQ] = g[x] If ...
-2
votes
0answers
71 views

unordered lists with maximum dispersion [on hold]

As you can implement the following I have a list $$L = {p1, p2, p3, p4, p5 ........ pn}, n <50$$ I need cluttering and print this list 4 ...
8
votes
3answers
908 views

Implement the Bisection algorithm elegantly and easily

Description: Rencently, I have finished my course Numerical Analysis, so I'd like to implement many algorithm that I have learned from that course.By this practice, I hope that I can improve my ...
-2
votes
0answers
28 views
4
votes
1answer
50 views

To embed metadata in a notebook, keeping them both human readable and easily parsable

I' m trying to set up a gizmo to manage the large notebooks collection, in my Mathematica workspace. The main idea is to embed indexing metadata in each notebook and manage them by means of function ...
6
votes
0answers
97 views

Good clearing practices

I have been using Mathematica for about 2 years and I'm pretty ok to write and optimize my code. Wanting to improve my practice, I often look at code examples. However, I can not determine if there is ...
3
votes
1answer
41 views

What options for project development exist if the Cloud and Mathematica Online cannot be used

Due to contractual obligations to protect IP and client information, we unfortunately, cannot use Cloud or Mathematica Online for development in the development of our projects. We are further ...
2
votes
0answers
85 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 ...
4
votes
2answers
203 views

Calculate $\pi$ using Monte Carlo methods

I know that we can have an estimate of $\pi$ using Monte Carlo methods. I know that we make a huge loop and each time we take randomly two numbers in the range [0,1] and calculate the number of ...
2
votes
2answers
56 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. ...
0
votes
0answers
38 views

Construct certain univariate functions over bounded interval having given set of moments [migrated]

We have a class of probability distributions (parameterized by $\alpha =\frac{1}{2},1,\frac{3}{2},2,\ldots$) over the interval $[-2^{-12} \cdot 3^{-3},2^{-16}]$ having as their $n$-th moments ...
57
votes
9answers
3k views

Updating Wagon's FindAllCrossings2D[] function

Stan Wagon's Mathematica in Action (second edition; I haven't read the third edition and I'm hoping to eventually see it), demonstrates a nifty function called ...
10
votes
1answer
167 views
412
votes
15answers
93k 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 ...
6
votes
2answers
255 views

Generating cylindrical geometry via extruding a section

Toady I want to build geometry as shown below: I know the Mathematica owns the built-in like Cylinder[], Sphere[] and so on, ...
-3
votes
0answers
21 views

Table of an equation roots [duplicate]

I would like to form a table of all roots of an equation (say sin(x)=0) lying inside a certain interval. What kind of Mathematica expression shall I use?
6
votes
2answers
305 views

What does empty {} mean in Module? [duplicate]

I have a question. I would like to know what an empty list ({}) means when used in Module[] as the code below shows? Why has a ...
7
votes
3answers
225 views

Simulation with two random walkers on a lattice with periodic boundaries

I am having some difficulties implementing a Monte Carlo simulation in order to compare the results to analytical calculations. The following code simulates a case with one random walker and a ...
9
votes
1answer
185 views

Fast implementation of Metropolis-Hastings update with multiple sets

This is an optimisation question rather than something I am unable to do. I have a naive, primitive working version of the code (I submit it below) but I am trying to make it work faster. I am asking ...
15
votes
9answers
617 views

Any built-in function to generate successive sublists from a list?

Given lst = {a, b, c, d} I'd like to generate {{a}, {a, b}, {a, b, c}, {a, b, c, d}} but using built-in functions only, ...
2
votes
0answers
48 views

A question regarding shadowed symbols

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

Is there a linter to help write good Mathematica code?

I don't do much real programming, but I've recently been turned on to Atom, which has linter plugins for over 50 languages to make coding easier (most drawing on pre-existing lint-like programs). In ...
0
votes
0answers
62 views

Why Mathematica rather than matlab? [duplicate]

I am not sure I can ask question here, but in my lab, there are two people using Matlab, and two people including me using MMA. They told me that Matlab can do Matrix calculation much faster than ...
9
votes
1answer
115 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 ...
0
votes
1answer
61 views

How to use Do and NestList combine?

g[x_]:=((i - 1/i)*x + (1/i)*(x/2))/2; I want to find the following list NumberForm[NestList[g, 0.8, 20], 16]; But don't ...
14
votes
3answers
901 views

Mathematica usage (success stories) for financial back-ends

I've been working for about 5 years in Java, developing financial back-offices (web-services, business logic, report generation etc.). I think Mathematica is very suitable for such calculations and ...
8
votes
1answer
295 views

Show how Mathematica defines a function

Is there a way to show how Mathematica defines a function, such as In: Something[Sqrt], Out: Sqrt[x] -> x^(1/2) As far as I understand it the command ...
4
votes
1answer
459 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 ...
2
votes
0answers
89 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 ...
4
votes
1answer
123 views

Loose binding of &

This code returns 2, as expected. ...
6
votes
2answers
105 views

How automatically perform an action each time a function is invoked?

Please, consider these functions: f[x_] := Module[{}, Return[x + 1]; ]; g[x_] := Module[{}, Return[x - 1]; ]; I want evaluate ...
10
votes
2answers
196 views

How to parse a clojure expression?

Clojure is a lisp-like language that runs on JVM and in Javascript. I just started learning it and I'm building a simple parser with Mathematica to understand and visualize it. Like other lisps every ...
87
votes
8answers
5k views

General strategies to write big code in Mathematica?

I think after six months of exposure to Mathematica and the Wolfram Language I am fairly OK with writing short codes and snippets. However, what are some general strategies to use in order to write ...
8
votes
2answers
2k views

How can I implement object oriented programming in Mathematica?

Roman Maeder's object oriented programming package is nice, but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.
0
votes
0answers
38 views

Construction of palettes [duplicate]

Is there a good documentation to help to construct my own palettes. The problem is to use a palette as an assistant to remember some long command line with many place holder and not to be obliged to ...
0
votes
1answer
65 views

Calculating the angle between the line joining two points and the x-axis [closed]

I need to calculate the angle between two points, the returned result should between $0$ to $2π$ and getAngle[point1, point2]==getAngle[point2, point1]. I have ...
139
votes
1answer
25k views

Mathematica Minecraft

Some time ago I asked myself: with all these great graphics and interactive capabilities of Mathematica, what kinds of 3D games can be implemented in it? And the answer which came to mind is ...
28
votes
3answers
936 views

Is using undocumented functionality a Bad Idea™?

Mathematica has a lot of very useful undocumented features. For example a hash table, a built-in list of compilable functions, additional options to CurrentValue, ...
2
votes
2answers
89 views

How to create some macros

I have two question in one. In the following code, I want to manipulate a plot in a centered cell. It is fastiduous to try always to remember the way to act. Could I define some macro as in a standard ...
0
votes
0answers
52 views

Function that outputs the dual of the formula

The exercise is simple: define a function that gives the dual of the formula. While I have experience in mathematics and logic, I do not have real experience in programming. Logic is propositional ...
2
votes
1answer
48 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 ...
72
votes
2answers
15k views

Is there an open source implementation of Mathematica-the-language?

I've seen questions before such as "What is the best open-source equivalent for Mathematica?", but that specific question (and that line of inquiry in general) cares more about the computer algebra ...
4
votes
0answers
125 views

Learning the Wolfram Language ‘from the bottom up’ [duplicate]

I'm a armchair programming-language theorist, and I know … quite a few programming languages, some to extensive depths. (Hell, I've built more than my fair share.) Most of the information I've found ...
3
votes
2answers
104 views

Matrix Diagonalization programming

I have a very simple problem, with me misunderstanding the use of Modules and Functions in general, in mathematica. I have a function of which I want to input a Matrix, and in the function I want ...
2
votes
1answer
119 views

How does exactly Check work?

Please, consider the following code : ...
0
votes
0answers
25 views

Discretization of a region for NDSolve using [duplicate]

I would like to mesh the region below in order to use it for a calculation by means of NDSolve. Could anyone help me to discretize this region for NDSolve using. Thank you very much. ...
0
votes
3answers
207 views

Avoid creation of OwnValues when inserting transformation rules into Experimental`OptimizeExpression

I have a large list of transformation rules that I want to simplify. I find Experimental`OptimizeExpression works as it gets me the answers. My question is: I ...
2
votes
1answer
67 views

Code optimizations with functions inside Module

I wrote a small code by using functions inside Module: ...
21
votes
0answers
348 views

Can code optimize code?

Are there functions, programs or packages that deal with optimizing mathematica code i.e. re-writing ineffecive or convoluted code. -This question has haunted me since I joined SE. The background for ...