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

Can I define an axiomatic (Boolean algebra) system and prove theorems using Mathematica?

The general question is Can I define an axiomatic system and prove theorems using Mathematica? The more concrete one is about Boolean algebra. I consider this axiomatic Boolean algebra system ...
1
vote
1answer
66 views

RandomVariate form a Specific Distribution with Restrictions

There are a lot of questions about generating random numbers form both uni-variate and bi-variate distributions. Mathematica has a lot of built in distributions for that purpose. However, I could not ...
1
vote
1answer
239 views

Millionaire quiz in mathematica

so here's the deal. I'm trying to write a millionare quiz in Mathematica. Now, this has been already done in other coding languages, specifically I've seen it done in C here: ...
1
vote
3answers
66 views

GatherBy based on condition imposed on index variable

Excuse me. This might be user specific question but I need your help. I have an indexed data, where positive integers are used for indexing data. I am trying to group data putting condition on index ...
3
votes
1answer
223 views

A bug fix to mathematica 10.0.1.0

There is a bug in the Wolfram Symbolic Transfer Protocol Development in C (Windows). I described it in the next answer by myself, from which I summarize: One cannot successfully compile the ...
0
votes
0answers
75 views

I cannot pass any script to `math`, in a command line

I want to run some lines of Mathematica code by a command-line call for math. As a test, I save just the following code in a file ...
4
votes
3answers
136 views

What is shorthand way of Reap list that may be empty because of zero Sow

Sometimes because of conditionals, you cannot guarantee that Sow will be called at least once. Reap[Sow[1]][[2,1]] results in ...
3
votes
0answers
63 views

How to assemble and disassemble a function into steps

I've watched many programmers (both novice and expert) write functions in Mathematica and have observed a common behavioral pattern. This pattern has many elements that would be automated and thus ...
1
vote
0answers
36 views

How to package a function for export?

I often post code for functions on Stack-Exchange, and then later find that they are unexecutable - that people can't use them because I mistakenly omitted some private functions or values that are ...
8
votes
2answers
302 views

Get rational and irrational parts

Consider an expression of the form $a + b \sqrt{2}$, where $a,b \in \mathbb{Q}$. How can I extract $b$ (or equivalently $a$) from this expression?
18
votes
0answers
247 views

How to perform document classification (i.e. extracting topics from text)?

