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

4
votes
0answers
69 views

Dealing with a nonlinear PDE using FEM

As far as I can see in the Mathematica documentation center, there are no built-in ways for solving nonlinear PDEs using Finite Element Method (FEM). I am dealing with a simple nonlinear ...
0
votes
0answers
27 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 ...
-2
votes
0answers
73 views

unordered lists with maximum dispersion [closed]

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 ...
-1
votes
1answer
50 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
29 views

how to know two aircraft getting far away each other? [closed]

Dataset: my algorithm is: calculate velocity vector each aircraft ...
4
votes
1answer
52 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
99 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
206 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 ...
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 ...
2
votes
2answers
57 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. ...
10
votes
1answer
168 views

Core functions or operations that every aspiring Mathematica programmer should know? [duplicate]

I am aware that there are common yet very powerful operations like Map, Thread, Apply, ...
-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
309 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
226 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 ...
2
votes
0answers
49 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
189 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 ...
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 ...
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 ...
2
votes
0answers
90 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 ...
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 ...
2
votes
2answers
91 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 ...
10
votes
2answers
204 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 ...
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 ...
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. ...
2
votes
1answer
67 views

Code optimizations with functions inside Module

I wrote a small code by using functions inside Module: ...
88
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 ...
0
votes
1answer
54 views

FullForm and the attribute HoldAll

I have noticed that TrueQ @ (And @@ {False, True, True, True}) gives False and, on the contrary, ...
1
vote
1answer
104 views

Module that prints first m positive odd integers and returns the square root of the sum of them

I am working on this problem and I feel like I've come so close. Write a module that takes as input a positive integer m, prints the first m positive odd numbers and returns the square root of the ...
1
vote
0answers
89 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
27 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
101 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
131 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
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 ...
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
46 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
163 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
136 views

Error propagation code

I have a code for error propagation :- ...