molekyla777
  • Member for 7 years, 11 months
  • Last seen more than a month ago
Finding the index of (x,y) pairs in a list
Accepted answer
3 votes

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

View answer
Extracting the body of a function
2 votes

If you use MMA 10 try DSolveValue instead of DSolve. In this case may help this: (*extracting expressions from Function*) t = Solution /. func_Function :> func[[2]]; (*extracting expressions from ...

View answer
Changing the atom color for plotting xyz-files
10 votes

Try this: t = Import["c:\\work\\temp\\1.xyz"]; allColors = {}; (*get all colors from Graphics3D*) Scan[If[MatchQ[#, RGBColor[__]], AppendTo[allColors, #]] &, t, Infinity]; allColors = ...

View answer
Importing an array from text file and convert it to truth table
Accepted answer
6 votes

Use Map: table = (Most[#] -> Last[#])& /@ arr

View answer
Computing a map between two lists
5 votes

With MMA10 this can be done by this code: DeleteDuplicates /@ GroupBy[Transpose@{L1, L2}, First -> Last] (*<|1 -> {2}, 2 -> {3, 1}, 3 -> {0}, 0 -> {0}|>*)

View answer
How to select states with equal times
0 votes

In MMA10 this can be done with TimeSeriesWindow EDIT Here base version of TimeSeriesWindow for MMA9 SelectBetweenDates[financialData_,{startDate_,endDate_}]:=Select[financialData,AbsoluteTime[...

View answer
Find the nearest locations for multiple points
0 votes

This may help: locations=RandomInteger[{-10,10},{4,2}]; holes=RandomInteger[{-10,10},{4,2}]; ListPlot[{locations, holes}, PlotLegends -> {"locations", "holes"}] distanceFunc = Nearest[holes, ...

View answer
Check if two lists are equal in any order
1 votes

Here is elegant way. Not fast but pretty func[lst1_List, lst2_List] := Module[{f1, f2, x}, SetAttributes[f1, Orderless]; SetAttributes[f2, Orderless]; f1[x__] := x; f2[x__] := x; TrueQ[{f1 @...

View answer
Plot part of a circle
0 votes

For plotting circles more natural use polar coordinate system: P1 = {Sqrt[2]/2, Sqrt[2]/2}; P2 = {-1, 0}; theta1 = ArcTan @@ P1; theta2 = ArcTan @@ P2; PolarPlot[1, {r, theta2, theta1}, PlotRange -&...

View answer
How do I set up initialization code for Wolfram Workbench MUnit tests?
Accepted answer
4 votes

Probably Child Test Files can help in your case. link

View answer
Spherical parametric plot
9 votes

covert your spherical parametrized curve into cartesian parametrized curve with formulas: $$\begin{cases} x&=r\sin\theta\cos\varphi\\ y&=r\sin\theta\sin\varphi\\ z&=r\cos\theta \end{cases}...

View answer
ContextPath and autocompletion with subpackages
1 votes

I think you have deal with Mathematica application. I know 2 way for solv this problem 1) Add path to your application in variable $Path. And then load with Get AppendTo[$Path,"C:\\path\\to\\your\\...

View answer
How to use multiple core in evaluation?
Accepted answer
2 votes

If your computation in each cycle takes little time there is no reason for paralleling this cycle. Prove: ParallelTable[i, {i, 1, 1000000}]; // AbsoluteTiming (*8 cores*) (*{0.449026, Null}*) Table[i,...

View answer
Save value computed in the loop and delete it
1 votes

First of all avoid using For loop better (and faster) use Do instead. stream = OpenWrite["c:\\1.txt"]; Do[ z = Exp[x^2]; Write[stream, z] , {x, 0, 100000, 0.5}]; Close[stream]; PS: it is best ...

View answer
Parallelization and evaluation of random number generation
1 votes

All function you need it's DistributeDefinitions and ParallelTry f1 := RandomInteger[{1, 24}] + RandomInteger[{1, 24}]; func[x_] := While[True, If[f1 === 2, Print["snake eyes"]; Return[...

View answer
One to Many Lists Merge
Accepted answer
4 votes

Approach using v10 functions: CustomMerge1[lists__] := Module[{assocList, keys, vals, res}, assocList = GroupBy[#, First -> Rest] & /@ {lists}; keys = Sort@DeleteDuplicates[Flatten[Keys /...

View answer
Setup default temporal directories for CCompilerDriver
Accepted answer
1 votes

There is undocumented function which return working (temporary) and target CCompilerDirectories[] (*{C:\Users\Александр\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64,C:\...

View answer
How to get a multiple line plot from a list of lists
Accepted answer
2 votes

Suppose input data is: lst = {{2, 4, 6, 8, 9}, {342432, 435345, 564564, 56756, 9945}, {23, 356, 565, 304, 564}, {3, 67, 76, 44, 7}} then using following code give 3 plots ListLinePlot[MapThread[...

View answer
Is there a way to riffle more than two lists?
4 votes

More genaral approach: Flatten@Riffle[{a, b, c, d, e, f, g}, Transpose@{{1, 2, 3}, {x, y, z}}] (*{a, 1, x, b, 2, y, c, 3, z, d, 1, x, e, 2, y, f, 3, z, g}*)

View answer
May I restrict caching to disk when memory runs low?
Accepted answer
3 votes

Use MemoryConstrained MemoryConstrained[yourCode, memoryLimit, actionOnMemoryLimitOverflow]

View answer
Strange behavior of function (memory leaks)
1 votes

I don't know why, but replacing Switch with nested If solved the problem of leaking memory.

View answer
Simplifying a time-series segmentation Query
1 votes

Small advice: use Missing[] instead of whitespace character. And dataset look better PS: if you have deal with time series probably better use TemporalData or TimeSeries

View answer
Using variables in file names during import/export
6 votes

Use ToString Do[ Export[yourPathToFile<>ToString[i+20]<>".csv", yourData[[i]]] ,{i,0,22}

View answer
How can I add a tangent arrow at a certain point of a curve in a LogPlot?
2 votes

EDIT Forgot for LogPlot. Firs of all read about tangent line. Then try to uderstand how work function getTangentVectAtValue func[t_]:=(1-t)^(-0.5); getTangentVectAtValue[func_,xValue_,vectLen_]:={{...

View answer
How to plot data points in the form X, Y, E(X, Y) where X and Y coordinates are not ordered?
4 votes

First of all read a help. It's say: Interpolation[{{{x1, y1, ...}, f1}, {{x2, y2, ...}, f2}, ...}] constructs an interpolation function of multidimensional data. Your data have form {{x1, y1, f1}...

View answer
List creation/manipulation
1 votes

Use Replace with levelspec = 1 createArray[array_, n_] := Composition[ Flatten[#, 1] &, Replace[#, x_ :> ConstantArray[x, n], 1] & ][array] Check function: createArray[{{a},{b},...

View answer
How to integrate a function which is only known at discrete points
1 votes

Let's denote values {t, f(t)} as F, then interpolate this array with ListInterpolation. fx = ListInterpolation[F[[All, 2]], {F[[1, 1]], F[[-1, 1]]}] Now we may use Integrate with fx Integrate[Sin[...

View answer
When I use Rule, why doesn't this work?
2 votes

It's not answer but comment Code k Esc.Esc k Esc.Esc k //. {k Esc.Esc k -> k} does not work becouse FullForm[k Esc.Esc k Esc.Esc k] (*CenterDot[k,k,k]*) and you try replace CenterDot[k,k] (...

View answer
Merging lists and adding common elements
2 votes

Sow, Reap implementation t = Join[L, J]; tags = DeleteDuplicates[t[[All, 1]]]; res = Reap[t /. {x_, y_} :> {Sow[y, x]}][[2]]; MapThread[{#1, Total@#2} &, {tags, res}] (*{{1, 1}, {2, 4}, {3, 3},...

View answer
Converting format of list
1 votes

Use data[[All,1]] for all x coordinates and data[[All,2]] for all y coordinates

View answer