Tag Info

New answers tagged

6

One can do it in five lines of code and ~0.02 seconds: n = 11; w = 7 | 8 | 9; parts = Pick[#, #.weights Product[1 - Times@@Transpose@#[[;;,c]], {c, constraints}], w] &@ Tuples[{0, 1}, n]; cliques = FindClique[#, ∞, All] &@ AdjacencyGraph[1 - Unitize[parts.Transpose@parts]]; subsets = Pick[Range@n, #, 1] & /@ parts; num = Length /@ subsets; ...


1

Edit - oops I see this is conceptually the same as Martin's.. A little different brute force approach: start by finding all subsets that meet the restrictions: constraints = {{11, 2}, {11, 3}, {11, 4}, {11, 6}, {11, 9}, {1, 6}, {5, 6}, {2, 5}}; weights = {3, 7, 3, 2, 4, 2, 2, 2, 3, 2, 1}; subsets = Select[ Subsets[Range[11], 5] , 7 <= ...


5

I think there's no generally efficient way to do this, since you can always choose the constraints such that they don't restrict anything, in which case you want to find all possible subset partitions. That being said, there's almost certainly a better approach than mine, but it works, and solves your example input in a second or so. Let's go: constraints ...


5

This may help to indicate what goes wrong. steffensenMethodB[ func_, {a_?NumericQ, b_?NumericQ}, ε_?NumericQ] := Module[{φ, ini = First@biSection[func, {a, b}, .5*10^-3], f, g}, φ[x_] := x + func[x]; f[x_] := -(φ[x] - x)^2; g[x_] := (φ[φ[x]] - 2 φ[x] + x); NestWhileList[(Print[{#, f[#], g[#]}]; # + f[#]/g[#]) &, ini, Abs[#1 - #2] > ε ...


6

1. Bisection algorithm The algorithm itself is fairly straightforward and "fast" in some sense: the number of iterations is roughly Log2 of the ratio of the initial interval length and the desired accuracy. My point is that the time spent by Flatten, Select, Thread, etc. in your function is fairly small. The significant time-waster is reevaluating the ...


4

In the following well known implementation of biSection, the use of shrinkInterval not needed. Of course your \[Xi] has to be positive. My condition on the input is a little bit stronger and makes the use of NumericQ superfluous. biSection[ func_, {a_, b_}, g_?Positive] /; func[a]func[b]<0 := Module[ {c, d, e}, {c,d}= If[func[a]>0, {b,a}, ...



Top 50 recent answers are included