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
45 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. ...
0
votes
0answers
44 views

A question about structure of if-else [on hold]

I have coded this program in Mathematica but I am not sure to make correct structure of if-else. Is anyone able to present guidelines in a way that error of program was not met? ...
5
votes
1answer
343 views

How to download pictures from webpage automatically?

Today, I read a good web page about love which owns many beautiful pictures. It is fussy for me to download every picture hand-by-hand, so I'd like to use Mathematica to do this case automatically. I ...
5
votes
1answer
258 views

Help with Permutations

I am currently trying to generate a list of permutations of length 2 of elements of a list of strings. For example: ...
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 ...
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 ...
73
votes
3answers
3k views

What is a Mathematica packed array?

A simple sounding question with a few sub questions: What is the difference between unpacked vs packed array? Are packed arrays more space efficent, how much so? Are packed arrays more time ...
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 ...
69
votes
5answers
5k views

What does the construct f[x_] := f[x] = … mean?

This question mentions "x := x = trickery". What does defining a function as f[x_] := f[x] = ... do and what is it good for?
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. ...
77
votes
3answers
3k views

Flatten command: matrix as second argument

One thing I could never wrap my head around is how Flatten works when provided with a matrix as the second argument, and the Mathematica help isn't particularly ...
9
votes
3answers
381 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}...
7
votes
2answers
213 views

Weird behavior of conditions when using OptionsPattern and OptionValue

I'm trying to define a function that is evaluated differently depending on its options. This code ...
1
vote
1answer
122 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 ...
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 ...
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=\...
2
votes
0answers
38 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 ...
4
votes
1answer
541 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 <...
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
242 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 ...
59
votes
3answers
3k views

Once more on object orientation in Mathematica: does it have to be so hard?

Recently I came across a set of problems which would be solved most easily within an object-oriented approach. I first attempted to solve them by other means, but found the complexity of the code ...
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 ...
323
votes
31answers
55k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
77
votes
2answers
16k 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 ...
34
votes
4answers
5k views

Fastest way to calculate matrix of pairwise distances

It is a very common problem that given a distance function $d(p_1,p_2)$ and a set of points pts, we need to construct a matrix ...
4
votes
1answer
503 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}...
9
votes
2answers
163 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
2answers
78 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
616 views

Is the renaming mechanism of `With` flawed?

I'm confused about the renaming mechanism of With: ...
2
votes
1answer
108 views

Speeding iterative computation

I want to get the following iterative sequence ...
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
232 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 ...
14
votes
2answers
379 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. ...
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 ...
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 ...
22
votes
2answers
1k views

Schedule programing problem with integer linear programming

I know how to model this question on paper, but I don't know how doing it in Mathematica. Imagine , there is a university student who want to choose courses for this semester and he got the ...
427
votes
16answers
97k 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
5k views

Creating custom functions with multiple arguments

I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual ...
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 ...
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. ...
4
votes
1answer
193 views

How to check and reset the boolean value of many options one times?

I defined a function which owns many options. In addtion, these options have a common characteristic. Namely, only accepting boolean value True or ...
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 ...
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 ...
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 ...
-6
votes
2answers
74 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 ...