Find the minima and maxima of a list

I have a list, such as:               testdata = {{1, 317}, {2, 317}, {3, 317}, {4, 317}, {5, 317}, {6,          317}, {7, 318}, {8, 318}, {9, 318}, {10, 318}, {11, 319}, {12,          319}, {13, 319}, {14, 319}, {15, 314}, {16, 314}, {17, 314}, {18,          314}, {19, 314}, {20, 314}, {21, 314}, {22, 314}, {23, 314}, {24,          314}, {25, 314}, {26, 314}, {27, 314}, {28, 306}, {29, 306}, {30,          306}, {31, 306}, {32, 293}, {33, 293}, {34, 293}, {35, 293}, {36,          293}, {37, 293}, {38, 293}, {39, 223}, {40, 223}, {41, 223}, {42,          223}, {43, 154}, {44, 154}, {45, 154}, {46, 154}, {47, 219}, {48,          219}, {49, 219}, {50, 219}, {51, 267}, {52, 267}, {53, 267}, {54,          267}, {55, 293}, {56, 293}, {57, 293}, {58, 293}, {59, 300}, {60,          300}, {61, 300}, {62, 300}, {63, 287}, {64, 287}, {65, 287}, {66,          287}, {67, 273}, {68, 273}, {69, 273}, {70, 248}, {71, 248}, {72,          248}, {73, 248}, {74, 232}, {75, 232}, {76, 232}, {77, 232}, {78,          203}, {79, 203}, {80, 203}, {81, 203}, {82, 180}, {83, 180}, {84,          180}, {85, 180}, {86, 163}, {87, 163}, {88, 163}, {89, 163}, {90,          158}, {91, 158}, {92, 158}, {93, 158}, {94, 179}, {95, 179}, {96,          179}, {97, 179}, {98, 203}, {99, 203}, {100, 203}, {101,          203}, {102, 228}, {103, 228}, {104, 228}, {105, 228}, {106,          228}, {107, 228}, {108, 228}, {109, 228}, {110, 228}, {111,          228}, {112, 228}, {113, 228}, {114, 228}, {115, 230}, {116,          230}, {117, 230}, {118, 230}, {119, 225}, {120, 225}, {121,          225}, {122, 225}, {123, 214}, {124, 214}, {125, 214}, {126,          224}, {127, 224}, {128, 224}, {129, 224}, {130, 228}, {131,          228}, {132, 228}, {133, 228}, {134, 239}, {135, 239}, {136,          239}, {137, 239}, {138, 244}, {139, 244}, {140, 244}, {141,          244}, {142, 232}, {143, 232}, {144, 232}, {145, 232}, {146,          231}, {147, 231}, {148, 231}, {149, 231}, {150, 192}, {151,          192}, {152, 192}, {153, 192}, {154, 128}, {155, 128}, {156,          128}, {157, 128}, {158, 112}, {159, 112}, {160, 112}, {161,          192}, {162, 192}, {163, 192}, {164, 192}, {165, 249}, {166,          249}, {167, 249}, {168, 249}, {169, 257}, {170, 257}, {171,          257}, {172, 257}, {173, 240}, {174, 240}, {175, 240}, {176,          240}, {177, 214}, {178, 214}, {179, 214}, {180, 214}, {181,          200}, {182, 200}, {183, 200}, {184, 200}, {185, 212}, {186,          212}, {187, 212}, {188, 212}, {189, 201}, {190, 201}, {191,          201}, {192, 201}, {193, 173}, {194, 173}, {195, 173}, {196,          140}, {197, 140}, {198, 140}, {199, 140}, {200, 137}, {201,          137}, {202, 137}, {203, 137}, {204, 149}, {205, 149}, {206,          149}, {207, 149}, {208, 164}, {209, 164}, {210, 164}, {211,          164}, {212, 203}, {213, 203}, {214, 203}, {215, 203}, {216,          242}, {217, 242}, {218, 242}, {219, 242}, {220, 270}, {221,          270}, {222, 270}, {223, 270}, {224, 275}, {225, 275}, {226,          275}, {227, 275}, {228, 266}, {229, 266}, {230, 266}, {231,          275}, {232, 275}, {233, 275}, {234, 275}, {235, 285}, {236,          285}, {237, 285}, {238, 285}, {239, 291}, {240, 291}, {241,          291}, {242, 291}, {243, 277}, {244, 277}, {245, 277}, {246,          277}, {247, 271}, {248, 271}, {249, 271}, {250, 271}, {251,          271}, {252, 271}, {253, 271}, {254, 271}, {255, 271}, {256,          271}, {257, 271}, {258, 271}, {259, 271}, {260, 266}, {261,          266}, {262, 266}, {263, 266}, {264, 195}, {265, 195}, {266,          195}, {267, 195}, {268, 128}, {269, 128}, {270, 128}, {271,          128}, {272, 193}, {273, 193}, {274, 193}, {275, 193}, {276,          252}, {277, 252}, {278, 252}, {279, 276}, {280, 276}, {281,          276}, {282, 276}, {283, 271}, {284, 271}, {285, 271}, {286,          271}, {287, 256}, {288, 256}, {289, 256}, {290, 256}, {291,          250}, {292, 250}, {293, 250}, {294, 250}, {295, 236}, {296,          236}, {297, 236}, {298, 236}, {299, 211}, {300, 211}, {301,          211}, {302, 211}, {303, 188}, {304, 188}, {305, 188}, {306,          188}, {307, 165}, {308, 165}, {309, 165}, {310, 165}, {311,          156}, {312, 156}, {313, 156}, {314, 153}, {315, 153}, {316,          153}, {317, 153}, {318, 165}, {319, 165}, {320, 165}, {321,          165}, {322, 191}, {323, 191}, {324, 191}, {325, 191}, {326,          228}, {327, 228}, {328, 228}, {329, 228}, {330, 261}, {331,          261}, {332, 261}, {333, 261}, {334, 267}, {335, 267}, {336,          267}, {337, 267}, {338, 267}, {339, 267}, {340, 267}, {341,          267}, {342, 267}, {343, 267}, {344, 267}, {345, 267}, {346,          267}, {347, 266}, {348, 266}, {349, 266}, {350, 266}, {351,          259}, {352, 259}, {353, 259}, {354, 259}, {355, 258}, {356,          258}, {357, 258}, {358, 258}, {359, 251}, {360, 251}, {361,          251}, {362, 251}, {363, 254}, {364, 254}, {365, 254}, {366,          252}, {367, 252}, {368, 252}, {369, 252}, {370, 260}, {371,          260}, {372, 260}, {373, 260}, {374, 275}, {375, 275}, {376,          275}, {377, 275}, {378, 209}, {379, 209}, {380, 209}, {381,          209}, {382, 136}, {383, 136}, {384, 136}, {385, 136}, {386,          175}, {387, 175}, {388, 175}, {389, 175}, {390, 240}, {391,          240}, {392, 240}, {393, 240}, {394, 267}, {395, 267}, {396,          267}, {397, 267}, {398, 255}, {399, 255}, {400, 255}, {401,          243}, {402, 243}, {403, 243}, {404, 243}, {405, 227}, {406,          227}, {407, 227}, {408, 227}, {409, 218}, {410, 218}, {411,          218}, {412, 218}, {413, 207}, {414, 207}, {415, 207}, {416,          207}, {417, 196}, {418, 196}, {419, 196}, {420, 196}, {421,          195}, {422, 195}, {423, 195}, {424, 195}, {425, 200}, {426,          200}, {427, 200}, {428, 200}, {429, 214}, {430, 214}, {431,          214}, {432, 214}, {433, 229}, {434, 229}, {435, 229}, {436,          229}, {437, 256}, {438, 256}, {439, 256}, {440, 283}, {441,          283}, {442, 283}, {443, 283}, {444, 285}, {445, 285}, {446,          285}, {447, 285}, {448, 293}, {449, 293}, {450, 293}, {451,          293}, {452, 294}, {453, 294}, {454, 294}, {455, 294}, {456,          294}, {457, 294}, {458, 294}, {459, 294}, {460, 293}, {461,          293}, {462, 293}, {463, 293}, {464, 278}, {465, 278}, {466,          278}, {467, 278}, {468, 277}, {469, 277}, {470, 277}, {471,          277}, {472, 266}, {473, 266}, {474, 266}, {475, 251}, {476,          251}, {477, 251}, {478, 251}, {479, 250}, {480, 250}, {481,          250}, {482, 250}, {483, 250}, {484, 250}, {485, 250}, {486,          250}, {487, 250}, {488, 250}, {489, 250}, {490, 250}, {491,          250}, {492, 239}, {493, 239}, {494, 239}, {495, 239}, {496,          159}, {497, 159}, {498, 159}, {499, 159}, {500, 139}, {501,          139}, {502, 139}, {503, 139}, {504, 215}, {505, 215}, {506,          215}, {507, 215}, {508, 267}, {509, 267}, {510, 267}, {511,          267}, {512, 289}, {513, 289}, {514, 289}, {515, 289}, {516,          267}, {517, 267}, {518, 267}, {519, 267}, {520, 256}, {521,          256}, {522, 256}, {523, 256}, {524, 222}, {525, 222}, {526,          222}, {527, 194}, {528, 194}, {529, 194}, {530, 194}, {531,          185}, {532, 185}, {533, 185}, {534, 185}, {535, 181}, {536,          181}, {537, 181}, {538, 181}, {539, 195}, {540, 195}, {541,          195}, {542, 195}, {543, 199}, {544, 199}, {545, 199}, {546,          199}, {547, 199}, {548, 199}, {549, 199}, {550, 199}, {551,          214}, {552, 214}, {553, 214}, {554, 214}, {555, 226}, {556,          226}, {557, 226}, {558, 226}, {559, 255}, {560, 255}, {561,          255}, {562, 268}, {563, 268}, {564, 268}, {565, 268}, {566,          274}, {567, 274}, {568, 274}, {569, 274}, {570, 274}, {571,          274}, {572, 274}, {573, 274}, {574, 274}, {575, 274}, {576,          274}, {577, 274}, {578, 274}, {579, 268}, {580, 268}, {581,          268}, {582, 268}, {583, 270}, {584, 270}, {585, 270}, {586,          270}, {587, 260}, {588, 260}, {589, 260}, {590, 260}, {591,          250}, {592, 250}, {593, 250}, {594, 250}, {595, 230}, {596,          230}, {597, 230}, {598, 230}, {599, 227}, {600, 227}, {601,          227}, {602, 227}, {603, 240}, {604, 240}, {605, 240}, {606,          240}, {607, 240}, {608, 240}, {609, 240}, {610, 235}, {611,          235}, {612, 235}, {613, 235}, {614, 156}, {615, 156}, {616,          156}, {617, 156}, {618, 108}, {619, 108}, {620, 108}, {621,          108}, {622, 190}, {623, 190}, {624, 190}, {625, 190}, {626,          237}, {627, 237}, {628, 237}, {629, 237}, {630, 261}, {631,          261}, {632, 261}, {633, 261}, {634, 242}, {635, 242}, {636,          242}, {637, 242}, {638, 215}, {639, 215}, {640, 215}, {641,          215}, {642, 191}, {643, 191}, {644, 191}, {645, 162}, {646,          162}, {647, 162}, {648, 162}, {649, 160}, {650, 160}, {651,          160}, {652, 160}, {653, 148}, {654, 148}, {655, 148}, {656,          148}, {657, 147}, {658, 147}, {659, 147}, {660, 147}, {661,          160}, {662, 160}, {663, 160}, {664, 160}, {665, 177}, {666,          177}, {667, 177}, {668, 177}, {669, 211}, {670, 211}, {671,          211}, {672, 211}, {673, 234}, {674, 234}, {675, 234}, {676,          234}, {677, 252}, {678, 252}, {679, 252}, {680, 261}, {681,          261}, {682, 261}, {683, 261}, {684, 261}, {685, 261}, {686,          261}, {687, 261}, {688, 259}, {689, 259}, {690, 259}, {691,          259}, {692, 245}, {693, 245}, {694, 245}, {695, 245}, {696,          252}, {697, 252}, {698, 252}, {699, 252}, {700, 267}, {701,          267}, {702, 267}, {703, 267}, {704, 278}, {705, 278}, {706,          278}, {707, 278}, {708, 277}, {709, 277}, {710, 277}, {711,          277}, {712, 267}, {713, 267}, {714, 267}, {715, 267}, {716,          267}, {717, 267}, {718, 267}, {719, 267}, {720, 267}, {721,          267}, {722, 267}, {723, 267}, {724, 267}, {725, 267}, {726,          267}, {727, 267}, {728, 267}, {729, 259}, {730, 259}, {731,          259}, {732, 259}, {733, 177}, {734, 177}, {735, 177}, {736,          132}, {737, 132}, {738, 132}, {739, 132}, {740, 202}, {741,          202}, {742, 202}, {743, 202}, {744, 258}, {745, 258}, {746,          258}, {747, 258}, {748, 285}, {749, 285}, {750, 285}, {751,          285}, {752, 278}, {753, 278}, {754, 278}, {755, 278}, {756,          268}, {757, 268}, {758, 268}, {759, 268}, {760, 251}, {761,          251}, {762, 251}, {763, 251}, {764, 242}, {765, 242}, {766,          242}, {767, 251}, {768, 251}, {769, 251}, {770, 251}, {771,          222}, {772, 222}, {773, 222}, {774, 222}, {775, 186}, {776,          186}, {777, 186}, {778, 186}, {779, 164}, {780, 164}, {781,          164}, {782, 164}, {783, 161}, {784, 161}, {785, 161}, {786,          161}, {787, 177}, {788, 177}, {789, 177}, {790, 177}, {791,          198}, {792, 198}, {793, 198}, {794, 198}, {795, 234}, {796,          234}, {797, 234}, {798, 249}, {799, 249}, {800, 249}, {801,          249}, {802, 249}, {803, 249}, {804, 249}, {805, 249}, {806,          249}, {807, 249}, {808, 249}, {809, 249}, {810, 249}, {811,          249}, {812, 256}, {813, 256}, {814, 256}, {815, 244}, {816,          244}, {817, 244}, {818, 244}, {819, 239}, {820, 239}, {821,          239}, {822, 239}, {823, 248}, {824, 248}, {825, 248}, {826,          248}, {827, 256}, {828, 256}, {829, 256}, {830, 256}, {831,          244}, {832, 244}, {833, 244}, {834, 244}, {835, 228}, {836,          228}, {837, 228}, {838, 228}, {839, 225}, {840, 225}, {841,          225}, {842, 225}, {843, 224}, {844, 224}, {845, 224}, {846,          224}, {847, 222}, {848, 222}, {849, 222}, {850, 222}, {851,          154}, {852, 154}, {853, 154}, {854, 128}, {855, 128}, {856,          128}, {857, 128}, {858, 206}, {859, 206}, {860, 206}, {861,          206}, {862, 262}, {863, 262}, {864, 262}, {865, 262}, {866,          289}, {867, 289}, {868, 289}, {869, 289}, {870, 271}, {871,          271}, {872, 271}, {873, 271}, {874, 244}, {875, 244}, {876,          244}, {877, 244}, {878, 222}, {879, 222}, {880, 222}, {881,          222}, {882, 206}, {883, 206}, {884, 206}, {885, 206}, {886,          196}, {887, 196}, {888, 196}, {889, 183}, {890, 183}, {891,          183}, {892, 183}, {893, 178}, {894, 178}, {895, 178}, {896,          178}, {897, 172}, {898, 172}, {899, 172}, {900, 172}, {901,          171}, {902, 171}, {903, 171}, {904, 171}, {905, 192}, {906,          192}, {907, 192}, {908, 192}, {909, 213}, {910, 213}, {911,          213}, {912, 213}, {913, 249}, {914, 249}, {915, 249}, {916,          279}, {917, 279}, {918, 279}, {919, 279}, {920, 282}};      Q1: I would like to get the peak and valley in the graph and draw it, Q2: I would like to find how many valleys are in this list, Q3: I would like to get the first 200 points and minimum valleys. This is what I've tried so far:               ListLinePlot[testdata]      * * * Thanks for your help, I have been successful :) this is my code               mins=Pick[testdata,MinDetect[testdata[[All,2]]],1];     maxs=Pick[testdata,MaxDetect[testdata[[All,2]]],1];     Show[ListLinePlot[testdata[[All,2]],Filling->Axis,AxesLabel->{number,ECG_Data}],ListPlot[maxs,PlotStyle->Red,PlotLegends->{"Peak"}],ListPlot[mins,PlotStyle->Blue,PlotLegends->{"Valley"}]]     Thr=200;          findpeak=Position[Differences[MaxDetect[testdata[[All,2]]]],-1];     findvalley=Position[Differences[MinDetect[testdata[[All,2]]]],-1];     peak=Extract[testdata,findpeak];     valley=Extract[testdata,findvalley];     valleysmin200=Select[valley,#[[2]]<Thr&];     f1=ListLinePlot[testdata,AxesLabel->{number,ECG_Data},Filling->Axis,FillingStyle->Automatic];     f2=ListPlot[peak,PlotStyle->{Red,PointSize[Large]},PlotLegends->{"Peak"}];     f3=ListPlot[valley,PlotStyle->{Blue,PointSize[Large]},PlotLegends->{"Valley"}];     f4=ListPlot[valleysmin200,PlotStyle->{Blue,PointSize[Large]},PlotLegends->{"Valley"}];     f5=ListLinePlot[Table[Thr,{Length[testdata]}],PlotStyle -> Pink];     Show[f1,f2,f3] (*modify peak & valley*)     Show[f1,f4,f5] (*valley<200*)     Length[valleysmin200]/2*12


