Tag Info

New answers tagged

4

As mentioned in the comments and as the error message says, FindMaximum only accepts integer domain constraints for linear optimization problems, while of course nx * wx is a non-linear term. For ILP problems, FindMaximum uses a specialized solver from the COIN-OR branch-and-cut (CBC) library. NMaximize is using a different approach.


2

How about NMaximize? NMaximize[{ Min[{funA[1.3, 0.7, x, y], funB[1.3, 0.7, x, y]}], 1 <= x <= 2 && 0 <= y <= 1}, {{x, 1, 2}, {y, 0, 1}}] {0.254965, {x -> 1.55733, y -> 0.775248}} To grab the max, x, and y values to later export, you can try: Clear[x, y]; a = Range[1.3, 2, 0.1]; b = Range[0.7, 1.4, 0.1]; With[{m = ...


3

Perhaps this? Clear[f, g, maxg]; f[y_] := 1 - y g[x_, y_] := x - y maxg[y_?NumericQ] := NMaxValue[{g[x, y], 0 <= x <= 1}, x] NMaximize[{f[y], y >= 0 && maxg[y] <= 1/2}, y] (* {0.500001, {y -> 0.499999}} *) See this answer for more information about the use of NumericQ: What are the most common pitfalls awaiting new users? There ...


1

The use of NumericQ as mentioned by MarcoB and Guess who it is. in the comments seems to be important. Also, estimating the integral using a Total[Table[]] as in the code I posted in the second revision of the question makes this method computational feasible enough to solve my problem.


3

There are three problems with your posted code. Your objective function is a 1x1 matrix rather than a scalar. Your constraint equation is malformed. One side is a 1x1 matrix, the other is a scalar. They should both be scalars. The variables should be in a flat list. @Willinski already gave a more natural way of expressing vectors in Mathematica, so that ...


8

Your corrected code: myVect = {x, y}; offDiag = {{0, 1}, {1, 0}}; Maximize[1/2*myVect.offDiag.myVect, myVect.{2, 2} - 1 == 0, myVect] {1/16, {x -> 1/4, y -> 1/4}}


8

w = RandomReal[{0, 1}, 10]; b = RandomReal[{0.5, 1}, 10]; a = RandomReal[{0, .5}]; rr = Array[r, 10]; Minimize[{w.Log@rr, Thread[a <= rr <= b]}, rr]


1

You have quite a small data set, so a really inefficient brute force search will still run pretty fast (<1 sec on my computer). I stress that this is STUPID way to do it, and with list manipulation you can surely make it MUCH more efficient. But as I said - it works. First, transform the data so that you could retrieve the data by calling f[x1,x2,x3], ...


2

I can't be sure what FindMinimum does. I can only find the various *Monitor options to see what major steps it takes. Then I might only infer, rightly or wrongly, why it does any of these things. I will say that I think it is behaving "correctly" in the sense of "as intended." When all the conditions are "right," the step taken by FindMinimum under ...


1

The calculation, as presented in the question, is ill-posed in that the maximum value is infinity for w1 or w2 equal to zero and the corresponding a not equal to zero. Bounding the ws away from zero and making a few other changes, as shown here, produces an answer. MaxValue[{-a2*Log2[w2] - a1*Log2[w1], 0.01 <= w1 <= q, 0.01 <= w2 <= q, 0 ...


3

As the Norm is positive, you don't really need the constraint to determine one minimum for p and t: nm = NMinimize[{ (Norm[{xm[t][p], ym[t][p]} - {xsc[t][p], ysc[t][p]}] - 10^7)^2 /. Soln, TOF - 10 (86400) < t < TOF + 10 (86400) && 0.8 < p < 1}, {t, p}, Method -> "NelderMead"] (* {0.000155262, ...


1

Here is my quick answer. Import the data from the files: files = FileNames["/sample_data/1_5ormore_methy_00*"]; data = Import[#, "Table"] & /@ files; Define a function to compute your values: f[s1_, s2_, vals_] := Times @@ (Beta[First@# + s1, Last@# + s2] & /@vals)/Beta[s1, s2]^Length@vals Apply the function to the data for each of the ...


2

As noted by the OP, adding the constraint, Norm[{xm[t][p], ym[t][p]} - {xsc[t][p], ysc[t][p]}] > 10000000 /. Soln triggers error messages, probably because p typically must be given a numerical value before t is given one in expressions such as xm[t][p]. See the documentation for ParametricFunction. This can be accomplished by defining ...


1

Of course this is possible. But I suggest that you break the problem down in smaller steps. Let's start with the problem of reading many files. If you have them in one directory, it can be as simple as files = FileNames["a*"]; data = Import[#,"Table"] &/@ files; This fills the list data with sub-lists, that contain the data n each file. Now you ...


6

As @Guess who it is. states in the comments, an overdetermined linear problem can be solved using Mathematica's LeastSquares[] functionality. To input your above system of equations: a = {{1, -2, 2, 2, 0, -2}, {1, -2, 2, -2, 0, 2}, {1, -2, -2, -2, -4, -2}, {1, 2, 2, -2, -4, -2}, {1, 2, -2, -2, 0, 2}, {1, 2, -2, 2, 0, -2}, {1, -2, -2, 2, 4, ...


3

A stupid workaround is simply to replace b with -b: q[a_?NumericQ, b_?NumericQ] := NIntegrate[Exp[a*(x^2 - 1) - b*(x^4 - 3.1)], {x, -Infinity, Infinity}]; yy = FindMinimum[{q[a, b], b > 0}, {{a, -2}, {b, .004}}] {4.13273, {a -> -0.5, b -> 8.27074*10^-8}} without any warnings. But it's a pity that FindMinimum behaves so inflexibly. Of ...


3

Integrate[Exp[a*(x^2 - 1) + b*(x^4 - 31/10)], {x, -Infinity, Infinity}] ConditionalExpression[ (Sqrt[-a]*E^(-a - a^2/(8*b) - (31*b)/10)* BesselK[1/4, -(a^2/(8*b))])/(2*Sqrt[-b]), Re[b] < 0 && Re[a] < 0] qExact[a_, b_] = Assuming[{a < 0, b < 0}, Integrate[Exp[a*(x^2 - 1) + b*(x^4 - 31/10)], {x, -Infinity, ...


2

The random functionality within Mathematica is all of a pattern: RandomFunction[range, outputStructure] where range depends on what RandomFunction you are using, e.g. for RandomInteger and RandomReal it is {min, max} and they both default to {0,1} if no min/max are supplied. The outputStructure tells the RandomFunction how many random numbers you want and ...


2

If you want to teach the students to interpret level sets, then it is possible visualize the behavior of a function by manipulating the level. There are various ways to set it up, to cue the students' recognition of the type of extremum, etc. Here's one, whipped up rather quickly. Clear[f, x, y, z]; f = x^3 + x z^2 - 3 x^2 + y^2 + 2 z^2 cpts = {x, y, z} /. ...


2

You can visualise a function of 3 paramters by putting one of them as argument of Manipulate: Manipulate[Plot3D[f /. z -> z1, {x, -3, 3}, {y, -3, 3}], {z1, -3, 3}]


5

another test: f = x^3 + x*z^2 - 3*x^2 + y^2 + 2*z^2; cpts = Solve[Grad[f, {x, y, z}] == 0, {x, y, z}, Reals] {{x -> 0, y -> 0, z -> 0}, {x -> 2, y -> 0, z -> 0}} hesse = D[f, {{x, y, z}, 2}] /. cpts {{{-6, 0, 0}, {0, 2, 0}, {0, 0, 4}}, {{6, 0, 0}, {0, 2, 0}, {0, 0, 8}}} {ev1[l1,l2,l3], ev2[l1,l2,l3]} = Eigenvalues /@ hesse {{-6, 4, ...


0

How about approaching the minization using derivatives? Solve[D[a^2*Exp[-b^2], a] == 0, a] {{a -> 0}}


3

This expression, designated exp for convenience, can be simplified substantially as follows. num = Map[FullSimplify[#] &, Numerator[exp]]; Map[FullSimplify[#, θ[_] ∈ Reals && ϕ[_] ∈ Reals] &, Denominator[exp] /. Abs[z_]^2 :> FullSimplify[Abs[z]^2, θ[_] ∈ Reals && ϕ[_] ∈ Reals]; /. Abs[z_]^2 :> z^2] den = ...


4

I get good result with v10.2 0n my Mac $Version "10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)" A = 10; a2 = 2; h2 = 1; b2 = 2; d2 = 1850; L2 = 5/100; \[Sigma]2 = 500; c2 = Which[0 < d2*T <= 50, 15/2, 50 < d2*T <= 200, 11/2, 200 < d2*T <= 400, 1/2, 400 < d2*T <= 500, 5/2, 500 < d2*T, 1, True, 1]; f[k_, T_] = A/T + ...



Top 50 recent answers are included