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

19
votes
5answers
4k views

How do I increase the readability of this code?

Below is some code I am working on; being a beginner. How can I increase the readability of the part behind Manipulate? I can't read my own code anymore, because it is simply too long and unordered. ...
11
votes
3answers
518 views

How to debug the C code for LibraryLink?

Recently, I use the C to rewrite a Mathematica function NonzeroBasis[], please see here for fully descriptions. Here, ...
9
votes
1answer
182 views

Random walk on a Sierpinski gasket

I am trying to simulate a random walk on a Sierpinski gasket. The best strategy i could come up with is to use Nearest point function to determine the next possible step of my walker. But this creates ...
7
votes
1answer
87 views

How does a construct like `i : func[arg_] := i = an expression using arg` work?

Occasionally I run into a Pattern that looks like i:func[arg_]:=i= an expression using arg I have two questions on this: Can ...
2
votes
0answers
184 views

How to perform convolutions on this complicated pdf?

I am working on problems related to the pdf q[y] where $y=Log[f]$ and f[x] is itself a pdf in x. But I can't figure out how to ...
0
votes
1answer
45 views

System of two implicit equations subject to (complicated) constraints. Infinite recursion?

I am trying to solve a system of two equations subject to 3 constraints which are rather implicit. With my (naive) code I obtain a list of recursions that Mathematica keeps on writing until I abort ...
0
votes
0answers
30 views

Produce a function of parameters from a solution to parametric equation [on hold]

I am trying to produce a very simple result, namely given some function $f(x,a)=0$ find a solution $x(a)$ and let it be a function that I later plot depending on $a$. However Mathematica does not ...
2
votes
1answer
99 views

Speeding iterative computation

I want to get the following iterative sequence ...
-5
votes
0answers
41 views

Iterator Problems [closed]

So for our class our teacher gave us this code to run for 100 trials of bobcat simulations. He just dropped it in our lap without explaining at all what he was doing, I really need this code to run ...
-2
votes
0answers
15 views

Question regarding Majoring in Maths etc [migrated]

I was wondering. Is it possible for someone to major in Maths as in do their masters in Maths once they've earned their degree in Computer Science?
1
vote
1answer
117 views

How to connect some separate components with shortest total length line

Maybe this post too hard.So I try to make a simple version to research. Simulating a simple graph than that post. ...
0
votes
0answers
14 views

Find a conformal map from disc onto trapezoidal plate [migrated]

how can conformal mapping a disk into a trapezoidal plate with defining favorite central point?
0
votes
4answers
92 views

Saving the values calculated in a list or a table

I cannot realise if it is a duplicate question. Sorry; if it is. This ...
1
vote
1answer
68 views

generating random algebraic matrix using elementary operations

I generate several algebraic matrices of 12x12 where each element is a combination no repeat of the variables x, y, z and operations +, -, *, /, power, establishment (square root), any of them or any ...
2
votes
0answers
47 views

Where can I find tutorials or examples about Internal` packages and other useful packages? [duplicate]

As an intermediate level Mathematica user, I consider one of the greatest barrier on my way to a higher level of programming is the lack of knowledge about extra packages like Internal` package or ...
15
votes
2answers
260 views

How to check the validity of an option value

I have a user-defined function, func, which takes the following form: func[arg1, arg2, options] Here is the actual code ...
1
vote
0answers
35 views

How Defer[1+Evaluate[1+1] work?

I want to generate some expressions. The expression is not evaluated expect some parts will evaluate first. A simple example is Defer[1+1+1] and in this expression ...
0
votes
1answer
95 views

How to overload the operator “*” as KroneckerProduct [closed]

Can I use the expression below a * b * c * d for short to instead KroneckerProduct[a,b,c,d] automatically when a,b,c,d are ...
-6
votes
2answers
73 views

Develop a loop with two counters [closed]

Description: I am trying to develop a function that would take two arguments n and m and would run another function multiple ...
1
vote
3answers
124 views

Basic Programming in Mathematica - How to build a loop [closed]

I want to build a loop with the following rules: I have a list a={5,7,8,9,5,6,8,6,7,8}. I want to print the mean of the first two ...
11
votes
5answers
2k views

Beautiful dance of the Earth and Venus around the sun

I have seen very nice dynamic graphics created by users of Ma. I would like to get help whether the following graphics can be created using Ma. I was not able to create the dynamic picture here. ...
0
votes
1answer
37 views

Looping over a function with several parameters

Folks I am a beginner in Mathematica and have a simple question regarding loops: Here's the problem, I have a dataset of with four columns and I need to loop over each row. So the matrix in which my ...
0
votes
1answer
70 views

A problem with the output

i using mathmatica to study lagrange Interpolating,however i couldn't make the output as I want I wrote both who is the output and how i needed ...
7
votes
1answer
108 views

Generalizing LongestCommonSequence to 3 or more arguments?

The function LongestCommonSequence finds a longest common subsequence between 2 lists. Apparently, this built-in function does not accept more than 2 arguments. How ...
1
vote
1answer
44 views

How to apply hermite InterpolatingPolynomial?

I found that to do hermite InterpolatingPolynomial I need to write: InterpolatingPolynomial[{{{1}, 2, 3}, {{2}, 6, 7, 8}}, x] however,i need to apply it on a ...
14
votes
2answers
362 views

Tips to move from functional programming to GUI-based applications

Even though this forum has some questions related to Mathematica programming tips I think that we still don't have specific help for those who want to learn to efficiently create GUIs in Mathematica. ...
2
votes
1answer
149 views

How to linearize an expression involving derivatives?

I want to linearize the expression involving function $y(x,t)$ $$[y^3(y_x-y_{xxx})]_x$$ by assuming $y(x,t)=y_0(t)+y\prime(x,t)$, where $y\prime(x,t)$ is a small variation. In other words, I will ...
1
vote
1answer
127 views

Speed Up Sampling of Perimeter of Polygon

I have a polygon whose vertices (points) are defined by some image coordinates that I have manually selected. The polygon is used to create a mask for a region of interest in a microscopy image. ...
0
votes
1answer
48 views

Experiment to test Infinite monkey theorem [closed]

I need to apply this experiment: For all numbers between [0,128] let be t {set total=0 repeat this experiment n times {set start=0 choose random number [0,255] lets be R While(R!=t) {...
5
votes
0answers
157 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 time-...
4
votes
1answer
56 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 ...
3
votes
1answer
71 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
99 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
251 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
58 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
174 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, ...
6
votes
2answers
314 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
239 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
50 views

A question regarding shadowed symbols

The more I study, the less I understand. This is the HelloWorld package: ...
9
votes
0answers
119 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
63 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 MMA....
9
votes
1answer
198 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
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
301 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
98 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
106 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 ...