# Tag Info

9

The following is fast and suggests an almost straight and horizontal line: p = Range[0, 1, 1/100]; v[x_] := v[x] = ChebyshevT[6, x] f[x_?NumericQ, a_?NumericQ, b_?NumericQ, c_?NumericQ] := a x x + b x + c abs[x_?NumericQ, a_?NumericQ, b_?NumericQ, c_?NumericQ] := (v[x] - f[x, a, b, c])^2 maxabs[a_?NumericQ, b_?NumericQ, c_?NumericQ] := Max[abs[#, a, b, c] ...

6

First get SimplexMethod to return a list, instead of printing them. Using NestWhileList is a good way to structure the computation of your iterative algorithm. Mapping the formatting, Grid[#, Dividers -> {-2 -> True, -2 -> True}] & /@ ..., on to the list of tables might better occur outside the function SimplexMethod. I usually format at the ...

5

I believe the following does more or less the same and is much easier to read: Clear[GraphicalMethod]; GraphicalMethod[c_?VectorQ, m_?MatrixQ, b_?VectorQ] := Module[{k, eqs, l2, l1, jeq, x = {x1, x2}}, k = c.LinearProgramming[-c, m, Thread[{b, -1}]]; eqs = Reduce /@ Thread[m.x == b]; jeq = Join[eqs, {k == x.c}]; {l2, l1} = Max@Flatten[Solve /@ (jeq ...

5

The following is a quick and dirty patch. You can do something more elegant taking it as a template: Clear[GraphicalMethod] GraphicalMethod[L_?VectorQ, A_?MatrixQ, b_?VectorQ, vars_?VectorQ] := Module[{obj = L.vars, cond = Thread[A.vars <= b]~Join~Thread[vars >= 0], r, sol, x1, x2}, sol = Maximize[{L.vars, Thread[A.vars <= b]~Join~Thread[0 ...

5

The extraneous points result from inadequate resolution in the ContourPlot used to provide initial estimates for crit. A simple but effective approach is to increase PlotPoints. ContourPlot[dx[x, y] == 0, {x, -xm, xm}, {y, -xm, xm}, PlotPoints -> 50, ContourStyle -> None, Mesh -> {{0}}, MeshFunctions -> Function[{x, y, z}, dy[x, y]]] ...

4

One common approach for "maxmin" problems, i.e., of the form maximimize (over $\{x_i\}$) $\min \{f_i(x_i)\}$, is to introduce an additional variable, say $t$, and reformulate the problem as maximize (over $t$ and $\{x_i\}$) $t$, subject to $f_i(x_i)\geq t, \forall i$. Example: f[x_, y_, z_] := x + 2 y - 5 z; g[x_, y_, z_] := 4 x - y + 9 z; ...

4

Update: I forgot to mention that first I changed the coefficients to exact numbers: p = 15 n (10 - c) - c^2; v = (1/2) p + n*Sqrt[p]; f = c*p - v; Then I did what I posted originally: The following returns an answer in less than 0.1 sec.: Solve[f1 == lam*g1 && f2 == lam*g2 && v == 20000, {c, n, lam}, Method -> Reduce] If I add lam ...

4

I don't quite feel like writing out the full solution. Nevertheless, I see that you're trying your best to adapt one of my previous solutions, and I will at least show a way for you to work a little bit smarter. One of the tenets of numerical computing is the one of exploiting the structure of the problem; what this says is that you look if there is any ...

4

As mentioned in the question, this is a bug. For a possible workaround, try RegionPlot[lhmin[y, M] > 0, {y, 0.1, 1.}, {M, 0, 10}, "NumericalFunction" -> False] Some related questions: (1), (2), (3).

3

My approach.. first do a least squares fit, which gives a global minimum, although with a different error measure: f[x_, a_, b_, c_] := a (x)^2 + b (x) + c; s1 = First@ Solve[(D[ Simplify[ Total[((f[#, a, b, c] - v[#])^2 & /@ Range[0, 1, .001])]] , #] & /@ {a, b, c, d}) == 0, {a, b, c}] Plot[{v[y], f[y, a, b, c] ...

3

If you make a plot of your function over a region you will see that it grows to infinity as o and n increase. mi[o_, n_] := Log2[1 + 4 o (Sqrt@n + Sqrt[1 + n])^2] Plot3D[mi[x, y], {x, 0, 5}, {y, 0, 5}, AxesLabel -> Automatic] So it is certain that you need to place a bound on it. Let's plot your example with a radius of three or less. max = ...

3

You could do for example: int[al_?NumericQ, be_?NumericQ] := NIntegrate[(funcr[al, be, x] - piece[x])^2, {x, 0, 1}] nm = NMinimize[{int[al, be], al >= 1, be >= 1}, {al, be}] Plot[{piece@x, funcr[al, be, x] /. nm[[2]]}, {x, 0, 1}, PlotStyle -> {{Thickness[.01], Red}, {Dashed, Thickness[.01], Blue}}]

3

I am not quite following what you are trying to do with norm or max. The procedure I followed was to make some data from your fake empirical cumulative probability function. piece[x_] := Piecewise[{{x^3, 1 >= x >= 0}, {1, x > 1}}, 0]; data = Table[{x, piece[x]}, {x, 0, 1, 0.02}]; Copy and paste your "model" funcr[al_?NumericQ, be_?NumericQ, ...

3

Don't compare to a single (shared) main-kernel variable (fmin) on each kernel. Instead, allow each kernel to find the smallest of the points it has checked. Let each kernel have its own private fmin. Then you'll have \$KernelCount candidates for the minimum. Finally select the smallest of these. ParallelCombine is made for precisely this type of approach. ...

2

Exact optimization with mixed real and integer variables is not yet implemented. ClearAll[a, s] Format[a[n_]] := Subscript[a, n]; Format[s[n_]] := Subscript[s, n]; Maximize[{3/100000 + 1/(400000000000*a[1]* a[2]) + (9*a[1])/ (100000*a[2]) - (a[1]*s[1] + a[2]*s[2])/ (50000*a[1]) - (3*(a[1]*s[1] + a[2]*s[2]))/ ...

2

The most straightforward parallelization of you code without a slowdown due to using SetSharedVariable is to use: f[x_, y_, z_] := Sin[x - z + Pi/4] + (y - 2)^2 + 13 n = 10^1*2.; LaunchKernels[]; AbsoluteTiming[ ParallelEvaluate[fmin = f[0., 0., 0.];]; ParallelDo[ If[# < fmin, fmin = #] &@f[xp, yp, zp];, {xp, 0., Pi, Pi/n}, {yp, -2., 4., ...

2

As pointed out by george2079 in the comment, it is adviseable to use arbitrary-precision numbers in this case, so we can set WorkingPrecision however high. test1[x_, y_] := 1/(1/100)^2*Exp[-(x^2 + y^2)/(1/100)^2] test2[x_, y_] := 1/(1/10)^2*Exp[-((x - 5)^2 + (y - 3)^2)/(1/10)^2] f[x_, y_] := test1[x_, y_] * test2[x_, y_] Then, for example, NArgMax[f[x, ...

2

I suggest altering the definition of test as follows: test = Compile[{{x, _Real}}, If[Sin[x] > 0.1, Tan[x], 0.], "RuntimeOptions" -> "EvaluateSymbolically" -> False ]; Note that the 0 third argument of If is changed to 0.. While it seems to compile correctly anyway for this particular example, my experience has been that Compile can ...

2

The problem resides in the fact that I was minimizing over a matrix not a number. This can be done, however, over the sum of the total matrix elements, by using the line: FinalFunct[a1_, a2_, a3_, b1_, b2_, b3_, c1_, c2_, c3_] := Sum[StateDifference[a1, a2, a3, b1, b2, b3, c1, c2,c3][[k]][[k]], {k, 1, Length[StateDifference[a1, a2, a3, b1, b2, b3, c1, c2, ...

2

Note what happens when you evaluate Abs[u] > 0.01, for a u with no value of its own: In[1]:= ClearAll[u]; Abs[u] > 0.01 Out[1]= Abs[u] > 0.01 Nothing! Mathematica can't figure out a value for Abs[u] without knowing anything about u, so it leaves the expression unchanged. This means that a conditioned pattern like u_ /; Abs[u] > 0.01 isn't ...

2

Not sure about what you want, but perhaps: f[v_] := v Sign[v[[-1]]]/GCD @@ v v0 = {-2, 2, 4, 6, 2, 2}; f@v0 (* {-1, 1, 2, 3, 1, 1} *)

1

FindMinimum[{f[x, z], g[x, z] <= g[x, y]}, z][[1]]

1

Update To start you have one data point that needs to be fixed. 7.94834000000012*E-05 -> 7.94834000000012*10^-5. Probably copied from a different format for numbers. Examine the data I am going to use the form from your original question. Using the minus sign in the exponent Jos*(Exp[-Voc/A/n] is not helpful. My understanding is that you have a ...

1

As I mentioned in a comment the original code has a mistake in the plotting commands -- it should be used f[y,a,b,c], not f[a,b,c,x]. I found that mistake using the solution by "belisarius has settled" as a base with the following code, which is specially made to get a parabola that fits the curve. First we select sampling points close to the ...

1

Here is what I get after increasing precision and using the default NMinimize function: In[64]:= mins = NMinimize[{Eqsa[12/10, 20], alpha1 >= 0 && c2 \[Element] Reals}, parameters, WorkingPrecision -> 40] Out[64]= {1.247337986088467518479435174601049848950*10^-7, {c2 -> \ -0.3374784431690519041004266735008459511493, d2 -> ...

1

Your expression is probably unbounded if your vars are left free. You could get something out of it under reasonable assumptions, though: vars = Variables@eq; const = And @@ Thread[Variables@eq > 1]; NMinimize[{eq, const}, vars] (* {-1593.64, {A1 -> 110.452, A3 -> 3314.57, c2 -> 1., c4a -> 3.36665, d2 -> 1., e3 -> 1.1436, alpha[1] ...

1

The error you get is the same error you get when you evaluate 3 < 4 + 2I - you are asking if a complex number is less than a real-valued one. Take the answer you get when you put in the equality, and then feed that back into a NMinimize[{OB[Q, R], Q >= 1, R >= 1, a == 0.02}, {Q, R}] (* {4.31243*10^6, {Q -> 478.281, R -> 94.4141}} *) a /. ...

1

Although, as the OP noted, Maximize[{Log[x] + Log[y], x + y == 10 && 0 < x && 0 < y}, {x, y}, Reals] returns unevaluated, Maximize[{Log[x] + Log[y], x + y == 10 && 0. < x && 0. < y}, {x, y}, Reals] (* {3.21888, {x -> 5., y -> 5.}} *) works. On the other hand, Maximize[{Log[x] + Log[y], x + y == 10 ...

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