# Tag Info

7

I did the same exercise myself the other day. Here is one way to do it. mS = {{0.04, 0.006, -0.004, 0.}, {0.006, 0.01, 0., 0.}, {-0.004, 0., 0.0025, 0.}, {0., 0., 0., 0.}}; vP = {0.12, 0.1, 0.07, 0.03}; vx = Array[x, 4]; muRange = 10.^(5 Range[0, 100, 1]/100 - 1); s = Monitor[Table[ {#[[1]], vx/.#[[2]]}&[ FindMinimum[{-vP.vx + mu ...

4

Your F wrapper function is doing nothing for you in your code, so I removed it and replaced it with direct calls to F1. NIntegrate in the argument to FindMinValue should not be evaluated unless it is passed explicitly numerical arguments, so it is best to wrap it in a function protected by NumericQ (functiontominimize below). Since all the other functions ...

3

This is a fairly common problem to encounter and in this case was a bit subtle due to having an outer and inner function both in need of being defined only for explicitly numeric input. So I'll repost my comment as an answer and make it a Community wiki. The FindMinumum objective itself needs to be defined only for numeric input. Which can be done as ...

6

The problem is that during the evaluation process it attempts to numerically integrate using the symbol a. That is the source of the warning message. However, if you persist (and ignore the warning), ArgMin will eventually switch over to using numerical values and output the correct value. ArgMin[{NIntegrate[(Tanh[x] - Erf[x/a])^2, {x, -5, 5}], 0.5 ...

0

Ok, so this is how I finally did it. I wrote the complex coefficients like A*Exp[i*m] and just set m to be 0 for the coefficients that you want real. Due to the nature of the problem, it's easy to write them like this ,instead of a+b*i.

0

Combine your vt and prof lists together. list = {vt, prof} The function findVt gives the next combined list of vt and prof. Form prof it drops the last element. findVt[comList_] := Module[{npva = 2, profList, profLen, mean, vtList, list1, list2}, vtList = First@comList; profList = Last@comList; profLen = Length[profList]; mean = Mean[vtList]; list1 = ...

6

In the comments I supposed that the reason why the algorithm stops is obtaining zero derivative with respect to b at the point {a, b} = {0., 1.} returned as the minimum. Let us check this statement by perturbing the actual Jacobian a little bit in order to make all the derivatives non-zero. Proceeding from the code in the question, we find the Jacobian and ...

7

Assume that you have your lists of unique resistor values (resistors) and of unique capacitor values (capacitors). For now, I generate two such lists as follows: resistors = Flatten@ Outer[ Times, PowerRange[1, 10000], {100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300, 330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, ...

0

This first assumption that I make is that the center of the circle lies at the point (0,0). If this is not the case, see MarcoB's comment from above. I further assume that you may actually have numerical values for the data and are using a function to simulate your acoustical data. If you have data that can be used directly. If you have a function then we ...

6

I am one of the many that does not consider this a bug as it is shared by probably the majority of statistical packages. (But there certainly is room for improvement in terms of warnings that could be given.) Iterative procedures work great if the starting values are close enough to the final values. When one doesn't know the final result this requirement ...

6

This looks like a numerical precision issue. Various approaches that precisely address this, all yield the same, correct solution: Scaling of the x values: data = {{0, 20}, {20, 10}, {40, 5}, {60, 2.5}, {80, 1.25}}; {xmin, xmax} = MinMax[data[[All,1]]]; data2 = {Rescale[data[[All, 1]]], data[[All, 2]]} // Transpose; fit1 = FindFit[data2, a*Exp[b*x], {a, ...

2

The following minimal change to the code produces results. l = 0; ch = 1; el = -.1; eh = .1; F[e_] = Max[0, Min[(e - el)/(eh - el), 1]]; d = .1; pi = .2; p2g = .05 Array[# &, 6]; p1sg = ConstantArray[0, 6]; Do[ Obj1[p_?NumericQ] := NIntegrate[(c + d - p) (1 - F[(1 - pi) p2g[[i]] + pi c - p]), {c, cl, p2g[[i]]}] + NIntegrate[(c + d - p) ...

2

As already stated in my comment, the solution is to use Set (=) for the "function definition" instead of SetDelayed(:=). The reason is that Set evaluates the r.h.s of l.h.s. = r.h.s. (abbreviations for left- and right-hand-side) once and whenever Mathematica encounters l.h.s it gets replaced with the evaluated form of r.h.s. SetDelayed on the other hand ...

4

This basically directly computes the angle that a line drawn from the origin to the point makes with the horizontal axis, and uses this to sort: list = {{100, 200}, {200, 300}, {300, 300}, {320, 150}, {250, 210}, {350, 220}, {380, 100}, {390, 300}}; ordList = SortBy[list, Apply[N[ArcTan[#1, #2]] &]] (* {{380, 100}, {320, 150}, {350, 220}, {390, 300}, ...

1

Just forbid the symbolic treatment by defining a numerical function: x = {{9.19, -7.67}, {9.59, -7.32}, {9.81, -7.99}, {12.53, -9.98}, \ {7.40, -6.26}, {8.03, -6.94}, {9.40, -7.56}, {9.71, -7.63}, {8.15, \ -6.89}, {11.57, -9.48}, {11.82, -9.67}, {10.97, -9.15}, {7.57, \ -6.20}, {11.50, -8.91}, {8.06, -6.13}, {8.65, -7.17}, {8.39, -7.01}, \ {14.04, -11.65}, ...

3

ParametricNDSolve will return a numerical ODE solution with any number of free parameters. This parametric solution can then be fed into NonLinearModelFit (or whatever home-brew chi-squared algorithm you want to cook up) to find the best-fit values for the parameters. As an example, suppose we want have the ODE $y''(x) = - y(x)$, with initial conditions ...

1

Since your objective function (sol) is continuously differentiable and you consider an open set for the optimization variables $r_1,r_2,r_3$, if a minimum of sol exists, it must satisfy the first-order necessary conditions. That is, the gradient of sol with respect to $\{r_1,r_2,r_3\}$ must be zero at the minimum. Therefore, we can solve a system of (in this ...

1

Here are two additional ways to do this. 1. ContourShading ContourShading is an option for ListContourPlot3D that allows one to specify graphics directives for each contour surface. However, such directives have to be specified explicitly, so I found it rather awkward to use: Table[ ListSliceContourPlot3D[ data, sl, ContourShading -> ...

3

You can use FindRoot! First, take a look at the contour plot of $f$: ContourPlot[f[h, b], {h, 1, 6}, {b, 0, 6}, PlotPoints -> 100, Contours -> {0.1, 0.3, 0.5, 0.7, 0.9}, ContourLabels -> True, ContourShading -> None, ContourStyle -> GrayLevel@0.7, FrameLabel -> {h, b}] Note that there is a saddle point at \$(h, b) = (1.75, ...

7

I took this code out of the examples given in ListSliceContourPlot3D . I only added the option BaseStyle -> Opacity[.6]. data = Table[x + y + z, {z, -1, 1, 0.2}, {y, -1, 1, 0.2}, {x, -1, 1, 0.2}]; Table[ ListSliceContourPlot3D[data, sl, BaseStyle -> Opacity[.6], PlotLabel -> sl], {sl, {"XStackedPlanes", "YStackedPlanes", ...

Top 50 recent answers are included