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

Dynamic programming: Fibonacci generator

I have the following piece of code: ...
1
vote
1answer
43 views

How to define a number of infix operators with predefined relative precedences

Reading a number of questions about infix operator notations I want to ask if somebody could reimplement the problem below in a simpler way, say modifying ...
1
vote
1answer
70 views

Program to demonstrate rotation according to quaternion values

On the Wolfram|Alpha website, I type quaternion(1,1,1,1) into the search field. Wolfram|Alpha shows a 3D transformation of the quaternion values representing the orientation of an object. I have 9 ...
0
votes
0answers
57 views

Mathematica requirements management [on hold]

Is there a way to use Mathematica notebook as a requirements document as it's possible in IBM DOORS ? ...
1
vote
2answers
122 views

intermediate steps of a Mathematica operation

How to make a multiplication or division, the intermediate steps. The numbers can be rational - decimals? it seems the OP merely wants Mathematica to show him how to multiply and divide the way ...
2
votes
1answer
69 views

Clean & efficient bounding box non-intersection test

I would like a quick test to tell me that segments $ab$ and $cd$ cannot intersect in the plane. If the maximum $x$-coordinate of $a$ and $b$ is less than the minimum $x$-coordinate of $c$ and $d$, ...
5
votes
1answer
93 views

Efficient upsampling of multidimensional array

I would like to efficiently upsample a multidimensional array. It's a 5000*5 matrix where each element is a submatrix 12*12 and it is that 12*12 matrix I want upsampled (to 24*24). The upsampling ...
1
vote
2answers
95 views

How to write a loop

I try to create a table which will describe traffic paths at a crossroads. Instead of using copy-paste repeatedly, I would like to write a loop. For example: ...
2
votes
0answers
62 views

What am I missing in this highly oscillatory integral?

I want to numerically integrate this equation (in python without calling Mathematica): $\int_0^\infty {\rm d}k f(k) J_v(r k) J_n(s k)$ where $f(k)$ is a non-smooth function, $J_v$ are the Bessel ...
3
votes
2answers
72 views

How to define UpValues about the derivative of NBSpline when the length of knots is unknown?

Description In the book “Programming in Mathematica” 3rd by Roman.E.Maeder, the author gives a topic about A new Mathematical Function in section 8.4. For instance, for the following formula: ...
4
votes
1answer
53 views

How to add UpValues to a symbol to make a expression expanded normally?

Here is a implementaion of Bernstein basis function. I add the following UpValues to ...
10
votes
2answers
236 views

Checking the argument of user-defined function with side-effect method

Today, I answered a question of mine that asked two month ago. Please see here Now I would like to add the argument checking in this function. Then I used a method that Mr.Wizard answered ...
3
votes
1answer
96 views

A pre-parsed HoldForm

HoldForm holds an expression's parsed form not its actual "inputted form" e.g. ...
5
votes
2answers
202 views

How do I “evaluate in place” programmatically? Need to evaluate Defer[] result in non-interactive setting

I need to evaluate the result returned from an external package, which contains Defer in it, but do this in a script without user interaction. I am not able to ...
3
votes
1answer
129 views

How can you get the area of a region from an image?

Suppose we have a square of side "L" m, How can I calculate the hatched area, if the corners of the square are centers of circles. It can be generalized to any region? edit: This is the result I ...
12
votes
1answer
208 views

How to add AccuracyGoal and PrecisionGoal options in a numerical function?

There are many built-in functions that contain AccuracyGoal, PrecisionGoal and ...
-2
votes
1answer
155 views

How to get the coordinates of points within an image?

How can I get the coordinates of an image, and make Mathematica draw the image from the coordinates found? I am interested in just the outlines of the regions. Here is an example of the kinds of ...
7
votes
1answer
101 views

How to select a submatrix containing similar elements from a matrix? [closed]

( This question is related but does not ( fully ) answer my questions. - Finding the position of similar elements in a matrix ) I have not written code yet, I am in the design phase of code for the ...
6
votes
1answer
68 views

Can Query operators be naturally cast as either Ascending or Descending?

One of the challenges of coming to grips with Query's on Association's and Datasets is ...
0
votes
0answers
38 views

Programming of basin of attraction for with memory iterative methods

I have made the programming for without memory method and i got the basin of attraction but i could not make it for with memory iterative method. I am sending you the programming of with memory ...
0
votes
1answer
48 views

Write a function pollard[n, B] that tries to factor an integer n, using Pollard's p − 1 method with at most B iterations [closed]

This is what I got but it seems it's not working. When I test it, it just goes through and nothing gets returned. Is there something I'm missing? ...
6
votes
1answer
118 views

Is there a practical way to define a default value for missing keys in an Association?

It can be very useful to define background or default value for an object that can be incremented or otherwise modified. A simple (and for me, common) use is a counter: ...
2
votes
1answer
83 views

Implicit derivatives in one line. How do I do it?

I have this little script to derive implicitly $PrePrint = # /. {D[y_, x_, NonConstants -> {y_}] :> y'[x]} &; Example: ...
0
votes
1answer
73 views
3
votes
1answer
100 views

Using function to transform a list

I have a list like that: {{Integer,String},....}, integer ranges from 1 to 900 and String "I" to "IV". And I need to find which pair of {x,y} each sublist is related to, so i can get a new list like ...
1
vote
2answers
83 views

Ask about the variable and constants in partial derivative in a loop

EDITED I have a function in a list like : func={2(x^2)+x*y+3(y^2)}; I want to have a UI that ask me which parameter (x or y) is a variable in a ...
2
votes
2answers
64 views

