wolfram-mathematica

Photo Mosaic in Mathematica: an example from 2008 doesn't work in Mathematica 8

匆匆过客 提交于 2019-12-04 07:48:30
I'm trying to get a Mathematica example working. It's the one on Theo Gray's blog . I think that Mathematica must have changed since he wrote that code (May 2008), since I'm unable to get anything reasonable out of it, despite changing nearly everything. Do I use ImageData instead of Import? Can anyone suggest a version of this code that works for Mathematica 8? imagePool = Map[With[{i = Import[#]}, {i, Mean[Flatten[N[i[[1, 1]]], 1]]}] &, FileNames["Pool/*.jpg"]]; closeMatch[c_] := RandomChoice[Take[SortBy[imagePool, Norm[c - #[[2]]] &], 20]][[1]]; Grid[Reverse[ Map[closeMatch, Import[

How to format two separate lists in columns, rather than rows in Mathematica?

泪湿孤枕 提交于 2019-12-04 07:45:02
This seems like it should be a piece of cake, but I haven't found the answer in Mathematica's documentation. Say I have two separate lists, for example x={1,2,3,4,5} and y={1,4,9,16,25}. I want to format these lists as a table with each list as a column, like this: x y 1 1 2 4 3 9 4 16 5 25 But if I do TableForm[x,y], I get only the first column, like this: 1 2 3 4 5 If I do Grid[{x,y}], I get a table, but formatted as rows instead of columns, like this: 1 2 3 4 5 1 4 9 16 25 Now, if I have my values as {x,y} pairs, rather than separate lists, then I can get almost what I want,like so: Input:

how does mathematica determine which rule to use first in substitution

风格不统一 提交于 2019-12-04 07:43:51
I am wondering if given multiple substitution rules, how does mma determine which to apply first in case of collision. An example is: x^3 + x^2*s + x^3*s^2 + s x /. {x -> 0, x^_?OddQ -> 2} Thanks. Mathematica has a mechanism which is able to determine the relative generality of the rules in simple cases, for example it understands that ___ (BlankNullSequence) is more general than __ (BlankSequence). So, when it can, it reorders global definitions according to it. It is important to realize though that such analysis is necessarily mostly syntactic. Therefore, while PatternTest (?) and Condition

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

我们两清 提交于 2019-12-04 07:35:29
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\"" -- not what you want! In fact, the only reason we could get the correct hash of "abc" was because the Mathematica representation of the symbol abc happens to be the string "abc". For the vast majority of strings, this will not be the case. So how do you take the hash of an

Mathematica internal number formats and precision

一曲冷凌霜 提交于 2019-12-04 07:15:41
Tangentially related to this question, what exactly is happening here with the number formatting? In[1] := InputForm @ 3.12987*10^-270 Out[1] := 3.12987`*^-270 In[2] := InputForm @ 3.12987*10^-271 Out[2] := 3.1298700000000003`*^-271 If you use *10.^ as the multiplier the transition is where you would naively expect it to be: In[3] := InputForm @ 3.12987*10.^-16 Out[3] := 3.12987`*^-16 In[4] := InputForm @ 3.12987*10.^-17 Out[4] := 3.1298700000000004`*^-17 whereas *^ takes the transition a bit further, albeit it is the machine precision that starts flaking out: In[5] := InputForm @ 3.12987*^

Create a Function for Customized Tabular Representation

家住魔仙堡 提交于 2019-12-04 06:49:25
I use the code below get an overview of parts of my data. What would be the best way to make a function out of the below code ? It would take a dataList as well as some graphical options (such as colors) as arguments and return a customized tabular representation as shown below. overviewtheData=Text@Grid[{Map[Rotate[Text[#], 90Degree]&,data[[1]]]}~Join~data[[2;;]], Background->{{{{White,Pink}},{1->White}}}, Dividers->{All,{1->True,2->True,0->True}}, ItemSize->{1->5,Automatic}, Alignment->Top, Frame->True, FrameStyle->Thickness[2], ItemStyle->{Automatic,Automatic,{{1,1}, {1,Length@data[[1]]}}-

Exporting sounds as WAV files

荒凉一梦 提交于 2019-12-04 06:15:34
I never worked too much with sounds in Mma. I have t = Sound[List["Violin",SoundNote[-6]]] How could I Export t as a .WAV file? When I try the obvious Export["c:\\test.wav",t] I get In this old thread Szabolcs said that it can't be done. Perhaps things have improved since 2007! Simon I think that it still can't be done. Mathematica supports creating and modifying MIDI objects, but leaves the sound generation from the midi to the underlying operating system. For now, you'll have to export to midi then use the midi interface on your system or an online service to convert to a sampled sound

Getting data out of CDF-player

一个人想着一个人 提交于 2019-12-04 05:43:00
For my Skeptics working group I wrote a program in Mathematica to test a dowser's ability to assess the status of persons shown to them by means of photographs. For a null measurement I distributed this document to my group's members in CDF form (the new v8 Computable Document Format, meant to be run with the CDF-player ). On my computer (using mma) it all works fine, but the others can't export the data (the program does an export to an Excel file). On reading the fine print I see that the player doesn't support Export. So my question is: Is there any way to get data out of CDF-player? For

Simplifying a very long symbolic expression by automatically introducing temporal variables or in any other way

北城以北 提交于 2019-12-04 05:39:14
After attempting to solve a symbolic math problem, I got an expression with about 17000 characters. I am using the symbolic toolbox for Matlab, but I am open to any suggestion (Mathematica, whatever). For obvious reasons, I won't copy-paste the expression straight into the question. Here is a link instead . Running the Matlab commands simplify and simple , and even attempts to collect didn't improve the situation (Some got it worse). But I am wondering, I don't care if the expression is evaluated in steps, with temporal parameters. Something like: z1 = a^2*y1; %Now the expression can be

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

落爺英雄遲暮 提交于 2019-12-04 05:37:54
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 StreamDensityPlot will have to be in the following way: data = { { { a, b, c }, {a, b, c}, {a, b, c}, { a, b, c }, {a, b, c}, {a, b, c}, { a, b, c }, {a, b, c}, {a, b, c}, } ... { { a, b, c }, {a, b, c}, {a, b, c}, { a, b, c }, {a, b, c}, {a, b, c}, { a, b, c }, {a, b, c