mathematica

Mathematica function foo that can distinguish foo[.2] from foo[.20]

Suppose I want a function that takes a number and returns it as a string, exactly as it was given. The following doesn't work: SetAttributes[foo, HoldAllComplete]; foo[x_] := ToString[Unevaluated@x] The output for foo[.2] and foo[.20] is identical. The reason I want to do this is that I want a function that can understand dates with ...

Show duplicates in Mathematica

In Mathematica I have a list: x = {1,2,3,3,4,5,5,6} How will I make a list with the duplicates? Like: {3,5} I have been looking at Lists as Sets, if there is something like Except[] for lists, so I could do: unique = Union[x] duplicates = MyExcept[x,unique] (Of course, if the x would have more than two duplicates - say, {1,2,2,2...

Mathematica running out of memory

I'm trying to run the following program, which calculates roots of polynomials of degree up to d with coefficients only +1 or -1, and then store it into files. d = 20; n = 18000; f[z_, i_] := Sum[(2 Mod[Floor[(i - 1)/2^k], 2] - 1) z^(d - k), {k, 0, d}]; Here f[z,i] gives a polynomial in z with plus or minus signs counting in binary. ...

Multiple assignment between lists in Mathematica 7

Suppose there are two lists a = {a1, a2, a3} and b = {b1, b2, b3}, and I want to write an assignment statement to make a1=b1,a2=b2,a3=b3 which only refers to a and b: Thread[a = b] But it only makes a={b1,b2,b3}. Using := (SetDelayed) instead of = doesn't work either. Any solution? Thanks. ...

Finding previously defined messages in Mathematica

Mathematica by default defines a lot of useful messages for signaling common errors, like functions being called with the wrong number of arguments or files not being found. In general, I prefer to use existing, defined messages wherever possible, because it makes it easier for them to be handled via mechanisms like Check, Quiet and On/O...

Export custom formatted expressions from Mathematica

How can I get Mathematica to export/save/write out a text file with proper Fortan77 formatting, i.e., 72 columns and a continuation marker on the sixth column. I am using Mathematica to generate large and complex analytic expressions, which I then need to insert into pre-existing Fortran77 code. I can get everything working correctly in...

Mathematical Programming Languages

Given my previous questions about the the usage of AMPL. Are there any other programming/scripting languages that are strictly meant for mathmatical processing? For example: Matlab (it does deviate a bit from a mathematical structure, but its close enough), Mathmatica, and AMPL ...

Getting started with Mathematica packages

Can someone offer some advice on how to get started with mathematica packages? I can save the following in a file named "Foo.m". When I run the input cell in that file, I can see the effects reflected in $ContextPath variable. BeginPackage["Foo`"] bar::usage = "barfunction"; Begin["`private`"] bar[w_] := w; End[]; EndPackage[]; H...

Possible to put equation's expression near its graphic representation?

Is it possible that when I Plot a function in Mathematica, it will automatically put near it it's equation(i.e. y = 2x) or even some other text? At first glance I don't find any option for it, but if there is one I'd like to know. Thanks ...

Targeted Simplify in Mathematica

I generate very long and complex analytic expressions of the general form: (...something not so complex...)(...ditto...)(...ditto...)...lots... When I try to use Simplify, Mathematica grinds to a halt, I am assuming due to the fact that it tries to expand the brackets and or simplify across different brackets. The brackets, while cont...

Possible to use Mathematica from other programming languages (python/C#) ?

Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program. Is it possible? ...

Mathematica, PDF Curves and Shading

I need to plot a normal distribution and then shade some specific region of it. Right now I'm doing this by creating a plot of the distribution and overlaying it with a RegionPlot. This is pretty convoluted and I'm certain there must be a more elegant way of doing it. I Googled, looked at the docs, found nothing. Help me SO! I guess Mat...

Connecting points in Mathematica

I have a collection of points displayed in a graphic: I'd like to know if there is any command that will connect them automatically along the xx and yy axis. This can be better understood looking at the following picture: (I am not asking how to implement the algorithm myself!). Thanks ...

HMAC (hash-based message authentication code, aka data signing) in Mathematica

It seems there's an implementation of HMAC in every language under the sun. (See below.) And the algorithm is quite straightforward: http://en.wikipedia.org/wiki/HMAC Has anyone implemented it in Mathematica? Here are pointers to implementations in other languages: http://docs.python.org/library/hmac.html http://php.net/manual/en/fu...

Running code in MatLab/Mathematica only after having written it all

I'd like to know if there's a way that when using Matlab, instead of having it interpret what I write line by line, if allows me to write all I want, and only interpret it when I hit an "Evaluate" button, or something like that. Coming from c++/c# I like to write the code I have to, and only then run it. Also I don't like it putting >>'...

Cryptographic hash (sha1 or md5) of data given as a string in Mathematica

The sha1 hash of "abc" is a9993e364706816aba3e25717850c26c9cd0d89d The only way to get Mathematica to tell you that with its Hash function is Hash[abc, "SHA"] // IntegerString[#, 16]& (The IntegerString thing is just to output it in hex like most implementations do.) Note that Hash["abc", "SHA"] gives the hash of "\"abc\"" ...

How to make animations out of a Table of images in Mathematica 7

If I have a set of pictures, how can I make it so I can get an animation out of them? In old versions of Mathematica, it was possible to compact them and then double click them so it would show them as sequence(i.e., animation), but I'm now using version 7 of Mathematica and that doesn't seem possible. How can I do so? ...

What does it mean when words are drawn blue in Mathematica?

Here is what I mean: Sometimes I don't know why, I get the names of functions blue. Is there any special reason? ...

When plotting a 3D Graphic, how to define the angle it will show?

I know I can after the plot is done, to rotate it with my mouse to the desired angle. Now, I'd like to know how to do the same through code. ...

How to import data from a file as list/array in Mathematica

I have data(points) that I have to import from another program to Mathematica, so I can plot it. I have control on how the points are going to be written to the file, so I can put them in any way I want. What is the best way to import them to Mathematica? As I'm going to use StreamDensityPlot, the variable I'll have to pass to StreamDens...