Sum broken into two sub-sums according to a condition on the terms

I have a sum in mind, but I want to break it into two sums and get a separate total for each of the two. All cases where the square root is accurate, i.e., exact All cases where the square root is ...
4
votes
3answers
130 views

How to get multiplication of the elements of a specific list/Matrix

Assume there is a list: List1={a,b,c,d}; Then I want to get these calculation: ...
4
votes
1answer
131 views

How to check the option value?

Given that I have a function func as follow: To check the value of options, I using the step-by-step method If[] ...
4
votes
1answer
65 views

How to define an expression which is differently evaluated in calculations and printed

Let's say, we have a list: values = {1.2, 0.04, 0.9}; Is it possible to replace 0.04 by some expression, which displays as ...
0
votes
0answers
67 views

How to spend any image in “2D” or “3D” to an image mesh, ie as a wire frame in black and white?

How to spend any image in "2D" or "3D" to an image mesh, ie as a wire frame in black and white? For example some of these: edit :example output
9
votes
1answer
104 views

How to implement a custom random process object?

I want to implement a custom random process thing1 to pass to RandomFunction. The process I have in mind is conceptually extremely simple: two alternating Poisson ...
1
vote
0answers
58 views

Should I Remove the initial symbols of Module?

Often we use Module to construct complicate function. Consider that Module create new vars every time we run the function, should I remove the initial values at the end of Module-function?Or should I ...
0
votes
0answers
79 views

Fun/Frustration With Coding Coding Theory

I have code following from this post: http://math.stackexchange.com/questions/1317722/fun-frustration-with-coding-coding-theory I think I am done with the code, but now I face a single problem. The ...
2
votes
1answer
150 views

How to determine whether an expression can act as a “good” function?

It's not easy to see whether an expression can act as a "good" function. A good function refers to an operater that transforms symbolic entities like 1+x^2 or ...
1
vote
0answers
63 views

Arrange order of evaluations (please help these unit vectors)

I need help to control order of evaluations. Here I try to use Manipulate to control n unit vectors. Their positions are initially random but head left. The 2 operations are 1) translation: moving ...
5
votes
0answers
43 views

How is CellContext->CellGroup supposed to work?

After reading the documentation on the subject, I still cannot get CellContext->CellGroup to work. Here's a simple example. (Unfortunately, I cannot easily ...
4
votes
1answer
140 views

Can I do constraint programming in Mathematica? [closed]

I would like to know if there is a way to do constraint programming in Mathematica? I think there are no built-in functions, but maybe some of you know some additional packages addressed to the ...
0
votes
1answer
80 views

Functions behaving weirdly

The following code f[k_, n_] := Sum[2*(1 + Sum[f[k - j, n - m - j], {j, 1, k - 1}]), {m, 1, n - k + 1}] f[4, 7] f[4, n] gives the output: ...
9
votes
0answers
95 views

Confused by the opts : OptionsPattern[ ] pattern

I'm trying to make sense of the syntax in the clause opts:OptionsPattern[], as found in this standard "rule-based" (pseudo-)function definition pattern: ...
1
vote
1answer
44 views

Why this isn't a valid argument? [duplicate]

I am having truble understanding why F1 produces an error, since both time and velocity are the same kind of object: ...
0
votes
1answer
55 views

Mathematica Code Involving For Loops Not Completing All Iterations [closed]

First of all, thank you for taking the time to read this. I'm working on a portion of code related to the genetic algorithm that is not producing the expected results. What the code is supposed to do ...
3
votes
1answer
88 views

Is it possible to update Dynamic objects even when they are off screen?

I am using Dynamic and DynamicModule to display graphics/statistics generated from a long-running set of parallel tasks. The ...
13
votes
2answers
345 views

How to programmatically ask if Mathematica is running as an Administrator

To avoid execution problems in a program I need to know if Mathematica has been "Run as administrator". What would be the cleanest way to programmatically getting this information?
5
votes
0answers
256 views

How to create protected single-file stand-alone CDF applications

After hours of work trying to understand how much protection I can get when creating stand-alone CDF applications I have come to the decision that the best protection to my work is provided by ...
0
votes
1answer
59 views

How to count column occurrences in a matrix?

I have a matrix of data, and I want to count the number of columns that match, and have some way to organize them by frequency. But I don't want to count the entire column, but consider the matrix ...
5
votes
1answer
120 views

Reap, Sow with Parallelize: bad performance, why?

I have a question about the performance of Reap and Sow with Parallelize. I am aware of the following questions How to collect result continuously (interruptible calculation) when running parallel ...
1
vote
1answer
50 views

Emulating Case Pattern replacement

As most regular users, I have developed utility functions complementing the Wolfram language for frequent tasks. In particular, I have variations on Cases (see ...
1
vote
1answer
145 views

Transform linear system into a matrix form

I have a system of linear equations in variables $A_n$ of form: $$ \sum _{k=-K}^K h_k A_{n-k} J_{n-k}\left(\frac{(1-i) \text{$\eta $Sqrt}(n-k)}{\sqrt{2}}\right)+A_n\left(\frac{(1-i) \eta ...
2
votes
3answers
110 views

Problem with the output of a function I program

(This is the function that I programmed) Zm2[Z_, nk_] := (zm2 = 0; For[i = 0, i < Length[Z], i++, zm2 += nk[[i]] *Z[[i]]* Z[[i]];]; Return[zm2];); ...