molekyla777
  • Member for 8 years
  • Last seen this week
Merge two lists for List3DPlot
Accepted answer
2 votes

Try this Transpose@{list1[[All,1]],list1[[All,2]],list2} or this MapThread[{#1[[1]], #1[[2]], #2} &, {list1, list2}]

View answer
How to find a fit for a function?
2 votes

Edit: This work for me. V1=ph1=beta=V2=w2=ph2=alpha2=alpha1=w1=1; F[t_]:=V1 (Cos[w1 t-ph1] Exp[-alpha1 t]-Cos[ph1] Exp[-beta t])+V2 (Sin[w2 t+ph2] Exp[-alpha2 t]-Sin[ph2] Exp[-beta t]); data=Table[{t,...

View answer
Extract X value from corresponding Y value from a List or Transpose
2 votes

Try this: Y={1,3,4,1,2,3,5,5,2}; X=Y-1; data=Transpose[{X,Y}]; Select[data,#[[2]]==Max[Y]&][[All, 1]] or shorter Pick[X, Y, Max[Y]]

View answer
Simplifying Fourier transform of a complicated function
2 votes

Check if CUDALink is supported on your system. Needs["CUDALink`"] CUDAQ[] If return True use CUDAFourier and CUDAInverseFourier function.

View answer
Make a scatter plot from two columns of matrix
2 votes

Try this. This approach correct if Length[xAxisdData]==Length[yAxesdData[[i]]] xAxisdData={1,2,3,4}; yAxesdData={{1,2,3,4},{1,4,9,16}}; dataToPlot=Transpose[{xAxisdData,#}]&/@yAxesdData; ...

View answer
Treat strings as variables?
2 votes

Edit Try this Eliminate[ToExpression[ToString[{"x1"+"x3"-"x4"==0,"x1"+"x2"+"x3"==0}]],{x1}]

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
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
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
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
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
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
Converting format of list
1 votes

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

View answer
ParallelMap returns incorrect results over Map
1 votes

Documentation say: Import["!prog","format"] imports data from a pipe. I suggest that ParallelMap sent many requests to external program in one time and it return errors, but Mathematica interpret ...

View answer
Finding maximum or minimum of implicit functions
1 votes

You function is f = x^2 + y^2 - (2 x^2 + 2 y^2 - x)^2; Then call function Maximize Maximize[f, {x, y}] (*{27/64,{x->3/4,y->0}}*) And here is plot of you function

View answer
A problem with parallelize
Accepted answer
1 votes

1) K is a built-in symbol. Don't use this symbol. 2) Use DistributedContexts with ParallelTable tab = ParallelTable[1/299792^2*d*(K[10^5, 10^9, RcG[d, t]] - K[10^5, 10^9, 7.6] - d*T) + f[d, RcG[d, ...

View answer
Few quick Mathematica questions about Dictionary
Accepted answer
1 votes

Try this langlength = ({#, Length@DictionaryLookup[{#, All}]} & /@ DictionaryLookup[All]); lst = Sort[langlength, #1[[2]] > #2[[2]] &]; TableForm[lst, TableHeadings -> {Range[Length[lst]...

View answer
Replace every Minus to Plus in Expression
1 votes

Allways you can use pattern replace expr1 = a^2 - b + c*d expr2 = a - b expr3 = -a + b - c expr/. Times[-1, x_] :> Times[1, x] (* a^2 + b + c * d a + b a + b + c *)

View answer
Summarize a list of pairs / (Using GatherBy and Tally?)
1 votes

Here is one way. MyFunc[l_] := Block[{t1, t2, res}, t1 = Tally[l[[All, 1]]]; t2 = Tally[l[[All, 2]]]; res = {t1[[All, 2]], t2[[All, 2]], t1[[All, 1]], t2[[All, 1]]}; Return[res]; ];

View answer
region plot in a 2-simplex
0 votes

Maybe this will be helpful: Module[{n=300,p=0.29,r1,r2,r3,r4,x,y}, r1=y>(1/2)*(n-x); r2=y+x<=n; r3=y>p/(1-p)*x; (*RegionPlot[#,{x,0,n},{y,0,n},PlotStyle\[Rule]Opacity[.3]]&/@{r1,r2,r3}*) ...

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
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
Minimum and maximum values under conditions
Accepted answer
0 votes

Not pretty, but work #@Select[data,MemberQ[#,Alternatives@@{1,2}]&][[All,6]]&/@{Max,Min}

View answer
Intersection of lists of disjoint intervals
0 votes

or more general: youFunction[intervals__] := Composition[ DeleteCases[#, Interval[]] &, DeleteDuplicates, (IntervalIntersection @@ # &) /@ # &, Subsets[#, {2}] &, ...

View answer
How to simultaneously change the color and thickness in ContourStyle?
0 votes

Use Directive ContourPlot[x+y,{x,-1,1},{y,-1,1},ContourShading->False,Contours->Range[1,10],ContourStyle->Directive[Thick,Red]]

View answer
Better way to select all array indexes matching predicate?
0 votes

Use functions Sow and Reap t = Reap[ Do[ If[data[[x]][[y]] == 1, Sow[{x - wx/2, y - wy/2, data[[x]][[y]]}]], {x, 1, wx}, {y, 1, wy} ] ] t = t[[2,1]]

View answer
1
2