Tagged Questions

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

Finding the number that gives remainder equal to 0

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
54 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: ...
-1
votes
0answers
37 views

How to create my own procedures in mathematica? [on hold]

I need to use some sequence of actions several times in my code. This actions includes cycles and some simple mathematics. Is it possible to create procedure (function) like in languges such as c, to ...
0
votes
0answers
44 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
70 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
61 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. ...
3
votes
1answer
78 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
83 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
100 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
43 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 ...
0
votes
0answers
24 views

Calculate number of probabilities [migrated]

I want to calculate a number of probabilities of a+b+c=1 For a vary from 0 to 1 with an incrementing of 0.1 For ...
6
votes
3answers
223 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
40 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
43 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
265 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
118 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
278 views
+100

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 ...
-2
votes
0answers
19 views

Defining an ORIGINAL derivative function? [duplicate]

NOTE: I do not want to use the Derivative or D functions. – I want to define an original function. I began with this definition of the derivative , which resulted in: Limit[ #, h -> 0] & /@ { ...
0
votes
1answer
79 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
78 views

Slowdown of Flat attributed function

I was trying to write an associative function f using the attribute Flat. ...
1
vote
3answers
104 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
61 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
58 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
107 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
170 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
43 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
16 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
60 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
69 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
53 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
465 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
377 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
50 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
99 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 ...
2
votes
1answer
77 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 ...
7
votes
1answer
89 views

why CopyFile cannot overwrite existing file?

CopyFile return $Failed when the file exists on destination. is there any way to force CopyFile to overwrite the existing one? the way I use now is DeleteFile and ...
2
votes
1answer
83 views

Please explain this while-loop

Code: ...
4
votes
0answers
121 views

Tutorial video on the Wolfram Language [closed]

A 3 hour video explaining the workings of the Wolfram Language is now available at: http://www.wolfram.com/broadcast/s?sx=Gaylord downloading the pdf or notebook here of entire lecture is very ...
4
votes
1answer
108 views

Association and rudimentary object-oriented programming

Doesn't Association provide us rudimentary object oriented programming via constructs like ...
9
votes
6answers
484 views

Best way to find permutation with specific total

Can anyone suggest a good way to find permutations of 12 digits, 0 to 4, totalling 24. I.e. two such permutations:- {2, 1, 4, 1, 2, 2, 2, 2, 2, 2, 1, 3} // Total ...
7
votes
2answers
145 views

Connecting to LeapMotion

Thanks to those who helped me with my previous question. I will help others too where I can. In the meantime I have a general question whether anyone has had success connecting Mathematica to the ...
6
votes
2answers
155 views

Manage a network of Arduinos using Mathematica and xbee

I'm trying to take 5 analog reads from two or more Arduinos at different times. So to do that my listening port via xbee is COM8, then I start a ...
5
votes
4answers
308 views

Is there any way to assign multiple values?

I am looking for something like "byref" assignment in programming languages. Let's assume I have: x1=x2=....=xn if I want to change their values ( say to 3 ) I need to set all of them like: ...
6
votes
1answer
131 views

Where can I put my conditions?

I just learned in this answer that you can put conditions inside a With and thus use computed values in them, like this: ...
7
votes
2answers
284 views

Recursive partitioning: Is there a better way to do this?

Consider the following function, which recursively splits a list into equal length sublists (the length of the list is assumed to be a power of the second argument): ...
6
votes
2answers
252 views

How to transform a matrix to upper-triangular with operation- tag elegantly?

Description: Recently, I have a thought that writing a function to show the transformation process when a matrix is transformed to upper-triangular. My trail ...
1
vote
1answer
126 views

Help in Bifurcation Diagram

My dears, I need to plot a bifurcation diagram for the following non-linear systems represented by the next Mathematica code ...