# Tag Info

0

I found the solution on another website "http://eternaldisturbanceincosmos.wordpress.com/2011/04/27/nminimize-in-mathematica-could-drive-you-insane/" which says "It turns out that NMinimize does not hold its arguments. This means that as the list of arguments is read from left to right, each argument is evaluated and replaced by the result of the ...

0

I found the solution on another website "http://eternaldisturbanceincosmos.wordpress.com/2011/04/27/nminimize-in-mathematica-could-drive-you-insane/" which says "It turns out that NMinimize does not hold its arguments. This means that as the list of arguments is read from left to right, each argument is evaluated and replaced by the result of the ...

3

There are two things that can be done to improve matters. One is to use constraints with weak inequalities that keep the log arguments above a minmium threshold. The other is to use an altered logarithm that allows argumens less-equal to zero and simply returns a suitable large negative. T = 10; J1 = 1; J2 = -0.2; bigValue = 10^6; myLog[x_?NumberQ] := If[x ...

1

Mathematica Learning Center has a nice tutorial about Constrained Optimization and Unconstrained Optimization available in ebook format (PDF). You can find more resources in the learning center if you search for "numerical optimization".

6

Collecting some links to useful resources from the comments: The documentation has a section on global optimization which has a short section devoted to each method. Presentation about NMinimize available on the Wolfram Library Archive: Numerical Optimization in Mathematica: An Insider's View of NMinimize NumericalMath`NMinimize: A New Standard Package ...

3

It is equivalent to minimize the absolute values. This can be set up as an explicit linear programming problem. The advantage over the approach of @bobthechemist (which is good, and I voted up) is that the problem can then be shipped to special case LP code. vars = Array[x, d2]; linearexprs = mat.vars - vec; constraints = Join[Thread[max >= ...

1

Since LeastSquares can be written as NMinimize[Plus @@ ((mat.{x1, x2, x3, x4} - vec)^2), {x1, x2, x3, x4}] Then you can use a similar approach to minimizing your desired function: NMinimize[Max @@ ((mat.{x1, x2, x3, x4} - vec)^2), {x1, x2, x3, x4}] Although whether or not this is the "best" way is likely up for debate.

4

Your formulation doesn't work because your constraints don't involve variables. The preferred solution was posted as a comment to your question, but for making your original one work you could do: NMaximize[{(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^ alpha, {c/2 - Sqrt[2 - c^2]/2 < p, p < c/2 + Sqrt[2 - c^2]/2, c == 1.2, alpha == ...

1

Here is the final result if you are interested. data = Import /@ FileNames["/home/marco/LatexDocs/analytical/uvvis/PHOS_*.CSV"]; data = data[[All, 2 ;;, {1, 2}]]; ListLinePlot[data, PlotLegends -> {"BB", "MR", "PT", "TB", "UI"}, AxesLabel -> {Style["wavelength (nm)" , FontSize -> 16], Style["Absorbance", FontSize -> 16]}, PlotRange ...

4

Import the data and filenames, cull the datasets of information that is not useful: data = Import /@ FileNames["*.csv"]; filenames = FileNames["*.csv"]; data = data[[All, 2 ;;, {1, 2}]]; ListLinePlot[data, PlotLegends -> filenames] Looks like PT data was either incorrectly collected or is effectively transparent in the region of interest. The ...

3

With[{s = Max[Cases[Log[Rest[Divisors[#]], #], _Integer]]}, {Surd[#, s], s}] &[yourNumberHere] Not surprisingly, most integers are there own "highest power". Here's from 2 to 1000:

2

You find the highest exponent for the base b: b^IntegerExponent[n,b]

1

Of all the approaches not yet presented here this one seems to be the fastest: containsAllSymbols[expr_, s_] := !FreeQ[expr, s] containsAllSymbols[expr_, first_, rest__] := And[!FreeQ[expr, first], containsAllSymbols[expr, rest]] EDIT: I claimed this to be faster than Complement[symbolsList, Variables@expression] but I was wrong, sorry. Note that this ...

4

I am not sure if the return value of Variables meets your standard. If so, this works. Complement[symbolsList, Variables@expression] == {} AbsoluteTiming@ Do[Complement[symbolsList, Variables@expression] == {};, {200000}] {0.575185, Null} As @Szabolcs commented, Level[expression, {-1}] may be a nice alternative. And it's actually faster in this ...

1

Here;s one approach: expression = {r^2 + A*b - 3}; vars1 = {r, A, b}; vars2 = {r, A, w, d}; Total[Boole[FreeQ[expression, #] & /@ vars1]] == 0 For example, this returns True for vars1 and False for vars2.

1

You can adapt the answer to the question, How can I implement the method of Lagrange multipliers to find constrained extrema?, to obtain the first-order system. Clear[U, px, py, x, y]; f[x_, y_] := U[x, y]; g1[x_, y_] := budget - {px, py}.{x, y} h[x_, y_, λ_] := f[x, y] - λ g1[x, y] Thread[ D[h[x, y, λ], {{x, y, λ}}] == {0, 0, 0} ] (* {px*λ + ...

1

Here's one way to get an answer: NMaximize[{Sqrt[Abs[p0 q2 + p2 q0]] + Sqrt[Abs[p0 q1 + p1 q0]] + Sqrt[Abs[p1 q3 + p3 q1]] + Sqrt[Abs[p2 q3 + p3 q2]], (0 < p0 < 1) && (0 < p1 < 1) && (0 < p2 < 1) && (0 < p3 < 1) && (0 < q0 < 1) && (0 < q1 < 1) && (0 < q2 < ...

3

In your comment you gave an explicit example of finding the value of $a$ which maximized $a$ times the area of the region of $x,y\in [0,1]$ such that $y\geq ax$ or $y\geq1/2$. You claim the optimum value of $a$ is 1, but this appears to be incorrect: Integrate[a Boole[y >= a x || y >= 1/2], {x, 0, 1}, {y, 0, 1}] Plot[%, {a, 0, 3}] \begin{cases} a ...

1

What you have proposed works in principal: inner[y_ /; NumericQ[y]] := ( lastx = NMinimize[-7 - 6 x + x^2 - 8 y - y^2, x]; First@lastx ) NMaximize[inner[y] , y ] lastx {-1.77636*10^-15, {y -> -4.}} {-1.77636*10^-15, {x -> 3.}}} When you see how slow this is ( a whole minute) with my simple example I think ...

Top 50 recent answers are included