define a function from a list

I would like to create a mapping from a list and I am wondering if there is a slick way of doing it. For example, consider the list               ls = WaveletFilterCoefficients[DaubechiesWavelet[2], "PrimalHighpass"]          {{-2, -0.0915064},{-1, -0.158494},{0, 0.591506},{1, -0.341506}}      I would like to define a function that maps                -2 -> -0.0915064      -1 -> -0.158494       0 ->  0.591506       1 -> -0.341506      and all other integers to zero. Any suggestions?


When does a list contain only ones?

I am starting with a list of length n that contains all -1's. For instance, when `n = 6` the list is `{-1, -1, -1, -1, -1, -1}`. I pick a random integer from 1 to n and toggle the element by multiplying by -1. In the given list, if I pick the third element, the new list would be `{-1, -1, 1, -1, -1, -1}`. I continue in this manner, picking an element randomly and toggling it from plus to minus or minus to plus. I wish to know how long it will take for the list to have all 1's. How long will it take to become `{1, 1, 1, 1, 1, 1}`? My code is:               toggle[box_, n_] :=       Block[{r, h = box},         r = RandomInteger[{1, n}];         h[[r]] = -h[[r]];         h]          n = 6;     trials = 40000;     box = ConstantArray[-1, n];     ans =        Table[sbox = box;              (NestWhileList[toggle[#, n] &,                             sbox,                             Total[#] != n &] // Length) - 1,             {trials}];     Mean[ans] // N      The exact answer for this one is 416 / 5. I am getting around 83 for my simulation, but it is deadly slow. Can I speed it up?


What are the min and max arguments to EdgeDetect?

What are the min and max arguments to `EdgeDetect`, for all methods and specifically `"Sobel"`? How do I find the limits or ranges of functions in the future? Or is it 255?


GraphPlot3D: How to plot undirected graph with a list of edges?

I have a list of edges defined based on vertices like this:               Edges={{2, 1}, {10, 9}, {11, 10}, {11, 4}, {17, 12},.....}      (*Where each number is the index of a vertex which has 3D coordinates*)      In order to plot a graph I first made Edges looks like this (I want to plot **undirected** graph)               edges = Flatten[Table[{Edges[[i, 1]] <-> Edges[[i, 2]]}, {i, 1, Length[Edges]}]];      Then I plot the graph               GraphPlot3D[edges, VertexLabeling -> False, (*VertexCoordinateRules -> nodescoord*), \BoxRatios -> Automatic,ViewPoint -> {0, 0, -Infinity}];      Where am I wrong? Is it the way I define edges using "<->"?


Nonlinear Optimization with conditional statement

I find Maximize doesn't work well under **conditional statement**. Here is an example. ![enter image description here](http://i.stack.imgur.com/q44hN.jpg) A car is driving up a slope. I want to find out the largest slope angle the car can drive upwards. I choose the slope angle `θ` and engine torque `τ` as decision variables. The friction force can be described by Coulomb friction model, which is a conditional statement ![enter image description here](http://i.stack.imgur.com/3OCva.jpg) The complete formulation is ![enter image description here](http://i.stack.imgur.com/DFbvG.jpg) Therefore, the Nonlinear Optimization can be solved by                 Maximize[{θ, 0 < θ < Pi/2 && 0 < τ < 2 &&                  If[τ/r < μs*G*Cos[θ], τ/r, μd G Cos[θ]] > G Sin[θ]}, {θ, τ}]      given the parameters: G = 70; r = 0.025; μs = 0.5; μd = 0.4; Mathematica gives `θ=0.380506`,,which is ArcTan[μd], whereas the expected result should be `θ=0.46364`,which is ArcTan[μs].


Plot lines and measure the distances between them

I have the following code:               aJ = 5.2;     OmJ = N[2 Pi/aJ^(3/2)]     {val1} = NSolve[o/OmJ == 2., o]      {val2} = NSolve[o/OmJ == 3., o]     {val3} = NSolve[o/OmJ == 5./2., o]     {val4} = NSolve[o/OmJ == 7./2., o]     {val5} = NSolve[o/OmJ == 4., o]      {val6} = NSolve[o/OmJ == 3./2., o]     {val7} = NSolve[o/OmJ == 5./3., o]     {val8} = NSolve[o/OmJ == 7./3., o]          d = 7;     n = 6;     p = ListPlot[        Flatten[Table[{o /. NSolve[o/OmJ == j/i, o], n}, {j, 2, 9, 1}, {i,            1, 4, 1}], 1],        Filling -> Axis, AxesLabel -> {"mean motion", "par"},         FillingStyle -> {Red}, PlotRange -> {{0.3, 2.2}, {0, 800}},         PlotMarkers -> Automatic, PlotStyle -> Black, ImageSize -> 700,        Epilog -> {{AbsolutePointSize[8], Black,            Text["Jupiter Position", {OmJ, 1}],            Point[{OmJ, 0.1}]},          {Blue, Text[Style["2:1", Bold, Black, 16], {o /. val1, d}],            Text[Style["3:1", Bold, Black, 16], {o /. val2, d}],            Text[Style["5:2", Bold, Black, 16], {o /. val3,  d}],            Text[Style["7:2", Bold, Black, 16], {o /. val4,  d}],            Text[Style["4:1", Bold, Black, 16], {o /. val5,  d}],            Text[Style["3:2", Bold, Black, 16], {o /. val6,  d}],           Text[Style["5:3", Bold, Black, 16], {o /. val7,  d}],            Text[Style["7:3", Bold, Black, 16], {o /. val8,  d}]}}];          t = Show[{p}, PlotRange -> {{0.3, 2.2}, {0, 8}}, ImageSize -> 600]      And i like to draw also lines under every texts. **Then** i like to know in such a way how far (the distance) a line is from another one. I red this post: Distance between point and line segments but i ddin't understand a lot.


How to replace subscript symbols

I have an expression with subscripted variables. I would like to replace all those terms with other symbols. For example, $P_1 + P_2^3 \rightarrow P1 + P2^3$ I used the following code but it doesn't work               X = Subscript[P, 1] + Subscript[P, 3]^2 - I*Subscript[P, 5]     X /. {Subscript[P, n_] -> Pn}      If I replace `Subscript[P, n_]` with `P[n]` then it works (e.g. $P_1$ will be replaced with `P[1]`) but I don't want the bracket. I want `P1` instead. Is there any way to solve this?


Using derivative d in Mathematica

In mathematics derivates are often written like $$d^2y \over dx^2$$ or $$dy \over dx$$ In Mathematica we have the function D, but is it possible to use a similar approach?


Having variables appear aqua in user defined function

In many of the inbuilt mathematica function, variables appear aqua like in: ![enter image description here](http://i.stack.imgur.com/flHO1.png) However, when creating your own function, variables no longer have that green coloring and are instead colored like an undefined variable ![enter image description here](http://i.stack.imgur.com/m1xqw.png) Is there any way to define functions so that variables used in arguments like in the manner above can get the aqua syntax coloring?


How do I make my function behave more like Plot?

I have written a function `Fun` as below:               Fun[x_Symbol, xrange_, imageSize_, axeslabel_] :=      Plot[x^2, {x, xrange[[1]], xrange[[2]]},         ImageSize -> imageSize,         AxesLabel -> axeslabel]          Fun[x, {-1, 2}, 400, {"x", "y"}]      ![enter image description here](http://i.stack.imgur.com/XRgbe.png) However, I'd like to rewrite it to use `OptionsPattern`               RewriteFun[x_Symbol, OptionsPattern[Plot]] :=        Plot[x^2, {x, -1, 2},          ImageSize -> OptionValue[ImageSize],          AxesLabel -> OptionValue[AxesLabel]]          RewriteFun[x, ImageSize -> 400, AxesLabel -> {"x", "y"}]      ![enter image description here](http://i.stack.imgur.com/pERvd.png) I have two problems.   * I don't know how to deal with an option like `{x, xmin, xmax}`.   * I don't how to get the kind of syntax coloring the varible `x` has in `Plot[x^2, {x, -1, 2}]`. ![enter image description here](http://i.stack.imgur.com/Ajifs.png) So my question is: How do I revise the `RewriteFun` to solve my problems?


Making sure that Timing[] isn't thrown off by caching

In playing with and comparing the various answers to my question here, I tried applying `Timing[]` to see how fast things ran, but it seemed that some of the answers (but not all of them) were a lot faster when run for a second time. How can I make sure that there isn't some kind of caching of intermediate results throwing off the `Timing[]`?


Why does JLink lock unopened jar-files in Windows

Since the introduction of `JLink` (maybe a bit later) it is possible to put jar libraries inside the directory-structure of packages. If this package is installed in one of the places Mathematica searches, the jar libraries are automatically found by `JLink`. The problem is that under 64 bit Windows XP, after loading `JLink` these files are locked and cannot be removed from within Mathematica, although none of the jars are really used, but only added to the class-path of Java. Let me give a short example: Place a `Test` folder with `Java` subfolder inside your `$UserAddOnsDirectory` and copy any jar file into the `Java` folder. This looks like               Test/     └── Java         └── blub.jar      When you now start a fresh Kernel and load `<<JLink`` you can verify by looking at `JavaClassPath[]`, that this directory and the jar was indeed added to the class-path. When you try to remove the complete folder, you get (a misleading) error message               DeleteDirectory[path, DeleteContents -> True]          (*         DeleteDirectory::dirne: Directory D:\Documents and Settings\mscheibe\         Application Data\Mathematica\Applications\Test not empty. >>     *)      After `Quit`-ing the kernel, calling `UninstallJava[]` or `JLink`QuitJava[]` the directory can be removed. This behavior does not occur in Linux or on MacOSX and I could only test it on `Windows XP 64 bit`. **Question:** Why, if the jar-path is only appended to the class-path, does `JLink` lock the files as they where opened for reading? Why does this happen on `Windows` only? Is there anyone, who has a deeper insight into `JLink` who can suggest a better solution that calling `JLink`QuitJava[]; Pause[2];` inside my module when I want to remove a jar-file found by Mathematica. **Remark 1:** This behavior is not restricted to automatically found jars. When you use java-code by manually adding a jar with `AddToClassPath[path]` the similar thing happens. **Remark 2:** I forgot to mention, that `JLink`QuitJava[]` does not really quit java like `Quit` would kill the kernel. Meaning, I call this and _without_ doing anything else I can still call my functions inside the jars. This seems to suggest, that `QuitJava[]` kills the class-loader instance Leonid is mentioning which locks the files. But a call to e.g. `JavaNew` seems to set up everything correct again.


Is it safe to launch/close kernels in the middle of a parallel calculation?

It appears that it is possible to launch additional kernels (or close existing ones) _during_ a parallel calculation. The newly launched kernels will be utilized for the rest of the calculation. Here's a simple way to test and illustrate this (in a fresh kernel):               LaunchKernels[2]          Parallelize[      Table[Pause@RandomInteger[20]; $KernelID, {i, 8}],      Method -> "FinestGrained"     ]      Now use `Evaluation -> Interrupt Evaluation...` to interrupt the evaluation and go into a subsession. In the subsession evaluate               $KernelCount (* check that we only have 2 kernels *)          LaunchKernels[4] (* launch 4 more *)          Return (* return from the dialog *)      Notice that when the `Table[]` finally finishes, we get results between 1 and 6 (I got `{2, 1, 6, 5, 4, 3, 2, 1}`). This means that all 6 kernels have been utilized during the rest of the evaluation, even though some kernels were only launched in the middle of the calculation. It is also possible to close some kernels during the calculation. In another test I got the following messages ... ![Mathematica graphics](http://i.stack.imgur.com/ePKP1.png) ... and the calculation seemed to finish correctly. **Question:** Is it safe to do this? Can this break anything if the timings are wrong? * * * Consider some code like this:               (* This uses LaunchKernels[] to launch more kernels        as compute resources become available: *)     manageKernels[] := ...          (* ensure that manageKernels[] is always evaluated on the master kernel *)     SetSharedFunction[manageKernels]           Parallelize[      Table[manageKernels[]; compute[i], {i, 100}],      Method -> "FinestGrained"     ]      Is this going to be safe? What if `manageKernels[]` uses `CloseKernels[]` as well?


Built-in Mathematica data: are they cached? how to speed up the loading?

Mathematica has numerous built-in data for **science** and **math**. Every first call to a data function in a new Mathematica session will "re-initialize indices" (download the data). Is there a way to store this data locally to save time on the next data call after Mathematica is restarted? ![enter image description here](http://i.stack.imgur.com/bUkv8.png) **======== Edit: further thoughts with Leonid's answer ========** After Leonid posted his answer, I decided to update this question – the title and content. I would ask about this anyway – so may as well do it here. The point is not in whether data were cached or not, but really in a method to speed up the load process. I just confused caching and loading. I do not want to take away “best answer” from Spartacus, because he did answer what I asked ideally, thanks. But thank you very much Leonid for posting your answer too. +1 to both of you.


Why these (error) messages?

Testing this answer I used:               stream = OpenWrite["A:\\out.txt"];          Block[{$Messages = stream},       Mod[1, 2, 3, 4, 5]     ]      and I was surprised to find that the contents of `out.txt` read: > >     Intersection::normal: >        Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[ >         Intersection[{StandardForm, TraditionalForm}, FormatType] >         , "MT"]\)\[NoBreak]. >> >   >     Intersection::normal: >        Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[ >         Intersection[{StandardForm, TraditionalForm}, FormatType] >         , "MT"]\)\[NoBreak]. >> >   >     Intersection::normal: >        Nonatomic expression expected at position \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] in \[NoBreak]\!\(\*StyleBox[ >         Intersection[{StandardForm, TraditionalForm}, FormatType] >         , "MT"]\)\[NoBreak]. >> >   >     General::stop: Further output of > \[NoBreak]\!\(\*StyleBox[Intersection::normal >         , "MT"]\)\[NoBreak] will be suppressed during this calculation. >> >   >     Options::optnf: >        \[NoBreak]\!\(\*StyleBox[FormatType >         , "MT"]\)\[NoBreak] is not a known option for > \[NoBreak]\!\(\*StyleBox[ >         Intersection[OutputStream[A:\out.txt, 12], >          {OutputStream[stdout, 1], OutputStream[stderr, 2], >           OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. > >> >   >     Options::optnf: >        \[NoBreak]\!\(\*StyleBox[FormatType >         , "MT"]\)\[NoBreak] is not a known option for > \[NoBreak]\!\(\*StyleBox[ >         Intersection[OutputStream[A:\out.txt, 12], >          {OutputStream[stdout, 1], OutputStream[stderr, 2], >           OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. > >> >   >     Options::optnf: >        \[NoBreak]\!\(\*StyleBox[FormatType >         , "MT"]\)\[NoBreak] is not a known option for > \[NoBreak]\!\(\*StyleBox[ >         Intersection[OutputStream[A:\out.txt, 12], >          {OutputStream[stdout, 1], OutputStream[stderr, 2], >           OutputStream[A:\out.txt, 12], stdout, stderr}], "MT"]\)\[NoBreak]. > >> >   >     General::stop: Further output of \[NoBreak]\!\(\*StyleBox[Options::optnf >         , "MT"]\)\[NoBreak] will be suppressed during this calculation. >> >   >     Intersection::heads: >        Heads \[NoBreak]\!\(\*StyleBox[List >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream >         , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1 >         , "MT"]\)\[NoBreak] are expected to be the same. >> >   >     Intersection::heads: >        Heads \[NoBreak]\!\(\*StyleBox[List >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream >         , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1 >         , "MT"]\)\[NoBreak] are expected to be the same. >> >   >     Intersection::heads: >        Heads \[NoBreak]\!\(\*StyleBox[List >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[OutputStream >         , "MT"]\)\[NoBreak] at positions \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] and \[NoBreak]\!\(\*StyleBox[1 >         , "MT"]\)\[NoBreak] are expected to be the same. >> >   >     General::stop: Further output of > \[NoBreak]\!\(\*StyleBox[Intersection::heads >         , "MT"]\)\[NoBreak] will be suppressed during this calculation. >> >   >     Mod::argt: \[NoBreak]\!\(\*StyleBox[Mod >         , "MT"]\)\[NoBreak] called with \[NoBreak]\!\(\*StyleBox[5 >         , "MT"]\)\[NoBreak] arguments; \[NoBreak]\!\(\*StyleBox[2 >         , "MT"]\)\[NoBreak] or \[NoBreak]\!\(\*StyleBox[3 >         , "MT"]\)\[NoBreak] arguments are expected. >> >   I expected only the last message. This looks like the result of a misconfiguration or Style Sheet problem but I don't know what it is. Do others get these messages? If yes, what is the explanation? If not, what might I have done to cause this?


How do I plot two Gaussians/normal distributions with 2 different means and 2 different standard deviations?

This is probably very easy for someone with more experience, but I am trying to plot only two Normal distributions, but for some reason my Method plots 4, instead of 2. I have:               Plot[Evaluate@       Table[PDF[NormalDistribution[μ, σ], x],             {μ, 6, 7}, {σ, 1, 2}],       {x, 0, 12}, Filling -> Axis]      which plots: ![enter image description here](http://i.stack.imgur.com/N8qyI.jpg) My intention was to plot $Normal(\mu_1,\sigma_1)$ and $Normal(\mu_2,\sigma_2)$ instead of all the 4 possible combinations of them. Thanks!


Plot in cylindrical coordinates

I am trying to plot a simple vortex in cylindrical coordinates give by $v_{\phi} = \frac{\Gamma}{2 \pi r}$ Is there an alternative method to plot this than, for example, using streamplot and converting r and the cylindrical unit vector $\vec{\phi}$ to cartesian rectangular coordinates?


Trouble combining planet orbits and positions in Graphics3D and Show

I am building an animated model of the solar system, where I would like to display the `OrbitPath`s of the planets along with their `Position`s at any one point in time. I would like to display the orbital paths as lines, just as they are given when inputting `AstronomicalData["Earth", "OrbitPath"]`. I'd like to display the positions as `Sphere`s though. For some reason, even though I am combining the two graphical elements, only the spheres are displaying, and I cannot see the orbit lines at all. Would anyone be able to pinpoint what I am doing wrong in my code?               Animate[      Show[       Graphics3D[        AstronomicalData[#, "OrbitPath"] & /@ AstronomicalData["Planet"]],        Graphics3D[        Sphere[AstronomicalData[#, {"Position", DateList[x][[;; 3]]}] & /@           AstronomicalData["Planet"], 5*10^10]]       ], {x, 1, 10000000000}, AnimationRate -> 100000000      ]      For the record, I tried putting the graphics primitives in a single `Graphics3D` and combining the spheres and lines into a single list of primitives, but that was throwing up too many problems so I figured this way would be more straightforward.


Mathematica cannot find CUDA driver

I have successfully installed CUDA 5.0 on my Ubuntu 12.10, with driver 304.54, toolkit and samples. Running deviceQuery gives me a successful output:                   Detected 1 CUDA Capable device(s)                Device 0: "GeForce 9500 GT"           CUDA Driver Version / Runtime Version          5.0 / 5.0           CUDA Capability Major/Minor version number:    1.1           Total amount of global memory:                 512 MBytes (536543232 bytes)           ( 4) Multiprocessors x (  8) CUDA Cores/MP:    32 CUDA Cores                etc...      bandwidthTest is also successful:                    Device 0: GeForce 9500 GT          Quick Mode               Host to Device Bandwidth, 1 Device(s)          PINNED Memory Transfers            Transfer Size (Bytes)    Bandwidth(MB/s)            33554432         5628.6               etc...      I stress that my card is listed among the compatible CUDA cards for Mathematica. However, in Mathematica 9.0.1.0, running                   Needs["CUDALink`"]         CUDAQ[]      returns                   False      running                   CUDAInformation[]      returns                   CUDAInformation::invdriv : CUDA was not able to find a valid CUDA driver.         Refer to CUDALink System Requirements      and running                   CUDADriverVersion[]      returns                   CUDADriverVersion::nodriv :          CUDALink was not able to locate the NVIDIA driver binary.         Refer to CUDALink System Requirements      So it cannot find both the binary and the libraries, and referring to the CUDALink system requirements help page is not helping. Any ideas?


Using Findroot within a loop

I am trying to get solution to an equation in a loop. The isolate equation works               rb = 2;     ri[x_] := FindRoot[y - ArcTan[y] - x == 0, {y, 0.01}]     ri[0.02151]     srb = y /. %     s = srb/rb     rinv = (s^2 + rb^2)^(1/2)      However, when I try to do it repeatedly with a `While`, `Do` or any other command, I do not get a solution for `y`. Any clues?               rb = 2;     ri[x_] := (FindRoot[Tan[y] - y - x == 0, {y, 0.01}];       srb := y /. %;       s := srb/rb;       rinv := (s^2 + rb^2)^(1/2))     i = 0.001;     While[i < 0.004, ri[i]; Print["i ", i]; Print["s ", s];        i = i + 0.001];      Thanks!


Multiplicate in an Integration with time

I am calculating the area of a step response. I try to use this Integral Criterion for my Calculation. The time t is multiplicated with the control error xd raised to the second power. ![enter image description here](http://i.stack.imgur.com/MvIzP.png) The problem is, that I dont know how to multiplicate the time with the control error xd in Mathematica. So my Integral looks like this: ![enter image description here](http://i.stack.imgur.com/pAbtd.png) My code is:                 fp2pi[tn_, kpr_, kps_, t1_, t2_?NumberQ] :=        NIntegrate[(1 - (InverseLaplaceTransform[(kpr kps (1 + 1/(s tn)))/(             s (1 + s t1) (1 + s t2) (1 + (                kpr kps (1 + 1/(s tn)))/((1 + s t1) (1 + s t2)))), s,              t]))^2, {t, 0, Infinity}, WorkingPrecision -> 5];      Here I am writing the function in a list, with different values for tn:               list = {};     Do[{values = Function[x, fp2pi[x, 3, 1, 1, 2]] /@ {i},         AppendTo[list, values]        }, {i, 1, 5}];     Print[list];      Thank you :)


Trouble with Flatten[]

I made this function:               f[g_] := Table[{ToExpression[ToString[x] <> ToString[n]], 1, 3}, {n, 1, g}]      When I evaluate the function with some g (say 8), I'll have this output:               {{x1, 1, 3}, {x2, 1, 3}, {x3, 1, 3}, {x4, 1, 3}, {x5, 1, 3}, {x6, 1, 3}, {x7, 1, 3}, {x8, 1, 3}}      When I add flatten to the function:               f[g_] := Flatten[Table[{ToExpression[ToString[x] <> ToString[n]], 1, 3}, {n, 1, g}]]      I'll have:               {x1, 1, 3, x2, 1, 3, x3, 1, 3, x4, 1, 3, x5, 1, 3, x6, 1, 3, x7, 1, 3, x8, 1, 3}      When I actually want:               {x1, 1, 3}, {x2, 1, 3}, {x3, 1, 3}, {x4, 1, 3}, {x5, 1, 3}, {x6, 1, 3}, {x7, 1, 3}, {x8, 1, 3}      I have also tried to use the `Flatten[]` with a level:               f[g_] := Flatten[Table[{ToExpression[ToString[x] <> ToString[n]], 1, 3}, {n, 1, g}], 1]      But I was unable to do it. What's happening? I could do it with string manipulation, but I guess there might be a way for `Flatten[]` to work. I'm trying to do this:               ArrayPlot[Table[RandomChoice[{q1, q2, q3} -> Range[1, 3]], {q1, 1, 3}, {q2, 1, 3}, {q3, 1, 3}], Mesh -> True, MeshStyle -> Black]      Where the result of the function is going to replace the `{q1, 1, 3}, {q2, 1, 3}, {q3, 1, 3}`.


How to sum up subelements of a list of unknown length

I'm simply looking for the `{}+{}` function for sublist elements of a list: (Parallel sums of elements)               c = {{1, 2, 3, 4}, {8, 7, 6, 5}};     Plus[c]     Mean[c]       desired={9, 9, 9, 9}      Where `Mean` does directly what it's supposed to, unfortunately `Plus` doesn't. I tried `Take` and `Part` but they both do not seem to work here . Additionally, my `c` consists of a varying number of elements. I tried to work with `Length[c]` and `Range` .. (`{}+{}` is no solution as list element number varies) thank you for help!!


Selectively converting numerical strings to expressions

I have a list of strings representing different types of data               {{"gw12-26b-pl1", "63.6512", "0.0076", "--", "Al2O3", "%", "23.4002"},      {"gw12-26b-pl3", "65.1182", "0.1257", "--", "SiO2", "ppm", "76.3388"}};      I want to convert the 'numerical strings' to expressions so that I can work with them. I want to end up with something like:               {{"gw12-26b-pl1", 63.6512, 0.0076, "--", "Al2O3", "%", 23.4002},      {"gw12-26b-pl3", 65.1182, 0.1257, "--", "SiO2", "ppm", 76.3388}}      I tried to convert the whole list using `ToExpression` and then convert non- numeric elements back to strings but this doesn't work because it is trying to evaluate elements like `gw12-26b-pl1`as an expression. Can anyone suggest an easy way to do this?


How can I draw a Cuboid given its center and its dimensions?

I want to draw a Cuboid accroding to the coordinates of its geometric center and its dimensions, rather than its diagnoal coordiantes. And How can I draw a triangular prism?


Color lost when saving Mathematica cell as HTML

Question 1(Color Lost Question[Solved by using `Item`]): When I evaluate the cell generated by               Grid[WordData /@ {"what","my"}, Frame -> True,        Background -> {None, {LightRed, Pink}}]      ![enter image description here](http://i.stack.imgur.com/SSGH8.jpg) ![enter image description here](http://i.stack.imgur.com/qtSIh.jpg) it looks good in my notebook, but the color get lost when I save the notebook as an HTML file. The same thing happens with some other functions, such as `Column`. I've spent some time to solve the problem and I found a solution which can partly solve the problem is to use `Item` to set the background colour. However, the `ItemSize` is still not working properly when the notebook is saved as HTML format. Here is the code:               Column[Table[Grid[Map[Item[Text@Style[#, FontSize->50,        FontColor->RGBColor@@RandomReal[{0,1},3]],        Background->RGBColor@@RandomReal[{0,1},3],        FrameStyle->AbsoluteThickness[3]]&,        resultListToUse[[i]],{2}],        Alignment->{{Center,Center,Center}},        Frame->All,        ItemSize->{20,5},        Spacings->{{20,20,20},1}],{i,Length@resultListToUse[[1;;4]]}],        Background->LightRed]      Here is my sample blog: quaternions.blog.163.com/blog/static/206082147201323095141897 Now I can select the words in the colored frame, however the words in one row are two tight with no enough spaces. Because some options such like `ItemSize` and `Spacings` didn't work properly when the notebook is saved as .html question2(Spaces Lost question): I want to convert the cell generated by `Grid` to HTML format with content is "Plaintext". I found that the `ItemSize` setting will no longer work properly when convert the output cell to HTML format. As cormullion show in the answer, when The output content in HTML is gif pictures, they looks good. How to make the words in one row with enough spaces?


Auto-complete for user defined functions

If I define a symbol in Mathematica, it doesn't show up in the autocomplete list that works for symbols in `System`. Test code:               foo = 1;     bar[x_] := x + 1     $ContextPath     Context@foo     Context@bar     (* =>          {Notebook$$35$859131`, System`}          Notebook$$35$859131`          Notebook$$35$859131`     *)      Neither `foo` nor `bar` will show up in the autocomplete list. Is it possible to make `foo` and `bar` show up in this list, without defining them in the `System` context? **Edit:** It works if I switch to the `Global` context, however I would like to have a separate context for each notebook. The question is then if you can add the notebook specific contexts to the autocomplete contexts?


How to blend some colors on a curve

I need to define a color gradient on a 3D curve, but I'm having some problems with this. Suppose we have a 3D curve defined as a parametric function of some real variable `phi` :               curve[phi_] := {...};      where `phi` runs from `phi1` to `phi2`. Now, I defined the **start** , **middle** and **end** colors like this :               Color1 := RGBColor[0.99, 0.2, 0.2, 0.2];     Color2 := RGBColor[0.2, 0.99, 0.2, 0.8];     Color3 := RGBColor[0.2, 0.2, 0.99, 0.2];          CurveColor[phi_] = Blend[{Color1, Color2, Color3}, phi];      The last definition doesn't work. I need the function `CurveColor[phi]` to output four real **positive** numbers **smaller than 1** , like this :               CurveColor[phi1] := {0.99, 0.2, 0.2, 0.2}     CurveColor[phi2] := {0.2, 0.2, 0.99, 0.2}      The colors should **blend smoothly** between `Color1` to `Color2` to `Color3`, and be uniformly distributed along the interval `phi1` to `phi2`). So how should I define that color function ? I don't need that function to be used in a plot3D. I only need the color data as a list of numbers. Please, notice that I'm working with _Mathematica 7_.


Strange behaviour of PolyLog Function

I discovered some strange behaviour of the `PolyLog[]` Function in _Mathematica_ which seems to me like a bug in the function implementation. It looks like `PolyLog` is breaking down for big arguments and non-integer orders               In[1]:=  -PolyLog[5/2, -E^500] // N     Out[1]:= 2.691151407447062*10^8626 + 9.87331945684138*10^8623 I      which is for sure incorrect. For such big arguments the `PolyLog` function has nice asymptotic approximations (which are e.g. used for complete Fermi-Dirac Integrals which are related to `PolyLog`'s) through $F_n(x)=-\mathrm{Li}_{n+1}(-e^x)$. This can be demonstrated by using even orders for the `PolyLog[]` with similar big arguments               In[2]:=  -PolyLog[4, -E^500] // N     Out[2]:= 2.60437*10^9      if compared to the asymptotic approximation $\frac{u^n}{\Gamma(n+1)}$ of $-\mathrm{Li}_n(-e^u)$               In[3]:=  u^4/Gamma[5] /. u->500 //N     Out[3]:= 2.60417*10^9      the results look o.k. The expected result of above given argument `E^500` and order `5/2` should be               In[4]:=  u^(5/2)/Gamma[5/2 + 1] /. u -> 500 // N     Out[4]:= 1.68209*10^6      I assume that the function algorithm somehow gets troubles with internal accuracy. Any ideas to "tell" _Mathematica_ to increase the accuracy for the numerical calculation?


How to check an algebraic number for membership in a list

I need to check an algebraic number for membership in a list of algebraic numbers. The numbers can be expressed in different forms (combinations of radicals, `Root` objects, trig functions), but the check should be exact. Now I use the following code:               ContainsAlgebraicQ[list_, a_] :=        MatchQ[Intersection[ list, {a}, SameTest -> (MinimalPolynomial[#1 - #2] === (#&) &)], {_}]      but in some cases evaluation of `MinimalPolynomial` takes significant time, although I only want to check the difference for zero. Is there a better approach for my task?


WeatherData acquirement in ListStreamPlot

I am trying to show the wind streams in a geographic area as following code for a range of time.Even if it works for realtime data but it doesn't work for range of time.I am filtering and also taking mean and it has no problem there.Could somebody help me please?                ListStreamPlot[Table[{{x, y},Through[{Cos, Sin}[Mean[DeleteCases[WeatherData[{y, x},      "WindDirection", {{2013, 5, 28}, {2013, 5, 29}}][[All, 2]],          Missing["NotAvailable"]]] \[Degree]]]}, {x, 20, 56, 4}, {y, 32,57, 4}]]


SparseArray row operations

Given a large (very) sparse matrix, A, how can I efficiently "operate" on only the nonzeros in a given row? For example: For each row in A, generate a list of column indices that have a magnitude (absolute value) greater than a threshold, r. My current approach is similar in spirit to a previous answer by Leonid (Efficient way to combine SparseArray objects?). I shamelessly steal his implementation of `spart`. **My current approach** First, let's build a random `SparseArray` for testing purposes.               randomSparseArray[n_Integer, r_Integer] := SparseArray[       Table[{Random[Integer, {1, n}], Random[Integer, {1, n}]} ->RandomReal[],{r}]     ,{n, n}];          A = randomSparseArray[10, 20]; (*10x10 matrix with 20 nonzeros*)      When `Part` is used to grab a row of `A`, a `SparseArray` representation is returned. Okay so let's rip this representation apart into its raw form using `spart`. For example the 3rd row of `A`               HoldPattern[spart[SparseArray[s___], p_]] := {s}[[p]];         raw = spart[A[[3]], 4];     (*{1, {{0, 2}, {{10}, {5}}}, {0.534313, 0.981372}}*)      And then use a combination of `Part` and `Position` to extract the column indices from `raw` . (here I use a threshold of 0.5)               ind = Flatten@Position[Flatten@raw[[3]],x_/;Abs[x]>0.5];     Flatten[raw[[2, 2]]][[ind]]      Wrapping this all up into a function:               thresholdIndex[A_SparseArray, r_] := Module[{raw, ind},     raw = spart[A, 4];     ind = Flatten@Position[Flatten@raw[[3]], x_ /; Abs[x] > r];     Flatten[raw[[2, 2]]][[ind]]     ]      We can now use `Map` to hit each row of `A` and search for column indices for elements with magnitudes greater than say, 0.5               Map[thresholdIndex[#, .5] &, A]      This whole process feels a little roundabout. First Mathematica has to extract a new `SparseArray` representation of a row (is this expensive?), we then chop it into pieces in order to work on it. Is there an easier way to do this while still maintaining performance? My other idea is to apply `spart` to the original matrix and work with the CSR (compressed-sparse-row) representation. But this seems to defeat the purpose of even using a `SparseArray` from the get go. **Sidebar** I've been starting to implement an efficient algebraic multigrid (AMG) package in Mathematica. AMG is a fast iterative method traditionally used to solve large sparse matrix equations produced from the discretization of elliptic PDEs. One of the steps in the algorithm is very similar in flavor to `thresholdIndex`. As a sidebar, does anyone know if a nice AMG has been implemented in Mathematica? I would like to build a tool similar to PyAMG (http://code.google.com/p/pyamg/).


Basic question on producing non-overlapping graph nodes in a graph

I am plotting a graph which has about 196 nodes.               GraphPlot[{1 -> 24, 2 -> 24, 20 -> 364, 20 -> 779, 21 -> 130, ...                    378 -> 386, 492 -> 841, 779 -> 783, 839 -> 841},           DirectedEdges -> False, VertexLabeling -> True,           Method -> "SpringElectricalEmbedding",           PackingMethod -> "ClosestPackingCenter"]      However when the output is produced it looks like below where many of the nodes are overlapping. How to tell Mathematica to produce a large picture so that no nodes overlap. True this might not be practical for very large graphs, but for 196 nodes, I would like no node to overlap another. ![enter image description here](http://i.stack.imgur.com/ehQwc.jpg)


Calculating pleasant colors for source code or web-design

I really like when the programs or editors I use have pleasant colors. Sometimes when there's nothing else to do or sometimes when there are very important, but incredibly boring things to do, I find myself tweaking color and font settings to make everything as comfortable as possible for me. This was one reason why I asked this question some time ago and it is the reason why I really appreciate people like Ethan Schoonover who invented the solorized color palette. Although his colors are nice, you cannot always use them because sometimes your IDE has maybe a _color basis_ you would like to keep because icons and buttons work nice with it. This is the case with the new Dracula theme of IDEA. Below is a screenshot of a method. Although the colors look good, there are details which I don't like   * The annotations (@Nullable) are too bright and the greenish yellow is ugly   * The method name is a bit too bright   * The green and red background selection is too colorful for my taste   * Finally, the normal font-color is a bit too bright to be calming.  ![enter image description here](http://i.stack.imgur.com/nx0vQ.png) **Question:** Can we use _Mathematica_ (and mathmatics) to create a custom set of colors   * which can be integrated into an existing color environment   * which play nicely together   * where no color catches all attention


Scoping in recursive function leading to unexpected results

I'm trying to implement Ramer-Douglas-Peucker line simplification in _Mathematica_ , and I'm running into an issue with recursion. My implementation of the algorithm is below:               RDP[points_, ϵ_] := (       Print[points];       start := points[[1]];       end := points[[-1]];       vec := Normalize[end - start];       dist[p_] := (         t := Dot[(p - start), vec];         loc := start + t*vec;         Norm[loc - p]         );       distances := Map[dist, points];       maxdist := Max[distances];       maxelem := FirstPosition[distances, maxdist][[1]];       res := If[maxdist < ϵ,         {start, end},         p0 := points[[1 ;; maxelem]];         p1 := points[[maxelem ;;]];         fst := RDP[p0, ϵ];          Print["Run with p1 = ", p1];         snd := RDP[p1, ϵ];         Join[fst, snd];         ];       Print["result ", res];       res       )     line := {{0, -1}, {5, 5}, {5, 16}, {11, 23}}     Block[{$RecursionLimit = 25}, RDP[line, 1]]      I'm getting a very strange result. A snippet of the output: > >     {{0,-1},{5,5},{5,16},{11,23}}   >     Run with p1 = {{5,16},{11,23}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}}   >     {{0,-1},{5,5}}   >     result {{0,-1},{5,5}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}}   >     {{0,-1},{5,5}}   >     result {{0,-1},{5,5}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}}   >     {{0,-1},{5,5}}   >     result {{0,-1},{5,5}}   >     {{0,-1},{5,5},{5,16}}   >     Run with p1 = {{5,5},{5,16}} >   It looks like `p0` and `p1` are set correctly after the split, and I can verify that the recursive call succeeds when it's called on `p0`. However, on the second recursive call, the value passed into the function is not the value that the function actually runs on; you can see that, when p1 is set to `{{5,16},{11,23}}`, `RDP[p1, ϵ]` actually runs with points set to `{{0,-1},{5,5},{5,16}}`. I'm not the most experienced _Mathematica_ user, and this is my first time implementing this sort of recursive function, so I might be missing something pretty simple. Any help or pointers welcome!


Subset of edges with a different color

I want to color a subset of the edges of my graph with a different color. My graph currently has a large number of edges, so the following is just a toy example               s = {1->2,1->3}     g = {1->2, 1->3,3->4,4->1}     GraphPlot[g,VertexLabeling->True]      Here `s` is a subset of `g` I would like to tell `GraphPlot` to plot the edges in `s` with a different color, and make the edges of `s` directed. How to do this? * * * EDIT: The closest I have coming after looking at some answer to another question on this site is               s = {{1,2},{1,3}}     g = {1->2, 1->3,3->4,4->1}     GraphPlot[g,VertexLabeling->True,EdgeRenderingFunction -> (If[          Intersection[s, {#2}] != {}, {Red ,Arrow[#1, .1]},                                        {Blue,Arrow[#1, .1]}] &)]      However, since I want the complement of the set `s` in `g` to be represented as blue segment (and not an arrow) I am not sure what I should write in place of `Arrow` inside `{Blue,Arrow[#1, .1]}` above.


Can mathematica simplify an expression setting simplified answer equal to zero?

Basically I want to reduce something like:               Subscript[P, 4] - Subscript[P, 5] == Subscript[R, 4, 5]* Subscript[i, 4, 5]      when only one of them is known (`Subscript[R, 4, 5] == 1`), so that _Mathematica_ expresses the simplified form as:               Subscript[i, 4, 5] + Subscript[P, 5] - Subscript[P, 4] == 0


Why Can't Mathematica Integrate this?

I have the following problem from a textbook I am trying to integrate: ![enter image description here](http://i.stack.imgur.com/gCjLN.png) So, following the directions in text, I am required to integrate each function. However, I cannot get Mathematica to integrate the first function. Here is my code:               Z1 := E^-x^2*Cos[x^2 + y^2]     Z2 := 2 - x^2 - y^2     Plot3D[{Z1, Z2}, {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1, ViewPoint -> {4, 1, 1}]     Integrate[Z2, {y, -1, 1}, {x, -1, 1}] - Integrate[Z1, {y, -1, 1}, {x, -1, 1}]      They plot OK: ![enter image description here](http://i.stack.imgur.com/mnZSr.png) but give me really strange output: ![enter image description here](http://i.stack.imgur.com/rWvpA.png) Could someone please explain how I can overcome this? Wolfram|Alpha can evaluate it without (much) trouble. Thank you for your time.


Why does saved graphic not look the same as graphic in notebook?

g1 = Plot[(x^2 - 4 x + 3)/(x + 1), {x, -5, 5}];          Rotate[g1, -90 Degree]      After saving the output of the rotated graph, I still get the graph of `g1`. ![enter image description here](http://i.stack.imgur.com/UZock.png) I get ![enter image description here](http://i.stack.imgur.com/MCf0V.jpg)


PolynomialReduce not working

I have a polynomial $f(x_1, x_2, \ldots , x_n)$ with coefficients in $Z[q,t]$, and I have a list of polynomials $g = g_1, g_2, \ldots , g_k$ where they are also polynomials in $(x_1, x_2, \ldots, x_n)$ and with coefficients in $Z[q,t]$. (Note that we are using specific values of $n$, like $n=3$ or $4$.) I am using PolynomialReduce$[f, \\{g\\}, \\{q,t\\}]$ to try to find the coefficients when $f$ is written as a $Z[q,t]$ linear combination of polynomials in $g$. However Mathematica always ouputs coefficients with $x_1, x_2,$ etc. when I only want $q$ and $t$ to be in the coefficients. Update: Upon suggestion, I also tried PolynomialReduce$[f, \\{g\\}, \\{x_1,x_2, \ldots x_n\\}]$ for the input, but mathematica still outputted coefficients with $x_1$, $x_2$, etc. For a couple of test cases I tried, I know for a fact that $f$ can be expressed as a $Z[q,t]$ linear combination of polynomials in $g$, so that is not the issue. Why is this happening? What can I do to fix it?


After editing a file Mathematica 10 interprets [...]^2 as [...(])^2

This is a very weird bug and I don't really know how to reproduce it, so I'll just copy-paste the whole code               Manipulate[Row[{DensityPlot[     Cos[k Norm[{x, y} - d {0, 2}] - f Pi t]/Norm[{x, y} - d {0, 2}] +       Cos[k Norm[{x, y} - d {0, -2}] - f Pi t]/       Norm[{x, y} - d {0, -2}], {x, 0, 10}, {y, -5, 5},        PlotPoints -> 50, ImageSize -> 300, PlotTheme -> "Minimal"],      Rotate[Plot[(200 + Abs[-2 d + y]^2 + Abs[2 d + y]^2 + 2 Sqrt[(100 + Abs[-2 d + y]^2) (100 + Abs[2 d + y]^2)]Cos[k (Sqrt[100 + Abs[-2 d + y]^2] - Sqrt[100 + Abs[2 d + y]^2])])/(2 f (100 + Abs[-2 d + y]^2) (100 + Abs[2 d + y]^2)), {y, -5, 5}, ImageSize -> 280], -Pi/2]}], {t, 0, 15}, {{f, 5}, 1, 10}, {{k, 5}, 1, 10}, {{d, 1}, 0.5, 3}]      Basically this is a simulation of the double-slit interference experiment with a plot of the intensity to the right. Note that **all the squares have to be written by Ctrl-6** so that they are superscript! So, the code looks like this when I open the notebook ![enter image description here](http://i.stack.imgur.com/9ggm8.png) Now try changing the `PlotTheme` by adding a second name, like `"Monochrome"`. Suddenly, all brackets and parentheses go red. Upon evaluation, Mathematica spits out errors as if there are no closing brackets. It seems like everything breaks down the moment I enter the quotation marks `""`. It is possible that this is a Mac-only bug. ![enter image description here](http://i.stack.imgur.com/s6xHe.png)


Get the unevaluated expression from a numbered cell

If a cell exists as below:               In[1] := (xyPoints = {{1,2},{2,5},{3,10}}; ListLinePlot[xyPoints])      Is it possible to get at the expression rather than the plot shown in Out[1]. In other words, can I somehow get the held CompoundExpression in In[1] rather than the evaluated plot?


SmoothDensityHistogram with logarithmic density

Is there a simple way for making `SmoothDensityHistogram` plots have logarithmic scaling for the density? With `DensityHistogram` it's a simple matter of `{"Log","PDF"}` for the _hspec_ argument, but `SmoothDensityHistogram` doesn't have a native option.


How to visualize Riemann surfaces?

In `WolframAlpha` we can easily visualize Riemann surfaces of arbitrary functions, ![enter image description here](http://i.stack.imgur.com/N1UD4.png) can we plot the Riemann surface of an arbitrary function using _Mathematica_ and with a better color scheme like these plots so that I can see the connection of the branches? ![enter image description here](http://i.stack.imgur.com/ytb0N.png) _Edit_ Here are more Riemann surfaces by Matthias Nieser et. Automatic Generation of Riemann Surface Meshes ![enter image description here](http://i.stack.imgur.com/fM007.png) ![enter image description here](http://i.stack.imgur.com/aSGVr.png) ![enter image description here](http://i.stack.imgur.com/wKssT.png) related: How can I recreate Trott's Riemann Surface plot in Mathematica? Visualization of Riemann Surfaces of Algebraic Functions Automatic Generation of Riemann Surface Meshes


Simplifying an ArcTan expression

The expression $\tan ^{-1}\left(\frac{\sqrt{L^2 \sin ^2(\theta )}}{\sqrt{L^2 \cos ^2(\theta )}}\right)$ can be simplified to $\theta$. After some attempts I got the following to do the job.               ArcTan[Sqrt[L^2 Cos[θ]^2], Sqrt[L^2 Sin[θ]^2]] //      PowerExpand // TrigToExp // Simplify // PowerExpand      It appears rather clunky to me. Is there a better way to simplify this expression.


Graphics copy paste

Background. I have a function ( stored in a package ) that creates 2D graphic images, its prototype looks like this:                 question[wi_, he_, co_] :=        DynamicModule[{},         Manipulate[           Graphics[{Translate[{color, Rectangle[{0, 0}, {.8, .4}]},              Tuples[{Range[width], Range[heigth]}]]}],          {color, Red}, {width, 1, 5}, {heigth, 1, 5},           Initialization :> {color = co, width = wi, heigth = he}]]       In the actual function the Graphics function is enclosed in a Dynamic[]. The function works as expected. Something that I don't understand happens when I do the following: 1) right- click ( Windows ) on an image and paste the image to elsewhere in the notebook; 2) repeat this for several different width / height combinations. 3) save the notebook 4) open the notebook 5) execute the function but with a different color, THEN: the color of the pasted images changes as well. **Question: How can I permanently copy and paste ( not, in any way, linked to code ) a graphic created in a Notebook with Graphics2D?** EDIT(2) per request of halirutan : Cell[BoxData[ GraphicsBox[GeometricTransformationBox[GeometricTransformationBox[ DynamicBox[Typeset`ToBoxes[ MapThread[FE`Y2`Y2`Private`fun$$93, {FE`Y2`Y2`Private`ptlst$$93, FE`Y2`Y2`Private`tplst$$93, FE`Y2`Y2`Private`colst$$93}], StandardForm, Graphics], ImageSizeCache->{{89.7606933090101, 182.2393066909899}, {81.76069330901011, 169.2393066909899}}], {{{{1, 0}, {0, 1}}, {0, 0}}, {{{-1, 0}, {0, 1}}, {1, 0}}, {{{1, 0}, {0, -1}}, {0, 1}}, {{{-1, 0}, {0, -1}}, {1, 1}}}], {{{0, 0}}, {{-0.7071067811865475, 0.7071067811865475}}, {{0.7071067811865475, 0.7071067811865475}}, {{0, 1.4142135623730951`}}}], PlotRegion->Automatic]], "Input"]


Get the coordinates from ContourPlot and RegionPlot

How do I get the coordinates from a contour plot I've done in _Mathematica_? For example, I have a two-variable function `f[x, y]`, for which I can make a contour plot:                   contour = ContourPlot[f[x, y] == 1, {x, -1, 1}, {y, -1, 1}];      I can access a nested list, containing lists of coordinates, from an exported file using                   Export["output.m", contour, "TEXT"]       but the nested list is inside the function `Graphics`. I would like to export only the corresponding nested list. What is a straightforward way to do that? Is there a way of doing that by manipulating directly the variable `contour`? **Edit** @Jens solution was                   Cases[Normal@contour, Line[x_] :> x, Infinity]      Is there a way to generalize it? The issue is that `Line` won't give us the points inside a region. E.g., I would like to get the coordinates corresponding to a region plot:                   region = RegionPlot[f[x, y] > 1, {x, -1, 1}, {y, -1, 1}];


Traces of products of Pauli matrices

Given a matrix $M$ of shape $2^L*2^L$, I would like to compute all the traces $\text{Tr}( M.(\sigma^{n_1}\otimes\sigma^{n_2}\otimes\ldots\otimes\sigma^{n_L})) $ for $n_1=1...4$, $n_2=1...4$, ..., $n_{L}=1...4.$, where $\sigma^n$ are the Pauli Matrices for $n=1..3$ and the identity for $n=4$. I can do this for specific values of $L$, but how do I write a function of $M$ and $L$ only that will perform this computation?


BarChart with ScalingFunctions -> "Log", Fixed axis

I want to make an animated `BarChart`. In this I want to plot different tables which range from $10^{-60}$ to $1$. For example:               {0.1,0.2,10^-3,10^-16,0.01,10^-20}      and the next data set goes to:               {0.11,0.19,10^-2,10^-12,0.0001,10^-10}      However, I can't set the `BarChart` with `ScalingFunctions->"Log"` to only start if a number for the chart is higher than $10^{-12}$. Does anyone know a way to fix this? P.S.: I already tried `PlotRange->{10^-12,1}`. Doesn't work though.


A problem on generating convex hull

For example, I typed the following:               data3D = {{3, -1, -6}, {3, -3, -4}, {1, 1, -6}, {1, -3, -2}, {-1,  1, -4}, {-1, -1, -2}};       Needs["TetGenLink`"];      {pts, surface} = TetGenConvexHull[data3D]      But I couldn't get the needed points and surfaces to generate a convex hull, instead I got error messages. How can I make it work or fix it?


Constructing symbol definitions for With

I would like to be able to define two arrays, one containing symbol names and one containing the values of those symbols, for use in constructs such as `With`. For example:               params = {a,b,c,d};     vals = {1,2,3,4};     With[{a=1,b=2,c=3,d=4},Print["Do something fancy"]]      I would like to construct the local variable assignment array {a=1, b=2, ....} automatically. The wishful thinking solution of `With[params = values, ...]` doesn't work and I've tried a random selection of Mapping, Threading and Holding, all to no avail. It looks like a similar question has been answered before however the function proposed by Leonid doesn't work in the `With` block. I suspect my issue focuses on an attempt to manipulate Symbols in a non-trivial manner (and by non-trivial, I simply mean anything beyond a = 1).


Plotting Phase Space

I have these two Equ' $$x'[t]=Sin[y]$$ $$y'[t]=Cos[x]$$ and im trying to plot the phase space(plane) for this system... ive tryed Equationtrekker but cant seem to find the way to use it this way... any help? Thanks!


Need help with phase diagram in mathematica

Sketch the phase diagram for systems with the following velocity functions where a and b are constants with b > a > 0 a. dx/dt = a, dy/dt = b b. dx/dt = a, dy/dt = x Please can someone show me how to draw the phase diagrams for these two functions here?


How can I draw this particular phase diagram in Mathematica?

Sketch the phase diagram for systems with the following velocity functions where `a` and `b` are constants with `b > a > 0`               a. dx/dt = a, dy/dt = b     b. dx/dt = a, dy/dt = x       Please can someone show me how to draw the phase diagrams for these two functions here? I know these functions are too simple but this is what we are learning to do in our class right now. So, I'd appreciate some help. Thanks.


Phase space vector field

I have a system of non linear equations and from `NDSolve` I get the solution. I plot the phase space with `ParametricPlot[{y1[t],y2[t]}/.solution,{t,0,10}]`. I want to plot the vector field and I want your help. To be more specific, I want to see whether the fixed points are stable or unstable. I know how to do it by watching them from nonlinear dynamics, but the vector field is a much more faster way to figure out about the stability of the fixed points.


Plotting a Phase Portrait

I'm trying to plot a phase portrait for the differential equation $$x'' - (1 - x^2) x' + x = 0.5 \cos(1.1 t)\,.$$ The primes are derivatives with respect to $t$. I've reduced this second order ODE to two first order ODEs of the form $ x_1' = x_2$ and $x_2' - (1 - x_1^2) x_2 + x_1 = 0.5 \cos(1.1 t)$. Now I wish to use mathematica to plot a phase portrait. Unfortunately, I'm unsure of how to do this because of the dependence of the second equation on an explicit $t$. Thanks.


Sort a list of coordinates by frequency from first component of each coordinate

The situation is that I have a List like this:               A = {{1, 11}, {1, 12}, {1, 17}, {1, 20}, {1, 52}, {4, 179}, {5, 10}, {5,        55}, {12, 16}, {13, 274}, {15, 206}, {17, 16}, {17, 23}, {17,        24}, {17, 25}, {22, 82}, {26, 131}, {30, 222}, {30, 391}, {40,        24}, {41, 31}, {41, 54}, {41, 78}, {41, 82}, {43, 42}, {44,        67}, {45, 21}, {47, 81}, {49, 192}, {52, 10}, {56, 67}, {56,        76}, {56, 79}, {56, 81}, {56, 89}, {56, 90}, {56, 91}, {56, 92}}      I would like to order the list A by frequencies from first component. I tried figure out this order with this function:                frec = Table[i[[1, 1]]  , {i,            Sort[Tally[A, #1[[1]] ==   #2[[1]]  & ], #1[[2]] > #2[[2]] & ]}]     {56, 1, 41, 17, 30, 5, 52, 49, 47, 45, 44, 43, 40, 26, 22, 15, 13, 12,               4}      It means that 56 appears as first component more than 1, and so on. But I really don't know how to use this order to produce something like this:               A = {{56, 67}, {56, 76}, {56, 79}, {56, 81}, {56, 89}, {56, 90}, {56, 91},         {56, 92},{1, 11}, {1, 12}, {1, 17}, {1, 20}, {1, 52},{41, 31}, {41, 54}, {41, 78}, {41, 82},{17, 16}, {17, 23}, {17, 24}, {17, 25}, ...       In advance, thanks to see the question.


Option AutoAction of Manipulate doesn't respond under Ubuntu

I'm using _Mathematica_ 10.0 under Ubuntu 14.04. When using the function `Manipulate` with option **AutoAction** , I find that the slider doesn't respond to my mouse movement _without clicking_. I need to _drag_ to move it. Similarly, every function that has the option **AutoAction** , such as `LocatorPane`, doesn't respond to my mouse movement as well. But under Windows 8.1, it works well. I refered to this page: Manipulate (Linux version of Mathematica). But my OpenJDK seemed to be up-to-date. What should I do? **Reference:** AutoAction - Wolfram Mathematica Documentation Center P.S. My OpenJDK version: > java version "1.7.0_55"   >  OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)   >  OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)


Select gives different answers in versions 8 and 9

Consider the code below:               s = Solve[(3 - Cos[4*x])*(Sin[x] - Cos[x]) == 2, x, InverseFunctions -> True];     Select[s[[All, 1, 2]], Element[#, Reals] &]      In MMA 8.0, I get               {-\[Pi], \[Pi]/2, \[Pi]}      but in MMA 9.0, I get an empty set { } Assuming the solution by MMA 8.0 is correct, can someone show me a work around for MMA 9.0?


Initial and boundary value errors

> NDSolve::ivone: Boundary values may only be specified for one independent > variable. Initial values may only be specified at one value of the other > independent variable. >> I keep getting this, although I wish to use NDSolveValue to solve the following differential equation: $\ u_{xx}-\frac{u_t}{\sqrt{t^2+x^2}}=-6u^5+(8+4e)u^3-(2+4e)u $ where e is a parameter, with the initial conditions being $\ u(0.001,x)=tanh(x), u_t(0.001,x)=0$ and the boundary conditions being $\ u(t,0)=0,u(t,6)=1 $. I have loads of operations I wish to perform on the solution, but every single operation depends on getting the solution in the first place. Here's the code I intend to run in order to perform everything I want on it:               eps4 = 0;     phi6m4 = NDSolveValue[{        D[u[t, x], x, x] -         D[u[t, x], t]*1/Sqrt[t^2 + x^2] == -6 u[t, x]^5 +              (8 + 4 eps4) u[t, x]^3 - (2 + 4 eps4)u[t, x],        u[0.001, x] == Tanh[x],        Derivative[1, 0][u][0.001, x] == 0,        u[t, 0] == 0, u[t, 7] == 1}          , u, {t, 0.001, 6}, {x, 0, 7}];      > NDSolveValue::ivone: Boundary values may only be specified for one > independent variable. Initial values may only be specified at one value of > the other independent variable. >>


How to plot X and Y data to see average data converging?

I initially have ran a large, say 1000 (to be changed later) number of monte carlo simulations (mcRun), and I want to see when the average data result starts to converge to a reasonable value. So I basically first ran 1000 simulations, and took average data based on 0 to first 10%(100), then average data based on 0 to 20%(200) and so on. So just to show the data: For[n = 0, n < 10, n++, Print [data[n]]] {622.917} {583.165} {564.45} {570.583} {584.956} {583.185} {579.662} {572.974} {570.253} {558.536} So how to plot this data where Y is data[0] to data[9] and X is 0.1 mcRun, 0.2mcRun...1 mcRun. Or possibly 3D animate later using Manipulate? as I will have more sensitivity analysis to be done later.


More than one expression in the Table[] command?

I would like to construct a Matrix using the Table[] command. The issue is that I would like to use more than one expression for it. What I need to obtain is something like this :               {{f[1, 1], g[1, 1], f[1, 2], g[1, 2]}, {f[2, 1], g[2, 1], f[2, 2],g[2, 2]}}      I tried to write a table containing the two expressions f[i,j] and g[i,j] inside the Table[] command but without success... What I obtain instead is something like this :               In[8]:= Table[{f[i, j], g[i, j]}, {i, 2}, {j, 2}]          Out[8]= {{{f[1, 1], g[1, 1]}, {f[1, 2], g[1, 2]}}, {{f[2, 1],         g[2, 1]}, {f[2, 2], g[2, 2]}}}      What would be the correct syntax to construct these type of matrices? Or am I completely wrong trying to use the Table[] command?


Parallelize plotting

I'm using Mathematica to make a few 3d plots. ~~For the sake of generality, let's say they are unrelated to each other (so I can't imagine making a table out of them)~~. However, the machine I'm using has 4 cores and plotting (evaluating the function at different points can be done pretty much independently, so I should be able to parallelize my plots (or even a single plot for that matter). How can I do this? Ps: If the question is not clearly posed or more information is needed, let me know. Edit: @halirutan's answer corrects my mistake, which I've now struck off.


Select row from a table by column value

I have the following:               animals = {{dog, black, 200}, {cat, white, 100}, {moose, brown, 500}, {zebra,black,100}}      If this came from a SQL table called animals, which has fields named: type of animal, color, weight I would say:               Select * from animals WHERE weight = 100      How do you do this in _Mathematica_?


Data Table Manipulation in Mathematica

I am a statistician searching for an efficient way to select rows or columns from a table of data in _Mathematica_. Let me pose the question in 2 parts with a SQL-style table of data:               List[{"ID", "Variable 1", "Variable 2"}, {"Alpha", 1, 0}, {"Beta", 1, 1}, {"Alpha", 1, 0}]]      Which, when formatted as a Grid looks roughly like this:               ID     Variable 1 Variable 2     Alpha       1          0     Beta        1          1     Alpha       1          0      **Part 1: How can the data in the header of the table, for example "ID", be set as the name of the list for that column? Ideally, the result would allow you to do the following:**               In[24]:= ID          Out[24]= {"Alpha", "Beta", "Alpha"}      _Would one need to write a function to dissect the header row and then line up the header names as the name of a list that corresponds to the appropriate header? Although one might ask 'Why not refer to everything as a position and avoid the renaming headache entirely?' it is extremely cumbersome when working with tens or hundreds of columns/variables to use a meaningless position to reference a variable._ **Part 2: How can an individual row, or subset of rows, be returned from a table? Essentially I'm looking for the equivalent of the "WHERE" clause in SQL or the "subset" function in R.** _For example in the "ID" column I might want to retrieve all the rows where "ID" == "Alpha". Do I have to create a method that iterates over the "ID" list, stores the position in the list where the value of the element is equal to "Alpha", and then concatenate a list that contains the value in that position for all the other lists?_ I'm confident I could write the functions I mention, but it seems unconscionable that Mathematica would overlook such a rudimentary data manipulation task. I understand there's also the DataManipulation package that allows for SQL queries, but I have to believe (hope?) there's a way native to Mathematica that's quicker. Thank you for indulging me! And my apologies in advance to all the Mathematica aficionados who might see this as a corrupt question for trying to program in another language while in Mathematica!


Simplifying nested If statements

Consider :               list = {100,102,103,99,106,107,104,112}      I want to consider, extract only the "big moves" of that time series. In this case the moves bigger then 5 from the moving point of reference. The pseudo code would go as such : Let's assume you have the data `x(t)` for `t=1` to `T`, You start from the first data point, `z(1) = x(1)`               if abs(x(2)-z(1))> delta,          z(2)= x(2),      elseif abs(x(3)-z(1))> delta,          z(2)= x(3),      elseif abs(x(4)-z(1))> delta,          z(2)= x(4),             if abs(x(5)-z(2))> delta,              z(3)= x(5),          elseif abs(x(6)-z(2))>delta,              z(3)= x(6),             if abs(x(7)-z(3))>delta,                  z(4)=x(7)             endif         endif     endif      I tried to write it with an `If` statement, but I don't know when my test is going to pass thus, how many `If`s to nest.               If[Abs[list[[2]]-list[[1]]]>5,        list[[2]],                  If[Abs[list[[3]]-list[[1]]>5,                  list[[3]]....      Here this process will stop at `list[[5]]` with `Abs[list[[5]]-list[[1]]=6` At this point, `list[[5]]` becomes my new point of reference :                If[Abs[list[[6]]-list[[5]]]>5,          list[[6]],                   If[Abs[list[[7]]-list[[5]]>5,                  list[[7]]....      So my desired output is the following :               {100,106,112}      I am pretty sure, this type of operation has a name but I don't know it. It felt like a `While[]` or `For[]` but I can`t figure it out. Please let me know how to improve the question.


Kernel inexplicably hangs if I define a pure function without suppressing output

**Save any unsaved work before trying as it may crash Mathematica and other programs by filling up the memory!** In v9.0.1.0 on OSX 10.8.5, if I start a new session and define two functions               f1P = Sin[#^Sin[Sqrt[Gamma[#]]]] &;      and               f2P = Sin[#^Sin[Gamma[(# + 1)]]] &;      they both work fine. Now, if I quit the kernel and define _the exact same functions_ but removing the `;`s when I evaluate the cell with `f1P`:               f1P = Sin[#^Sin[Sqrt[Gamma[#]]]] &      I get some output (`Sin[#^Sin[Sqrt[Gamma[#]]]] &`). Then if I try to evaluate the cell with the second function definition the kernel hangs indefinitely. In fact the kernel can't handle the definition of `f1P` without `;` at all (if I try to give it values nothing happens). Strangely, this isn't the case with `f2P`: I remove the semicolon, evaluate and it runs fine. But with `f1P` the kernel consumes more and more ~~CPU~~ memory. I have not idea why CPU usage spiked yesterday - I tried this today and it increased to ~35% but not more. The memory demand keeps growing though until the Kernel gets terminated or until Mathematica crashes. This seems to be a bug with Mathematica on OSX as other people confirmed and I have now reported it to WR so I will edit again once I have confirmation from them. Still, if anyone has any idea what might be happening I'd like to know. **\---EDIT---** This issue has been resolved in version 10. WR have confirmed the bug which _"causes unusual memory usage on a Mac because of the Predictive Interface"_


Integrate with FunctionInterpolation differs from NIntegrate

In working with interpolating functions and integration, I noticed a lot of differences between `NIntegrate` and `Integrate` in the case of a function applied to an interpolating function. In order to provide a simple example, look at this output:               ifun = Interpolation[ {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}}]     NIntegrate[x*ifun[x], {x, 0, 5}]      > >     32.5694 >                 xifun = FunctionInterpolation[x*ifun[x], {x, 0, 5}]      > FunctionInterpolation::precbd: Requested precision [Infinity] is not a > machine-sized real number between \$MinPrecision and \$MaxPrecision. >>               out = Integrate[xifun[x], {x, 0, 5}];     N[out]      > >     32.591 >   The difference is at the second decimal place, or of the order of 0.06%. For more complicated functions (lots of data values and Bessel functions, I get errors of more than 100%). I would like to know the reason of the error. In my real-life example I only get correct answers using the `NIntegrate` method. I know there is this other question: How to integrate functions of linearly interpolated data? But they don't use `FunctionInterpolation` and I think that there should be a simple explanation for this difference. My data is also not linearly- interpolated.


Import tweets from Twitter

Robert Raguet-Schofield in the Mathematica Blog introduced a way to import tweets from Twitter into _Mathematica_. I attempted to use this method. I started with this line of code:               xml = Import["https://twitter.com/statuses/user_timeline.xml?screen_name=WolframResearch"]      and received this message: > FetchURL::httperr: The request to URL > https://twitter.com/statuses/user_timeline.xml?screen_name=WolframResearch > was not successful. The server returned the HTTP status code 404 ("Not > Found"). Then I tried this               xml = Import["https://twitter.com/WolframResearch"]a      and this time I got some output. But when I continue the procedure to extract the tweets with this line               tweets = Cases[xml, XMLElement["text", _, {s_String}] :> s, ∞]      I get an empty set. How can I import tweets into _Mathematica_ in an effective way, given I am not a familiar with Apachi?


Accessing Twitter API using Mathematica

How do interact with the Twitter API using Mathematica? SocialMediaData is a lovely function, but appears to be severely limited in what it can draw from Twitter. For example, if I want to get a list of retweets of a Tweet I've sent there's an API call for this but not a means of doing so through SocialMediaData. How do I augment the function with all the API has to offer?


Finding a mapping between elements in two lists that satisfy some criterion (such as being less than threshold Euclidean distance apart)?

I have two lists of $d$-dimensional coordinates, for example setting $d=3$ we might write:               L1 = {{1,2,3},{4,5,6},{7,8,9},{999,999,193}}     L2 = {{80,-10,-12},{1.1,2.4,3.1},{6.99,8.0435,8.999},{4,5.02,6.02}}      Here, some of the elements in $L_2$ are just the elements in $L_1$ perturbed in 3-space by some small amount (a MSD $\leq 0.5$), with the mapping $(1,2,3) \to (2,4,3)$ and where the coordinates at positions four in $L_1$ and one in $L_2$ do not having a mapping (i.e. there's not necessarily a bijection for the lists). Is there a simple "one-liner" in Mathematica 9 that allows us to compare two lists and return a list of points that satisfy some mapping criterion, e.g. Euclidean distance in the above example? Update - For the above example, setting the Euclidean distance to $R=1$ we'd specifically like to output: {{{1,2,3},{1.1,2.4,3.1}},{{4,5,6},{4,5.02,6.02}},{{7,8,9},{6.99,8.0435,8.999}}} (Elements can be in whatever order.) Could we do this for a set of more than two lists?


print the name of the variable in a list without evaluation

a := az + 1     b := bz + 5     list := {a, b}      I'd like mathematica to print               a = az + 1     b = bz + 5      so basically it needs to first print the name of the variable in the list, followed by "=", and followed by the actual content of the variable. **update (1):** so here is something close to what I want               a := az + 1     b := bz + 5     list := {Hold@a, Hold@b}     Column[Table[Print[list[[i]], "=", ReleaseHold@list[[i]]], {i, 1, 2}]]      outputs:               Hold[a]=1+az     Hold[b]=5+bz      However, I don't know how to get rid of `Hold[]`. I'm also hoping there is a more elegant way.


How to split a file?

Is there a way to split an external file using Mathematica? (Other than importing it, dividing it internally and exporting the parts) For instance like some File Split utility do.


Generating high quality charts in Mathematica for use in LaTeX and Word

I frequently have a probelem using my charts in reports because the text (axes labels and tick marks) look low resolution (fuzzy). When I export my charts, i export them as PNG files. Unless I'm mistaken, this is the correct file format for vector graphics. In _Mathematica_ , the charts look great at any size, but when I export and drag them into Word, they don't look nearly as nice any more. Does any one have any tricks they use to use the _Mathematica_ charts in applications like Word?


How to properly plot a response of a transfer function in Mathematica?

I'm trying to display the output response of a transfer function in Mathematica with and without a compensator. The problem is very strange: while the transfer function compensate is showing well, the other is not. The plot seems incomplete and no matter what `PlotRange` I set, the graph always stays incomplete at the same point. Here is a screenshot: ![enter image description here](http://i.stack.imgur.com/w43qV.png) Anybody have an idea of what is wrong? I'm pretty sure the math itself is okay, because I get the second transfer function from the first. But when I want to compare the two responses graph, the first always stays incomplete.


Looking for a input template for Limit

I'm using v. 8. I'm looking for a limit input template (analogous to the integral template), but I can't seem to find it in any of the palettes. Can anyone help? Edit: I'm looking for a 2D input (traditional form) purely for typesetting purposes (no calculations) Something analogous to the integral template (pictured below): ![enter image description here](http://i.stack.imgur.com/0n8R3.png)


Redirect of mathematica graphics output to another computer screen

I need send the result of my calculation to the screen connected to HDMI output as a full-screen image. As I understand, I need change the DisplayFunction to usage of certain OutputStream. Do anybody help me with creation of proper DisplayFunction? Which parameters are needed? Now I use DisplayFunction->CreateDialog and manually move the window to second screen, but it is evidently stupid way.. I need more or less precise alignment of an image at the HDMI-screen, which is normally reproducible each time.. Could anybody show me right way for creation of the true redirection of graphics output?


Manipulate - why does the axis scale change when I release the slider?

I was playing around with Manipulate to demonstrate simple geometric idea of conic sections and put this little sample together. When i move the slider it moves my plane, which is what I expect. However, when I let go of the slider, the graphics are rescaled. So how I stop that? I have set the `PlotRange` and `AspectRatio`, so I don't understand why the scale is changing.               Manipulate[       plot = Plot3D[n, {x, -1, 1}, {y, -1, 1},         AspectRatio->1, PlotRange->{{-1, 1}, {-1, 1}}, Mesh->False];       cone = Graphics3D[{Opacity[0.3], Cone[{{0, 0, -1}, {0, 0, 1}}, 1]},         PlotRange->{{-1, 1}, {-1, 1}}, AspectRatio->1];       Show[{plot, cone}, AspectRatio->1],       {{n, 0}, -1, 1}]


How to extract sample values from an imported WAV file?

Suppose I read a file with               B = Import["something.wav"]      Now how can I obtain a list of sample values?


What's wrong with this pattern of the form Except[Repeated[....]]?

I'm trying to build a head that recognizes molecules. Here's the code               Mol::arg = "Invalid molecule.";     Mol[Except[Subscript[_String, _Integer] ..]] := Message[Mol::arg]      I'd expect that this code should recognize molecules of the form               Mol[Subscript["C", 4], Subscript["N", 5]]      but it should issue the message if something like               Mol[Subscript["C", 4], 7]      is entered. However, when I enter this last one, no message is issued. I don't understand what I'm doing wrong.


Finding the eigenfunctions of one and two dimensional Harmonic Oscillator

(Edited) For finding the ground state wave function of: $ H\psi(x) = (-1/2)d^2\psi(x)/dx^2 + (1/2)x^2\psi(x) = E \psi(x)$ I have written:               mOneDSchEq[n_] :=     Table[Switch[i - j, -1, p[x[i]],      0, (10/(n + 1))^2 q[x[i]] - 2 p[x[i]], 1, p[x[i]], _, 0], {i,      n}, {j, n}];          q[x_] := -x^2; p[x_] := 1;     Xarray[n_] := Do[x[i] = -5 + i 10/(n + 1), {i, 0, n + 1}];          EigVec[n_] := Eigenvectors[mOneDSchEq[n]];     lisEigVec = EigVec[35];     OneEigVec[j_] := Part[Reverse[lisEigVec], j];     y[i_] := Part[OneEigVec[1], i];     listOfPoints =      Join[{{x[0], 0}}, Table[{x[i], y[i]}, {i, 1, 35}], {{x[36], 0}}];     ListPlot[listOfPoints, PlotJoined -> True, PlotRange -> All,      PlotLabel -> "Ground State Wave Function of Harmonic Oscillator",      AxesLabel -> {"x", "y"}]      Which I have obtained the Gaussian, correctly. The question that came to my mind is that: Is it possible by knowing the ground stat eigenvalue, i.e. 1/2, solving the Schrödinger equation numerically, and obtain the ground state wave function? in other words, to solve: $ H\psi(x) = (-1/2)d^2\psi(x)/dx^2 + (1/2)x^2\psi(x) = (1/2) \psi(x)$ or $ H\psi(x) = (-1/2)d^2\psi(x)/dx^2 + (1/2)x^2\psi(x) = (3/2) \psi(x)$ So, I wrote:               s = NDSolve[{-(1/2) \[Psi]''[x] + (1/2) x^2(\[Psi][x]) == (1/2) \[Psi][       x], \[Psi][-5] == 0, \[Psi][5] == 0}, \[Psi], {x, -5, 5}]          Plot[Evaluate[\[Psi][x] /. s], {x, -5, 5}, PlotRange -> All]      BUT, I got nothing. What is the problem? The other question is that, I was traveling through the website and found an elegant approach to two dimensional Harmonic Oscillator here. My question is, if again we want to solve the Schrödinger equation numercally and obtain wave functions, now two dimensional, by knowing the eigenvalues, what should we do? For example: $ H\psi(x,y) = (-1/2)(d^2/x^2 + d^2/dy^2)\psi(x,y) + (1/2)(x^2 + y^2)\psi(x,y) = (1) \psi(x,y) $ and $ H\psi(x,y) = (-1/2)(d^2/x^2 + d^2/dy^2)\psi(x,y) + (1/2)(x^2 + y^2+ x y)\psi(x,y) = (0.96) \psi(x,y) $ Thanks for your attention!


How to express this output in the form $X=A.x$?

This problem arose in my stereo vision project. I have two matrices: $$ A = \left( \begin{array}{ccc} \text{x1}*\text{p131}-\text{p111} & \text{x1}*\text{p132}-\text{p112} & \text{x1}*\text{p133}-\text{p113} \\\ \text{y1}*\text{p131}-\text{p121} & \text{y1}*\text{p132}-\text{p122} & \text{y1}*\text{p133}-\text{p123} \\\ \text{x2}*\text{p231}-\text{p211} & \text{x2}*\text{p232}-\text{p212} & \text{x2}*\text{p233}-\text{p212} \\\ \text{y2}*\text{p231}-\text{p221} & \text{y2}*\text{p232}-\text{p222} & \text{y2}*\text{p233}-\text{p223} \end{array} \right) $$ $$B = \left( \begin{array}{c} \text{p114}-\text{x1}*\text{p134} \\\ \text{p124}-\text{y1}*\text{p134} \\\ \text{p214}-\text{x2}*\text{p234} \\\ \text{p224}-\text{y2}*\text{p234} \end{array} \right) $$ I computed the following vector k:               k = Simplify[Inverse[Transpose[A].A].Transpose[A].B]      And mathematica output a huge answer for k (as expected), wich I think it's not necessary for me to type it in here. Here is where my problem starts. This computation must be done at 120 Hz, where all entries of A and B are known, but only $\text{x1,x2,y1}$ and $\text{y2}$ change from time to time (forcing me to recompute the whole transpose and inverse thing every time they change). I would like to express the matrix k as $$k = k1*k2 $$ where $k1$ entries are functions only of the $\text{p}_{ijk}$ and $k2$ entries are functions only of $\text{x1,x2,y1}$ and $\text{y2}$. I suppose mathematica won't directly do that, but maybe I could use it to help me in the process. To illustrate better what I mean for $k=k1*k2$ let me do an example: Suppose I have the following vector $k$ $$k=\left( \begin{array}{c} \frac{b+a}{a} \\\ a-b \\\ 1+a.b \\\ \frac{a}{b} \end{array} \right)$$ I could rewrite it as $$ k=\left( \begin{array}{c} 1+\frac{b}{a} \\\ a-b \\\ 1+a.b \\\ \frac{a}{b} \end{array} \right) $$ and then as a matrix multiplication: $$ k=\left( \begin{array}{c} 0 & 0 & 0 & 0 & 1 & 1\\\ 1 & -1 & 0 & 0 & 0 & 0\\\ 0 & 0 & 1 & 0 & 0 & 1\\\ 0 & 0 & 0 & 1 & 0 & 0 \end{array} \right)*\left( \begin{array}{c} a\\\ b\\\ a.b\\\ \frac{a}{b} \\\ \frac{b}{a} \\\ 1 \end{array} \right) $$ Where only the second factor depends on $a$ and $b$ Hope I made myself clear. Any help would be appreciated!


Property assignment on a graph vertex using PropertyValue does not work inside a function

I created this function:               AddStone[board_Graph, v_, s : white | black | empty] :=         PropertyValue[{board, v}, VertexState] = s      This function should change the VertexState property of vertex `v` in graph `board` to one of `white`, `black`, or `empty`. That's simple enough, right? Then I created a graph:               board = GridGraph[{5, 5}];      But then if I execute:               AddStone[board, 8, white]      I get an error: > "Set::setraw: Cannot assign to raw object PropertyValue[{ ... > ,8},VertexState]=white." where the "..." stands for an image of the graph `board`, which I obviously need not draw here. In the Documentation for `PropertyValue` it is stated that one can set properties this way. In fact, the code               PropertyValue[{board, 4}, VertexState] = white      does work without issuing any messages.


Graph label smushed in when printing

I was playing around with the printing options because at first my notebook's printout was strangely way too large. However, after apparently solving the problem, now I noticed that when I print out this test graph (adapted from here), the labels and axis titles got smushed in when printing even though they show up fine in both the Working and Printout environment. I tried to remove the formatting of the graph (ImageSize->400, LabelStyle->14, RotateLabel->False) so that MMA would print the graph the best way it sees fit, but that didn't solve the probe Any idea what might have caused this behavior?               energy[theta_, speed_, m_, g_, len_] :=        m g len (1 - Cos[theta]) + (1/2) m len^2 speed^2;          m = 1; g = 9.8; len = 10;          data = Table[        energy[i, j, m, g, len], {j, -4, 4, .01}, {i, -3 Pi, 3 Pi, Pi/20.}];          ListContourPlot[data, InterpolationOrder -> 2, Contours -> 20,       MaxPlotPoints -> 30, DataRange -> {{-3 Pi, 3 Pi}, {-4, 4}},       FrameTicks -> {{{-4, -3, -2, -0, 1, 2, 3, 4},          None}, {{-3 Pi, -2 Pi, -Pi, 0, Pi, 2 Pi, 3 Pi}, None}},       FrameLabel -> {{"\[Theta]'(t)", None}, {"\[Theta](t)",          "constant energy levels for nonlinear pendulum model"}}]      ![Smushed in label](http://i.stack.imgur.com/lj9pM.jpg)


How to repeat a plot with different options

I'd like to have first a function plot and then the same plot repeated inside a `Manipulate`, with additional things (like tangent planes etc.). I can do               plot=Plot3D[<whatever>]      and then               Manipulate[Show[plot,<whatever>],...]      but there is one problem. I'd like to have the _second_ plot semi-opaque, so that things are more visible. My question is either (1) how to achieve this using my approach with `plot=Plot3D[...]`, or (2) is there any better approach? I've seen this question, but the first answer seemed too complicated (am I wrong?) and the second one didn't work for me...


How to compile Map and MapAt

I have a long list (say, million of elements, like this one:               {{{1.0, 2.0}, 3}, {{4.0, 5.0}, 6},...}      I would like to compile a function `powq[list_,q_]` that would replace this list by a list in which the terms 3,6,.... are replaced by `3^q`, `6^q`,....:               {{{1.0, 2.0}, 3^q}, {{4.0, 5.0}, 6^q},...}      For a general function `f`, interactively, I can do it as follows:               mf[list_]:=MapAt[f, list, 2]      Then `Map[mf,list]` produces the desired result:               {{{1.0, 2.0}, f[3]}, {{4.0, 5.0}, f[6]}}      But I am having problems with defining               powq:=Compile[{{list,_Real,2},{q_Real]}},....]


Is there a way to interactively read a point from a Graphics3D?

Suppose I have a tesselation, e.g. the Stanford bunny:               bunny = Import["http://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj", "OBJ"]      ![Stanford bunny](http://i.stack.imgur.com/lOysk.png) I'd like to be able to click on one of the vertices of the tessellation and either get its coordinates, or even better, its index in the `GraphicsComplex`. Is there a way to do this?


Importing and manipulating strings - time data

I have a list of time durations, which are strings of the form: `"hh:mm:ss"`. Here's a sample for you to play with:               durations = {"00:09:54", "00:31:24", "00:40:07", "00:11:58", "00:13:51", "01:02:32"}      I want to convert all of these into numbers in seconds, so that I can actually do useful things with this data! How would I go about doing this? There must be some way to get _Mathematica_ to extract the relevant things from each string. Thanks. Edit: I'm surprised that there doesn't seem to be a question related to this already - but it may be that I was using the wrong search terms.


Help function ? sometimes doesn't show help

I was just wondering if this is a known bug. When I want to get basic help using the `?` command before some function name, it typically works for a while, but I've noticed that after I've computed some stuff (like, around 150 or so inputs), _Mathematica_ doesn't pull up the help, but instead just lists the attributes of the command. I'm running version 9.0.1 on OS 10.9.3, but this was also happening on an entirely different system with an older OS (10.6.8 I believe). If I restart the kernel, it works again. If I can reproduce the problem, I will post a screenshot. * * * **Addendum**. I have now been able to take a screenshot of the issue: ![enter image description here](http://i.stack.imgur.com/4XdjX.png)


Configure initial directory

How can I configure the initial directory? By configure, I mean set it so that when Mathematica starts the initial directory is one of my choosing. By the by, what exactly is the significance of the initial directory? Is that the default location of where a notebook gets saved?