1
$\begingroup$

Consider the following code

U={0.,0.,0.,0.,0.00817368,0.0122626,0.0163535,0.0208655,0.025796,0.0311445,
0.0370913,0.0436378,0.0507843,0.0579272,0.0669387,0.0778145,0.0905629,
0.103309,0.117888,0.134298,0.152544,0.170798,0.189057,0.206303,0.222534,
0.23775,0.252964,0.268183,0.283408,0.297553,0.310615,0.322596,0.334586,
0.346587,0.358596,0.370278,0.381626,0.392649,0.403679,0.412966,0.420502,
0.426288,0.432074,0.437862,0.443651,0.448986,0.453863,0.458279,0.46269,
0.467095,0.470992,0.474378,0.477252,0.480125,0.482991,0.485854,0.488778,
0.491768,0.494822,0.497876,0.502303,0.505044,0.507866,0.509265,0.510464,
0.511369,0.51204,0.512616,0.51319,0.513758,0.514338,0.514918,0.515905,
0.517295,0.519157,0.521105,0.52315,0.52523,0.527329,0.529441,0.531565,
0.534286,0.537608,0.541534,0.546153,0.551458,0.557451,0.563453,0.569467,
0.575485,0.58312,0.59236,0.603189,0.613984,0.635441,0.646097,0.658031,
0.685707,0.715436,0.731621,0.765757,0.78281,0.815485,0.842481,
0.855269,0.880847,0.893636,0.91831,0.92928,0.949413,0.959497,
0.969594,1.,1.,1.,1.};

NArgMax[BSplineBasis[{3, U}, #, x], x] & /@ Range[1, 110]

(*  {-6.96782,-6.96782,0.0119939,0.0165329,0.0210818,0.0260265,-6.96782,
  0.0374016,
 0.0438958,0.050987,0.0587446,0.0679349,0.0786408,0.0908766,0.104096,
 0.118843,
0.135094,0.152704,0.170715,0.188626,0.205784,0.222104,0.237665,0.252966,
0.268094,0.282946,0.296996,0.310156,0.322511,0.334591,0.346563,0.358458,
0.37011,0.38149,0.392473,0.402905,0.412026,0.419731,0.426147,0.432075,
0.437824,
0.443456,0.448749,0.453666,0.458239,-6.96782,-6.96782,-6.96782,-6.96782,
-6.96782,-6.96782,-6.96782,0.48588,0.488811,0.491795,0.494937,-6.96782,
-6.96782,-6.96782,-6.96782,-6.96782,-6.96782,-6.96782,-6.96782,0.512607,
 0.513189,0.513762,0.514371,-6.96782,-6.96782,-6.96782,0.519238,0.521148,
0.523172,0.52524,0.527336,0.529495,0.531829,0.534608,0.537935,0.541891,
0.546514,-6.96782,-6.96782,-6.96782,0.5696,0.576193,0.583977,0.59306,
0.604126,0.616939,0.632554,0.646816,0.66453,0.686672,0.712298,0.735337,
0.762662,0.786454,0.813548,0.837907,0.857441,0.878478,0.895491,0.91522,
0.930455,0.94651,0.960092,0.974142,0.988382} *)

In general, the relative values should be in the interval [0,1]. Obviously, the builtin gives the wrong results? In addtion, it takes much time.

So is there any fast method to compute the maxima-arguments?

Update

Although adding the constrint "0<=x<=1" could deal with the above proble, however, it is time-consuming when executing it just once. And in fact application, I need to execute it about 10-100 times.

enter image description here

$\endgroup$
3
  • $\begingroup$ What is it that you want to achieve? $\endgroup$
    – corey979
    Oct 11 '16 at 14:29
  • $\begingroup$ @corey979 I need the corresponding maxima position as the parameter values, then feed it to other function:) $\endgroup$
    – newer
    Oct 11 '16 at 14:31
  • $\begingroup$ Try NArgMax[{BSplineBasis[{3, U}, #, x], 0 <= x <= 1}, x] & /@ Range[1, 110], or NMaximize[{BSplineBasis[{3, U}, #, x], 0 <= x <= 1}, x] & /@ Range[1, 110] might be better $\endgroup$
    – corey979
    Oct 11 '16 at 14:40
0
$\begingroup$

If you give good starting points to FindMinimum, it's pretty fast (thanks to the OP for a considerable improvement):

maxima = FindArgMax[BSplineBasis[{3, uuu}, #, x],
      {x, uuu[[# + 1]], uuu[[# + 1 + 3]]}] & /@ Range[1, 110]; // AbsoluteTiming
(*  {0.023998, Null}  *)

Visualization:

ListPlot[Flatten@maxima, PlotRange -> All]

Mathematica graphics

The maxima are steadily increasing, so it looks like a pretty good result.

$\endgroup$
6
  • 1
    $\begingroup$ Thanks for your fast method. In fact, to my knowledge, for the i-th B-spline basis $N_{i,p}(x)$ of degree $p$, whose valid interval should be $[x_i,x_{i+p+1}]$. Namely, the starting point could be setted to $x_i$. Thanks a again:) $\endgroup$
    – newer
    Oct 12 '16 at 3:03
  • $\begingroup$ @newer Thanks for the accept. You might want to avoid the very edge of the support. My way attempted (in a rather unclever way) to get two points near the "middle." One would probably run into trouble if the points get outside the support of the function. $\endgroup$
    – Michael E2
    Oct 12 '16 at 3:10
  • 1
    $\begingroup$ So I think the above code could be revised to FindArgMax[ BSplineBasis[{3, U}, #, x], {x, U[[# + 1]], U[[# + 1 + 3]]}] & /@ Range[1, 110]. $\endgroup$
    – newer
    Oct 12 '16 at 3:10
  • $\begingroup$ @newer Yes, that is probably better. $\endgroup$
    – Michael E2
    Oct 12 '16 at 3:16
  • $\begingroup$ In addtion, I am so sorry for that I cannot upvote to this good answer owing that I have the upvote-privilage.:) $\endgroup$
    – newer
    Oct 12 '16 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.