wolfram-mathematica

What is the most efficient way to construct large block matrices in Mathematica?

依然范特西╮ 提交于 2019-12-03 02:38:50
Inspired by Mike Bantegui's question on constructing a matrix defined as a recurrence relation, I wonder if there is any general guidance that could be given on setting up large block matrices in the least computation time. In my experience, constructing the blocks and then putting them together can be quite inefficient (thus my answer was actually slower than Mike's original code). Join and possibly ArrayFlatten are possibly less efficient than they could be. Obviously if the matrix is sparse, one can use SparseMatrix constructs, but there will be times when the block matrix you are

Using MySQL databases in Mathematica

感情迁移 提交于 2019-12-03 02:27:39
I've seen it's possible to make a connection between Mathematica and MySQL databases using Input Needs["DatabaseLink "] and conn = OpenSQLConnection[JDBC["MySQL(Connector/J)", "yourserver/yourdatabase"], "Username" -> "yourusername", "Password" -> "yourpassword"] (in case anyone wants to give it a try). Documentation of DatabaseLink here , by the way. Does anyone have experience using Mathematica in this way, probably to analyze data contained in the database? Are there obvious drawbacks (speed, memory needed, etc.)? I recently used databases to speed up a Manipulate[] block. Without the

Optimally picking one element from each list

会有一股神秘感。 提交于 2019-12-03 02:11:42
I came across an old problem that you Mathematica/StackOverflow folks will probably like and that seems valuable to have on StackOverflow for posterity. Suppose you have a list of lists and you want to pick one element from each and put them in a new list so that the number of elements that are identical to their next neighbor is maximized. In other words, for the resulting list l, minimize Length@Split[l]. In yet other words, we want the list with the fewest interruptions of identical contiguous elements. For example: pick[{ {1,2,3}, {2,3}, {1}, {1,3,4}, {4,1} }] --> { 2, 2, 1, 1, 1 } (Or {3

How to insert a column into a matrix, the correct Mathematica way

可紊 提交于 2019-12-03 02:07:54
问题 I think Mathematica is biased towards rows not columns. Given a matrix, to insert a row seems to be easy, just use Insert[] (a = {{1, 2, 3}, {4, 0, 8}, {7 , 8, 0}}) // MatrixForm 1 2 3 4 0 8 7 8 0 row = {97, 98, 99}; (newa = Insert[a, row, 2]) // MatrixForm 1 2 3 97 98 99 4 0 8 7 8 0 But to insert a column, after some struggle, I found 2 ways, I show below, and would like to ask the experts here if they see a shorter and more direct way (Mathematica has so many commands, and I could have

Abstract algebra and Programming [closed]

為{幸葍}努か 提交于 2019-12-03 01:56:29
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am going to start learning Abstract Algebra- Groups, Rings,etc. I am interested to know any programming language, if at all which can help me learn/try the concepts I learn in theory. EDIT: I am not really looking at implementing what I learn. I am interested to know any language which already supports them. 回答1

Mathematica Module versus With or Block - Guideline, rule of thumb for usage?

你离开我真会死。 提交于 2019-12-03 01:56:12
问题 Leonid wrote in chapter iv of his book : "... Module, Block and With. These constructs are explained in detail in Mathematica Book and Mathematica Help, so I will say just a few words about them here. ..." From what I have read ( been able to find ) I am still in the dark. For packaged functions I ( simply ) use Module, because it works and I know the construct. It may not be the best choice though. It is not entirely clear to me ( from the documentation ) when, where or why to use With ( or

how to generate such an image in Mathematica

此生再无相见时 提交于 2019-12-03 01:51:23
I am thinking of process an image to generate in Mathematica given its powerful image processing capabilities. Could anyone give some idea as to how to do this? Thanks a lot. Brett Champion Here's one version, using a textures. It of course doesn't act as a real lens, just repeats portions of the image in an overlapping fashion. t = CurrentImage[]; (* square off the image to avoid distortion *) t = ImageCrop[t, {240,240}]; n = 20; Graphics[{Texture[t], Table[ Polygon[ Table[h*{Sqrt[3]/2, 0} + (g - h)*{Sqrt[3]/4, 3/4} + {Sin[t], Cos[t]}, {t, 0., 2*Pi - Pi/3, Pi/3} ], VertexTextureCoordinates ->

Import data from URL

偶尔善良 提交于 2019-12-03 01:50:57
The St. Louis Federal Reserve Bank has a great set of data available on a variety of their web pages, such as: http://research.stlouisfed.org/fred2/series/OILPRICE/downloaddata?cid=32217 http://www.federalreserve.gov/releases/h10/summary/default.htm http://research.stlouisfed.org/fred2/series/DGS20 The data sets get updated, some as often as daily. I tend to have an interest in the daily data (see the above settings on the URLS) I'd like to import these kinds of price or rate data streams (accessible as CSV or Excel files at the above URLs) directly into Mathematica. I've looked at the

Importing Google Sketchup models in Mathematica

馋奶兔 提交于 2019-12-03 01:42:47
Google's Sketchup is a nice, simple 3D-object modeler. Moreover Google has an enormous warehouse of 3D objects so that you actually don't have to do much modeling yourself if you aren't particularly gifted in this area. Many of the 3D buildings in Google Earth are made with Sketchup. The capability to import Sketchup's SKP files in Mathematica would be very nice, but alas, it doesn't do that yet. The free version of Sketchup doesn't export to any other formats than the KMZ (Google Earth) and DAE (Collada) formats. Though MMA can read KMZ/KML files it doesn't read those containing 3D objects.

Monitoring progress of a parallel computation in Mathematica

自作多情 提交于 2019-12-03 01:33:34
I'm building a large ParallelTable , and would like to maintain some sense of how the computation is going. For a non parallel table the following code does a great job: counter = 1; Timing[ Monitor[ Table[ counter++ , {n, 10^6}]; , ProgressIndicator[counter, {0, 10^6}] ] ] with the result {0.943512, Null} . For the parallel case, however, it's necessary to make the counter shared between the kernels: counter = 1; SetSharedVariable[counter]; Timing[ Monitor[ ParallelTable[ counter++ , {n, 10^4}]; , ProgressIndicator[counter, {0, 10^4}] ] ] with the result {6.33388, Null} . Since the value of