wolfram-mathematica

Mathematica fast 2D binning algorithm

邮差的信 提交于 2019-11-30 02:21:46
I am having some trouble developing a suitably fast binning algorithm in Mathematica. I have a large (~100k elements) data set of the form T={{x1,y1,z1},{x2,y2,z2},....} and I want to bin it into a 2D array of around 100x100 bins, with the bin value being given by the sum of the Z values that fall into each bin. Currently I am iterating through each element of the table, using Select to pick out which bin it is supposed to be in based on lists of bin boundaries, and adding the z value to a list of values occupying that bin. At the end I map Total onto the list of bins, summing their contents

Keyboard shortcut to Un/Comment out code in Mathematica 7?

走远了吗. 提交于 2019-11-30 02:11:28
A keyboard shortcut to comment/uncomment out a piece of code is common in other programming IDE's for languages like Java, .Net. I find it a very useful technique when experimenting through trial and error to temporarily comment out and uncomment lines, words and parts of the code to find out what is and isn't working. I cannot find any such keyboard shortcut on the Mathematica front end in version 7. I know that it is possible to comment out code by selecting the code, right mouse click and select Un/Comment from the menu that appears but this is too slow while coding. I tried to access this

How to Block Symbols without evaluating them?

∥☆過路亽.° 提交于 2019-11-30 02:06:49
Suppose I have a list of names of Symbol s: f1 := Print["f1 is evaluated!"]; list = {"f1", "f2"}; The obvious way to Block these Symbol s leads to evaluation of them: In[19]:= With[{list=Symbol/@list},Block[list,f1//ToString]] During evaluation of In[19]:= f1 is evaluated! During evaluation of In[19]:= f1 is evaluated! Out[19]= Null But without evaluation we could Block them without any problem: In[20]:= Block[{f1, f2}, f1 // ToString] Out[20]= "f1" Is it possible to inject this list into the Block scope without evaluating the Symbol s? Here is yet another technique to do this: SetAttributes

Can we generate “foveated Image” in Mathematica

空扰寡人 提交于 2019-11-30 02:01:08
" Foveated imaging is a digital image processing technique in which the image resolution, or amount of detail, varies across the image according to one or more "fixation points." A fixation point indicates the highest resolution region of the image and corresponds to the center of the eye's retina, the fovea." I want to use such image to illustrate humans visual acuity, The bellow diagram shows the relative acuity of the left human eye (horizontal section) in degrees from the fovea (Wikipedia) : Is there a way to create a foveated image in Mathematica using its image processing capabilities ?

Struct data type in Mathematica?

孤人 提交于 2019-11-30 01:13:29
问题 After playing with Mathematica's symbolic and numerical capabilities, I find it to be a decent programming language, too. However, something making it less appealing as a general-purpose language is the lack of C-like struct data type (or the record type as known in Pascal). How can I get around this problem? 回答1: Update : Mathematica 10 has introduced Association, which has many of the most important properties of a struct . (See new answer.) The original, somewhat deprecated version of this

Is there a “normal” EqualQ function in Mathematica?

百般思念 提交于 2019-11-30 00:46:29
On the documentation page for Equal we read that Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits). Here are examples (32 bit system; for 64 bit system add some more zeros in the middle): In[1]:= 1.0000000000000021 == 1.0000000000000022 1.0000000000000021 === 1.0000000000000022 Out[1]= True Out[2]= True I'm wondering is there a "normal" analog of the Equal function in Mathematica that does not drop last 7 binary digits? In[12]:= MyEqual[x_, y_] := Order[x, y] == 0 In[13]:=

What is the best way to find the period of a (repeating) list in Mathematica?

做~自己de王妃 提交于 2019-11-30 00:37:49
问题 What is the best way to find the period in a repeating list? For example: a = {4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2} has repeat {4, 5, 1, 2, 3} with the remainder {4, 5, 1, 2} matching, but being incomplete. The algorithm should be fast enough to handle longer cases, like so: b = RandomInteger[10000, {100}]; a = Join[b, b, b, b, Take[b, 27]] The algorithm should return $Failed if there is no repeating pattern like above. 回答1: Please see the comments interspersed with the code on how it

Minimizing NExpectation for a custom distribution in Mathematica

百般思念 提交于 2019-11-29 23:24:37
This relates to an earlier question from back in June: Calculating expectation for a custom distribution in Mathematica I have a custom mixed distribution defined using a second custom distribution following along the lines discussed by @Sasha in a number of answers over the past year. Code defining the distributions follows: nDist /: CharacteristicFunction[nDist[a_, b_, m_, s_], t_] := (a b E^(I m t - (s^2 t^2)/2))/((I a + t) (-I b + t)); nDist /: PDF[nDist[a_, b_, m_, s_], x_] := (1/(2*(a + b)))*a* b*(E^(a*(m + (a*s^2)/2 - x))* Erfc[(m + a*s^2 - x)/(Sqrt[2]*s)] + E^(b*(-m + (b*s^2)/2 + x))*

using python to solve a nonlinear equation

穿精又带淫゛_ 提交于 2019-11-29 23:21:49
问题 I have never used python but Mathematica can't handle the equation I am trying to solve. I am trying to solve for the variable "a" of the following equations where s, c, mu, and delta t are known parameters. I tried doing NSolve, Solve, etc in Mathematica but it has been running for an hour with no luck. Since I am not familiar with Python, is there a way I can use Python to solve this equation for a? 回答1: You're not going to find an analytic solution to these equations because they're

Why won't this work? Dynamic in a Select

强颜欢笑 提交于 2019-11-29 23:18:25
Ok, I do this: Select[Range[1, 20], # > Dynamic[q] &] And then I create the slider: Slider[Dynamic[q], {1, 20}] And it'll always return an empty set! Why! Update The goal of this is to have the set change as I move the slider. The key is to remember that Dynamic does not control anything about evaluation directly. What it does is to create a spot on the screen which has evaluation properties. If, for example, you were to evaluate the following in a fresh Mathematica session... b=5; Dynamic[a=b]; b=6; Print[a]; ...then what will be printed? Instead of evaluating it immediately, think about it