wolfram-mathematica

Is there a “normal” EqualQ function in Mathematica?

廉价感情. 提交于 2019-11-30 11:54:53
问题 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

Optional named arguments without wrapping them all in “OptionValue”

天大地大妈咪最大 提交于 2019-11-30 10:11:19
Suppose I have a function with optional named arguments but I insist on referring to the arguments by their unadorned names. Consider this function that adds its two named arguments, a and b: Options[f] = {a->0, b->0}; (* The default values. *) f[OptionsPattern[]] := OptionValue[a] + OptionValue[b] How can I write a version of that function where that last line is replaced with simply a+b ? (Imagine that that a+b is a whole slew of code.) The answers to the following question show how to abbreviate OptionValue (easier said than done) but not how to get rid of it altogether: Optional named

Circular/Angular slider

点点圈 提交于 2019-11-30 09:55:56
A recent SO question reminded me of some code I tried to write a while back. The aim is to make a CircularSlider[] object that can be used for angle-like variables in dynamic objects. The framework for my solution (below) comes from the ValueThumbSlider[] defined in the Advanced Manipulate Functionality tutorial. The main difference is that in ValueThumbSlider[] the value of the slider and the position of the LocatorPlane[] are the same thing, whilst in my CircularSlider[] they are not - and this leads to problems. The first problem is that moving the Locator will not change the slider value.

Why doesn't RuleDelayed hold Unevaluated?

时光怂恿深爱的人放手 提交于 2019-11-30 09:27:20
The Mathematica 's evaluator generally holds (or restores?) Head s Unevaluated of expressions supplied as arguments for Symbol s: In[1]:= f[s, Unevaluated[1 + 1]] Out[2]= f[s, Unevaluated[1 + 1]] In[5]:= Trace[f[s,Unevaluated[1+1]],TraceOriginal->True] Out[5]= {f[s,Unevaluated[1+1]],{f},{s},f[s,1+1],f[s,Unevaluated[1+1]]} But it is not true for RuleDelayed . Moreover, any number of Unevaluated wrappers are stripped in the case of RuleDelayed : In[1]:= Attributes@RuleDelayed RuleDelayed[s, Unevaluated[1 + 1]] RuleDelayed[s, Unevaluated@Unevaluated[1 + 1]] RuleDelayed[s, Unevaluated@Unevaluated

How to create a function directly from the output of Solve

混江龙づ霸主 提交于 2019-11-30 09:09:29
If I evaluate Solve[f[x,y]==0,x] , I get a bunch of solutions like: {{x -> something g[y]}, {x -> something else}} , etc. Now I want to convert each of those x->somethings into a function. Typically, my requirements are low, and my function f[x] is at the most a cubic, with straightforward solutions for x . So I've always just defined g1[y_]:=something , g2[y_]:=... etc, manually. However, for a function that I have now, Solve outputs a complicated polynomial running 4 pages long, and there are 4 such solutions. I've tried reducing to simpler forms using Simplify , Collect , Factor etc, but it

Known issues with copying code from Mathematica to other platforms?

假装没事ソ 提交于 2019-11-30 09:00:20
I just noticed that if you have this in MMA (8.0.1 / win7-64): and you copy it to SO (just ctrl-c ctrl-v), you get this: (maxY - minY)/stepy/(maxX - minX)/stepx which is not mathematically equivalent . It should be this: ((maxY - minY)/stepy)/((maxX - minX)/stepx) or this (the InputForm of the above): ((maxY - minY)*stepx)/((maxX - minX)*stepy) It's not caused by StackOverflow's internals as the same happens with a copy to NotePad. Are there more issues like this (especially when working with SO, but also in general) that we should be aware of? What causes this, can it be fixed on our side,

How to perform a complicated change of variables for a polynomial (in Mathematica)

邮差的信 提交于 2019-11-30 08:40:36
I have an integer polynomial in four variables (w, x, y, and z) that I know can be written as an integer polynomial in these six variables: a = w z b = x y c = w^3 + z^3 d = x + y e = w^3 x + y z^3 f = w^3 y + x z^3 How can I use Mathematica (or maybe Java) to easily do this change of variables? Daniel Lichtblau Such rewriting can be done by forming a Groebner basis of the replacement polynomials, with respect to a variable order that favors using a-f over w-z. Then use PolynomialReduce with respect to the same order to rewrite your polynomial. Here is an example. I'll start with replacement

Adaptive gridlines

馋奶兔 提交于 2019-11-30 08:33:11
问题 I want to use gridlines to create an effect of millimeter graphing paper on a 2d graph, to show how multi-variable function depends on 1 variable. The scales of different variables differ a lot, so my naive approach (that I have used before) does not seem to work. Example of what I have at the moment: << ErrorBarPlots` Cmb[x_, y_, ex_, ey_] := {{N[x], N[y]}, ErrorBar[ex, ey]}; SetAttributes[Cmb, Listable]; ELP[x_, y_, ex_, ey_, name_] := ErrorListPlot[ Cmb[x, y, ex, ey], PlotRange -> FromTo[x

Determine the position of a point in 3D space given the distance to N points with known coordinates

久未见 提交于 2019-11-30 07:56:25
I am trying to determine the (x,y,z) coordinates of a point p. What I have are the distances to 4 different points m1, m2, m3, m4 with known coordinates. In detail: what I have is the coordinates of 4 points (m1,m2,m3,m4) and they are not in the same plane: m1: (x1,y1,z1), m2: (x2,y2,z2), m3: (x3,y3,z3), m4: (x4,y4,z4) and the Euclidean distances form m1->p, m2->p, m3->p and m4->p which are D1 = sqrt( (x-x1)^2 + (y-y1)^2 + (z-z1)^2); D2 = sqrt( (x-x2)^2 + (y-y2)^2 + (z-z2)^2); D3 = sqrt( (x-x3)^2 + (y-y3)^2 + (z-z3)^2); D4 = sqrt( (x-x4)^2 + (y-y4)^2 + (z-z4)^2); I am looking for (x,y,z). I

Find root of implicit function in Mathematica

只愿长相守 提交于 2019-11-30 07:47:19
Find root of implicit function in Mathematica I have an implicit function, for example: f(x,y) = x^3 + x*y + y^2 - 36 I want to find the root, ie solutions to the equation f(x,y) = 0 Drawing the solution is easy: ContourPlot[x^3 + x*y + y^2 - 36 == 0, {x, -2 Pi, 2 Pi}, {y, -3 Pi, 3 Pi}] however I would like to have the data that is in the plot and not only the visual plot. So how do I find the data of the plot? tomd I'm not sure if I am interpreting your second question properly, but assuming you require a list of (x,y) points from the generated ContourPlot, one way of doing this might be the