Tag Info

New answers tagged

5

I think I finally understand what you were asking (takes me a while to get in gear in the morning...), and I believe that you are simply running into numerical problems. In fact, according to its documentation, Minimize will call NMinimize automatically when given numerical input. NMinimize (docs here) will still attempt a search for a global minimum on ...


1

With the constraint x^2 + y^2 == 1, you are minimizing the Cost function on the boundary of the unit disk centered on the origin, i.e. only along the rim of that circle. What you seem to want is optimizing anywhere within the unit disk. You want an inequality there in the constraint: Minimize[{Cost[0.27, 0.96286, x, y], x^2 + y^2 <= 1}, {x, y}] (* ...


0

This sidesteps the question. To find the minimum on the constrained surface try FindMinimum[Cost[0.27, 0.96286, x, Sqrt[1 - x^2]], {x, 0.1}] with the result {0.873162, {x -> 0.244627}}. The curve takes this form Plot[Cost[0.27, 0.96286, x, Sqrt[1 - x^2]], {x, -1, 1}]:


1

The LinearProgramming[...] solution. Recall the canonical minimization form for linear programming: \begin{align} \mathrm{minimize}\ \mathbf{c}^\mathrm{T}\mathbf{x} \ \mathrm{subj\ to:\\} \mathbf{Ax}\ge \mathbf{b} \mathrm{\ and \ } \mathbf{x\ge0} \end{align} In the interest of keeping this answer simple and informative, we can throw out the nonlinear ...


7

Let's create a fake spectrum with two peaks: spectrum = Table[ {lambda, Exp[-(lambda - 350)^2/(50^2)] + Exp[-(lambda - 430)^2/(25^2)]}, {lambda, 200., 800., 1.} ]; ListLinePlot[spectrum, PlotRange -> All] Now let's use FindPeaks to find the positions of those peaks, using only the absorbance values, i.e. the $y$ values in the list above: ...


2

data returns: {114.754, {tomatoe -> 1.72651*10^-8, lettuce -> 0.58548, spinach -> 3.53893*10^-8, carrot -> 8.48321*10^-9, sunflower -> 9.69807*10^-10, tofu -> 0.87822, chickpea -> 3.3596*10^-9, oil -> 4.43666*10^-10}} Where 114.754 is the minimum total energy with the constraints you have given. ...


1

Just use the following instead of your print statement: Print[cost[tomatoe, lettuce, spinach, carrot, sunflower, tofu, chickpea, oil] /. data[[2]] ] (* Out: 2.32728 *) The Minimize function returns the following data structure: {114.754, {tomatoe -> 1.72651*10^-8, lettuce -> 0.58548, spinach -> 3.53893*10^-8, carrot -> 8.48321*10^-9, sunflower -> ...


1

I add the following code to the end of your notebook: Clear[x]; dx = 0.05; {x[0], y[0]} = {0, y /. Last@NMinimize[{F[0, y, a, b]}, {y}, Method -> "NelderMead"]}; Do[{x[i], y[i]} = {i*dx, y /. Last@ NMinimize[{F[i*dx, y, a, b], y[i - 1] - dx < y < y[i - 1] + dx}, {y}, ...


5

Since the QuadraticProgramming method is not documented, it is also not supported (however, bug reports on it are welcome!) It has been implemented some years ago using a rather dated by now version of the COIN-CLP library, which has a number of known problems. Future versions will hopefully bring optimization improvements and use more modern libraries.


1

I'm not sure what you mean by Ki,j but perhaps this vars = ToExpression@ Flatten@Table["K" <> ToString[i] <> "$" <> ToString[j], {i, 20}, {j, 20}]; or this vars = Flatten@Table[k[i, j], {i, 20}, {j, 20}]; Then one can use it thus: Assuming[vars ∈ Reals, Refine[ Apply[ Times, Sqrt[vars ^ RandomInteger[4, ...


3

I think there is enough information in the question to make a confident guess at the problem. The key clue is in the quoted error message: Nearest::neard: "The default distance function does not give a real numeric distance when applied to the point pair ...


2

You basic problem can be broken down to this simple example myExpr = m^2; f[m_] := m*myExpr f[3] (* 3*m^2 *) You can use Trace to see the steps of evaluation, but to cut it short here are the two steps that happen when you call f[3]: Every occurrence of m in the right side of the definition of f is replaced by 3. This is unfortunately only one ...


1

To get around the "wall of code" problem, here's another approach: Define an upper-diagonal matrix with the coefficients of the polynomial in it, and use dot products to generate the polynomial. For example, if you want to define the polynomial $a x^2 + b x y + c y^2$, you could write this as: mat = {{a, b},{0, c}}; varvec = {x,y}; polynom = ...


3

Look at LK4[{a, b, c, d}, I, 0, 0, 0, 0] What has happened is that the a in the argument {a, b, c, d} has been replaced by {1, 2, 3, 4} in the Sum[..., {a, 1, 4}] code in the definition of LK4. If you change the definition of LK4 to use a different iterator, you get consistent results: LK4[coeff_, tau_, xi1_, xi2_, x_, y_] := ...


3

Simplifying complicated results sometimes takes a long time, so many Mathematica functions do not do so by default. Or they do it under a time constraint. Such is the case here, and in addition, FullSimplify is needed to simplify the nested Root objects. Note we need to add the constraints as assumptions to get the desired simplification. res = ...


3

Catch/Throw: findMin[target_, steps_] := Block[{nbr = -1}, solsOpt = ReleaseHold@Catch@NMinimize[f[x, y], {x, y}, Method -> "NelderMead", EvaluationMonitor :> {nbr += 1; If[Mod[nbr, steps] == 0, Print["Step: ", nbr, " ; Current value: ", f[x, y], " ; parameters: ", {x, ...


4

Defining just one of the points of the region with a decimal point helps, suggesting that the method chosen by FindMaximum for integer coordinates is a perhaps a linear programming method, and gets stuck at the observed {5, 5}. Instead one can do: region = Polygon[{{0., 0}, {10, 0}, {10, 5}, {5, 5}, {5, 10}, {0, 10}}]; result = Last@FindMaximum[{x + ...


3

Thanks to a comment from @ilian, I came back to the question: Since the objective function is linear, probably the solution for all these regions except Disk[] comes from a linear programming method, so there are no iterations to monitor And indeed, that's we see. Change the function to e.g. $x^{2}+y^{2}$ and EvaluationMonitor/StepMonitor works a ...


2

Mathematica does not like your h[i]s. If you introduce shrt[head_, indices_] := ToExpression[StringJoin[ ToString /@ Flatten[ {head, indices}]]] so that e.g. shrt[h,1] becomes h1 or shrt[h,{i,j}] hij Then this works: S = 10^-9.2; cl = 3*10^8 ; f = 5.9*10^9; w = cl/f ; A = (4*π/w)^(2/1); β = 2.5 ; m ...


4

[Edit notice: It turns out the system can be integrated exactly, which leads to faster performance.] Using DSolve I replaced the approximate coefficients 0.2 and 0.8 by the exact numbers 2/10 and 8/10; otherwise, things that should cancel out do not and lead to false singularities. myode1 = Function[{kp1, kp2, θ, temp, HRT, p1in}, Evaluate@ ...


2

Here is one variant that seems to evaluate to a number. myode1[p1in_?NumericQ, HRT_?NumericQ, temp_?NumericQ] := ParametricNDSolveValue[{p1'[t] == 1/HRT (0.2 p1in - p1[t]) - kp1*Exp[θ (temp - 20)] p1[t], p2'[t] == 1/HRT (0.8 p1in - p2[t]) - kp2*Exp[θ (temp - 20)] p2[t] + kp1*Exp[θ (temp - 20)] p1[t], p1[0] == 0.2 p1in, p2[0] ...


3

You have a couple problems. First, as Andrew Cheong pointed out, Evl1 and Evl2 should be SetDelayed (:=). As you can see from evaluating h[1,1], S and R don't seem to get substituted: h[1, 1] (* -R + 0.44949 S + 0.5 (-0.744563 R + 2. S) *) This is because Mathematica first Sets (=) the values of the Evl* to expressions involving the symbols R and S. ...


1

Here are the $x$ and $y$ values that minimize your function: mydata = Table[ {x, y} /. Minimize[{2*Exp[-x] + 0.5*Exp[-y], x >= 0, y >= 0, x + y == z}, {x, y}][[2]], {z, 0, 3, .1}]; Here are the actual minima values of your function for the minimizing values of $x$ and $y$: myminima = 2*Exp[-#[[1]]] + 0.5*Exp[-#[[2]]] & /@ mydata; ...



Top 50 recent answers are included