# Tag Info

1

As @SjoerdSmit mentioned in the comments, I had a syntax error for the 'data' section of my FindFit function. It should read {{1000, Pi/2}} instead of how I had written it above. This is because the first argument of FindFit should be a SET of data. Thanks to Sjoerd!

0

f[th_, t_] := (3 + t^2 + 6 th + 3 th^2)/(6 t^3) Plot3D[f[th, t], {t, -10, 10}, {th, -10, 10}, AxesLabel -> {t, th}, PlotRange -> {-10, 10}, PlotPoints -> 100] This is more easily visualized by plotting f in 2D, for a few discrete values of t: Plot[{f[th, .1], f[th, .5], f[th, 1], f[th, -.1], f[th, -.5], f[th, -1]}, {th, -10, 10}, PlotRange -&...

5

Really this should have a concrete example in Mathematica copy-pastable format. Anyway, I'll show a few ways using a made-up example. We'll eventually get it down to straight linear algebra. To keep it simple I'll assume the matrix has distinct eigenvalues. This restriction can be lifted of course. Also as has been noted in comments, without loss of ...

3

DSolve solution for positive/negative halfplane Needs["VariationalMethods"] eulereqs = EulerEquations[a f'[x]^2 + b f[x]^2 + c Abs[f[x]], f[x], x] (* Out[] *) 2 b f[x] + c Abs'[f[x]] - 2 a f''[x] == 0 DSolve can't solve this right away because of the Abs'[x] term, but if we assume f[x] > 0 (or f[x] < 0 to the same effect) we can get solution ...

1

I think the error was the value for M. (Also cleaned up the code a bit.) ClearAll["Global*"] a0 = 5.29*10^(-11); wx = 2 Pi*45; wz = 2 Pi*133; h = 1.054*10^(-34); (* M=2.72*10^(-23); *) M = 163.9 1.66 10^-27; add = 130*a0; n = 15*10^3; az = Sqrt[h/(M*wz)]; l = wz/wx; f[X_] := (1 + 2 X^2)/(1 - X^2) - 3 X^2 ArcTanh[Sqrt[1 - X^2]]/(1 - X^2)^(3/2); yqf[as_]...

0

f[x_] := (x + y)^2; obj[x_?NumericQ] := First@FindMaximum[{f[x], 0 < y < 1}, y]; Plot[obj[x], {x, 0, 2}] Or you could use obj[x_?NumericQ] := FindMaxValue[{f[x], 0 < y < 1}, y]

4

NMinimize finds the solution if you increase the WorkingPrecision NMinimize[pMeBis[k, 0.9, 10^31], k \[Element]Integers,WorkingPrecision -> 50] (*{2.0293883409099669577878953337601566621641181036332*10^-31, {k ->10}}*)

5

The numerical portion of the NMinimize function likely gets confused with all the large powers of 10. Try the non-numeric version instead, making sure to use only integers or rational numbers, so it does not convert to numerics automatically: Minimize[pMeBis[k, 9/10, 10^31], k ∈ Integers]//N {0., {k -> 10.}}

8

A severe problem is that Table generates an unpacked array, a thing that is often very annoying. When converting to an image, it is packed automatically (one can check that, e.g., with DeveloperPackedArrayQ[ImageData[Image[dat]]]). And because many functions work faster on packed arrays than on unpacked ones, this increases the performance. A vectorized ...

10

Is there any faster way available? There is, if you're willing to to use a different definition of "local maximum". If a local maximum is any value at least as high as any value in a 11x11 neighborhood, then you can use UnitStep[dat - Dilation[dat, 5]], which is about 16 times faster for your data: RepeatedTiming[MaxDetect[dat];][[1]] 0.016 ...

9

Why is MaxDetect so much slower when Chop is applied? Because Chop returns exact zeros what prevents packing of the matrix attempted by MaxDetect. You can detect an attempt to pack the array with Trace: Trace[MaxDetect[{{1.}}], DeveloperToPackedArray] // Flatten Applying N after Chop gives almost the same speed as without Chop because now the matrix can ...

6

A little bit faster than @kglr 's tricky answer is Position[dat, Max[dat]]

5

Look at FunctionRange Clear["Global`*"] f[a_, b_, c_] := a^b + c FunctionRange[ {f[a, b, c], 1 <= a <= 10, 0 <= b <= 3, 0 <= c <= 100}, {a, b, c}, y] EDIT: Alternatively, use MinValue and MaxValue f[a_, b_, c_, d_] = ((a*b)/1000)*c + d; cond = {-99 <= a <= 99, 0 <= b <= 1000, -500 <= c <= 500, 0 <= d <= 50}; ...

0

Here is some code which I think should do what you are after: ClearAll@scoreResults; scoreResults[a_ /; NumericQ[a[0]]] := Module[{temp, i}, temp = 0; For[i = 0, i < 2, i++, temp = temp + a[i]; If[a[i] > 300, temp = temp + 100000 ] ]; temp ] NMinimize[{scoreResults[a], {a[0] > 222, a[1] > 333}}, {a[0], a[1]}] note ...

Top 50 recent answers are included