I need to build a multi-label text classifier. There are a bunch of techniques for doing this, and it's called automatic document classification. I'm trying to use the EM technique (expectation ...
2
votes
1answer
94 views

What is the correct way to break a long expression across multiple lines?

This is probably a very simple question and I am probably not using the right keywords in my search; but I have a long expression that I would like to break across multiple lines to improve ...
0
votes
1answer
49 views

How can I assign a vector unknown function to solve the ODE system?

I noted that using non-scalar variables is convenient when a system of differential equations is governed by a process that may be difficult to express symbolically. Taking a example from the tutorial ...
0
votes
1answer
40 views

Elegant ways of solving this file batching task

There are a batch of data files in a folder (dir = "D:\\Documents\\datadir"), each of which consists of a list of data items, one per line. Each data item is a pair ...
0
votes
0answers
45 views

Question about treillis structures

I have difficulties finding a command to plot multiple segments connected in nodes in Mathematica. Ultimately, my goal is to modelise something like this by entering nodes coordinates. Also, the ...
-1
votes
1answer
35 views

Finding the number that gives remainder equal to 0 [closed]

Hi i'm not english so I'll try to explain this as good as I can . If we have for example 250 : 5 = 50 , remainder 0 let's say I don't know the number i'm going to divide (because it is generated ...
2
votes
0answers
71 views

Mod[1.2, 0.2] is not equal to zero

I'm new to mathematica but this doesn't seem to make any sence In[1]:=Mod[1.2, 0.2] Out[1]=0.2 Why is it not zero? Edit: This is what I wanted to do: ...
0
votes
0answers
80 views

Solving for a Transfer Matrix

I am currently working on a program that will solve a transfer matrix and extract several elements. Particularly, the transfer matrix is characterized by four elements in a ...
4
votes
0answers
77 views

Implement a piecewise function elegantly and efficiently

Given that $$ g(x)= \begin{cases} max(x_{min},x-m) & 0.5x \leq max(x_{min},x-m) \\ 0.5x & max(x_{min},x-m)<0.5x<min(1,x+m) \\ min(1,x+m) & min(1,x+m)\leq 0.5x \end{cases}$$ ...
1
vote
2answers
66 views

How do you apply an algorithm individually to an array with many graphs

I have and array with many graphs to which I want to apply an algorithm (below) to each graph in an array that contains all my graphs. ...
4
votes
1answer
110 views

How to use RunProcess to import external function?

I have a functions written in an external language called GO. How can I quickly load them into the kernel for use as Mathematica functions? The two ways I've tried are with MathLink and LibraryLink ...
5
votes
1answer
88 views

How to implement kvo in Mathematica 10? [duplicate]

Key value coding and observing is something that other languages do well, like objective-c for instance. What's the best way to achieve something similar in Mathematica (if at all possible)? That is, ...
1
vote
2answers
44 views

How to get the outermost command evaluated first?

I have an expression like ToString[Stuff[...]]. I plan on having the Stuff[...] be manipulated as a string according to the output of other parts of the program. The problem is that Mathematica tries ...
1
vote
1answer
110 views

For loops in Mathematica [duplicate]

I'm actually the first time using loops in Mathematica. For example, I have: For[i = 1, i <= n, i++, For[j = 1, j <= n, j++, ....] How it is possible now ...
0
votes
0answers
44 views

Find the maximum/ minimum of the function f(x,y,z) = x+2y+3z on the curve of intersection of the plane x-y+z = 1 and the cylinder x^2+y^2 = 1 [duplicate]

How to write the program for: Find the maximum/ minimum of the function f(x,y,z) = x+2y+3z on the curve of intersection of the plane ...
6
votes
3answers
238 views

Calculating integral by Romberg Algorithm

In my "Numeric Anasyis" course, I learned the Romberg Alogrithm to calculate the numerical integral. The Romberg Alogrithm as shown below: $$ ...
0
votes
1answer
47 views

Symbol appears in multiple contexts when load two packages with unique function names

I have two packages "packageA" and "packageB". The function names across packageA and packageB are unique. No two functions have the same name. When I issue the ...
0
votes
1answer
47 views

Programming a series involving alternative log expressions

This is likely my error but I cannot see it. I define a vector: x1 = {{{2, 2}}, {{2, 1}, {3, 1}}, {{3, 2}}, {{2, 1}, {5, 1}}} If x1[[ i, 1,2]] is 2, I would like to find $(\log$ x1[[ i,1,1]]$^2$). ...
5
votes
1answer
277 views

How to solve this probability symbolically or numerically?

I am trying to calculate the following probability $$\mathbb{P} \big(\sum_{i=1}^{m} (A_i + S_i) \le L < \sum_{i=1}^{m+1} (A_i + S_i) \big)$$ where, $$A_i \sim \exp(\lambda), \quad S_i \sim ...
5
votes
0answers
147 views

How to download and combine S&P 500 stock prices

I want to download historical S&P 500 stock prices and combined them into one big file, having only one column of date referencing all stocks. Here is what I have do so far. ...
15
votes
1answer
292 views

Why does this line increase the consumed memory?

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I ...
0
votes
1answer
95 views

Optimizing Chi-square distance between two distribution

I want to program the chi-square between two distribution Xu and Vu with length N. This function is defined as below: Xu and Vu are real and positive. ...
4
votes
1answer
82 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
1
vote
3answers
107 views

Creating a list of lists as a function of a list

I have a list of length n whose elements are all 1 and -1. For each -1 in the list i want to create a list with a -1 in the same spot and a 1 everywhere else. For example: A list like {-1, -1, 1} ...
0
votes
0answers
66 views

Using Animate/ListPointPlot3D on more than one list

I have a couple orbits defined which have been mapped into one array as shown: ...
1
vote
0answers
59 views

Updating procedural fitting algorithm to more efficient style?

For some time now, I have used this procedural programming approach to fit data in my research that is too cumbersome for the built in Mathematica functions. (Although this simple example works fine ...
0
votes
0answers
22 views

A question about conditional replacement [duplicate]

{g[x, y, z], h[x, y], f[]} /. (f_[t___] /; f != List) :> Plus[t] Why is the output of this expression ...
3
votes
2answers
115 views

RandomFunction and Histograms

RandomFunction[QueueingProcess[3, 5], {0, 15}] Histogram[data, Automatic, "PDF"] gives a very nice way to see the histogram based on the specified process. ...
1
vote
1answer
180 views

How can I call the R-programming packages in my Mathematica?

I am trying to call the R-programming package called highfrequency in my Mathematica so that I can use its function rCov. I ...
4
votes
1answer
53 views

what's the meaning of “-mathlink” as part of Arg for LinkLaunch?

LinkLaunch["MathKernel -mathlink"] LinkLaunch["MathKernel"] The both code line above can launch a MathKernel. What's the difference of them? what's the meaning of ...
0
votes
0answers
20 views

what's the difference between CreateKernelLink() and CreateKernelLink(String Arg)?

I have a .NET program which will connect to MathKernel. When the program runs, there will be a icon of MathKernel on the taskbar. ...
0
votes
0answers
62 views

What is the meaning of //N in mathematica? [duplicate]

As the title says, What is the meaning of //N? i can't remember it.I tried looking in documentaion center, but it came up with nothing. Help appreciated.
2
votes
0answers
79 views

Distance Time Warp (DTW) function implementation in mathematica

The DTW (Distance time warp) is given here http://en.wikipedia.org/wiki/Dynamic_time_warping There is an implementation of DTW in R as well as MATLAB. However i am unable to find something for DTW in ...
1
vote
0answers
58 views

Programming for matrix manipulation

I want to write a programme which operates on nd x nd matrices. The programme looks the matrix as a n x n block matrix where ...
3
votes
2answers
132 views

Why the function cannot achieve the expected result?

Today, I write a toy code (Framed the prime in a list) to practice Mathematica programming ,which as shown below: Trail 1: ...
4
votes
2answers
475 views

How to create a function like in Python

I want to call a function that would perform a function rather than assigning an expression to them. I.e. ...
4
votes
2answers
387 views

Colorize Grayscale Image

I have a grayscale image that contains two objects. The grayscale pixel values can be divided into three intervals where two of them represent objects and the third represents the background. The ...
1
vote
2answers
54 views

Using conditionals to check if LinearSolve found a solution

Is there some way to check if LinearSolve found a solution using conditionals in Mathematica 9? I need to solve a large number of linear equations, but I am only interested in the cases where there ...
0
votes
1answer
101 views

Turning a 2D 3 body problem into 3D not so easy?

I have programmed a 3 body problem, that can in theory work for more than 3 bodies. I apologize in advance for the length of the code that I posted, I don't really know how much one would need to ...
3
votes
1answer
89 views

Image background subtraction using parallel computing

I am developing a program for pattern recognition. I want to use the parallel computing to get a real time application. I have two cameras where each one gives n frames/second. I need to process the ...