13

Here's an implementation of interval complement that is meant to be used with Interval expressions. Interval represents closed intervals according to the documentation, and this is consistent with the things the built-in functions do with intervals. However, in this implementation of the interval complement I simply ignore whether an interval is open or ...


10

A possible cause of a mental block in this scenario is to think that we need to find a way to include all numbers that are infinitely close to our endpoints. Since we are working on a computer though our numbers are not continuous, so we are actually dealing with a discrete set of numbers. What we need to do is create a new interval where the boundaries are ...


8

A possible approach for dependent intervals: Interval@*Through@{MinValue, MaxValue}[u + u^2, {u} ∈ Interval[{-100, 100}]] (* Interval[{-(1/4), 10100}] *)


8

int = {{3, 7}, {17, 43}, {64, 70}}; com = Partition[#, 2]& @ {1, Sequence @@ Riffle[int[[All, 1]] - 1, int[[All, 2]] + 1], 100} {{1, 2}, {8, 16}, {44, 63}, {71, 100}} NumberLinePlot[{Interval @@ int, Interval @@ com}, PlotTheme -> "Detailed"]


6

If you do not bother about the endpoints, you could define a complement function in the following way: complement[x_Interval] := Interval @@ Partition[Flatten[{-\[Infinity], List @@ x, \[Infinity]}], 2] complement[Interval[{1,2}]] (* Interval[{-\[Infinity],1},{2,\[Infinity]}]*) complement[Interval[{1,2},{3,4}]] (*Interval[{-\[Infinity],1},{2,3},{4,\[...


5

I voted once to close this question as OP gave us not enough information about what is the desired output and the context. Since I can't vote to close the second time I decided to write something :) Couple of thoughs at the begining. First of all, I'd use Reduce to deal with this problem and convert only the result. But if you ask I find it a good ...


5

u = Interval[{-100, 100}] According to ref / Interval / Possible Issues Intervals are always assumed independent so u + u^2 is something like v + u ^ 2 -> Interval[{-100, 100}] + Interval[{0, 10000}]. What can also be surprising, is the fact it is different from u + u * u which we can think of as v + u * w. I the first example u^2 is at least 0 but ...


5

I believe this has to do with the fact that intervals "grow" just a bit on evaluation with machine numbers to ensure that values at the endpoint will be included in the interval. NestList[Interval @@ # &, Interval[{0., 1.}], 5] // InputForm (* {Interval[{-2.2250738585072014*^-308, 1.0000000000000002}], Interval[{-4.450147717014403*^-308, 1....


5

This is not a complete solution but it may help. Manipulate[ Graphics[{{Circle[{0, -1}, 1]}, {Blue, Disk[{0, -1}, 1, {ArcTan[1/b], ArcTan[1/a]}]}, {Blue, Disk[{0, -1}, 1, \[Pi] + {ArcTan[1/b], If[b < 0, \[Pi], 0] + ArcTan[1/a]}]}, {Green, Line[{{{a, 0}, {0, -1}}, {{b, 0}, {0, -1}}}]}}, Frame -> True, PlotRange -> {{-...


5

Yes, this is perfectly possible. In fact, there are multiple ways to do this. The most straightforward is to use DeleteCases, as @kale points out in the comments: interval = Interval[ {2894486400, 2894486400}, {2894659200, 2894832000}, {2895004800, 2895004800}, {2895177600, 2895350400} ]; DeleteCases[interval, {x_, x_}] Interval[{2894659200, ...


5

I would argue that all of your questions apply to any statistical regression package and the answers are all about statistical regression analysis concepts rather than Mathematica. With NonlinearModelFit you are fitting the model $$y(t)=p_0+p_1 \cos{(2 \pi t/365+\phi)}+\epsilon_t$$ with independent and identically distributed errors where $\epsilon_t \sim ...


5

sol1 = -2.11198 < x < 0. || 0. < x < 0.372591; sol2 = x < -2.11198 || x > 0.372591; region1 = List @@ (ImplicitRegion[#, x] & /@ sol1); region2 = List @@ (ImplicitRegion[#, x] & /@ sol2); rb1 = First @ RegionBounds[#]& /@ region1 {{-2.11198, 0.}, {0., 0.372591}} rb2 = First @ RegionBounds[#]& /@ region2 {{-∞, -2....


5

Clear["Global`*"] ArgMin[x^2, x ∈ Interval[{1, 2}]] (* ArgMin::objfs: The objective function {Subscript[x, 1]^2} should be scalar-valued. ArgMin[x^2, x ∈ Interval[{1, 2}]] *) The subscript in the error message indicates that it was expecting a vector. Use ArgMin[x^2, {x} ∈ Interval[{1, 2}]] (* 1 *) For the second example, P = {-2, -1, 1, 2}; RegionQ[...


5

Clear["Global`*"] p[x_] := -(16/81) + (2438 x)/405 - (218719 x^2)/8100 + (1111463 x^3)/ 21600 - (79331 x^4)/1600 + (4779 x^5)/200 - (459 x^6)/ 100 - (16/81) + (2438 x)/405 - (218719 x^2)/8100 + (1111463 x^3)/ 21600 - (79331 x^4)/1600 + (4779 x^5)/200 - (459 x^6)/100; The function is negative in the intervals neg = Reduce[p[x] < 0, ...


4

intervalsA = {{1, 2}, {3, 4}, {5, 7}, {8, 8.5}}; intervalsB = {{1.5, 3.5}, {4.1, 6}, {9, 10}}; IntervalIntersection @@ Interval @@@ {intervalsA, intervalsB} Interval[{1.5, 2}, {3, 3.5}, {5, 6}]


4

I think there is a bug with Interval. What I find for this moment: $$ \begin{array} {c|c|c|c} \text{Function} & \text{Interval} & \text{Result} & \text{Should be}\\ \hline \text{UnitStep} & [-4,5] & [0,1] & [0,0],[1,1]\\ \text{Sign} & [0,1] & [-1,1] & [0,0],[1,1]\\ \text{Round} & [0,2] & [0,2] & [0,0],[1,1],[...


4

For version 10 you might use: interval ~Select~ DuplicateFreeQ Interval[{2894659200, 2894832000}, {2895177600, 2895350400}] For other versions alternatives to DeleteCases include: Select[interval, UnsameQ @@ # &] Pick[#, UnsameQ @@@ #] & @ interval Benchmarks As requested: generate[n_] := Sort @ RandomInteger[n, ⌊.7n⌋] ~Partition~ 2 // ...


4

I can't say how to fix it, but the explanation is simple: IntervalMemberQ[Interval[{0, Pi/2}], x] for the symbolic x immediately returns False, so your statements are: Reduce[ whatever && False , x ] (* False *) and Reduce[Equivalent[0 <= x <= Pi/2, False], x] which is the same as : Reduce[! (0 <= x <= Pi/2), x] hence x &...


4

A different way to go that captures more information than merely the intervals is: result = TransformedDistribution[x^2 + x, Distributed[x, UniformDistribution[{-100, 100}]] ]; Plot[Evaluate[PDF[result, x]], {x, -1, 1}] (* Discover that the likelihood of various results is not uniform. *) Interval[{ Minimize[{x, #}, x, Reals][[1]], Maximize[{x, #}, x, ...


4

You can use a custom Piecewise function for the plotting, Plot[Evaluate[ Table[Piecewise[{{y[b][x], x <= b}}, Null] /. sol, {b, {0.3, 0.2, 0.1}}]], {x, 0, 0.3}]


4

A new and mostly rewritten version of the original answer which was flawed. See edit history if interested. As any operation making $MaxNumber higher (more precisely: higher enough for its Precision to notice) results in an overflow, the Interval created here has the form Interval[{$MaxNumber - something small, Overflow[]}] The "something small" is ...


4

I was just inspired by @kglr to illustrate: f[x_] := 1/1000 x^4 - 280/1000 x^2 + 25; sim[a_, b_, n_] := With[{u = RandomVariate[UniformDistribution[{a, b}], n]}, {#, f@#} & /@ u]; Manipulate[ Module[{res = sim[a, b, n], mn = Integrate[f[x], {x, a, b}]/(b - a)}, Show[Plot[f[x], {x, a, b}], ListPlot[res, PlotStyle -> Red], GridLines -&...


4

First, your xDates and xCaptions are not correctly formatted: you have to get rid of the outer square brackets: xDates = {{{1999, 03, 11}, {2000, 09, 11}}, {{2011, 09, 11}, {2012, 05, 6}}, {{2012, 06, 14}, {2014, 02, 12}}, {{2014, 04, 14}, {2015, 09, 11}}}; xCaptions = Flatten@{{"Abc"}, {"Def"}, {"Ghi"}, {"Jkl"}}; Additionally, Flatten the original ...


4

Reduce[{4 Sin[θ]^2 == 1 + 4 Cos[θ], 0 <= θ < 2 π}] (* θ == π/3 || θ == (5 π)/3 *) Solve[{4 Sin[θ]^2 == 1 + 4 Cos[θ], 0 <= θ < 2 π}] (* {{θ -> π/3},{θ -> (5 π)/3}} *)


4

ConditionalExpression[] seems suited for this. Note the use of MapThread[] for incorporating both the numbers and the intervals, as well as the increased PlotPoints setting. vals = {1.17, 1.38, 1.56, 2.34, 2.9, 4.12, 4.76}; ints = {{50*^-9, 100*^-9}, {45*^-9, 90*^-9}, {40*^-9, 80*^-9}, {32*^-9, 70*^-9}, {23*^-9, 50*^-9}, {21*^-9, 40*^-9}, {19*^-9, ...


4

With list = {{2.5285, 2.54381}, {1.77463, 1.0246}, {1.30668, 1.31949}, {0.986982, 1.78699}, {1.71224, 0.00986564}, {0.733888, 0.768184}, {0.0570823, 1.71373}}; Try: Select[VectorQ[#, 0 <= # <= 1 &]&]@ list (* Out: {{0.733888, 0.768184}} *) You could wrap this in a function for convenience and to change the upper limit: Clear[...


4

I will present two solutions, a hard (and not quite complete) one and an easy (but undocumented) one. First, the hard one. Use Interval[real] to determine the default widening. Consider: r = 1.23`2; (int = Interval[r]) //InputForm Interval[{1.214375`1.9944477065044612, 1.245625`2.0054822046051672}] Note how an Interval object is created that includes ...


4

You can use region functionality for this. 10-dimensional hypercube (trivial): RegionMeasure @ Cuboid[-ConstantArray[1, 10], ConstantArray[1, 10]] 1024 10-dimensional hyperball: RegionMeasure @ Ball[ConstantArray[0, 10]] π^5/120


3

You might try List @@ (Drop[#, {2, -2}]& /@ List @@@ Reduce[Sin[x] < 1/2 && 0 < x < 2 π, x]) {{0, π/6}, {(5 π)/6, 2 π}}


3

Note that foo = Reduce[{ Sin[x] < 1/2, 0 <= x <= 2 π }, x, Reals] (* 0 <= x < π/6 || (5 π)/6 < x <= 2 π *) almost gives you what you want. We can rewrite this to be in interval form, ineqsToIntervals[x_Or] := List @@ ( x /. { Inequality[a_, Less, _, Less, b_] :> Row[{"(", a, ",", b, ")"}], ...


Only top voted, non community-wiki answers of a minimum length are eligible