Tag Info

New answers tagged


Use this: f = Compile[{{lst, _Real, 2}, {val, _Real, 1}}, First@First@Position[lst, val]]; f[samplelist, {1, 3}] (*3*)


ITS CRAZY I linked WolframRTL_Minimal.dll instead of WolframRTL.dll and then I put WolframRTL_Minimal.dll in the path where Visual Studio creates the executable :) Now it works and display 416.16 :)


Not sure if this is what you want, but this is much faster: ClearAll[a, c, phi, t1, psi, g]; a = 0; c[t_] := t*{Cos[t], Sin[t]} phi = Integrate[Sqrt[c'[t].c'[t]], {t, a, t1}, Assumptions -> t1 \[Element] Reals && t1 > 0]; psi = InverseFunction[Function[{t1}, Evaluate@phi]]; g[s_] := g[s] = c[psi[s]] ParametricPlot[g[x], {x, 0, 40}, PlotRange ...


This seems to work: cf = Block[{n, x, y}, Inactive[Compile][{y}, expr] // Activate] Edit - Some observations Inactivate effectively blocks evaluation of heads in an expression by wrapping them with Inactive. It does not hold or otherwise protect other symbols from being evaluated. This was inconvenient above, and I used Block to protect n, x and y in ...


Use good old Hold in place of Inactivate: expr = Hold[Block[{x = ConstantArray[0.0, 100]}, Do[x[[n]] = Sin[n/Pi]*Cos[y + n/100], {n, 100}]; x]]; then you can do simply use expr /. Hold[code_] :> Compile @@ Hold[{y}, code] which is, using injector pattern.

Top 50 recent answers are included