wolfram-mathematica

PatternTest not optimized?

笑着哭i 提交于 2019-12-07 00:51:51
问题 In preparing a response to An unexpected behavior of PatternTest in Mathematica I came across an unexpected Mathematica behavior of my own. Please consider: test = (Print[##]; False) &; MatchQ[{1, 2, 3, 4, 5}, {x__?test, y__}] During evaluation of In[1]:= 1 During evaluation of In[1]:= 1 During evaluation of In[1]:= 1 During evaluation of In[1]:= 1 False Since, as Simon's quote of the documentation concisely states: In a form such as __?test every element in the sequence matched by __ must

An efficient data structure or method to manage plotting data that grow with time

你离开我真会死。 提交于 2019-12-07 00:47:05
问题 I'd like to ask if the following way I manage plotting result of simulation is efficient use of Mathematica and if there is a more 'functional' way to do it. (may be using Sow, Reap and such). The problem is basic one. Suppose you want to simulate a physical process, say a pendulum, and want to plot the time-series of the solution (i.e. time vs. angle) as it runs (or any other type of result). To be able to show the plot, one needs to keep the data points as it runs. The following is a simple

Redefine Noncommutative Multiplication in Mathematica

巧了我就是萌 提交于 2019-12-07 00:34:49
问题 Mathematicas NonCommutativeMultiply (**) does not simplify terms like a**0=0**a=0 a**1=1**a=a or a**a=a^2. I would like to redefine ** to do this. I was using NCAlgebra to do this but I need ReplaceRepeated (//.) and NCAlgebra, as their documentation says, specifically breaks this functionality in mathematica. Can some show me how to Clear the attributes of ** and redefine this multiplication do the same things it would normal do plus dealing with 1 and 0. I really do not need the

How can I make Mathematica kernel pause for an external file creation

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 21:44:09
问题 Is it possible to pause Mathematica kernel during a computation? Here is an example. Module[{}, Mathematica code.... .......... .......... { Calls an external program with some argument Needs to wait for an external program to create a file (* How ?*) } Mathematica code using that file content.... ........... ........... ] I can come up with a Do[..] loop solution that keeps on checking in a specified directory whether a file is created or not. Once it finds the file it reads the content and

histogram without vertical lines in Mathematica

随声附和 提交于 2019-12-06 19:21:12
问题 I am trying to make an histogram without vertical lines. I'd like to have a plot which looks like a function. Like this: The same question has been asked for R before ( histogram without vertical lines ) but I'm on Mathematica. I have been looking into the ChartStyle options without success. 回答1: There probably are ways to do this by fiddling with EdgeForm[] and FaceForm[] in Histogram , but I've found it simpler to roll one on my own, whenever I need it. Here's a very simple and quick

Combining Lists of Word Frequency Data

家住魔仙堡 提交于 2019-12-06 19:18:11
问题 This seems like it should be an obvious question, but the tutorials and documentation on lists are not forthcoming. Many of these issues stem from the sheer size of my text files (hundreds of MB) and my attempts to boil them down to something manageable by my system. As a result, I'm doing my work in segments and am now trying to combine the results. I have multiple word frequency lists (~40 of them). The lists can either be taken through Import[ ] or as variables generated in Mathematica.

how to output the data set when using histogram in mathematica

落爺英雄遲暮 提交于 2019-12-06 15:54:10
In Mma, the Histogram function only generates graphics. I am wondering how I can to get the data set; is there any convenient built-in function for this? Many thanks. HistogramList was added to Mathematica V8 to expose the binning and height calculations. HistogramList[a] For V7 you can hack the third argument to get the bins and counts. Histogram[a, Automatic, (Print[{##}]; #2) &] Perhaps a bit of internet searching would help as well. This was my answer (of June 18, 2010) to a similar question in the Mathematica newsgroup comp.soft-sys.math.mathematica: data = RandomReal[NormalDistribution[0

posmax: like argmax but gives the position(s) of the element x for which f[x] is maximal

旧时模样 提交于 2019-12-06 12:43:40
Mathematica has a built-in function ArgMax for functions over infinite domains, based on the standard mathematical definition . The analog for finite domains is a handy utility function. Given a function and a list (call it the domain of the function), return the element(s) of the list that maximize the function. Here's an example of finite argmax in action: Canonicalize NFL team names And here's my implementation of it (along with argmin for good measure): (* argmax[f, domain] returns the element of domain for which f of that element is maximal -- breaks ties in favor of first occurrence. *)

Definition lookup speed: a performance issue

天涯浪子 提交于 2019-12-06 12:41:42
问题 I have the following problem. I need to build a very large number of definitions(*) such as f[{1,0,0,0}] = 1 f[{0,1,0,0}] = 2 f[{0,0,1,0}] = 3 f[{0,0,0,1}] = 2 ... f[{2,3,1,2}] = 4 ... f[{n1,n2,n3,n4}] = some integer ... This is just an example. The length of the argument list does not need to be 4 but can be anything. I realized that the lookup for each value slows down with exponential complexity when the length of the argument list increases. Perhaps this is not so strange, since it is

Getting current context from within Package

空扰寡人 提交于 2019-12-06 12:11:46
I had something like the following in my notebook. test1[g_] := (g == 5); test2[g_] := (g == 6); tests={"test1", "test2"} ToExpression[#][5] & /@ tests When I put this code in a package it doesn't work because test1 is now called MyPackage'Private'test1 . How can I modify the last line to make this code run both inside package and inside notebook? Update Here's why I was doing doing ToExpression as opposed to using Symbols. In retrospect, maybe it's easier to use Symbols instead I had a function which I call like getGraphs["LeafFree","Planar",!"Tree",...] to get all graphs that are leaf free,