Tag Info

New answers tagged

0

From the documentation - If the internal implementation is using Round this could explain your results. Round rounds numbers of the form x.5 toward the nearest even integer.


5

It's a rounding problem. You can see it from: numbers = Rationalize@{0., 0.6, 0.8, 1., 1.2, 1.4, 1.8} midpoints = MovingAverage[numbers, 2] Nearest[numbers, #] & /@ midpoints (* {{0, 3/5}, {3/5, 4/5}, {4/5, 1}, {1, 6/5}, {6/5, 7/5}, {7/5, 9/5}} *) BTW, for long lists and reusable results use Nearest this way: f = Nearest[numbers]; f /@ midpoints


2

Try some thing like this: SetDirectory[dir]; files = FileNames["*.txt"]; Export[newdir <> "\\" <> files[[#]], Cases[Import[files[[#]]], {1, _}][[;; , 2]]] & /@ Range[Length[files]]


1

You can use Select if you are willing to modify your function slightly: Select[lis, (Function[{x, y}, #][2, 2] == 4) &] (*{x + y, x y}*)


0

Using the OP's function f lis = {x - y, x + y, x*y}; f[a_, b_] := # /. {x -> a, y -> b} & Map[First, Cases[Map[{#, f[2, 2][#]} &, lis], {_, 4}]] {x + y, x y} Alternatively Reap[Map[If[f[2, 2][#] == 4, Sow[#]] &, lis]][[-1, 1]] {x + y, x y}


1

list = {x - y, x + y, x*y}; Using a different test function, that tests for the equality and accepts the equality value as a parameter: testFun[{a_, b_, c_}] := (# /. {x -> a, y -> b}) == c &; testList = {{2, 2, 4}, {2, 0, 2}}; (* {2, 2, 4} means f[2,2] == 4, and {2, 0, 2} means f[2,0] == 2 *) You can either Map over list, returning the ...


1

Not sure if this would this would achieve what you described (I haven't been using MMA as much as I would like so my answer might be clumsy): Clear[countSameLetters] countSameLetters[list_List, distance_Integer] := Position[ Flatten@Differences@Position[list, #] & /@ CharacterRange["a", "z"], distance] // Length To display each distance with ...


1

comp[a_, b___, c_] := a == c k[list_, dist_] := Count[ListConvolve[SparseArray[{1 -> 1, # -> 1}, #]&[dist+1], list, {-1, 1}, 0, Times, comp], True] list = {d, a, e, a, e, b, e, b, c, d, d}; k[list, #] & /@ Range[Length[list] - 1] (* {1, 4, 0, 1, 0, 0, 0, 0, 1, 1} *)


3

Leaving your first part unchanged Remove["Global`*"] firstline = {1, 2, 3, 2, 7}; secondline = {4, 3, 2, 5, 7}; typeOfEndCondition = 0; cc = {3, 2}; In the second part of your code there is only a ; missing after the Print function: avald1 = Table[{}, {i, 5}]; For[i = 1, i <= Length[cc], i++, If[typeOfEndCondition == 0, conline = ...



Top 50 recent answers are included