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
1answer
62 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
305 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 ...
1
vote
0answers
109 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
124 views

Loose binding of &

This code returns 2, as expected. ...
6
votes
2answers
109 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
84 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 ...
3
votes
2answers
100 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
234 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
53 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
51 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
126 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
110 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
123 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. Needs["NDSolve<...
2
votes
1answer
71 views

Code optimizations with functions inside Module

I wrote a small code by using functions inside Module: ...
93
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
55 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
105 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
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
29 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
106 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
136 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
2answers
162 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
85 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
73 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
177 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 "de"...
3
votes
1answer
156 views

Error propagation code

I have a code for error propagation :- ...
2
votes
1answer
67 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
76 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
109 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
278 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
81 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
82 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
156 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
50 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
380 views

Implementation of tensor product formula

For the Bézier surface, which owns the following matrix definition: $$\begin{align*} \mathbf S(u,v)&=\sum_{i=0}^m \sum_{j=0}^n \mathbf P_{i,j} B_{m,i}(u) B_{n,j}(v)\\ &=\small \begin{pmatrix}...
2
votes
1answer
104 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
33 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
220 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
88 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
104 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
131 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
35 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
135 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
849 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: ...