New answers tagged

0

Finding the convex hull of points in $\Re^d$ and expressing it as a set of (in)equalities is hard. However, I would suggest you transform the problem by writing feasible points as convex combinations of the given points, i.e. $$x=\sum_{i=1}^{d} w(i)\, x(i)$$ and then optimize over the simplex $$\{ 0\leq w(i) \leq 1, \sum_{i=1}^{d} w(i) = 1\}$$ ...


3

For 2D, Just find the Polygon representing the convex hull and just use RegionMember: (* fake data *) rand = Round[RandomReal[{0, 1}, {10, 2}], 1/100]; prims = MeshPrimitives[ConvexHullMesh[rand], 2][[1, 1]]; Refine[RegionMember[Polygon[Round[prims, 1/100]], {x, y}], {x, y} ∈ Reals] 1/25 (1/20 - x) + 18/25 (-(1/50) + y) >= 0 && -(23/25) ...


1

One way to treat this in some very special, low dimensional and friendly cases is to use ParametricRegion (*Dimension and number of points*) d = 5; np = 4; (*Generate data*) data = RandomInteger[{-10, 10}, {np, d}]; (*Convex hull*) ws = Array[w, Length[data]]; reg3 = ParametricRegion[ {Sum[ws[[i]]*data[[i]], {i, Length@data}], Total[ws] == 1} , ...


8

Not an answer, more of a extended comment. (Since the question requires the use of PeakDetect.) Some (more than half actually) of the local extrema are missed. This becomes obvious using Log plots (modifying the code of ubpdqn): data = Table[{x, (Sin[10 x] + 2) Exp[-x^2]}, {x, -4, 4, .01}]; peaks = Pick[data, PeakDetect[data[[;; , 2]], .01, .0005], 1]; ...


2

Clear[range] range[v0_, theta_] := v0^2 Sin[2 theta]/g Solve[{D[range[v0, theta], theta] == 0, 0 <= theta <= 90 Degree}, theta] (* Out: {{theta -> π/4}} *)


0

From FindMinum's point of view the objective function you are minimizing is a "black-box function", meaning it is an oracle, that yields values, but not derivatives, or Hessians. If the method chosen by FindMinimum to solve the problem requires a gradient of the objective function at a point, finite differences are used to approximate it. The multitude ...


4

From the FindRoot documentation: FindRoot[lhs == rhs, {x, x0, x1}] searches for a solution using $x_0$ and $x_1$ as the first two values of $x$, avoiding the use of derivatives. ... If you specify two starting values, FindRoot uses a variant of the secant method. Indeed, that does the job pretty much instantly: FindRoot[func[u] - num == 0, {u, -3, 3}] ...


0

Well, I have finally found a satisfactory solution. In such a case I can shift my datasets along X axis to make their dataranges non-overlapping and then use Piecewise to apply any set of models with any number of common parameters. Basically, It would look somewhat like this: NonlinearModelFit[Join[datasets], Piecewise[Table[{selectedFuncs[[i]][x], ...


1

Just another way (but not desired presentation style): grid = {{131, 673, 234, 103, 18}, {201, 96, 342, 965, 150}, {630, 803, 746, 422, 111}, {537, 699, 497, 121, 956}, {805, 732, 524, 37, 331}}; dim = Dimensions[grid]; vw = Catenate@ MapIndexed[ (#2[[2]] - 1) 5 + #2[[1]] -> #1 &, grid, {2}]; s = GridGraph[dim, VertexLabels -> "Name", ...


6

I wanted to be able to extract the path from your recursive memoized function, but I couldn't make it happen. But here is a function to find the minimum path from the upper left to the bottom right corners of an array of numbers, minimalpathsum[grid_] := Module[{dims, vertcoords, graph, weights, path, indices}, dims = Dimensions@grid; vertcoords = ...


2

With a slight modification of your MinPath function so that it takes a matrix as input ClearAll[MinPathF, nextF] MinPathF[mat_][i_, j_] := MinPathF[mat][i, j] = mat[[i, j]] + Piecewise[{{Min[MinPathF[mat][i + 1, j], MinPathF[mat][i, j + 1]], i < Length[mat] && j < Length[mat[[i]]]}, {MinPathF[mat][i + 1, j], i < ...


5

findGlobalMin[func_, x_Symbol] := Module[ {min = MinValue[func, x] // Simplify}, {min, Select[ Solve[{ D[func, x] == 0, D[func, {x, 2}] > 0}, x] // Simplify, (func /. #) == min &]}] f[x_] = -5 x^4 + 5 x^6 + x^2; findGlobalMin[f[x], x]


5

You can do the example emulating pen/pencil and paper,e.g.: y[x_] := x^4 - x^2 c = x /. Solve[D[y[x], x] == 0, x] r = D[y[x], {x, 2}]; ans = Pick[c, (r > 0 /. x -> #) & /@ c] Plot[y[x], {x, -1.5, 1.5}, Epilog -> {Red, PointSize[0.02], Point[{#, y@#} & /@ ans]}]


5

The original problem is an interesting example where a direct usage of Solve and NSolve fails. However Reduce can succeed solving it if we set unknowns in an appropriate order, thus there is no need to play with numerical functionality if symbolic one can resolve the given system. We can observe that there is a solution under the given condition with a == ...


3

Oh boy, what a question! This is very similar to some stuff I played a few weeks ago (Kerbal, what a game!). What follows solves (I think) the question you are asking. An approach that seemed to to help was to split the problem into to: before, and after the engine burn. I do this with the knowledge that the most efficient landing will comprise just a ...


2

It seems to me that generating only the valid combinations might be labor-intensive. Instead I first generate all possible combinations of elements, one from each column, labeling them with the indices of the rows from which each element was picked, and calculating the total you want to have minimized: allcombos = MapThread[ {#1, Total@#2} &, { ...


0

First, I want to repeat @m_goldberg's comment and tell you that z as defined in the code does not match the definition in the text. Other than that, the meaning of the error you got is as stated. This either means that at $(1,1)$ the function is undefined due to a singularity (e.g. is equal to $+\infty$), undefined due to error in definition which does not ...


5

This is more of a long comment, hopefully you can find some of these ideas helpful because I don't know how to completely implement this. Therefore, I'd really appreciate comments from more experienced users about whether they think this is feasible or not. If we define a list of "switching times" and then define a function that takes this list as an ...


4

First, using the rest of your definitions, redefine x3 using Set so that it doesn't recompute the integral for each evaluation: Clear[x3] x3[t_, k_] = Simplify[ Integrate[1/m force[τ] 1/Sqrt[k/m] Sin[Sqrt[k/m] (t - τ)], {τ, 0, t1/2}, Assumptions -> t1 ∈ Reals] + Integrate[1/m force[τ] 1/Sqrt[k/m] Sin[Sqrt[k/m] (t - τ)], {τ, t1/2, t1}, Assumptions ...


2

I'm assuming the objective is to find "the best" set of models (all with a single common parameter) with potentially different models for each of many data sets. Using NonlinearModelFit one could fit a combined model with all data sets and a specific set of models. One would obtain the AIC value for each of the all possible specific sets of models (one ...


4

datadamped = Import["http://comsics.usm.my/tlyoon/teaching/ZCE111_1516SEM2/data/\ data_A6Q2.dat", "Data"]; max = datadamped[[#]] &@FindPeaks[datadamped[[All, 2]], 0][[All, 1]] min = datadamped[[#]] &@FindPeaks[-datadamped[[All, 2]], 0][[All, 1]] This gives you list of maximums and minimums. If you need a fit you probably want to simplify the ...


2

By putting x^0.5 in your code, Mathematica assumes that you want to use machine arithmetic, and so will not return a result (since a doesn't have a definite numerical value.) If you use x^(1/2) or Sqrt[x] instead, Mathematica will try to solve the problem symbolically instead of numerically, and actually return a symbolic result. This result can then be ...


2

I think this is just a matter of using the correct syntax. Since Interval[{0, 10}] is a one-dimensional region, its elements have the form {x} instead of just x: RandomPoint[Interval[{0, 10}]] (* {3.23781} *) Element[%, Interval[{0, 10}]] (* True *) The documentation for NArgMax does say NArgMax[... , x ∈ reg] constrains x to be in the region reg ...


6

It is because there is no general solution for your problem, even for b being a positive integer: When b is odd, the maximum is positive infinity, while for even b it is not. You may want to use things like Maximize[-x^# + a*x, x] & /@ Table[i, {i, 5}] to observe.


2

You can extract all the local minimums and maximums by extracting where the derivative becomes zero: {sol,paortaextrm}=Reap@NDSolve[{Vheart'[t] == (( (Vtotal - (Dblood * g * h*Ciliac)/133.25)/ Cvc) - ((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, \[Omega], t])) + (Vheart[t] - Vo)/Cheart)/ Piecewise[{{Rmitral, ( (Vtotal - (Dblood ...


0

Just for the record, if you are willing to (re)sample your function to have {x, y} pairs instead of a regular function or InterpolatingFunction, there are multiple methods available (see for example here and here): Original function: getRLine3[MMStdata_, IO_: 1][x_: x] := ListInterpolation[#, InterpolationOrder -> IO, Method -> "Spline"][ x] ...



Top 50 recent answers are included