wolfram-mathematica

Return equality from Mathematica function

£可爱£侵袭症+ 提交于 2019-12-31 04:28:06
问题 I have a function that returns equalities, which I want to print, for example, x==y, or 2x+5==10. These usually have no meaning for mathematica, it cannot simplify it furhter. However, sometimes the both sides are equal, but I want to be able to print the equality in unevaluated form: that is, I want Mathematica to print x==x, and not True. A very simple example: Print[printableEqual[x,y]] should print x==y, while Print[printableEqual[x,x]] should print x==x Edit: The reason is that I have a

picking specific symbol definitions in mathematica (not transformation rules)

一笑奈何 提交于 2019-12-30 08:52:36
问题 I have a following problem. f[1]=1; f[2]=2; f[_]:=0; dvs = DownValues[f]; this gives dvs = { HoldPattern[f[1]] :> 1, HoldPattern[f[2]] :> 2, HoldPattern[f[_]] :> 0 } My problem is that I would like to extract only definitions for f[1] and f[2] etc but not the general definition f[_], and I do not know how to do this. I tried, Cases[dvs, HoldPattern[ f[_Integer] :> _ ]] (*) but it gives me nothing, i.e. the empty list. Interestingly, changing HoldPattern into temporary^footnote dvs1 =

How is the BarSpacing option really implemented in Mathematica?

不问归期 提交于 2019-12-30 06:24:27
问题 I'm trying to implement a DateListBarChart function that takes dated data and outputs a bar chart with the same placements as DateListPlot . It's essential that they plot data in the same horizontal position if given the same data, so they can be combined using Show . I am finding it difficult to get the settings for BarSpacing right so that the horizontal range of the plot doesn't change, and the bars stay in essentially the same place. I have been unable to infer the correct scaling so that

Command completion in mathematica : suggest rules/options

安稳与你 提交于 2019-12-30 04:20:08
问题 In current version of Mathematica these keyboard shortcuts are quite handy Ctrl+K completes current command GraphPl -> press Ctrl+K -> GraphPlot Ctrl+Shift+K completes current command and adds argument placeholders which could be replaced with actual values with tab key GraphPl -> press Ctrl+Shift+K -> GraphPlot[{vi1->vj1,vi2->vj2,...}] However I couldn't find any keyboard option to show associated settings/options For instance Say If I need to plot a graph with different layouts, I know I

Question on “smart” replacing in mathematica

跟風遠走 提交于 2019-12-30 02:25:09
问题 How do I tell mathematica to do this replacement smartly? (or how do I get smarter at telling mathematica to do what i want) expr = b + c d + ec + 2 a; expr /. a + b :> 1 Out = 2 a + b + c d + ec I expect the answer to be a + cd + ec + 1 . And before someone suggests, I don't want to do a :> 1 - b , because for aesthetic purposes, I'd like to have both a and b in my equation as long as the a+b = 1 simplification cannot be made. In addition, how do I get it to replace all instances of 1-b , -b

Find the largest rectangular block satisfying some condition without iterating explicitly

一个人想着一个人 提交于 2019-12-30 02:10:21
问题 I have a few large 2D arrays like: 1 2 3 4 5 -------------- 1 | 0 1 1 1 0 2 | 0 1 1 1 0 3 | 0 1 0 1 1 4 | 0 1 0 1 1 So, the largest rectangular block (by area) satisfying ==1 starts at (1,2) and its dimensions are (2,3). How to find it with Mathematica without iterating explicitly? NB: Just to ease your testing here is one of my samples: matrix = ImageData@Binarize@Import@"http://i.stack.imgur.com/ux7tA.png" 回答1: This is my attempt using BitAnd maxBlock[mat_] := Block[{table, maxSeq, pos},

Why won't this work? Dynamic in a Select

十年热恋 提交于 2019-12-29 18:00:23
问题 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. 回答1: 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;

How to make ImageTransformation produce an anamorphic version of image

随声附和 提交于 2019-12-29 06:49:13
问题 I'm experimenting with the ImageTransformation function to try to make anamorphic versions of images, but with limited progress so far. I'm aiming for the results you get using the image reflected in a cylindrical mirror, where the image curves around the central mirror for about 270 degrees. The wikipedia article has a couple of neat examples (and I borrowed Holbein's skull from them too). i = Import["../Desktop/Holbein_Skull.jpg"]; i = ImageResize[i, 120] f[x_, y_] := {(2 (y - 0.3) Cos [1.5

custom function with non-standard evaluation (behaves like Table)

被刻印的时光 ゝ 提交于 2019-12-29 06:30:49
问题 I'd like a function AnyTrue[expr,{i,{i1,i2,...}}] which checks if expr is True for any of i1,i2... It should be as if AnyTrue was Table followed by Or@@% , with the difference that it only evaluates expr until first True is found. Short-circuiting part is optional, what I'd really like to know is the proper way to emulate Table 's non-standard evaluation sequence. Update 11/14 Here's a solution due to Michael, you can use it to chain "for all" and "there exists" checks SetAttributes[AllTrue,

Implementing a Quadtree in Mathematica

*爱你&永不变心* 提交于 2019-12-29 02:24:09
问题 I have implemented a quadtree in Mathematica. I am new to coding in a functional programming language like Mathematica, and I was wondering if I could improve this or make it more compact by better use of patterns. (I understand that I could perhaps optimize the tree by pruning unused nodes, and there might be better data structures like k-d trees for spatial decomposition.) Also, I am still not comfortable with the idea of copying the entire tree/expression every time a new point is added.