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.
5
votes
5answers
227 views
How can I use nested conditionals inside my functions?
I'm a big fan of using conditionals inside my functions to deal with cases, that is, to pattern match in stages and possibly leave a function unevaluated.
...
5
votes
2answers
288 views
How can I get exactly 5 logarithmic divisions of an interval?
I'd like to get exactly 5 divisions from x to y on a log scale. Can FindDivisions do this?
5
votes
3answers
113 views
Unencoding encoded URLs in a function
Is there a built-in function for decoding encoded URLs in Mathematica?
I would like to convert an encoded URL, for example
...
5
votes
3answers
143 views
How could I implement the equivalent of NextPrime
I would like to know what an implementation of the function NextPrime would look like if it were implemented in Mathematica's core language.
5
votes
1answer
288 views
How can I view the code implementing a built-in Mathematica function? [duplicate]
Possible Duplicate:
What is the most convenient way to read definitions of in-memory symbols when we don’t have the source files?
I would like to look at the code that implements ...
5
votes
3answers
258 views
Mathematica quine
A quine is a computer program which takes no input and produces a copy of its own source code as its only output. There are many trivial quines in Mathematica:
...
5
votes
1answer
190 views
Alternative to overloading Set
In the ideas shared in my answer to this post Struct equivalent in Mathematica? at the end I propose a solution that changes the way Set works in a particular case that can be expressed in plain words
...
5
votes
2answers
192 views
How can I use Max[] in a function that is passed a list not find the max of the list
For most functions in Mathematica, passing them a list will call the function on each element of the list. For example:
...
5
votes
3answers
145 views
Scope within Context
To define some package-wide functions/variables, what approach is recommended? I tried to use contexts with the Begin function, but this failed:
...
5
votes
1answer
224 views
How to monitor the progress of Map?
I have a function doSomethingComplicated[...] that takes about 10s on average to evaluate. My list, listOfArgs has about 10000 ...
5
votes
3answers
275 views
How to ensure that Polygon[list] plots a simple polygon?
Consider the following code which plots a triangle.
p = {{0, 0}, {.2, 0}, {0, .2}};
{Cyan, Polygon[Dynamic[p]]} // Graphics
Then adding (for example) ...
5
votes
3answers
227 views
How to eliminate the need to double evaluate a Manipulate so that a Module in its Initialization section works?
Using V 8.04 on windows.
I think this issue might be related to the fact that Mathematica reads main body the Manipulate before evaluating or running the Initialization option.
Or, might be ...
5
votes
2answers
119 views
How to silence all messages associated with a built-in symbol?
The post title's pretty much says it all...
The reminder of this post just describes the little headway I made with this problem, FWIW.
One would hope that
...
5
votes
2answers
177 views
Applying different color to result of a geometric transformation
Background: consider the following two snippets.
...
5
votes
3answers
167 views
HoldFirst and inserting additional options into a Grid of Graphics
This is related to my earlier question, but is specific to an issue I have encountered with the use of the HoldFirst
First, let's create some fake data for ...
5
votes
2answers
655 views
Solving a tridiagonal system of linear equations using the Thomas algorithm
I'm trying to write a function that can solve a tridiagonal system of linear equations using the Thomas algorithm. It basically solves the following equation. (Details can be found at the Wiki page ...
5
votes
1answer
112 views
How to create a Hyperlink within the current Notebook?
Using “Create Hyperlink” dialog window I can create a link to a tagged cell in my notebook (it's “Destination notebook: Current notebook” radio button).
Now, I can't figure it out how to create such ...
5
votes
3answers
180 views
Question about modifying a Slider2D control
Background: I want to develop a custom control, based on a 2D slider. I currently have this ( working ) example.
...
5
votes
1answer
183 views
NestList and Euler's method
I am new to mathematica and so just experimenting with various programming constructs. Recently have been looking at NestList and how I could use this to implement ...
5
votes
1answer
117 views
Implementing myMapThread with Thread, Apply
Problem:
Exercise 5.2.1 from Wagner's Book: implement myMapThread in terms of Thread/Apply such that it works with the Power/Equal examples below.
My Attempt:
...
5
votes
1answer
323 views
Multi-objective genetic algorithm in Mathematica?
Is there any implementation of a multi-objective genetic algorithm for Mathematica?
5
votes
1answer
117 views
Should Row be used in place of StringForm?
I've been using Mathematica for a long time, so I have a habit of using some of the older functions even when newer, better ones have been added to replace them.
...
5
votes
0answers
70 views
Convert logical relational expression to / from disjunctive and conjunctive forms?
I would like to convert logical relational expressions in disjunctive form, e.g.,
$$(x \lt -1) \lor (-1 \lt x \lt +1) \lor (x \gt +1)$$
into conjunctive form, e.g.,
$$(x \ne -1) \land (x \ne +1)$$
...
5
votes
0answers
213 views
Is it possible to construct a function to make a poor man's Mathematica database?
I have a function that is set up to write to a database with 10-20 standard variables with 10 fields each, but the application is going to a place where database access is not available. Can ...
4
votes
4answers
232 views
How to compile the code for generate Pythagorean_triple?
I am finding Pythagorean_triple, it worked slowly. I tried to compile, but it gives some warnings.
I also use "Case" or "Do" ,both of them failed.I'm sure my CCompiler has been set correctly.
How can ...
4
votes
3answers
279 views
4
votes
3answers
775 views
Basic questions about running Mathematica
Is there a command window and an editor in Mathematica 8 similar to
those in Matlab? In Mathematica GUI mode, all I saw is write code and run it in the same
notebook.
In my Ubuntu terminal, I ...
4
votes
2answers
302 views
Developing domain specific languages and computational knowledge engines using Mathematica
In one of Leonid Shifrin's excellent summaries, he mentioned that MMA capabilities include developing Domain Specific Languages (DSL).
I'd like to develop a Health care IT application that can
...
4
votes
3answers
327 views
How to make brute force coding more efficient?
Hi guys and guysettes,
The little Mathematica I've been using/seen so far, it seems to be all about neat "one-liners" using the underlying functions and working with lists & maps to solve issues, ...
4
votes
3answers
138 views
Keep function range as a variable
Plot[2*x^2 - x + 2, {x, -1, 1}] plots a function of x from -1 to 1. As far as I can see, I cannot "save" this range in a variable:
...
4
votes
3answers
160 views
Brackets in output make unable to use output to identify matrix element
I'm trying to write a code where each matrix element swaps with a randomly selected neighbor (cardinal directions only) to redistribute the matrix. So far I've been able to replace an element with its ...
4
votes
2answers
142 views
How to Text justify string that includes SubScriptBox in it?
I am using Grid to document a demo I have. i.e. I am writing the documentation of the demo as a help option, which will display information when clicked on.
Everything is working well. I am using the ...
4
votes
4answers
202 views
why I see the error “only assignments to symbols are allowed” in Module context and not in global?
V 8.04, on windows.
When I type
Remove["Global`*"]
foo[] := Module[{Subscript[a, 1] = "x"}, 0];
foo[]
I get the expected error "only assignments to symbols ...
4
votes
2answers
143 views
Finding all/most roots of a discontinuous function more consistently?
I have the equation:
f[x_]:=α Tan[α*a] - Sqrt[c - α^2]
and ideally I want to find all of its positive zeros, given a and c, with variable alpha. The problem is ...
4
votes
2answers
199 views
Improve performance and style of solution to Project Euler #32
Since I'm fairly new to Mathematica, I'm trying to learn better ways to improve my coding skills so I've turned to Project Euler and this site to speed up my learning pace. Anyways, I was trying to ...
4
votes
3answers
144 views
Creating Multi-Tabbed Grid with Preserved Contents and Overview Grid
I am in the process of creating an application/panel that will aide me in scheduling hours for my staff of ten or more. I am hoping to create a multi-tabbed grid within which I may collect data about ...
4
votes
3answers
162 views
Is it possible to replicate the “magic” of OptionPatterns[] with DynamicModule's local variables?
Creating richer interactive interfaces that are generated by a DynamicModule invariably requires more complex data structures and in particular, a larger argument ...
4
votes
2answers
154 views
Split string into sub-strings of length n [duplicate]
Possible Duplicate:
Partition string into chunks
How can I split a string into sub strings of length n? For example I have a string
"ABCDEabcde1234"
...
4
votes
1answer
153 views
Maximizing functions with Which statements
I'd like to be able to find the maximum value that my Capex function (see below) generates. This is a fairly simple function so I could just add it up but I have more complex functions of a similar ...
4
votes
1answer
195 views
How to organize and run functions?
I am very new to Mathematica. I thought I would try it out for my first assignment in my computer science class. Until now I have only used C-base languages including C#, Java, Objective-C, and ...
4
votes
1answer
201 views
Symbolic bit vectors
I'd like to see how addition and xoring bitvectors mix together. To do this, I implemented (a primitive) vec_add and vec_xor:
...
4
votes
1answer
245 views
Can a Table iterator “leak” into a Module?
I want to repeatedly call a module by using a Table statement. When I use an i iterator in the Table command calling the module, I receive the error message ...
4
votes
3answers
95 views
Modify this code using Module and While
I have written a recursive function and would like to re-write the code using Module AND While to compare the timings.
Here is my recursive function for f[n], where 6 n f[n] = f[n-1] + n! for n>0 and ...
4
votes
3answers
189 views
More structure in Source Code/Notebooks
Mathematica is great for small and quick projects and has a great syntax. However as soon as a project grows I run into trouble. How do you scale and maintain projects in Mathematica? What is beyond ...
4
votes
4answers
173 views
clean functional way to get first n rows that yield maximum rank
I have a matrix A and want the matrix consisting of the first n rows of A, having the same rank as A, where n is minimal.
More generally, I want the shortest "start piece" of a list, such that some ...
4
votes
1answer
232 views
4
votes
2answers
140 views
why set values in this way doesn't work?
question is as follows
define a list
ttt={1,2};
and if I set values in this way
{ttt[[1]],ttt[[2]]}={3,4}
then the value ...
4
votes
2answers
118 views
How can I compare the previous value and the current value implemented during NestWhileList?
I am trying to write a part of my code. I am using NestWhileList. However, I couldn't find out the right syntax for testing. It should compare previous result and current result and continue if it is ...
4
votes
1answer
130 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:
...
4
votes
1answer
119 views
How to avoid conflicts between local variable names and symbolic arguments in Block constructs?
I am using Block inside the definition of some recursive functions.
If the Block definitions use short variable names, like ...

