Hot answers tagged

9

If more ad hoc, inexact approaches are welcome, one way to generate relatively uniform density of points on a sphere is to use Monte Carlo Lloyd's algorithm (modified for the spherical case): With[{points = 200, samples = 40000, iterations = 20}, Nest[With[{randoms = Join[#, RandomPoint[Sphere[], samples]]}, Table[Normalize@Mean@Extract[randoms, ...


9

This is my try in creating a minimal example with only one variable. There are a couple problems to solve: Minuit2 is in C++, so we need a way to integrate it with mathematica through mathlink. This is a bit cumbersome, but in principle straightforward. This first example uses a mathematica function with minimum user input, that is, it does not uses a user-...


8

In part, your trouble stemmed from an attempt to determine exact/symbolic results from your data. Even for this modestly-sized set, the objective function you were feeding to Minimize[] is already sufficiently complicated, which is why it takes long. As I previously noted, using NMinimize[] instead will give you the numerical values you need. Less ...


8

EvaluationMonitor is going to be called whenever the objective function is being evaluated, that is much more often than StepMonitor. The reason for not getting any points back is that the StepMonitor specification is not propagated to the NMinimize call. Try the following syntax instead nlm = Reap @ NonlinearModelFit[data, Exp[a x/(b + c x)], {a, b, c}, x,...


6

Create the list b as you have shown. nst[n_] := Length[NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]] b = With[{stps = Array[nst, nn]}, Table[Max[Take[stps, n]], {n, nn}]]; It looks like ListPlot[b, PlotStyle -> Blue] It is apparent that we want to locate the first point in each group of horizontal points and use that in the ...


6

Minimize + MinimalBy work on the test case: MinimalBy[Minimize[x /. #, C[1]] & /@ solutions, First] (* {{π/2, {C[1] -> 0}}} *)


5

Correct me if I'm wrong... but I suppose, pedantically speaking, there are only five solutions defined by Platonic solids, and trivial solutions for 0-3 points (extension of CirclePoints). Thus: ClearAll[spherePoints]; spherePoints[r_: 1, n_ /; 0 <= n < 4] := {##, 0} & @@@ CirclePoints[r, n]; (spherePoints[r_: 1, PolyhedronData[#, "VertexCount"]...


5

I had the same idea as Jim Baldwin, as constraints are often implemented as penalty functions. Here is one that severely penalized any negative residual. The parameter scale might need to be adjusted to be a significant fraction of the range of the data values. ClearAll[penalty]; penalty[residuals_?VectorQ, scale_: 10] := scale*Length@residuals*(1 - ...


4

This is a corrected version of poor quality post I originally posted. This is to classify the extreme values using Lagrange multiplier method. The bordered Hessian for 2D case with one constraint is calculated. Projections onto x-z and y-z plane are used just to show the minima and maxima (local and global for constraint): f[x_, y_] := x^3 - x*y + y^2 + 3 ...


4

Aha~ I suppose this question is created while solving this. Am I correct @yode :P So here's an easy solution, simple, elegant, and may I say even quite fast after some optimization? pt = With[{p = Table[{x[i], y[i], z[i]}, {i, 80(*number of charges*)}]}, p /. Last@ NMinimize[ Total[1/Norm[Normalize[#1] - Normalize[#2]] & @@@ ...


4

The error message tells everything: "NMaxValue::nnum: "The function value {-0.31322198} is not a number at {s,t} = {0.6524678079740285,0.04524817776440737}"" NMaxValue[First[f[s, t]], {s, t} ∈ Rectangle[{0, 0}, {1, 1}]]


3

Your question seems to assume a line search-type method. From the documentation, then: Method -> {"QuasiNewton", "StepControl" -> {"LineSearch", "MaxRelativeStepSize" -> s} } Where s is some positive value. If BFGS is too sophisticated for you, you could try using the conjugate gradient method instead. Indeed, there are a large number of ...


3

Another follow up, specifically to @Jim Baldwin's comment. Instead of plotting the full curve, we can also plot a certain number of points and see how they vary with the parameter t, i.e.: Clear[v] th = Array[v, Length[trainComposed[[1]]] - 1]; lwrPlot = Manipulate[ Show[listPlot, With[{x = #}, With[{bounds = Values@NMinimize[ ...


3

Just a follow-up to @J.M.'s answer to show the effect of the value of t: trainX = {100, 320, 213, 512, 58, 84, 113, 142, 93, 121, 421, 432, 249, 254}; trainY = {140000, 400000, 241000, 489000, 78000, 123000, 139000, 143000, 97000, 134000, 392000, 458000, 311000, 378000}; rX = MinMax[trainX]; rY = MinMax[trainY]; Manipulate[ (* Make a table of ...


2

With[{n = {3, 4, 5, 6, 7, 20}}, Partition[show[points[#]] & /@ n, 3]] // GraphicsGrid With the code below, with piecewise spring forces (exclusively repulsive) and Cartesian vectors. A different model for force and switch to spherical vectors would probably be wise. show[points_] := Graphics3D[{ Opacity[.5], Sphere[], Opacity[1], PointSize[...


2

Expanding on answer by Louis using Table Return maximum value and associated value of variables (a, b, c) as replacement rules: Module[{max = {0, 0, 0, 0}, val}, Table[ If[(val = a*b + b*c + a/c) > First[max], max = {val, a, b, c}], {a, 5}, {b, 5}, {c, 5}]; Clear[a, b, c]; {First[max], Thread[{a, b, c} -> Rest[max]]}] (* {51, {a -> 5, ...


2

Most of the Methods used by NMinimize try to enforce constaints by creating a penalty function, which behaves such that when constraints are violated, the penalty function should grow and thus take us away from unconstrained minima. You can read a little about it here. In order to do this, NMinimize actually needs to know the functional dependence of the ...


2

Maybe something like MinimalSolveSolution[expr_, x_, o___] := MinimalSolveSolution[Solve[expr, x, o]] MinimalSolveSolution[sol:{{x_ -> _}..}] := iMinimalSolveSolution[x /. sol] MinimalSolveSolution[__] = $Failed; iMinimalSolveSolution[l_List] := Min[iMinimalSolveSolution /@ l] iMinimalSolveSolution[ConditionalExpression[val_, cond_]] := ...


2

For points uniformly spaced in angular variables, you can use CirclePoints. spherepoint[m_, n_] := Union@Flatten[Table[Join[{Cos[q]}, Sin[q] #] & /@ CirclePoints[n], {q, 0, Pi, Pi/m}], 1] ListPointPlot3D[spherepoint[20, 30], BoxRatios -> 1] For uniformly spaced in Cartesian coordinates, things would be complicated. The ...


1

Here's one way code this optimization problem in MMA (I am guessing it concerns a resource allocation problem in a broadcast multi-carrier communication channel). First, define a convenience function for the (subcarrier) capacity as follows: r[p_, h_] := (1./8.) Log[2, 1 + p h] It is also convenient to define the following two (abstract) matrices whose ...


1

I think it's only a question of accolades Maximize[(-(1 - x^2) (y^2 - 4) - x^2 - y^2 + 5)/(x^2 + y^2 + 1)^2, {x,y}] return {9, {x -> 0, y -> 0}}


1

Do not use the pattern x_?NumericQ when defining const, because you are not using it numerically but symbolically. f[x_] := 42 + x const[x_] := {f[x], f[2*x], f[3*x]} NMinimize[x^2, Thread[const[x] <= 4], {x}] {1444., {x -> -38.}} Note that I have removed a lot of unnecessary code from your definition of const.



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