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
3answers
275 views

Mathematica style guide?

I encountered this site today https://code.google.com/p/google-styleguide/ regarding the programming style in some languages. What would be best programming practices in Mathematica, for small and ...
2
votes
1answer
63 views

ControlType -> None Vs. Module inside Manipulate (i.e. making everything local)

I'm building a program on another one made available in the Wolfram Demonstration Project. I've noticed that in the original code (working flawlessly) many variables were made local inside the ...
10
votes
5answers
320 views

For a given expression: if it appears, remove it, but if it is absent, add it

While reformatting Szabolcs's code from (42660) I noticed this interesting operation: ...
2
votes
1answer
64 views

Are there methods to serialize and deserialize large calculation runs? [closed]

I have a fairly large calculation to map an electric field over large areas (square kilometers). This runs for a fairly long time. Are there ways to serialize the current state of a running ...
0
votes
1answer
30 views

New output cell generated for each run of a GraphicsGrid - is there a way to simply update the same output cell each run?

I have a Code cell that generates a set of plots in a GraphicsGrid[]. Each time I execute the Code cell, a new Output cell is generated. Is there a way to simply update a single output cell instead ...
1
vote
0answers
67 views

Code turns dark blue after trying to run it [closed]

I have a large amount of data in my N-Body Code. I imagine Mathematica doesn't really like this, but is there any other reason for my code turning a navy blue colour after I try to run it?
0
votes
0answers
37 views

Define column types in a Dataset - Failure on append and Typesystem

I have a basic function that populates a Dataset according to user specified parameters. ...
1
vote
1answer
69 views

How would I obtain a list of column names in a Dataset?

I really love the addition of Dataset to Mathematica. I would like to write a basic utility function that exports a Dataset to Excel. Is there a way to get a list of column names from a Dataset?
-3
votes
1answer
75 views

How to make X and Y = Z? [closed]

Hello I have a big question, maybe it's extremely easy but for now I'm unable to make it work. I'm a programmer and what I need to do is for example: if X = 2 and Y = 1 then Z = 1 if X = 3 and Y = 1 ...
4
votes
2answers
88 views

How would I programmatically add a row to a Dataset?

I would like to use a Dataset to track the process of a lengthy calculation over a large volume of material. Dataset appeals to me because of the power of the queries and it also looks like it may ...
0
votes
0answers
12 views

all does not work [duplicate]

Thanks blochwave for giving me a detailed answer, but I have already used all these methods and none of them has worked well, it is clearly written in mathematica "get help" file that the Timing[] and ...
2
votes
1answer
109 views

How to speed up my code about Divisors?

This code is about PE496 In[21]:= ParallelSum[n*Count[Divisors[n^2], a_ /; n < a < 2 n], {n, 1, 10^5}] // AbsoluteTiming Out[21]= {5.987342,10724527832} I ...
0
votes
1answer
114 views

Finding CPU time of more than one expressions

I want to find the computational time (CPU time) of my code. When I use TimeUsed or Timing commands they give the CPU time of ...
0
votes
0answers
32 views

How to simultaneously change variables shared by several functions?

I designed a fit program, the framework follows: a matrix build function: Q[a_,b_,c_,d_]; several matrix manipulate functions shared the variables {a,b,c,d} like this: ...
0
votes
1answer
80 views

InterpolatingFunction used to work with mathematic 7 but not working with mathematica 10

This code is used to work perfectly with Mathematica 7 and now it is not working with Mathematica 10. Any help is appreciated. CL05 = InterpolatingFunction[{{0.5, 11.99999999999999}}, {1, ...
7
votes
3answers
260 views

Interactively inspecting parts of an object

There have been times when I want to find the structure of an object in order to extract some part of it. For example, extracting the x and y coordinates from a Graphics object generated by Plot. I ...
0
votes
1answer
72 views

How can I use manipulate on multiple lists within a function?

So I have my N-Body Problem set up like so, and I can plot it in ListPointPlot3D, but I cannot figure out how to stick this into a manipulate function. ...
7
votes
2answers
310 views

How to get short definition of all built in Mathematica Functions?

The first post in "Mathematica Weekly Newsletter - Tuesday, December 30, 2014" really attracted my attention as I was always looking for a complete list of built in Mathematica functions with short ...
3
votes
1answer
194 views

A problem about Steffensen method

Two days ago,I asked a question about bisection algorithm. Thanks for Michael E2 giving me a good solution My algorithm 1, I use the bisection algorithm to generate a initial value that contain a ...
5
votes
2answers
275 views

Implement the Bisection algorithm elegantly and easily

Description: Rencently, I have finished my course Numerical Analysis, so I'd like to implement many algorithm that I have learned from that course.By this practice, I hope that I can improve my ...
0
votes
1answer
64 views

Data file organized in strings

I am working in a data set : The original question, They are strings of thousands stars,and each one contains a lot of parameters, and the following item is called identifies, they are the names ...
-2
votes
0answers
61 views

Loop construction

I would like to solve a linear system using the Thomas algorithm, as explained in the picture below. I tried to solve it writing each entry using its definition (3.53). But, if the matrix is larger, ...
1
vote
2answers
68 views

Subroutine execution repetition

I like to write second and third lines repeated operation only once as a separate module with some Name. In each main program line a set of different set boundary conditions data is given,Name invoked ...
0
votes
2answers
145 views

Exctrating data information from a file.txt

I really did previous long search in the site and I couldn't find any answer that might help me. So I am asking it. I have the following data set, ...
13
votes
11answers
1k views

Divide all but the maximal element in a list by 10?

I have a list of numerical data, and I want to write a program that will keep the maximum as it is, but reduce the rest by certain factor (such as 10). For example: ...
4
votes
0answers
110 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
71 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
242 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
74 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
237 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
80 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
141 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 ...
8
votes
1answer
118 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
309 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?
19
votes
0answers
265 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
98 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
54 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
41 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
36 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
78 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
96 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
85 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
69 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. ...
5
votes
1answer
121 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
91 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
46 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
119 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 ...