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

Key mapping an association applied to a distribution

I am attempting to import data from a database, group it according to a given identification parameter, get it's statistically relevant information, and then export it as a JSON object for ...
0
votes
0answers
5 views

Formula for the area of a trapezoid when only points are known [migrated]

I am making a personal website and the main menu consists of scaled trapezoids. I can find the coordinates of the points for each trapezoid, and I know the parallel edges. I need a formula that can be ...
0
votes
0answers
6 views

Please help with this C calculation [migrated]

Why I can not get a result of 2 while giving input of 2.2 as a float. With logic that 2.2 gets converted to 220, than when it goes through the first for loop I am going to get a remainder of 20(which ...
10
votes
1answer
2k views

Programming the fiver game

Obviously, even if I ask a lot of question I am, obviously, still a dummy!!!! I want to program the fiver game. It's a very simple game played solitary on a $5 \times 5$ the rule is elementary : if ...
-4
votes
0answers
38 views

How to add new formula in existing formula in certain time?

Good day, May anyone help me to give an idea to edit the coding For as below towards my problems. β1 = 0; β3 = 0; β2 = Pi/2; For[t = 0, t < 30, t++, A = {{E^(Iβ1 + Iβ3)Cos[tβ2], E^(Iβ1 - I\β3)...
1
vote
1answer
121 views

Which data tabulation concept is best suited for discrete dynamic programming problems (e.g. for optimum series of account withdrawals)?

A bank account has starting balance, which shall be completely withdrawn in n steps, such that the sum of benefits of withdrawals is maximum. Remaining balance yield interest between steps such that ...
3
votes
0answers
63 views

Finding all Minimal Cut Sets for Site Percolation?

I want to disconnect the left side from the right side. The minimal cut set $C$ is a set of vertices by which the lattice $\mathbb L-C$ becomes disconnected. Consider the example below $\mathbb L=\...
6
votes
2answers
159 views

Finding all minimal paths in site percolation?

I want to find all minimal site percolation paths from the left side to the right side, small demo grid. A related question is here on finding bond percolation paths instead of minimal site ...
2
votes
0answers
37 views

Why FinancialDerivative fails for the Spread case?

According to the documentation center for FinancialDerivative in version 10.4, when there are multi assets, we still may use ...
0
votes
1answer
51 views

Constructing a root solution diagram (not to tell bifurcation)

Suppose I have a third order equation depending of one parameter say .5 4 x (1 - x) (x - .5) - .5 m x^2 where m the parameter. Obviously there are 3 roots for ...
22
votes
0answers
241 views

Which Object-oriented paradigm approach to use in Mathematica?

Which Object-Oriented Paradigm (OOP) approach to use in Mathematica for: general implementation, or a particular project? There are a lot of related questions and answers in MSE on doing OOP that ...
0
votes
2answers
76 views

Finding and plotting a parametric solution to a complicated equation (transcendental, log-polynomial)

I am trying (desperately) to find a way to solve a transcendental equation whose solution $x$ depends on non-numerical parameters $a$ and $b$. And then to produce a ...
24
votes
1answer
614 views

Is the renaming mechanism of `With` flawed?

I'm confused about the renaming mechanism of With: ...
21
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
569 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
231 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 ...
8
votes
1answer
102 views

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

Occasionally I run into a Pattern that looks like i:func[arg_]:=i= an expression using arg I have two questions on this: Can ...
4
votes
1answer
502 views

How to perform convolutions on this complicated pdf?

For a known pdf f[x], I need to calculate integrals over the probability density of the sum of Log[f[x]] over independent samples: $$Q[t,n]\equiv P(\sum_{i=1}^{n}...
2
votes
1answer
108 views

Speeding iterative computation

I want to get the following iterative sequence ...
1
vote
1answer
125 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. ...
1
vote
4answers
93 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
69 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
49 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
3answers
301 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
36 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
97 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
125 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
39 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
115 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
378 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
135 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) {...
4
votes
1answer
58 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
100 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
256 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
176 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
323 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
243 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
124 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
64 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
202 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 ...