Given a sorted list of numbers $S$, I want to create a function that accepts a list of numbers $L$ and for each number $l \in L$ it returns the index of the largest number $s \in S$ such that $s {0.405196, 4.56535, 7.04274, 7.95001, 8.6823} And, here are a couple examples of the argument to the function: {6.67917, 8.33874, 4.61316, 4.83263, 9.52033} {6.0669, 1.22425, 6.13959} Then, I want to create a function such that return: One possibility is to use: But, this approach is quite slow when dealing with large arguments: {1.15025, Null} I'm interested in arguments on the order of 10^6 elements, and ordered sets $S$ on the order 10^4 elements. Is there a faster method?SeedRandom[13];
S = Sort @ RandomReal[10, 5]SeedRandom[10];
list1 = RandomReal[10, 5]
list2 = RandomReal[10, 3]f
:f = findIndices[S];
f[list1]
f[list2](*
{2, 4, 2, 2, 5}
{2, 1, 2}
*)findIndices[s_] := Interpolation[
Thread[{s, Range@Length@s-1}],
InterpolationOrder->0,
"ExtrapolationHandler" -> {Evaluate[Length[s]]&, "WarningMessage" -> False}
]f = findIndices[S];
tst = RandomReal[{.5, 10}, 10^6];
f[tst]; //AbsoluteTiming
Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]
Comments
Post a Comment