title: Path construction using `Nearest` shows ill behavior?

text: I have a `dataSet` that I'm trying to sort choosing a starting point and going to its nearest neighbor, and then to its nearest neighbor and so on. To do so, I've written the following code (wich im sure is not optimal)               ordDataSet = NestList[With[{elem = Nearest[#[[1]], #[[2]]][[1]]},          {Select[#[[1]], (# != elem &)], elem}] &,          {Delete[dataSet, {startIdx}], dataSet[[startIdx]]}, 300][[All,2]];      What the code does is given the starting point `dataSet[[startIdx]]` and the list `Delete[dataSet,{startIdx}]`, uses `Nearest` to find the nearest neighbor `elem`, and return the pair `{newDataSet,elem}` where the new list is the original data set minus the starting point and the nearest neighbor. Then it nests. At first glance this works very well, but for some reason, it starts misbehaving at some point. For the actual `dataSet`               dataSet ={{0,107.212,-166.757},{0,104.104,-164.502},{0,112.403,-150.885},     {0,115.978,-158.598},{0,105.259,-163.986},{0.00417,107.759,-166.45},     {0.00417,104.471,-164.266},{0.00417,107.026,-151.875},{0.00417,105.777,-163.744},     {0.00417,116.652,-158.168},{0.00833,108.316,-166.138},{0.00833,104.845,-164.025},     {0.00833,113.825,-150.301},{0.00833,117.3,-157.713},{0.00833,106.307,-163.497},     {0.0125,114.546,-150.},{0.0125,117.949,-157.25},{0.0125,105.226,-163.78},     {0.0125,108.883,-165.822},{0.0125,106.855,-163.25},{0.0167,118.582,-156.766},     {0.0167,109.459,-165.5},{0.0167,101.6,-140.503},{0.0167,115.272,-149.69},     {0.0167,107.423,-163.003},{0.0167,105.617,-163.531},{0.0208,110.046,-165.175},     {0.0208,108.007,-162.753},{0.0208,119.185,-156.256},{0.0208,106.019,-163.277},     {0.0250,119.72,-155.695},{0.0250,110.631,-164.839},{0.0250,106.428,-163.019},     {0.0250,116.72,-149.036},{0.0250,108.607,-162.502},{0.0292,120.192,-155.087},     {0.0292,111.232,-164.501},{0.0292,109.223,-162.248},{0.0292,117.451,-148.698},     {0.0292,106.845,-162.755},{0.0333,107.27,-162.487},{0.0333,117.414,-152.444},     {0.0333,118.18,-148.348},{0.0333,120.441,-154.333},{0.0333,111.84,-164.158},     {0.0375,110.494,-161.728},{0.0375,107.703,-162.214},{0.0375,118.904,-147.984},     {0.0375,112.455,-163.807},{0.0417,111.158,-161.467},{0.0417,119.618,-147.603},     {0.0417,113.078,-163.451},{0.0417,108.146,-161.937},{0.0458,108.595,-161.654},     {0.0458,113.709,-163.089},{0.0458,111.838,-161.204},{0.0500,112.534,-160.938},     {0.0500,112.654,-141.388},{0.0500,114.345,-162.72},{0.0500,109.044,-161.363},     {0.0500,112.524,-160.933},{0.0500,120.969,-146.763},{0.0542,113.234,-160.665},     {0.0542,121.605,-146.304},{0.0542,109.504,-161.068},{0.0583,109.975,-160.769},     {0.0583,122.156,-145.782},{0.0583,115.631,-161.958},{0.0583,100.877,-151.789},     {0.0583,115.968,-141.83},{0.0625,122.61,-145.19},{0.0625,116.281,-161.565},     {0.0625,110.451,-160.464},{0.0625,101.965,-151.715},{0.0625,114.685,-160.109},     {0.0667,110.933,-160.153},{0.0667,116.931,-161.162},{0.0667,115.445,-159.836},     {0.0667,122.707,-144.366},{0.0708,111.42,-159.836},{0.0708,117.583,-160.748},     {0.0708,104.149,-151.56},{0.0708,116.223,-159.561},{0.0750,111.913,-159.512},     {0.0750,117.022,-159.288},{0.0750,118.22,-160.316},{0.0750,105.254,-151.482},     {0.0792,118.863,-159.875},{0.0792,112.41,-159.182},{0.0792,117.82,-159.},     {0.0792,106.37,-151.402},{0.0833,107.494,-151.318},{0.0833,100.785,-147.01},     {0.0833,112.91,-158.844},{0.0833,119.491,-159.413},{0.0833,118.672,-158.738},     {0.0875,113.414,-158.499},{0.0875,119.579,-158.508},{0.0917,113.919,-158.146},     {0.0917,103.978,-147.28},{0.0958,114.425,-157.784},{0.100,114.93,-157.413},     {0.100,107.059,-147.566},{0.104,113.234,-150.814},{0.104,115.433,-157.031},     {0.108,115.932,-156.638},{0.113,116.423,-156.232},{0.113,101.498,-145.35},     {0.117,116.906,-155.813},{0.117,102.399,-145.22},{0.121,117.374,-155.376},     {0.121,103.297,-145.086},{0.125,117.826,-154.921},{0.125,104.183,-144.944},     {0.129,118.252,-154.444},{0.133,118.644,-153.937},{0.133,105.938,-144.636},     {0.138,118.996,-153.401},{0.138,106.801,-144.466},{0.142,119.308,-152.835},     {0.142,107.658,-144.286},{0.146,119.57,-152.235},{0.146,108.498,-144.09},     {0.150,109.328,-143.88},{0.150,119.787,-151.607},{0.154,119.966,-150.958},     {0.154,110.138,-143.652},{0.158,110.927,-143.404},{0.158,120.106,-150.289},     {0.163,120.211,-149.605},{0.163,111.689,-143.134},{0.167,120.259,-148.896},     {0.167,112.415,-142.835},{0.171,113.099,-142.506},{0.171,119.977,-147.999},     {0.175,120.277,-147.493},{0.175,113.727,-142.137},{0.179,120.589,-146.993},     {0.179,114.291,-141.726},{0.183,114.772,-141.264},{0.183,120.91,-146.499},     {0.188,115.167,-140.749},{0.188,121.239,-146.01},{0.192,121.576,-145.524},     {0.192,115.485,-140.189},{0.196,121.922,-145.041},{0.196,115.723,-139.584},     {0.200,122.274,-144.561},{0.200,115.898,-138.947},{0.204,122.634,-144.083},     {0.204,116.027,-138.288},{0.208,116.109,-137.61},{0.213,123.371,-143.131},     {0.213,116.16,-136.921},{0.217,116.162,-136.215},{0.217,123.739,-142.65},     {0.221,124.081,-142.15},{0.221,116.199,-135.54},{0.225,124.382,-141.622},     {0.225,115.642,-134.569},{0.229,124.612,-141.048},{0.229,115.929,-134.06},     {0.233,124.705,-140.391},{0.233,116.244,-133.565},{0.238,124.403,-139.499},     {0.238,116.576,-133.078},{0.242,116.922,-132.599},{0.242,120.971,-137.197},     {0.246,120.605,-136.819},{0.246,117.284,-132.126},{0.250,117.66,-131.659},     {0.250,120.585,-136.614},{0.254,120.676,-136.469},{0.254,118.049,-131.197},     {0.258,120.824,-136.357},{0.258,118.452,-130.74},{0.263,121.006,-136.266},     {0.263,118.869,-130.287},{0.267,121.211,-136.19},{0.267,119.287,-129.833},     {0.271,121.431,-136.125},{0.271,119.665,-129.354},{0.275,119.977,-128.839},     {0.275,121.662,-136.069},{0.279,121.901,-136.021},{0.279,120.191,-128.271},     {0.283,122.148,-135.978},{0.283,120.266,-127.633},{0.288,122.4,-135.941},     {0.288,120.148,-126.902},{0.292,122.655,-135.908},{0.292,119.772,-126.057},     {0.296,122.915,-135.88},{0.296,119.114,-125.106},{0.300,123.178,-135.855},     {0.300,118.23,-124.103},{0.304,123.442,-135.833},{0.304,117.299,-123.157},     {0.308,123.71,-135.815},{0.308,116.465,-122.334},{0.313,123.978,-135.799},     {0.313,115.785,-121.644},{0.317,115.25,-121.066},{0.317,124.249,-135.786},     {0.321,124.521,-135.776},{0.321,114.834,-120.578},{0.325,124.794,-135.768},     {0.325,114.516,-120.159},{0.329,125.068,-135.763},{0.329,114.275,-119.795},     {0.333,114.099,-119.476},{0.333,125.343,-135.759},{0.338,125.619,-135.759},     {0.338,113.974,-119.193},{0.342,125.902,-135.762},{0.342,113.892,-118.939},     {0.346,113.848,-118.71},{0.346,126.18,-135.766},{0.350,113.834,-118.503},     {0.350,126.46,-135.772},{0.354,113.847,-118.313},{0.354,126.739,-135.78},     {0.358,113.886,-118.14},{0.358,127.018,-135.79},{0.363,127.298,-135.802},     {0.363,113.943,-117.98},{0.367,127.579,-135.816},{0.367,114.018,-117.833},     {0.371,114.109,-117.695},{0.371,127.86,-135.832},{0.375,128.142,-135.85},     {0.375,114.215,-117.568},{0.379,128.424,-135.871},{0.379,114.333,-117.449},     {0.383,114.462,-117.338},{0.383,128.706,-135.893},{0.388,114.602,-117.233},     {0.388,128.989,-135.918},{0.392,114.75,-117.135},{0.392,129.272,-135.945},     {0.396,129.556,-135.975},{0.396,114.907,-117.043},{0.400,129.84,-136.006},     {0.400,115.07,-116.956},{0.404,115.241,-116.874},{0.404,130.124,-136.04},     {0.408,115.417,-116.796},{0.408,130.409,-136.077},{0.413,115.599,-116.723},     {0.413,130.694,-136.116},{0.417,115.785,-116.653},{0.417,130.979,-136.158},     {0.421,115.976,-116.588},{0.421,131.265,-136.202},{0.425,131.551,-136.249},     {0.425,116.17,-116.525},{0.429,116.368,-116.466},{0.429,131.837,-136.3},     {0.433,116.568,-116.41},{0.433,132.123,-136.353},{0.438,116.772,-116.357},     {0.438,132.41,-136.409},{0.442,116.977,-116.307},{0.442,132.697,-136.468},     {0.446,132.985,-136.531},{0.446,117.186,-116.259},{0.450,133.273,-136.597},     {0.450,117.395,-116.214},{0.454,133.56,-136.668},{0.454,117.606,-116.171},     {0.458,133.849,-136.742},{0.458,117.819,-116.131},{0.463,118.033,-116.093},     {0.463,134.137,-136.82},{0.467,118.247,-116.057},{0.467,134.426,-136.903},     {0.471,134.715,-136.991},{0.471,118.462,-116.024},{0.475,135.004,-137.085},     {0.475,118.678,-115.992},{0.479,135.294,-137.184},{0.479,118.895,-115.963},     {0.483,135.584,-137.29},{0.483,119.112,-115.936},{0.488,135.874,-137.402},     {0.488,119.328,-115.911},{0.492,136.164,-137.523},{0.492,119.544,-115.888},     {0.496,136.455,-137.654},{0.496,119.761,-115.868},{0.500,119.977,-115.849},     {0.500,136.746,-137.795},{0.504,120.193,-115.833},{0.504,137.038,-137.95},     {0.508,120.411,-115.819},{0.508,137.331,-138.12},{0.513,120.627,-115.807},     {0.513,137.625,-138.31},{0.517,137.922,-138.525},{0.517,120.839,-115.797},     {0.521,121.052,-115.789},{0.521,138.222,-138.775},{0.525,121.263,-115.784},     {0.525,143.043,-147.527},{0.525,138.528,-139.074},{0.529,121.473,-115.78},     {0.529,143.1,-147.916},{0.529,138.847,-139.456},{0.533,121.682,-115.779},     {0.533,143.082,-148.164},{0.533,139.204,-140.01},{0.533,140.401,-143.007},     {0.538,121.89,-115.781},{0.538,143.053,-148.367},{0.542,122.095,-115.784},     {0.542,143.011,-148.517},{0.546,122.3,-115.79},{0.546,142.974,-148.641},     {0.550,142.948,-148.745},{0.550,122.502,-115.799},{0.554,142.94,-148.841},     {0.554,122.701,-115.81},{0.558,142.942,-148.914},{0.558,122.898,-115.823},     {0.563,142.963,-148.976},{0.563,123.092,-115.84},{0.567,123.282,-115.858},     {0.567,143.003,-149.027},{0.571,143.063,-149.07},{0.571,123.468,-115.88},     {0.575,143.145,-149.11},{0.575,123.651,-115.904},{0.579,123.829,-115.931},     {0.579,143.247,-149.136},{0.583,124.002,-115.961},{0.583,143.37,-149.154},     {0.588,124.169,-115.995},{0.588,143.515,-149.166},{0.592,124.329,-116.031},     {0.592,143.684,-149.17},{0.596,143.873,-149.168},{0.596,124.481,-116.07},     {0.600,144.087,-149.16},{0.600,124.625,-116.112},{0.604,124.759,-116.158},     {0.604,144.324,-149.146},{0.608,124.882,-116.206},{0.608,144.583,-149.125},     {0.613,124.991,-116.258},{0.613,144.858,-149.102},{0.617,125.086,-116.313},     {0.617,145.161,-149.069},{0.621,125.164,-116.371},{0.621,145.489,-149.03},     {0.625,125.223,-116.432},{0.625,145.841,-148.985},{0.629,146.216,-148.934},     {0.629,125.261,-116.497},{0.633,146.612,-148.877},{0.633,125.276,-116.563},     {0.638,125.264,-116.632},{0.638,147.033,-148.814},{0.642,125.224,-116.704},     {0.642,147.477,-148.745},{0.646,125.154,-116.776},{0.646,147.943,-148.67},     {0.650,148.431,-148.588},{0.650,125.052,-116.849},{0.654,148.943,-148.5},     {0.654,124.918,-116.923},{0.658,149.477,-148.407},{0.658,124.752,-116.997},     {0.663,150.034,-148.306},{0.663,124.555,-117.069},{0.667,150.611,-148.198},     {0.667,124.329,-117.14},{0.671,124.075,-117.209},{0.671,151.211,-148.084},     {0.675,123.798,-117.275},{0.675,151.833,-147.964},{0.679,152.472,-147.835},     {0.679,123.499,-117.338},{0.683,123.183,-117.398},{0.683,153.136,-147.7},     {0.688,153.821,-147.558},{0.688,122.852,-117.456},{0.692,122.509,-117.51},     {0.692,154.527,-147.409},{0.696,122.155,-117.562},{0.696,155.25,-147.251},     {0.700,121.794,-117.61},{0.700,155.98,-147.08},{0.704,121.425,-117.656},     {0.704,156.746,-146.908},{0.708,121.052,-117.699},{0.708,157.531,-146.729},     {0.713,120.674,-117.74},{0.713,158.338,-146.542},{0.717,120.293,-117.778},     {0.717,159.164,-146.347},{0.721,119.91,-117.814},{0.721,160.011,-146.144},     {0.725,160.876,-145.933},{0.725,119.524,-117.849},{0.729,119.137,-117.881},     {0.729,161.759,-145.713},{0.733,138.983,-129.306},{0.733,132.82,-128.392},     {0.733,118.75,-117.911},{0.733,162.66,-145.485},{0.738,163.577,-145.247},     {0.738,118.362,-117.94},{0.738,141.38,-129.709},{0.738,131.315,-128.279},     {0.742,117.972,-117.967},{0.742,164.514,-145.},{0.742,130.272,-128.245},     {0.742,130.258,-128.242},{0.742,143.342,-130.024},{0.746,129.413,-128.244},     {0.746,117.583,-117.992},{0.746,145.14,-130.295},{0.750,117.193,-118.016},     {0.750,128.681,-128.269},{0.750,166.436,-144.478},{0.750,146.841,-130.531},     {0.754,148.513,-130.75},{0.754,128.023,-128.307},{0.754,167.422,-144.203},     {0.754,116.803,-118.039},{0.758,116.413,-118.06},{0.758,168.401,-143.906},     {0.758,127.418,-128.356},{0.758,150.161,-130.951},{0.758,100.035,-93.1424},     {0.763,126.853,-128.413},{0.763,169.419,-143.611},{0.763,116.023,-118.081},     {0.763,151.804,-131.137},{0.763,101.189,-93.1484},{0.767,115.633,-118.1},     {0.767,153.443,-131.308},{0.767,170.453,-143.306},{0.767,126.319,-128.477},     {0.771,125.809,-128.545},{0.771,171.502,-142.99},{0.771,115.243,-118.118},     {0.775,125.32,-128.618},{0.775,172.565,-142.664},{0.775,114.854,-118.136},     {0.775,104.853,-93.1614},{0.779,124.847,-128.694},{0.779,158.429,-131.756},     {0.779,173.641,-142.326},{0.779,114.465,-118.152},{0.779,106.142,-93.1641},     {0.783,124.389,-128.773},{0.783,160.12,-131.884},{0.783,114.076,-118.168},     {0.783,174.729,-141.976},{0.783,107.439,-93.1533},{0.788,161.832,-132.005},     {0.788,175.829,-141.614},{0.788,113.687,-118.184},{0.788,123.943,-128.854},     {0.792,123.508,-128.938},{0.792,113.299,-118.199},{0.792,163.566,-132.118},     {0.792,176.939,-141.239},{0.792,110.183,-93.1532},{0.796,123.082,-129.023},     {0.796,111.604,-93.1513},{0.796,178.059,-140.849},{0.796,112.911,-118.213},     {0.796,165.333,-132.228},{0.800,122.664,-129.109},{0.800,179.152,-140.426},     {0.800,112.522,-118.228},{0.800,167.121,-132.328},{0.800,113.059,-93.1484},     {0.804,122.253,-129.197},{0.804,180.284,-140.006},{0.804,112.134,-118.242},     {0.804,168.949,-132.43},{0.804,114.547,-93.1443},{0.808,116.067,-93.1385},     {0.808,121.849,-129.286},{0.808,111.747,-118.257},{0.808,181.418,-139.568},     {0.808,170.806,-132.527},{0.813,182.55,-139.11},{0.813,121.45,-129.376},     {0.813,172.714,-132.631},{0.813,111.36,-118.272},{0.817,174.666,-132.739},     {0.817,110.973,-118.287},{0.817,183.673,-138.627},{0.817,121.056,-129.466},     {0.817,119.203,-93.1213},{0.821,120.667,-129.558},{0.821,184.733,-138.086},     {0.821,110.587,-118.302},{0.821,176.687,-132.865},{0.821,120.818,-93.1095},     {0.825,110.2,-118.318},{0.825,120.282,-129.65},{0.825,185.8,-137.531},     {0.825,122.463,-93.095},{0.829,109.814,-118.335},{0.829,186.812,-136.925},     {0.829,119.9,-129.743},{0.829,124.138,-93.0775},{0.833,187.63,-136.179},     {0.833,109.428,-118.353},{0.833,119.522,-129.836},{0.833,125.841,-93.0562},     {0.833,101.434,-76.7516},{0.833,183.346,-133.463},{0.838,109.043,-118.371},     {0.838,119.147,-129.929},{0.838,127.53,-93.0084},{0.838,188.095,-135.196},     {0.838,186.301,-134.068},{0.838,103.785,-77.2176},{0.842,118.774,-130.023},     {0.842,108.657,-118.391},{0.842,129.287,-92.978},{0.846,108.272,-118.412},     {0.846,108.625,-78.1698},{0.846,118.404,-130.118},{0.850,118.036,-130.212},     {0.850,107.886,-118.434},{0.850,132.878,-92.9027},{0.854,117.67,-130.308},     {0.854,134.71,-92.8557},{0.854,113.665,-79.1537},{0.854,107.502,-118.459},     {0.858,107.117,-118.485},{0.858,117.305,-130.403},{0.858,116.271,-79.6627},     {0.863,116.942,-130.499},{0.863,118.94,-80.1854},{0.863,106.733,-118.513},     {0.863,138.437,-92.7383},{0.867,116.581,-130.595},{0.867,106.35,-118.543},     {0.867,121.666,-80.7181},{0.871,116.22,-130.692},{0.871,105.966,-118.576},     {0.871,142.17,-92.5433},{0.875,105.583,-118.611},{0.875,144.07,-92.4357},     {0.875,115.861,-130.789},{0.875,127.349,-81.8495},{0.879,105.2,-118.649},     {0.879,115.502,-130.886},{0.879,145.973,-92.3099},{0.883,115.144,-130.984},     {0.883,104.818,-118.69},{0.883,133.39,-83.0948},{0.888,149.743,-91.9766},     {0.888,114.786,-131.082},{0.888,104.437,-118.735},{0.888,136.58,-83.7813},     {0.892,151.488,-91.6963},{0.892,104.056,-118.783},{0.892,114.429,-131.182},     {0.896,114.072,-131.281},{0.896,153.213,-91.3845},{0.896,103.676,-118.834},     {0.900,113.714,-131.382},{0.900,103.296,-118.889},{0.900,154.775,-90.9557},     {0.904,155.686,-90.1154},{0.904,102.917,-118.948},{0.904,113.357,-131.483},     {0.908,102.54,-119.011},{0.908,113.,-131.585},{0.913,112.642,-131.687},     {0.913,102.163,-119.078},{0.917,101.787,-119.149},{0.917,112.284,-131.791},     {0.921,111.926,-131.895},{0.921,101.412,-119.225},{0.925,111.566,-132.001},     {0.925,101.038,-119.305},{0.929,111.206,-132.108},{0.929,100.666,-119.39},     {0.933,110.845,-132.216},{0.933,100.294,-119.479},{0.938,110.483,-132.326},     {0.942,110.12,-132.437},{0.946,109.756,-132.55},{0.950,109.392,-132.665},     {0.954,109.025,-132.781},{0.958,108.657,-132.9},{0.963,108.288,-133.02},     {0.967,107.917,-133.143},{0.971,107.545,-133.268},{0.975,107.171,-133.396},     {0.979,106.797,-133.527},{0.983,106.42,-133.66},{0.988,106.043,-133.796},     {0.992,105.664,-133.936},{0.996,105.284,-134.078},{1.00,104.903,-134.225}};      Here is a 3d representation of the `dataSet` ![enter image description here](http://i.stack.imgur.com/gKHPg.png) Starting the code at the last point of `dataSet`               ordDataSet = NestList[With[{elem = Nearest[#[[1]], #[[2]]][[1]]},          {Select[#[[1]], (# != elem &)], elem}] &,          {Delete[dataSet, {-1}], dataSet[[-1]]}, 300][[All, 2]];      works very well, until step 243 where everithing goes bad (sorry for the huge gif) ![enter image description here](http://i.stack.imgur.com/jfJ8C.gif) Looking at the 3d plot, is clear that the nearest neighbor is `ordDataSet[[245]]`, but manually calculating the distance confirms that the nearest point is `ordDataSet[[244]]`. What is wrong then, my code, the displayed plot or the calculation of the Norm? * * * **EDIT** > Kuba wrote > > I hope I have not missed the point but the problem is you are probably using > `BoxRatios->1` which can affect the judgement. I tried to see this before posting, but using `AspectRatio` instead of `BoxRatio`. Lucky for me, the small dimension plays a crucial role in connectendness, and it should be rescaled to wiegth as much as the _yz_ coordinates. Rescaling the data:               rescDataSet = MapAt[100# &, dataSet, {All,1}];          rescOrdDataSet = NestList[With[{elem = Nearest[#[[1]], #[[2]]][[1]]},           {Select[#[[1]], (# != elem &)], elem}] &,           {Delete[scaledDataSet, {-1}], scaledDataSet[[-1]]}, 300][[All, 2]];      everithing goes as expected: ![enter image description here](http://i.stack.imgur.com/aq73t.gif) Thank you very much Kuba!


title: Specify a variable as an integer

text: I have a formula that always evaluates to a certain number for any variable `X` under one condition that `X` is an integer and greater than 0. So how can I evaluate `Func[X]` and specify that X is an integer greater than 0? is there a way to do that? I tried saying `Func[Round[X]]` but it didn't work, it just used `Round[X]` as a variable instead of understanding that it means `X` is an integer. Ok I will give exactly what I'm trying to do, it's fairly simple: $p= \begin{array}{cccccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\ 0.5 & 0 & 0.5 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\ 0.5 & 0 & 0 & 0 & 0.5 & 0 & 0 & 0 & 0 & 0 \\\ 0 & 0.5 & 0 & 0 & 0 & 0.5 & 0 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0.5 & 0 & 0.5 & 0 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0.5 & 0 & 0.5 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\ \end{array} ;$ $\text{mainWin}=\\{0,12.4461,24.8921,37.3382,49.7842,62.2303,74.6763,87.1224,99.5685,112.015\\};$ $u=\\{0,0,0,1,0,0,0,0,0,0\\};$ Now I'm evaluating: $(u.\text{MatrixPower}[p,x]).\text{money}$ where $x$ is a positive integer This will always evaluate to: **37.3382** which if you notice is the fourth entry in $money$ which is also the state that we started with. Now I want to know if mathematica can figure that out (that it always evaluates to this number) if I indicate that $x$ is a positive integer. If I just use $x$ normally:               (u.MatrixPower[p, x]).mainWin // Simplify      I get:               37.3382 + (2.77553*10^-24 - 1.91762*10^-31 I) (-0.5)^     x - (1.77636*10^-15 - 1.59872*10^-14 I) (-0.116393 - 0.396276 I)^     x + (3.55271*10^-15 - 1.95399*10^-14 I) (-0.116393 + 0.396276 I)^     x + (7.10543*10^-15 - 4.73403*10^-15 I) (-2.20245*10^-16)^     x - (5.68434*10^-14 + 2.27918*10^-16 I) 0.732786^x      As you can see I just want to get rid of that imaginary part The answers here are quite educational (I'm new to Mathematica) but unfortunately they don't give the required outcome. Just for the interested; this is modelling the outcome of a gamble where you have p as the probability matrix, your initial state is number 4. and what I'm doing here is guaranteeing that I get one outcome no matter how many times I gamble, and that outcome is equal to whatever I started with. This is Mathematica code:               p = \!\(\*     TagBox[     RowBox[{"(", "", GridBox[{     {"1", "0", "0", "0", "0", "0", "0", "0", "0", "0"},     {"0.5`", "0", "0.5`", "0", "0", "0", "0", "0", "0", "0"},     {"0.5`", "0", "0", "0", "0.5`", "0", "0", "0", "0", "0"},     {"0", "0.5`", "0", "0", "0", "0.5`", "0", "0", "0", "0"},     {"0", "0", "0", "0.5`", "0", "0.5`", "0", "0", "0", "0"},     {"0", "0", "0", "0", "0.5`", "0", "0.5`", "0", "0", "0"},     {"0", "0", "0", "0", "0", "0", "1", "0", "0", "0"},     {"0", "0", "0", "0", "0", "0", "0", "1", "0", "0"},     {"0", "0", "0", "0", "0", "0", "0", "0", "1", "0"},     {"0", "0", "0", "0", "0", "0", "0", "0", "0", "1"}     },     GridBoxAlignment->{             "Columns" -> {{Center}}, "ColumnsIndexed" -> {},               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {},               "ItemsIndexed" -> {}},     GridBoxSpacings->{"Columns" -> {     Offset[0.27999999999999997`], {     Offset[0.7]},      Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {     Offset[0.2], {     Offset[0.4]},      Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},               "ItemsIndexed" -> {}}], "", ")"}],     Function[BoxForm`e$,          MatrixForm[BoxForm`e$]]]\);     mainWin = {0, 12.4460563, 24.89211259, 37.33816889, 49.78422519,         62.23028148, 74.67633778, 87.12239407, 99.56845037, 112.0145067};     u = {0, 0, 0, 1, 0, 0, 0, 0, 0, 0};     (u.MatrixPower[p, x]).mainWin // Simplify


title: Graphics plot of point using unfilled circle

text: I'd like to be able to place points on a plot using `Graphics[{Point[{a,b}],....}]` but have the plot symbol be an unfilled circle. I've looked around but can't find any way of doing this. Is there one? Thanks. After reading the first response, perhaps I should add a bit more. I'd like to be able to do the following:               p1 = Plot[x^2,{x,-3,3}]     p2 = Graphics[Style[Point[{0,0}],PointSize[Large]]     Show[p1,p2]      but with an unfilled circle instead of a dot. The solution proposed in the first answer falls short in two ways: first, the unfilled circle does not properly hide graphics elements underneath it; second, the circle will appear as an ellipse, not a circle, in the (likely) event that the underlying graphic does not have aspect ratio 1. The application here is for plotting piecewise discontinuous functions and showing clearly which endpoint at a jump discontinuity holds the value at the point.


title: System of differential equations - solving for a constant

text: I will reformulate my question in the hopes it will be more intelligible. First, I defined the functions:               f1[r_] = b*SphericalBesselJ[l, α*r];     f2[r_] = c*SphericalHankelH1[l, I*β*r];          g1[r_] := D[f1[r], r]/(f1[r]);     g2[r_] := D[f2[r], r]/(f2[r]);      And I want to set:               f1[a]==f2[a]      g1[a]==g2[a]      Is it possible to use these two equations to find another equation that relates Alpha, Beta and a?


title: Mathematica 9.01 and CUDA under VB 2013 and modified CCompilerDriver

text: I tried to force CUDA using Visual Studio 2013 C compiler by manipulating the VisualStudioCOmpiler file found at C:\Program Files\Wolfram Research\Mathematica\9.0\AddOns\Applications\CCompilerDriver When run, CUDA will not run at all.Mathematica hangs at Needs["CUDALink`"] Anyone faced similar problem? HAs anyone tried to make the same modification?


title: Dynamically filling matrix with a[[n,m]] = 1/a[[m,n]]

text: I'm building a square matrix, with 1s on the diagonal and elements in U the inverse of elements in L, which are random integers drawn from the sequence 1, ..., 9. Given the nature of the problem I need to solve, conceptually this does the trick perfectly.               size = 5; (*size of matrix*)     range = {1, 9}; (*the range of integers, min to max*)     init = RandomInteger[range, size]; (*builds the initial vector*)     matrix = Transpose[Table[init/init[[i]], {i, size}]];       (*constructs the matrix from the initial vector the way the problem requires*)      `matrix` is an "ideal" matrix, because in a second step a hypothetical user should be able to perturb it by modifying the elements in L, with elements in U changing accordingly; i.e., becoming the inverse `matrix[[1,2]] = 1/matrix[[2,1]]`, and so on. This is the best I have done so far to implement the dynamic behavior I want.               onscreen = SparseArray[{       {i_, i_} -> 1,         (*1s on the diagonal*)       {i_, j_} /; i - j >= 1 :> InputField[Dynamic[matrix[[i, j]]]],         (*InputFields to edit L part of matrix*)       {i_, j_} /; i - j <= 1 :> Dynamic[1/matrix[[j, i]]]         (*the U part of matrix - comment below*)       }, {size, size}]      I use `onscreen` as the means for the user to enter the desired values. Now he/she can edit the L part of `matrix`, and the U part of `onscreen` should reflect what is expected in `matrix`. However values in U of `matrix` don't change. How can I make it happen? I should remark that `matrix` will be needed for further calculations, so I can't populate it with `Dynamic`.


title: how to nest parallelized computations on a cluster?

text: I am lucky to have access to a computational cluster and I could submit my job to many-many cores. As I need to evaluate a numerical integral within a numerical integral, I would like to know if I can set things up (e.g. during the compilation of the inner integral as compiled function) in a way that would run the inner function on 8 cores (on a single node) and distribute the outer one across nodes in the cluster?               tmp = Compile[      {{z,_Real},{zz,_Real}},      NIntegrate[1 - \[Xi]u[zzz]/\[Xi]c[zzz], {zzz, z, zz},Parallelization -> True]      ]     g[z_] := NSolve[       T'[z]/(1 - T'[z]) - (k SurvivalFunction[H,z]/(z PDF[Hstar, z]))       *NIntegrate[(1 - g) Exp[tmp[z, zz]] PDF[H, zz]/SurvivalFunction[H, z],        {zz, z, \[Infinity]}], g, Reals]     N[g[2000000], 10]      Simple `LaunchKernel` and `Parallelize` did not seem to give me this control. (If it made sense in the first place...) Separately, I would evaluate my function (`g`) for many points (a `List`), but as all for all points `g` uses the integrals over the right tail of the same distribution, actually it sounds like a waste of time to calculate them separately, even if I do it within a single call like `ParallelTable`. Would Mathematica notice that it could use some calculations across the evaluations? Or shall I explicitly separate the useful object first? Or can I call some clever `Fold`? Could any of this be parallelized? (Not trivial if I try to be cheap and ask Mathematica to solve for a function only implicitly defined in an expression.) **EDIT** : Actually the code as given does not run, but gives the error > CompiledFunction::cfsa: "Argument zz at position 2 should be a !(\"machine- > size real number\")." Probably because of the outer integral having upper limit of infinity?


title: How to guess initial complex value for FindRoot

text: I have to solve a transcendental equation for a parameter, say $\beta$. Now, the $\beta$ has a range from $ik$ to $k$ where $i$ is the usual imaginary root $\sqrt{-1}$ and $k$ is a real number. Problem is, the transcendental equation has multiple solutions, and so I cannot guess what will be the proper choice for the initial value of $\beta$ in `FindRoot`. I could do it if $\beta$ ranges from $p$ to $q$ where $p$ and $q$ are reals by plotting the transcendental equation's lhs and rhs. However, I don't know how to plot complex ranges. Is there any way to guess the initial values?


title: PaddedForm adds an additional padding character

text: I would like to get a sequence from `"01"` to `"10"`. I tried               ToString@PaddedForm[#, 1, NumberPadding -> "0"] & /@ Range@10          (*{"01", "02", "03", "04", "05", "06", "07", "08", "09", "010"}*)      But this returns `"010"` instead of `"10"`. What am I doing wrong? And yes, I know I can do               StringTake[ToString[PaddedForm[#, 1, NumberPadding -> "0"]], -2] & /@ Range@10          (*{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"}*)      But this feels like a hack.


title: Plot help with axes coordinates

text: Plot[{4 - 2 y, (5 + y)/3}, {y, 1, 10}]      ![graph](http://i.stack.imgur.com/o4Dve.png) How do I make Mathematica tell me the coordinates for cuts with the y-axis, other than just looking at it?


title: how to work with list as function parameter

text: I want to output an arrow based on input from user and I tried writing this small function to achieve this:               g[{matric}] :=       For[i = 1, i < Length[mat], i++,        Graphics[{Arrow[{{0, 0}, {matric[[1]], matric[[2]]}}]}, Axes -> True,         AspectRatio -> Automatic]]      To call it: `g[mat[[1]]]` which is not working !! I want to send array as list for example `{{1,2},{3,4}}` and create its output as arrow but I don't know how to break this list. The second problem is that I can generate plots using `Apply[f,arg,{1}]` but it gives different plots for different elements in the list,so how can I combine them together in one plot. I know about `Show` command but I just wanted to know if there is any other way too.


title: Plotting the discrete solution to a PDE

text: So I went through all the grunt work of solving a PDE in discrete form for a research project. Now I have a Temperature solution as a function of time and space: $$ T_{i}^{n+1}=\left( \dfrac {\lambda _{1}} {\rho_{1}c_{1}}\right)\left( \dfrac {\Delta t} {\Delta r^{2}}\right)\left( 1-\dfrac {\Delta r} {r}\right) T_{i-1}^{n}+\left( 1-2\left( \dfrac {\lambda _{1}} {\rho _{1}c_{1}}\right) \left( \dfrac {\Delta t} {\Delta r^{2}}\right) \right) T_{i}^{n}+\left( \dfrac {\lambda _{1}} {\rho_{1}c_{1}}\right)\left( \dfrac {\Delta t} {\Delta r^{2}}\right)\left( 1+\dfrac {\Delta r} {r}\right) T_{i+1}^{n}+\dfrac {\Delta t} {\rho_{1}c_{1}}\omega_{b1}c_{b}(\left( T_{b}-T_{i}^{n}\right)+\dfrac {\left( P\lambda _{1}\right) } {\omega_{b_{1}}c_{1}}) $$ But my problem now is I don't know how to plot this in mathematica. I'm looking to plot this Temperature as a function of time online (for fixed radius). As you can see, I have delta t and delta r increments and the variable n is my time variable while i is my space variable. I also have initial conditions for when t = 0 (n = 0). I also have another solution just for i = 0 but I didn't write it out here. Is this just a matter of creating a recursive function and then using plot? Because I tried that and it isn't working for me. Any ideas on how to go about plotting this in mathematica would be greatly appreciated. Thanks! Mathematica Code (with dummy numbers for coefficients):               T[n_, i_] := T[n + 1, i] = 3*T[n, i - 1] + 2*T[n, i] +                   3*T[n, i + 1] + 4 ((300 - T[n, i]) + 8)          T[n + 1, 0] = 5*T[n, 0] + 6*(3 + 2 (300 - T[n, 0])) + 10     T[0, i] = 300      Everytime I run this, I get a recursion depth of 256 exceeded.


title: Are there any videos that show how different Mathematica expressions are evaluated?

text: Are there any videos that show how different _Mathematica_ expressions are represented internally as object graphs and demonstrate how they are transformed during an evaluation? I am asking because I believe it can help to develop better intuition about the evaluation process, in particular, which parts of expressions are shared, and which are copied, what happens when different scoping constructs are evaluated, how parts of expressions are modifoed, how evaluation rules are selected from up- and downvalues and how pattern matching is performed etc. I found some interesing animations at http://reference.wolfram.com/flash, but they are mostly intended to give intuition about what are the _results_ of some built-in functions, rather than the _evaluation process_ itself.


title: Making a Stock Options Database in Mathematica

text: I am trying to use _Mathematica_ to create a stock options database of sorts. That is I wish to write a function that imports the option chain of a given stock. Unfortunately Wolfram has yet to put stock options on the data server associated with `FinancialData[]` so I decided to obtain the necessary data from _Yahoo Finance_. Here is the function I wrote to do this:               rules = {"Jan" -> "01", "Feb" -> "02", "Mar" -> "03", "Apr" -> "04",      "May" -> "05", "Jun" -> "06", "Jul" -> "07", "Aug" -> "08",      "Sep" -> "09", "Oct" -> "10", "Nov" -> "11", "Dec" -> "12"};          acquireOptions[stock_String] :=      Module[{z =      StringSplit[Import["http://finance.yahoo.com/q/op?s=" <> stock <>"+Options"]],index1, index2},     index1 = Position[z, "Expiration:"][[1, 1]] + 1;     index2 = Position[z, "Call"][[1, 1]] - 1;     ArrayFlatten[(Partition[(DeleteCases[z[[index1 ;; index2]], "|"] /.           rules), 2] /. {x_String,          y_String} :> {"20" <> y <> "-" <> x}) /. {x_String :>        Cases[Import[         "http://finance.yahoo.com/q/op?s=" <> stock <> "&m=" <> x,          "Data"], {_?NumberQ, _String, __?NumberQ}, \[Infinity]]}]]      I should note that I had to study the structure of the _Yahoo Finance_ website hard core to make this work. Although it is functional the problem I have is that it is simply too slow. Running this function for a single stock takes about 30 seconds. Lets assume there are 1000 stocks that have options that I would want to acquire (there are probably a lot more than 1000, I would literally want to be able to acquire every last option). This would take about 8 and a half hours which is just too long. So I'm interested in how I can do this more efficiently. If I used parallel table on my 8 core machine could I expect this to only take about 2 hours? Besides for the code I've written, I saw that _Yahoo_ has a query language YQL that can be used to pull data off their servers. I then saw that Mathematica has Database Link SQL operations. I don't know much about SQL/YQL but would this have been a better direction to go in? If so would anyone be able to show how to link Mathematica and YQL and provide an example where YQL is used in Mathematica to obtain options data? Oh and in case anyone was wondering why I am doing this, it is for an investment model I'm working on. Thanks


title: How does PolarPlot render a nested list of functions?

text: I am getting unexpected plots from `PolarPlot` when I provide a list of functions that I generate using `Table`. I suspect the issue is related to the presence of nested lists, but I want to understand how `PolarPlot` is rendering the nested list of functions. I expect the output to be a plot showing the curve of each function in my list. I do not know what functional form would generate the plot that I do observe. For example:               f[a_, b_, c_, t_] := 1 + (1/a)Sin[b + c*t]     t1 = Table[f[a, b, c, t], {a, 3}, {b, 0, Pi/2, Pi/2}, {c, 1}]     PolarPlot[t1, {t, 0, Pi}] (* Not expected result *)     PolarPlot[t1[[1, {1, 2}, {1}]], {t, 0, Pi}] (* Not expected result *)     PolarPlot[Flatten[t1], {t, 0, Pi}] (* Expected result *)     PolarPlot[t1[[1, {1, 2} ,1]],{t, 0, Pi}] (* Expected result *)


title: How do you adjust tick direction on a 3d plot?

text: I have a 3d plot with oddly angled tick marks. Whether it's due to the viewing angle being unexpected or some other reason, the tick marks on the bottom axes are angled up along the sides rather than in to the plane. In order to fix this, I'd like to manually change the tick angle back to what it should be, but I can't find the setting that controls tick direction. Any help? Edit: Here is a simple example that illustrates the problem: suppose I plot               Plot3D[x + y, {x, 0, 1}, {y, 0, 1}]      At first, the tick marks on the x and y axes are in the x-y plane. However, if I rotate the point of view, I fairly quickly (around `ViewPoint -> {2.22811, -2.31877, 1.05302}`) find that the ticks switch from being in the x-y plane to pointing up along the z axis. I want to stop it from doing that, so that the ticks stay in the x-y plane for other choices of ViewPoint. This really seems like the sort of thing there ought to be a setting for.


title: Make 2D vector norm graph

text: I have: List of points on 2D plane:               pointsz0 = ToExpression@Import@"http://pastebin.com/raw.php?i=VQfP0HgB";      And I have some values in those numbers:               table = ToExpression@Import@"http://pastebin.com/raw.php?i=7g4QNPPw";      Now since `pointsz0` are only 2D (notice `z = 0`), I would like to create a 2D graph. At a `point[[1]]` I want `table[[1]]`. To make things a bit more clear. My numbers are actually vector norms and I would like to make a nice graph showing how the norm of a vector changes in given points. Most likely using colors. That's the idea.


title: Evaluating $n$-th derivative of a function at a given point

text: I have a function defined as follows: \begin{array}{ccccc} g & : & [-1,1] & \to & \mathbb C \\\ & & x & \mapsto & \frac{1}{(x-z)^k} \\\ \end{array} where $k$ is a positive integer and $z$ a complex number outside $[-1,1]$ . I want to plot the sequence $\displaystyle \frac{|g^{(n+1)}(0)|}{2^n (n+1)!}$. I tried to do what follows:               g[x_, z_, k_] = 1/(x - z)^k          DiscretePlot[Abs[D[g[x, 5 + I*1/5, 3], {x, n + 1} /. x -> 0]]/(2^n (n + 1)!), {n, 1, 500}]      But the error               General::ivar: 0 is not a valid variable.       pops up. What have I done wrong ?


title: Why does Maximize return a wrong answer?

text: I want to find the maximum of the following function, but get a wrong result. What am I doing wrong?               Clear[x, y, xx, yy]     peaks[x_, y_] :=        3*(1 - x)^2.*Exp[-(x^2) - (y + 1)^2] -         10*(x/5 - x^3 - y^5) Exp[-x^2 - y^2] - 1/3 Exp[-(x + 1)^2 - y^2];     N[Maximize[peaks[xx, yy], {xx, yy}]]     NMaximize[{peaks[x, y], x >= -2, x <= 2, y >= -2, y <= 3}, {x, y}]     peaks[0, 2]     peaks[1.28568, -0.00484756]      When you look at these graphs, you realize that the results are strange:               peaks[x_, y_] := 3*(1 - x)^2*Exp[-(x^2) - (y + 1)^2] -                       10*(x/5 - x^3 - y^5) Exp[-x^2 - y^2] - 1/3 Exp[-(x + 1)^2 - y^2];     Plot3D[peaks[x, y], {x, -2, 2}, {y, -2, 3},          ColorFunction -> "DarkRainbow",          AxesLabel -> Automatic]     ContourPlot[peaks[x, y], {x, -2, 2}, {y, -2, 3},           ColorFunction -> "DarkRainbow",          ContourLines -> False,           Contours -> 25]      ![Mathematica graphics](http://i.stack.imgur.com/QcoGl.png)


title: Depth from Graphics3D

text: Consider this simple 3D rendering with some geometric primitives:               Graphics3D[{Cylinder[{{-1, -1, 0}, {-1, -1, 1}}, .42], Cuboid[],        Polygon[{{-2, -2, 0}, {2, -2, 0}, {2, 2, 0}, {-2, 2, 0}}],        Sphere[{.3, -.6, .5}, .5]}, Boxed -> False]      How can I get the depth of each _pixel_ of the rendering, i.e. the distance of the corresponding point to the camera? **Edit:** The required depth image would be something like the OpenGL z-buffer. Vertices alone are not enough - I need the depth of every pixel in the rendered image.


title: How do I draw a Circular Graph colored like this in Mathematica?

text: I must plot some data in radians and would like to use this image as a background to that graph. Although it looks good the lines are degraded in image form. thus the reason for this question. Can something like this be drawn in Mathematica? ![Colored Circular Graph](http://i.stack.imgur.com/uSM96.jpg)


title: How to apply Gaussian kernel to smooth density of points on 2D (algorithmically)

text: I have a set of points on a 2D surface and need to build a heatmap. However, I also need to smooth out the density/distribution by applying some sort of kernel (Gaussian kernel, for example). I Know what Gaussian distribution is, and I have no idea, how mathematically apply the Gaussian kernel to the points on 2D so I can get a smooth distribution or density of points. I know there are functions in Wolfram to do that, but this is more like a research problem, so I need to understand the THEORY of it. Let's say, I am a theory person, and I am NOT in needs of programming. I just need to understand the underlying math of it, why it is still Can someone, please, explain to me, possibly with an example? Or take me to a website that I can read about it? I'd much appreciate that. Thanks


title: Do/For loop for plots

text: I have a lot of points that I would like to get shown on a plot. The problem is that sometimes I only have 2 points while other times i have 10 points. I've tried to make a for loop to create a plot with the points but without any luck. This is my code I have for now:               Point1 = {x -> 2, y -> 4};     point1dot =        ListPlot[{{Point1[[1, 2]], Point1[[2, 2]]}},         PlotStyle -> {AbsolutePointSize[5]}];     Label1 = Graphics[        Text[StyleForm["Point 1", FontSize -> 9], {Point1[[1, 2]] + 0.25,           Point1[[2, 2]] + 0.25}]];     Show[point1dot, Label1]      In this example there is only one point, but sometimes it will look like this:               Point1= {x -> 2, y-> 4};     Point2= {x -> 4, y-> -1};     Point3= {x -> 6, y-> 2};     Point4= {x -> 11, y-> 4};     Point5= {x -> 4, y-> 5};     Point6= {x -> 3, y-> -1};      It will become a great shortcut for my work if it could generate it itself instead of editing it manually all the time. So here is my question: Is it possible to make some sort of for loop (it doesn't have to be for), that takes value from my points and create a listplot with the label based on the amount of different numbers?


title: How to apply tags to expression terms?

text: I often see on this site and at the mathgroup the repeated questions on how to rearrange expression that _Mathematica_ "likes" to keep in one form, but the user prefers in another. Consider this trivial example:               (x^2 - 1)/(x + 1) // Simplify      _Mathematica_ returns `-1 + x`, rather than the `x - 1` that the user might prefer. I have seen many answers to these questions and gave a few myself. The problem here is that the answers are non-universal; they strongly depend upon the expression in question. Besides, they require some additional programming for sorting terms, and the more complex the formula, the longer will be the code that does the sorting. It seems that the problem of sorting terms in analytic expressions into the desired order might be solved, if one could assign tags to the terms to be sorted. One would then sort the terms according to a specified list of such tags. Now comes my question, can you tell me how to apply tags to expression terms?


title: How can I speed up numerical integration of multidimensional integral?

text: I am numerically solving an integral equation that contains a double integral. I have managed to get a solution but it takes forever. I am wondering if there is a way to speed up numerical integration of multidimensional integrals. Here is the code: First a couple of functions that enter the calculation (if I don't include them, the integration will be faster)               g = Pi          cs[x_] := 2*ArcCos[x]/Sqrt[1 - x^2];          csh[x_] := 2*ArcCosh[x]/Sqrt[x^2 - 1];          pref[t_, v_, d_] :=        1/d^2*(1 + 10^(2*(v - t)) (1 - 1/d^2)) /          Sqrt[1 - 1/4*((10^(2*t) + 10^(2*v))/10^(t + v) - 10^(v - t)/d^2)^2]          piece[d_,v_] :=        If[d Astart[v] < 1, cs[d Astart[v]], If[d Astart[v] > 1, csh[d Astart[v]], 2]]      Here is the actual iteration               Clear[Astart, A, precision, values]          precision = 10^-1;          Astart[t_] = -g*t + 1;          values = ParallelTable[{t,        1 + g/(Pi^3*2)         (NIntegrate[Log[10]*10^(v - t)*pref[t, v, d]*((d^2*Astart[v] - 1)*(Pi - g*piece[d,v]) +              d*Astart[v]*g^2*csh[g])/(d^2*Astart[v]+ g^2 - 1),           {v, -Infinity, 0},           {d, 1/(10^(t - v) + 1), 1/Abs[10^(t - v) - 1]},           WorkingPrecision -> 12,           PrecisionGoal -> 3,           MaxRecursion -> 20,           AccuracyGoal -> 12,           Method -> {"SymbolicPreprocessing",  "OscillatorySelection"-> False, "SymbolicProcessing"->0}         ])},       {t, Union[Range[-5.6,-1.6, 0.5]~Join~Log10[Range[0.08, 0.98, 0.1]]]}];           A[t_] = Interpolation[Re@values, t, InterpolationOrder -> 2, Method-> "Spline"]      Perhaps I should also mention that this later on iterated into a while loop until convergence is achieved (just to give a better picture on the amount of total waiting time...) EDIT: I have added in the code also the method the 'fastest' method that I could find, however it still runs for ages... Given the particular form of the integration limits, is there any better trick to help mathematica? Also, by inspection I can see that the result explodes logarithmically which might be another reason why it is so slow.


title: Defining a rule with functions of arbitrary arguments

text: I have a set of "functions operators", say A1[u],A2[u],A3[u],and I would like to define a rule such that, for instance,               (x*A1[u1]).(y*A2[u2])      returns               x*y*A1[u1].A2[u2]      I have been trying something like:               operatorset = {A1[u1],A2[u1],A3[u1],A1[u2],A2[u2],A3[u2]};     distri = Dot -> Composition[Distribute, Dot];     rule1 = {Dot[Times[scalar1__, z1_ /; MemberQ[operatorset, z1]],          Times[scalar2__, z2_ /; MemberQ[operatorset, z2]]] ->         scalar1*scalar2 *z1.z2};      It works, however, I will need this kind of product when the operators have other arguments, like A1[u1^2], A2[u3], etc. Is there a way to define an "operatorset" where each operator has arbitrary arguments? Thanks in advance.


title: Loading Statistics`Library`

text: I need to use a number of functions from the`Statistics`Library`` namespace. Since that is a bit of a mouthful I would like to import it, but I get errors:               In[42]:= Needs["Statistics`Library`"]          During evaluation of In[42]:= Get::noopen: Cannot open Statistics`Library`. >>          During evaluation of In[42]:= Needs::nocont: Context Statistics`Library` was not created when Needs was evaluated. >>          Out[42]= $Failed          In[43]:= << Statistics`Library`          During evaluation of In[43]:= Get::noopen: Cannot open Statistics`Library`. >>          Out[43]= $Failed      I can use individual functions from the namespace               In[44]:= Statistics`Library`DistributionDimensionality[      NormalDistribution[]]               Out[44]= 1      so the problem is not in the name. What is the problem then? What is the correct way to do the import?


title: How to count number of {True,True} outputs?

text: Do[Print[{x + y + z == 3, x + y > z}], {x, 1, 2, 1}, {y, 1, 2, 1}, {z, 1, 2, 1}]      If I run this syntax I get a series of Outputs, I am trying to Count only the number of outputs which is `{True,True}`


title: Importing LTSpice data into mathematica

text: I am working with LTSpice (Discret electrical circuit ( Spice) simulator). I would like to import LTSpice ouput data into mathematica for processing and plots. An example of a file can be found here (https://www.dropbox.com/s/ixbp11p6876pz1o/Test_SCOneDiode.raw) Any comments, suggestions and helps are welcome! Thank you in advance


title: Linear Stability Analysis Routine. Normal Modes in NDSolve

text: I want to make the linear stability analyis of a nonlinear system of PDEs. So for example then I want to plot what happens to the amplitudes of the modes. To do that I need to solve my equations with different initial conditions, which can be parametrised by the wavelenght $k$. There's what I do, but doesn't seem to work. I write down the equations               eqn1[λ_, ω_, v_, α_, δ_, σ_, A_] := **Something**     eqn2[λ_, ω_, v_, α_, δ_, σ_, A_] := **Something**      I prepare the parametrisation (I would like to put my different solutions - functions of $x,t$ - in the arrays SolVec1,2; and my different maximums - functions only of $t$ - in the arrays MaxVec1,2) :               SolVec1 = Table[0, {i, Nk}]; SolVec2 = Table[0, {i, Nk}];     MaxVec1 = Table[0, {i, Nk}]; MaxVec2 = Table[0, {i, Nk}];          Initial[x_, kk_] := {0.01*Sin[2 Pi kk*x / L], 1 - 0.01 Cos[2 Pi kk*x / L]/L};          Max1[sol_, t_] := First[Maximize[sol[x, t], 0 <= x <= L, x]];      I call NDSolve inside a loop on $k$:               Nk=3;          For[kk = 1, kk <= Nk, kk + 1,            sol1 = {θ, ϕ} /. First[NDSolve[{       eqn1[0.1, 0.13, 0.1, 0.08, 0.3, 0, 0] == 0,       eqn2[0.1, 0.13, 0.1, 0.08, 0.3, 0, 0] == 0,         **HERE, BOUNDARY CONDITIONS, I DO NOT WRITE THEM FOR SIMPLICITY**      θ[x, 0] == First[Initial[x, kk]],       ϕ[x, 0] == Last[Initial[x, kk]]}, {θ, ϕ}, {x,        0, L}, {t, 0, T}, AccuracyGoal -> 5, PrecisionGoal -> 4,       MaxSteps -> 200000]];           SolVec1[[kk]] = sol1[[1]];      SolVec2[[kk]] = sol1[[2]];           MaxVec1[[kk]]=Max1[sol1[[1]],t];      MaxVec2[[kk]]=Max1[sol1[[2]],t];          ]      Where I filled the various arrays. First question >> This doesn't work, it gets stuck in the loop. Why? Second question >> I would like to plot the different solutions (which will be saved in SolVec1,2) on the same graph, with different colors. For example for the different initial conditions:               Plot[{SolVec1[[n]][x, 0]}, {n, 1, Nk}, {x, 0, L}, PlotRange -> All]      does this make any sense? How could I do otherwise?


title: Generating a matrix using sublists A and B n times

text: I want to write a function that generates a square matrix from sublists. My sublists are `a = Range[0, x, 0.5]; b = Range[0.25, x + 0.25, 0.5];` Suppose x=2, then I can manually evaluate {a,b,a,b,a} to generate an 5x5 matrix. I want to make the matrix automatically, of course, but without using a loop. I've tried different ways to do it, with Nest, Range and Table, but I can't make it work. Do I absolutely have to use a loop?


title: How to plot a 2D region when there are 3 free parameters?

text: How could I obtain the region of payments, with the parameters a,b,c,d between 0 and 1 and the sum of all equals 1? After the comment/recommendation of belisarius... I edit the original question and.... ask you a question in the last line of code.               P = {{a, b}, {c, d}}          A = {{2, -1}, {0, 1}}         B = {{-1, 1}, {2, -1}}          A[[1]].P[[1]] + A[[2]].P[[2]]          f1[a_, b_, c_, d_] = A[[1]].P[[1]] + A[[2]].P[[2]]     f2[a_, b_, c_, d_] = B[[1]].P[[1]] + B[[2]].P[[2]]          ParametricPlot[{f1[a, b, c, d], f2[a, b, c, d]}, {  a, 0, 1}, {b, 0,        1}, {c, 0, 1}, {d, 0, 1} ]      In the last line, How Can I code for consider only a,b,c,d in [0,1] with a+b+c+d=1 ? It´s similar to obatin all the convex combinations of the points (a(i,j),b(i,j))


title: Scaling the x-axis in ListLogLogPlot[] or ListLogPlot[] in lieu of DataRange

text: I will present my existing workaround but I am wondering if there is a better solution that takes less time (my solution seems to ~double the time it takes to produce the desired plot). Using DataRange would be ideal, but I'm either missing something or it doesn't work when a ListPlot has logarithmic axes. I have some data in a list (1D) that I'm plotting with ListLogLogPlot. I know that the x-values should range from 1 to 5000; with ListPlot I would just use DataRange to take care of this. However, DataRange seems to do nothing when using ListLogPlot or ListLogLogPlot. Let's do an example:                   fakedata = Table[1/x, {x, 1, 100, .1}];         ListLogLogPlot[fakedata, Frame -> True, ImageSize->500]      ![enter image description here](http://i.stack.imgur.com/rsmEb.png) Adding DataRange->{1,5000} does nothing to the plot. I can instead make a new list, composed of the x-values since I know they should vary linearly from 1 to 5000 over the length of the data:                   sol = Solve[1 == m + b && 5000 == m*Length@fakedata + b, {m, b}];         fakexvals =             Table[Evaluate[x*m + b] /. First@sol, {x, 1, Length@fakedata}];      Using this new list, I can get the desired plot:                   ListLogLogPlot[Transpose[{fakexvals, fakedata}], Frame -> True,          ImageSize -> 500]      ![enter image description here](http://i.stack.imgur.com/DaFaC.png) This is _ok_ for this example, but it becomes cumbersome with the data set is large. It appears to take Mathematica roughly twice as long to create the list plot from x-y pairs versus just y-values. I have some data sets with 200,000 points and for these generating a list plot from {x,y} pairs takes between 10-20 seconds.


title: Tell ParallelMap[] to use just specific kernels

text: Is there a way to tell `ParallelMap` to use just some specific kernels (as is possible for `ParallelEvaluate`)? **Background:** I have 6 local and 16 remote kernels. During some analysis I call `ParalleMap` twice. One `ParallelMap` is quicker using all the kernels, but one is actually slower (probably bandwidth limited). This is why I would like to run one `ParallelMap` on all the kernels and the other only on the local kernels. I don't want to close the kernels in between if possible. I also tried setting the parallelization method to `"CoarsestGrained"` or `"FinestGrained"`, but that didn't help much. **Edit:** Could somebody shed light on why the following does not work?               num = 10;     list = Range[num];     function = Labeled[Framed[#], $KernelID] &;     ParallelMap[function, list]     aKer = Kernels[];     Block[{Parallel`Protected`$kernels = aKer[[{2, 3}]]},        ParallelMap[function, list]     ]      ![Mathematica graphics](http://i.stack.imgur.com/M9OxY.png) The second map is still run on 4 of the Kernels instead of just two. I traced `ParallelMap` to               Parallel`Developer`ParallelDispatch[Parallel`Combine`Private`cmdl]      and               Parallel`Developer`ParallelDispatch[Parallel`Parallel`Private`cmds_] :=         Parallel`Developer`ParallelDispatch[Parallel`Parallel`Private`cmds,Kernels[]]     Kernels[]:=Parallel`Protected`$kernels      so overriding `Parallel`Protected`$kernels` should in theory work.


title: Why only up to two \[Prime] superscripts are interpreted as derivatives?

text: I noticed that only up to two `\[Prime]` superscripts are interpreted as derivatives. Is there a reason for this restriction? Is it documented?               \!\(\*SuperscriptBox["Sin","\[Prime]"][x]\)     (* Cos[x] *)          \!\(\*SuperscriptBox["Sin","\[Prime]\[Prime]"][x]\)     (* -Sin[x] *)          \!\(\*SuperscriptBox["Sin","\[Prime]\[Prime]\[Prime]"][x]\)     (* (Sin^\[Prime]\[Prime]\[Prime])[x] *)      * * * ![Screenshot](http://i.stack.imgur.com/pOSgF.png) * * * The regular apostrophe can be used any number of times though:               Sin'''[x]     (* -Cos[x] *)


title: How can I add arbitrary code into DefaultKeyTranslations.tr?

text: The solution to this question on how to get latex code for a text cell (which Mathematica doesn't do correctly) was formulated as a palette but I need it as a keyboard shortcut. How can I add an item to DefaultKeytranslations.tr that executes this solution's code? And in general, how does one construct a key command that executes arbitrary code, not just front-end packets and tokens?


title: Triple series - evaluation delayed

text: Trying to figure out if the infinite triple series has a nice closed form. It seems _Mathematica_   is unable to help us here. Numerically, things remain the same, no response. Could you help?               N[ Sum[ n! k! m!/(n + k + m + 2)!, {n, 0, ∞}, {k, 0, ∞}, {m, 0, ∞}]]      **EDIT** : in 2 variables, the double series evaluates to $\pi^2/6$.


title: Anti-aliasing with the multiple-object form of Polygon?

text: Observe:               rand = RandomReal[1, {4, 3, 2}];          Graphics @ Polygon @ rand      ![Mathematica graphics](http://i.stack.imgur.com/dZ1JA.png)               Graphics[Polygon /@ rand]      ![Mathematica graphics](http://i.stack.imgur.com/HIizb.png) I am losing anti-aliasing when I use the multiple-polygon syntax form of `Polygon`. Yet it is possible for _Mathematica_ to apply AA as can be shown with:               Style[      Graphics @ Polygon @ rand,      Antialiasing -> True     ]      (Incidentally this `Style`-applied AA does not copy with Szabolcs's Image Uploader but the in-Notebook appearance is identical to the second output above.)   * Why am I losing anti-aliasing here?   * Is there a system option to turn it on, and with what caveat?


title: Trying to combine an image with a Plot

text: I've got this picture: ![JuliaSet](http://i.stack.imgur.com/NLMXG.png) The image has a resolution of 2001x2001. The left most pixel has an x-value of -2, and the right most pixel has an x-value of 2. Same goes for the y-values. Now I am trying to load this image into _Mathematica_ and get it on the right scale inside a graphics environment. I've tried using inset like this:               julia = Import["http://i.stack.imgur.com/NLMXG.png"];     Graphics[{Blue, Rectangle[{-2, -2}, {2, 2}],          Inset[julia, Center, Center, 4]}, PlotRange -> {{-3, 3}, {-3, 3}},        Axes -> True, AxesStyle -> Orange]      ![](http://i.stack.imgur.com/m2rhH.png) This still gives a little blue border around some sides, giving me the impression that it is not centered properly. Is there a better way to do this?


title: Image Shadow Removal in Mathematica

text: The task is: ![enter image description here](http://i.stack.imgur.com/rSOow.png) **Image shadow removal** is an important topic in image processing. If you feel curious about it, you may take a look **here**, or just google for it **image shadow removal** There are also a few questions on SE around it. For example:   * http://dsp.stackexchange.com/questions/2247/how-can-i-remove-shadows-from-an-image   * http://stackoverflow.com/questions/9081930/how-to-remove-the-shadow-in-image-by-using-opencv However, I did not find any Mma implementations out there, and I don't want to reinvent the wheel if it is already rolling. Does anybody know of some Mma codebase for using it as a starter? Note: I have to do this for a few images, so I may go the manual way better than spend many hours in developing a full blown algorithm.


title: Overlay Rectangle on a ListPlot

text: I have a ListPlot of 100 data points in the range of 0 and 1. Now I'm trying to find a way to overlay (four) rectangles onto the listplot in 0.25 steps horizontally. Essentially I just have BinLists and try to visualize the Bins on the ListPlot with rectangles. I drew a nice little picture with paint (since I can't draw it in mathematica yet :)) which hopefully makes it a little more clearer..I only drew three rectangles.. ![enter image description here](http://i.stack.imgur.com/XSqXE.png) It seems somehow complicated to me and I don't get it to work (except with paint ^^), can someone help me out?


title: Fix Parameters for NonLinearModelFit?

text: Is it possible to fix the parameters for `NonLinearModelFit` within the function itself instead of defining the fix parameters at the beginning of the notebook? I am fitting multiple sets of data with the same function and certain parameters go to zero in some of the data sets. Fixing them to zero inside the function would be a lot easier than constantly changing which parameters are being used to fit the data.


title: Finding all maxima and minima of a function

text: To find all (global and local) extrema of a function in R3 I have written: Example-function               n = 2.;          terrain[x_, y_] :=  2 (2 - x)^2 Exp[-(x^2) - (y + 1)^2] -        15 (x/5 - x^3 - y^3) Exp[-x^2 - y^2] - 1/3 Exp[-(x + 1)^2 - y^2];          fun = terrain[x, y];          plot = Plot3D[fun, {x, -n, n}, {y, -n, n}, PlotRange -> All, ColorFunction -> "DarkTerrain", Mesh -> False, PlotStyle -> Opacity@0.7]      ![enter image description here](http://i.stack.imgur.com/Xw8LZ.jpg) One can observe 3 maxima and 3 minima.               NMaximize[fun, {x, y}]      > {6.4547, {x -> -0.3593, y -> -0.5519}} And               FindMaximum[fun, {x, y}]      > {6.1972, {x -> -0.0529, y -> 1.2130}} return two of the maxima but miss the third. My idea then was to map `NMaximize`over "sufficient sectors" of the function:                p = Flatten /@ Tuples[Partition[Range[-n, n], 2, 1], 2]      > {{-2., -1., -2., -1.}, {-2., -1., -1., 0.}, ... , {1., 2., 1., 2.}} (This algorithm was kindly provided by Kuba) The next steps are:               max1 = NMaximize[{fun, p[[#, 1]] <= x <= p[[#, 2]], p[[#, 3]] <= y <= p[[#, 4]]}, {x, y}] & /@ Range@Length@p;     max2 = Chop@Partition[Cases[max1, _Real, Infinity], 3];      The result contains wrong points at the edges of the sectors which can be deleted with               filter = # || (# /. b -> c) &[Or @@ MapThread[Equal, {Table[b, {n*2 + 1}], Range[-n, n]}]]      > b == -2. || b == -1. || b == 0. || b == 1. || b == 2. || c == -2. ||   >  c == -1. || c == 0. || c == 1. || c == 2.               max3 = DeleteCases[max2, {_, b_, c_} /; Evaluate@filter]      > {{6.45471, -0.359311, -0.551929}, {6.19724, -0.0529807, 1.21301}, {5.4426, > 1.26211, -0.0152309}} now gives us the three maxima.               maxpoints = Graphics3D[{PointSize@0.05, Point /@ RotateLeft /@ max3}]      Repeating max1 through max3 with NMinimize finally gives this image: ![enter image description here](http://i.stack.imgur.com/fvtco.jpg) Summing - up:               extrema[foo_, maxmin_, color_] :=      Module[{res},       res = maxmin[{foo, p[[#, 1]] <= x <= p[[#, 2]],             p[[#, 3]] <= y <= p[[#, 4]]}, {x, y}] & /@ Range@Length@p;       res = Chop@Partition[Cases[res, _Real, Infinity], 3];       res = DeleteCases[res, {a_, b_, c_} /; Evaluate@filter];       Graphics3D[{color, PointSize@0.05, Point /@ RotateLeft /@ res}]]          Show[plot, extrema[fun, NMaximize, Black],       extrema[fun, NMinimize, Red], ViewPoint -> {0, 0, Infinity}]      Although my approach works, it is pretty slow (more than 2 seconds to find the extrema), and, having found it only by trial and error, I am not sure if this solution is general enough. I would welcome any comments how to improve on this.


title: Can Mathematica automatically take advantage of the GPU on the new Mac Pro?

text: I'm upgrading my Mac to one of the new Mac Pro R2D2 Darth Vader models that have just been released. They come standard with twin AMD FirePro D300 cards, or twin D500 cards. I don't need that much graphics processing power, and since I understand the D500 puts out a lot more heat than the D300, and I really don't like fan noise ... I was going to go for the D300s. However, Apple's Mac Pro blurb says: > The FirePro D500 supports fast double-precision computations, executing at > one-quarter the performance of single-precision floating point rather than > the 1/16 performance seen in the D300 and most consumer GPUs And this got me wondering: If GPUs support double precision numerics, is it possible currently (or in the works??) for _Mathematica_ to AUTOMATICALLY take advantage of the massive teraflop GPU power for numerical computations? I don't want to have to specially load CUDALink libraries or to write special code or to specially load OpenCL functions … I just want to use standard _Mathematica_ functions. In brief: Can _Mathematica_ automatically take advantage of the new Mac Pro GPU for numerical calculations? If not, I think I'll stick with the quieter, cooler D300 GPU, … and max something else out! * * * Addendum: Apple's new Autovectorizer in OSX Mavericks https://developer.apple.com/library/mac/documentation/Performance/Conceptual/OpenCL_MacProgGuide/AutoVectorizer/AutoVectorizer.html#//apple_ref/doc/uid/TP40008312-CH7-SW1 > Using OpenCL is easier than ever as of OS X v10.7: The autovectorizer allows > you to write one kernel that runs efficiently on both a CPU and a GPU. You > can invoke the autovectorizer regardless of whether you are compiling from > Xcode or building the kernels at runtime.


title: How to control format options of an exported animation?

text: My woes with Mathematica animations exported in SWF-format continue. The goal is to Export an animation in SWF-format, and also make it scalable, so that when I embed it into a slide set (produced by LaTeX) in PDF-format, the animation will resize when I zoom in/out. I have asked a related question on TeX.SE, where a solution via converting the animation into an MP4-file was suggested. That solution works, but lossy compression (or something) makes the end result look passable but not nearly as good as the same animation in a Mathematica notebook. Following the further discussion in TeX.SE I looked at the header of the generated SWF-file with a text editor (NotePad). Indeed, there reads `scaleMode - noScale`. So time to study Mathematica's help files. Promising sounding options are listed in `ref/format/SWF`. Most notably _Scalable_ and _ControlAppearance_ (kind of pointless to have those unclickable control buttons in the end product). So let's try...               roll[u_] := Show[       {ParametricPlot[{Cos[t] + u, Sin[t] + 1}, {t, 0, 2 Pi},          AspectRatio -> Automatic, AxesOrigin -> {0, 0},          Ticks -> {{0, 2 Pi, 4 Pi, 6 Pi}, {}}],        ParametricPlot[{u, 1} - t {Sin[u], Cos[u]}, {t, 0, 1}],        ParametricPlot[{t - Sin[t], 1 - Cos[t]}, {t, -0.6, u}],        Graphics[{PointSize[0.02], Point[{u - Sin[u], 1 - Cos[u]}]}]},        PlotRange -> {{-1.2, 20}, {-0.2, 4.2}}, Axes -> True]          sykloidi = Animate[roll[u], {u, 0, 20}]          Export["Analyysi I/2013/kalvot12-13/sykloidi.swf", sykloidi,       AnimationDuration -> 6, FrameRate -> 8, Scalable -> True,       ControlAppearance -> None]      Nope. No change. The .swf still does not scale. In the header of the SWF-file it still reads `scaleMode - noScale`, and the control buttons didn't disappear either. > Did I use wrong syntax for `Export` in the above snippet? What's the right > way of doing this?


title: Can't find where to download VEST package for Mathematica

text: In the Internet I have found the article about the VEST package for abstract vector calculus simplification in Mathematica. http://arxiv.org/abs/1309.2561 However, I can not find any reference for downloading this package. Does anybody know where I can download this package?


title: Why does Dynamic for PlotRange in ListLinePlot prevent the proper range from being used?

text: I am using `Manipulate` to simulate Brownian motion. I want to be able to zoom in. Thus, I want to use `Dynamic` for the `PlotRange` option so that this can be done quickly without recomputing the motion. It works properly without `Dynamic` (except for speed), but using `Dynamic` changes its operation so that the range is no longer what I ask for once I zoom in sufficiently. See this by changing the "horizontal zoom". I also have the same `PlotRange` in Show. It seems I need both. No doubt I am not doing other things optimally, but this issue is a separate problem. Here is my code, first without the first `Dynamic` and second with it. At the end is a smaller example. It behaves differently, but again the behavior depends on whether PlotRange has Dynamic or not. This last example contains both types of code in it. It comes in two forms, one using Show and one not.               Manipulate[     Module[{bmPath, iterate}, SeedRandom[seed];      iterate[l_List] :=      Module[{i = 1, len = Length[l], new = l},      While[i < Length[new],       new = Insert[        new, (new[[i]] + new[[i + 1]])/2 +          RandomVariate[NormalDistribution[0, .5/Sqrt[(len - 1)]]],         i + 1]; i = i + 2]; new];      bmPath = {0, RandomVariate[NormalDistribution[0, 1]]};      Do[bmPath = iterate[bmPath], {n}];      Show[ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},      DataRange -> {0, 1},      PlotRange -> {Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0,          1}], vcenter + {-2, 2}/2^(scale/2)}],      Plot[{Sqrt[x], -Sqrt[x]}, {x, 0, 1},      PlotStyle -> If[bound, Dotted, Opacity[0]]],      PlotRange ->      Dynamic[{Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0, 1}],        vcenter + {-2, 2}/2^(scale/2)}],      AxesOrigin -> Dynamic[{hcenter, vcenter}],      ImageSize -> {475, 360}]],     {{n, 10, "detail"}, 1, 40, 1, Appearance -> {"Labeled", "Open"},      AnimationRate -> rate}, {{rate, 1, "rate"}, 1, 3, 1,      Appearance -> "Labeled"}, {{bound, False,      "show sqrt bounds"}, {True, False}}, Delimiter, {{hcenter, .5,      "horizontal center"}, 0, 1, .01/2^(zoom - 1),      Appearance -> {"Labeled", "Open"},      AnimationRate -> .2/2^(zoom - 1)}, {{vcenter, 0,      "vertical center"}, -3, 3, .01/2^(scale - 1),      Appearance -> {"Labeled", "Open"},      AnimationRate -> .1/2^(scale - 1)}, Delimiter, {{zoom, 1,      "horizontal zoom"}, 1, 20, 1,      Appearance -> {"Labeled", "Open"}}, {{scale, 1,      "vertical scale"}, -2, 20, 1,      Appearance -> {"Labeled", "Open"}}, Delimiter, {{seed, 77777,      "new random case"}, 10000, 999999, 1, Appearance -> "Open",      AnimationRate -> newrate}, {{newrate, 1, "rate of new case"}, 1, 10,     1, Appearance -> "Labeled"},     ControlPlacement -> Right, SynchronousUpdating -> False]               Manipulate[     Module[{bmPath, iterate}, SeedRandom[seed];      iterate[l_List] :=      Module[{i = 1, len = Length[l], new = l},      While[i < Length[new],       new = Insert[        new, (new[[i]] + new[[i + 1]])/2 +          RandomVariate[NormalDistribution[0, .5/Sqrt[(len - 1)]]],         i + 1]; i = i + 2]; new];      bmPath = {0, RandomVariate[NormalDistribution[0, 1]]};      Do[bmPath = iterate[bmPath], {n}];      Show[ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},      DataRange -> {0, 1},      PlotRange -> Dynamic[{Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0,          1}], vcenter + {-2, 2}/2^(scale/2)}]],      Plot[{Sqrt[x], -Sqrt[x]}, {x, 0, 1},      PlotStyle -> If[bound, Dotted, Opacity[0]]],      PlotRange ->      Dynamic[{Clip[{hcenter - 2^(-zoom), hcenter + 2^(-zoom)}, {0, 1}],        vcenter + {-2, 2}/2^(scale/2)}],      AxesOrigin -> Dynamic[{hcenter, vcenter}],      ImageSize -> {475, 360}]],     {{n, 10, "detail"}, 1, 40, 1, Appearance -> {"Labeled", "Open"},      AnimationRate -> rate}, {{rate, 1, "rate"}, 1, 3, 1,      Appearance -> "Labeled"}, {{bound, False,      "show sqrt bounds"}, {True, False}}, Delimiter, {{hcenter, .5,      "horizontal center"}, 0, 1, .01/2^(zoom - 1),      Appearance -> {"Labeled", "Open"},      AnimationRate -> .2/2^(zoom - 1)}, {{vcenter, 0,      "vertical center"}, -3, 3, .01/2^(scale - 1),      Appearance -> {"Labeled", "Open"},      AnimationRate -> .1/2^(scale - 1)}, Delimiter, {{zoom, 1,      "horizontal zoom"}, 1, 20, 1,      Appearance -> {"Labeled", "Open"}}, {{scale, 1,      "vertical scale"}, -2, 20, 1,      Appearance -> {"Labeled", "Open"}}, Delimiter, {{seed, 77777,      "new random case"}, 10000, 999999, 1, Appearance -> "Open",      AnimationRate -> newrate}, {{newrate, 1, "rate of new case"}, 1, 10,     1, Appearance -> "Labeled"},     ControlPlacement -> Right, SynchronousUpdating -> False]               Manipulate[     Module[{bmPath}, bmPath = {0, 2, 1};      Row[{ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},       DataRange -> {0, 1},       PlotRange ->        Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2,           2}}], ImageSize -> {200, 100}],      ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},       DataRange -> {0, 1},       PlotRange -> {Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0,           1}], {-2, 2}}, ImageSize -> {200, 100}]}]],     {{zoom, 1, "horizontal zoom"}, 1, 20, 1,      Appearance -> {"Labeled", "Open"}},     ControlPlacement -> Right, SynchronousUpdating -> True]               Manipulate[     Module[{bmPath}, bmPath = {0, 2, 1};      Row[{ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},       DataRange -> {0, 1},       PlotRange ->        Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2,           2}}], ImageSize -> {200, 100}],      Show[ListLinePlot[bmPath, AxesLabel -> {"Time", "Location"},        DataRange -> {0, 1}],       PlotRange ->        Dynamic[{Clip[{.5 - 2^(-zoom), .5 + 2^(-zoom)}, {0, 1}], {-2,           2}}], ImageSize -> {200, 100}]}]],     {{zoom, 1, "horizontal zoom"}, 1, 20, 1,      Appearance -> {"Labeled", "Open"}},     ControlPlacement -> Right, SynchronousUpdating -> True]


title: Plotting a function dependent on $x/d$

text: I have a problem in plotting a function. The example code is as following:               d = 0.1;     M[x_] := ((x/d) - 0.4);     Plot[p[x], {x, 0, 10}, Ticks -> {{0, d, 2d, 3d}, {1, 1}}]       I would like to have $d,\ 2d,\ 3d$ and so on the x-axis label at right positions, i.e. at $0.1,\ 0.2$ and so on. How can I achieve this?


title: Deformed style when exporting eps files

text: I want to export a plot into an eps file. Below I present a sample plot code in order to demonstrate the two issues that appear. (1). `LabelStyle`: When I use "Times" or "Helvetica" style all seem to work fine. However, when I choose "Traditional" or "Tahoma" the style of the labels in the exported eps file is horribly deformed. This happens regardless the procedure I use; using the `Export` command or choosing the plot and then form `File -> Save Selection As ...` (2). Capital Greek letters: I use the capital Greek letter `Theta` for the label of the y-axis. However, I discovered that many capital Greek letters are also deformed in the exported eps or pdf file. Many thanks in advance and I look forward for your replies and comments               S1 = Plot[Exp[-x]*Sin[7*x], {x, 0, 5}, Axes -> False, Frame -> True,       FrameLabel -> {"x", "Θ(x)"}, RotateLabel -> False, PlotStyle -> Red,       LabelStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"],       PlotRange -> All, ImageSize -> 500]           Export["Plot.eps", S1]      * * * Thank you very much for all your replies and I am really very sorry for not responding sooner. I am using the latest version 9.0 of Mathematica in Windows XP SP3. However, the same issues appear in older versions (8,7, ... , 4) which are also installed in my PC. Therefore, I suppose that the version is irrelevant. Below I present three exports using different format (eps, pdf and jpg). I used "Tahoma" style. First the .jpg output. All seems to be OK. ![enter image description here](http://i.stack.imgur.com/k4gh5.jpg) Then the .pdf output. Well, the Greek capital letter Theta is deformed. ![enter image description here](http://i.stack.imgur.com/zLfGE.png) And finally, the .eps output loaded in GSView 5.0. Here, not only the Greek letter but also the axis labels are deformed. However, if I convert the exported .eps file to .pdf with Adobe the axis labels are becoming normal as Fig. 2 but still the Greek letter is deformed. ![enter image description here](http://i.stack.imgur.com/3RHyC.png) If I am correct, I encounter an issue regarding fonts. So, I would be very grateful if you could suggest me some solutions to my problem.


title: How could I generate words starting with P,h,D?

text: A friend of mine is a PhD candidate and posted a picture on Facebook with funny words starting with 'p', 'h' and 'd' like "Please hire. Desperate" or "Permanent head Damage". I thought I could try and programmatically generate some word combinations with Mathematica. Here is my version. Most of the results are meaningless, but occasionally a good combination will show up like "panegyric happiness date".   1. Could it be improved (i.e. increase its signal/noise ratio)?   2. Could the following construct be condensed `{"." -> "", ";" -> "", "," -> "", ... -> ""`? Schematically: `{".", ";", ","} - >""`   3. The reason I used `StringMatchQ` with `Map[]` is because I didn't know how to group the results based on the first letter of the words, e.g. {please, hire, permanent, damage, head, desperate} -> {{please, permanent}, {hire, head}, {damage, desperate}}`. Also, I used words from `DictionaryLookup[]`, picking those with the most meanings (to increase the likelihood of a meaningful combination), but the results were worse. Here is my code:               ClearAll["Global`*"];          allWords =        ExampleData[{"Text", "PrideAndPrejudice"}, "Words"] // DeleteDuplicates;          phdWords = Pick[          allWords,          StringMatchQ[allWords, #]] & /@ {"p" ~~ __, "h" ~~ __, "d" ~~ __};          phdWords =       StringReplace[#,          {"." -> "", ";" -> "", "," -> "", "!" -> "", "?" -> "",            "\"" -> ""}] & /@ phdWords;          filterWordsByPart[wordList_, part_] :=       Select[        wordList,        MemberQ[          WordData[#, "PartsOfSpeech"], part] &];          finalWords = MapThread[        filterWordsByPart,        {phdWords, {"Adjective", "Noun", "Noun"}}];          Table[       Flatten@(RandomSample[#, 1] & /@ finalWords),       {20}] // Grid[#, Frame -> All] &      And this is a sample output: ![enter image description here](http://i.stack.imgur.com/EAVBP.png)


title: Group theory - symmetry inequivalent sqaure matrices with PBC

text: I would like to obtain the symmetry inequivalent possible occupations of indistinguishable objects in a square lattice with periodic boundary conditions. Examples:   * 1 object in a 4 by 4 square lattice has 16 **equivalent** positions -> **1 inequivalent position**.   * 2 objects in a 3 by 3 square lattice has 2 **inequivalent** positions.              000    000     000    010     110    100        * 2 objects in a 4 by 4 square lattice has 5 **inequivalent** positions.              0000    0000    0000    0000    0000     0000    0000    0000    0000    0010     0000    0000    0100    0010    0000     1100    1010    1000    1000    1000      ![Some equivalent positions in a 4x4 square lattice](http://i.stack.imgur.com/24MM6.jpg) I can search for the inequivalent positions with a bruteforce approach by applying all possible symmetries to all possible initial configurations of 1 or 2, 3 objects and so on. Anyway, I was wondering if there is a way to do this with group theory in Mathematica. I tried starting from this SO question but I didn't manage to get translations working. Thanks in advances.


title: problem with coloring spherical harmonics

text: I want to color a spherical harmonics. So I write as follows.               color[θ_, φ_] :=        RGBColor[(Sign[Re[SphericalHarmonicY[2, 1, θ, φ]]] + 1)/2, 0,                 (-Sign[Re[SphericalHarmonicY[2, 1, θ, φ]]] + 1)/2 ];     SphericalPlot3D[ Re[SphericalHarmonicY[2, 1, θ, φ]], { θ, 0, Pi}, {φ, 0, 2 Pi},                       ColorFunction -> Function[{x, y, z, θ, φ, r}, color[ θ, φ]]]      I expect that the output plot should show the parity of the spherical harmonics with red corresponding to the positive part and blue corresponding to the negative part. But the actual result is all Blue! ![spherical harmonic](http://i.stack.imgur.com/2kUi8.gif)


title: Slice through Graphics3D

text: is there any possibility to slice through a Graphics3D object? At the end I would like to have a stack of images slicing , e.g. $n$ times in $z$-direction: $((x,y,z_{0}), (x,y,z_{1}),…,(x,y,z_{n}))$ Here is an example of random spheres, which I would like to slice.               z = 100;     p = RandomReal[100, {z, 3}];     r = RandomReal[10, {z}];     obj = GraphicsComplex[p, Sphere[Range[z], r]];     t0 = AbsoluteTime[];     gr = Graphics3D[obj, Axes -> True]      I would be pleased about any suggestions.


title: Failure to export graphics by right-click when Notebook magnification is changed

text: When I try to export graphics as PNG, JPG and other rasterized formats using the right-click and choosing `Save Graphic As...`, if the notebook magnification is changed from 100%, Mathematica fails to export the image and returns the following Error: "The specified setting for the option WindowSize cannot be used." However this does not happen when `Export` function is used to export the graphic. ![enter image description here](http://i.stack.imgur.com/C5UjW.png) I think this is a bug. I am using _Mathematica_ v9.0.1 installed on Microsoft Windows 7 (64 Bits). **UPDATE** This bug is still present in version 10.0.0.0.


title: 2D Arrangment/Optimization Problem

text: Okay, I have a list of angles, call it A. How would I arrange them in a 2D m-by-n grid G such that the distances between each adjacent angle-element (row- and column-wise) is minimized? G has as many elements as A, or more. I get to pick m and n. Duplicating elements from A is allowed, but every element from A must be used at least once. Toy Example 1:               A = {0, 10, 10, 20, 20, 20, 20, 30, 30}      Put them in a 3x3 array:               G = {      {0,  10,  20},      {10. 20,  30},      {20, 30,  20}     }      Toy Example 2 (list of 5 angles, put them in a 3x2 grid, so have to duplicate 1 element):               A = {0, 350, 10, 20, 30}          G = {      {0,   10, 20},      {350,  0, 30}     }      Hopefully that was clear enough? Let me know if it wasn't....


title: How to use ChoiceDialog or PopupMenu with ClickPane

text: What I am trying to do is modify the standard `ClickPane` example where a list of points (`pts`) is added to with each click, in the following way: when a click occurs, some sort of choice window appears, and the user then clicks on one of the options. This is added as a third element in each point, so that `pts` becomes a list of `{x,y,text}` triples (and incidentally gets displayed on the graphic using `Text[]`). Here's the starting point that includes the triples               pts = {{0, 0, "No ID"}};          DynamicModule[{},       ClickPane[         Dynamic@Framed@Graphics[           Map[Text[#[[3]], #[[{1, 2}]]] &, pts],           PlotRange -> 1,           Axes -> True],         AppendTo[pts, Append[#, "No ID"]] &]]      The simplest thing I tried is to replace the "No ID" with a Choice Dialog               speciesList = {"No ID", "Oak", "Sycamore", "Plane", "Birch",                    "Ginko", "Ash", "Beech", "Cherry", "Maple"};          pts = {{0, 0, "No ID"}};          DynamicModule[{},       ClickPane[         Dynamic@Framed@Graphics[           {Point[pts[[All, {1, 2}]]]},           PlotRange -> 1,           Axes -> True],         AppendTo[pts, Append[#, ChoiceDialog["Pick one", speciesList]]] &]]      This does cause a choice dialog to pop up, but the dynamic evaluation seems to go into a spin and I have to abort. Any thoughts on what is going wrong would be appreciated. What I would really like to do is have a `PopupMenu` appear right there at the click point (because input dialogs appear floating in the middle of the screen, which can be a long way away), but that seems harder...


title: Any efficient way to make complete homogeneous symmetric functions in Mathematica?

text: We do have elementary symmetric functions, `SymmetricPolynomial[k, {x_1, ..., x_n}]` . But I didn't find complete homogeneous symmetric functions. The induction method to compute $h_n$ from $e_i$ and $h_j$ ($j\leq n-1$) is not that efficient. Is there any easier way to do this?


title: Agglomerate output to Graph

text: I'm using the HierarchicalClustering package to cluster some data. So let's say I have this:               Needs["HierarchicalClustering`"]          In[21]:= Agglomerate[{1, 1, 2, 10, 4, 8}, Linkage -> "Single"]          Out[21]= Cluster[Cluster[Cluster[Cluster[1, 1, 0, 1, 1], 2, 1, 2, 1], 4, 4, 3, 1],  Cluster[8, 10, 4, 1, 1], 16, 4, 2]      Is there a direct way to go from that output to an undirected graph structure? The HierarchicalClustering package can create graphs as Dendrograms:               DendrogramPlot[{1, 1, 2, 10, 4, 8}, LeafLabels -> (# &),  Linkage -> "Single"]      But I would like to use the graph functions to work with the data. Maybe I'm doing this wrong and I don't even need the HierarchicalClustering to cluster my data. I would appreciate any ideas. Thanx!


title: Using uniform coloring in MatrixPlot

text: I have a rectangular matrix, which is `m`-by-10. Each element is either 0 or 1. I would like 0 to correspond to white elements, and 1 to red elements. This works fine if `m = 100` or similar small values:               m = 100;     list = Table[Table[RandomInteger[], {j, 1, 10}], {i, 1, m}];     Tally[Flatten[list]]     MatrixPlot[list, FrameTicks -> None, ImageSize -> {300, 300},       ColorRules -> {0 -> White, 1 -> Red}]      ![MP1](http://i.stack.imgur.com/cohTl.gif) However, if I choose `m = 200`, the coloring becomes strange and no longer only white or red:               m = 200;     list = Table[Table[RandomInteger[], {j, 1, 10}], {i, 1, m}];     Tally[Flatten[list]]     MatrixPlot[list, FrameTicks -> None, ImageSize -> {300, 300},       ColorRules -> {0 -> White, 1 -> Red}]      ![MP2](http://i.stack.imgur.com/Fqtji.gif) Why do I see orange if each element is either 0 or 1? Is there any way I can correct this so that the only colors that appear are white or red? Setting `ColorFunctionScaling -> False` does not seem to correct the problem: ![MP3](http://i.stack.imgur.com/Cnixq.gif)


title: How to add a barlegend to a listlineplot?

text: I'm trying to add a color bar legend to a ListLinePlot with multiple lists. With 20+ lists a normal Legend gets long and bulky. Basically, each list line is associated with a different value. I've created a color gradient for the lines using the Hue function but cannot figure out how to get BarLegend to work with ListLinePlot. I've included a sample of the plot I have so far. It would be a much cleaner presentation with a colorbar for the legend. How do I do this, in an elegant way? I'd even settle for a non-elegant method right now. ![example of what I have](http://i.stack.imgur.com/5Nooe.jpg)


title: Drawing tubes with a While loop

text: I'm trying to make a plot with many objects in it using a `While` loop. Something like the following:               Graphics3D[       While[ϕforwhile < Pi/3,          {Lighter[Blue, .1],             {Tube[               Table[                 u*{Sin[Pi/2]*Cos[ϕforwhile], Sin[Pi/2]*Sin[ϕforwhile], Cos[Pi/2]},                 {u, 0, 1, 1/10}],               .005]}};         ϕforwhile = ϕforwhile + Pi/12;]]      Does anyone know how to make this work?


title: How do I pull from a data list for parameter values in a system of ODEs and then solve and plot?

text: I have a parameter set list and I would like to solve a system of ODEs multiple times using each parameter set in the list. Then I would like each set of solutions to be graphed on the same plot. For example: I have imported this list of parameter sets:               {{ "a", "b", "c", "d"}, {1, 5, 1, 3}, {2, 3, 2, 2}, {3, 3, 3, 1}}      Then I have this system               system={x'[t] == a*x[t] + b*y[t], y'[t] == c*x[t] + d*y[t], x[0] == 10, y[0] == 0};      I would like to substitute each parameter set in for a,b,c,d respectively, then solve using               sol = DSolve[system, {x[t], y[t]}, {t}]       for each parameter set (or NDSolve, ParametricNDSolve if appropriate) Then I would like all sets of solutions to be plotted on the same graph               Plot[{x[t] /. sol, y[t] /. sol}, {t, 0, 7}, PlotRange -> Automatic].      Note, I would like to use this example to understand the process and apply it to a larger system with more parameters and a larger list of sets of parameters.


title: Image Processing: Using AdjacentBorders with SelectComponents

text: I've been doing some image processing and have been having trouble with the `AdjacentBorder` command. I've got an image in which I have several elements that are on the borders, and I was able to use `ComponentMeasurements[image,"AdjacentBorders"]` to obtain the list of what borders these elements touch. However, when I go to use `SelectComponents`, I'm unable to select the elements that are just on one border. Is this possible, or can I only select the components that are bordering a certain amount of borders? This is the image I started with this image ![](http://i.imgur.com/AC0bvkG.png) and the code I've used since.               j := Import@"http://i.imgur.com/AC0bvkG.png"     k := Binarize[j, FindThreshold[j]]     l := SelectComponents[k, "FilledCircularity", -7]     m := ImageCrop[l]     ComponentMeasurements[m, "AdjacentBorders"]      > >     {1 -> {Top}, 2 -> {Right}, 3 -> {Left}, 4 -> {Left}, 5 -> {Right}, >      6 -> {Bottom, Right}, 7 -> {Left, Bottom}} >   I used `ComponentMeasurements` to ensure that I did have points on the borders, which I did.


title: How to combine a plot with an image

text: I have an external data file data which contains the position of stars of a galaxy simulations and it looks like this               data = Import["NGC_1566.out", "Table"];     L0 = ListPlot[data, Frame -> True, Axes -> False,           PlotStyle -> {Darker[Green], PointSize[0.001]},           PlotRange -> {{-60, 60}, {-60, 60}}, AspectRatio -> 1]      ![enter image description here](http://i.stack.imgur.com/KffdP.jpg) and here is a real image of the NGC 1566 ![enter image description here](http://i.stack.imgur.com/3WFIL.jpg) Now I would like to plot and fit my data on top of the real image. Any suggestions?


title: How can I regroup elements in a list into a tree based on their values?

text: I have a list of elements in an outline, here is an example that is only 3 levels deep:               {         {{"1"},"Setup code"},         {{"1","1"},"Local variables"},         {{"1","2"},"Option variables"},         {{"1","3"},"Check for null Input"},         {{"2"},"Argument Logic"},         {{"2","1"},"X Spec"},         {{"2","2"},"One Dimensional Case"},         {{"2","2","1"},"Tick and Label Generation"},         {{"2","2","2"},"plot generation"},         {{"2","2","3"},"bin names generation"},         {{"2","2","4"},"bar chart generation"},         {{"2","3"},"Y Spec"}     }      And I'd like to transform it into a list of trees of the form {parentNode, {childNode1, childNode2, ...}}, and the nodes themselves are are like {{"1","2",...}, "label"}. For example, the above would become:               answer = {     {         {{"1"},"Setup code"},         {             {{"1","1"},"Local variables"},             {{"1","2"},"Option variables"},             {{"1","3"},"Check for null Input"}         }     },          {         {{"2"},"Argument Logic"},         {             {{"2","1"},"X Spec"},             {                  {{"2","2"},"One Dimensional Case"},                  {                       {{"2","2","1"},"Tick and Label Generation"},                       {{"2","2","2"},"plot generation"},                       {{"2","2","3"},"bin names generation"},                       {{"2","2","4"},"bar chart generation"}                  }             },             {{"2","3"},"Y Spec"}         }     }          }      The reason being that once it is in this form, OpenerView[] could be used to make an interactive collapsable outline, for instance:               ToOutline[l_List] :=        Panel @ Grid[          Partition[           Panel /@ ToOutline1 /@ l //. {x_, list_List} :>              ToOutline1[{x, list}], 4, 4, 1, {}],           Alignment -> Top] /. {n : {__String}, s_String} :>          Row[{StringJoin @ Riffle[n, "."] , "  ", s}];     ToOutline1[{x_, list_List}] :=       OpenerView[{x, Column[Panel /@ list]}, True]     ToOutline[answer]      generates ![enter image description here](http://i.stack.imgur.com/XYhLQ.png) ## Motivation This questions helps solve the problem of extracting comments from a file in Wolfram Workbench of the form `(* tag:1:2:2:3... text... *)`. So for example if I had commented my function MyFun with a comment like `(* MyFun:1:... text... *)`, I could extract them as follows:               CommentsToOutlineElements[filePath_, ID_] := Module[{allComments, commentsIDs, IDs, commentsStrings},         allComments = Cases[Import[filePath, "Comments"], _?(!StringFreeQ[#, ID]&)]         commentsIDs = StringSplit[#1, Whitespace][[1]]& /@ allComments;         commentsStrings = StringCases[#1, Shortest[s__]~~Whitespace~~Longest[c__] :> c][[1]]& /@ allComments;         IDs = Rest[StringSplit[#,":"]]& /@ commentsIDs;         Transpose @ {IDs, commentsStrings}     ]     CommentsToOutlineElements["User/...", "MyFun"]      And then generate a nice outline of the function, as per this question.


title: Using Refresh to skip expensive computations

text: I have several variables in my `DynamicModule` and some parts of my computation depend only on subset of them. I am trying to use Refresh to "cache" values but can't make it work. Example of the problem:               verySlowFunction[x_] := Module[{}, Print["SLOW"]; x * x];          DynamicModule[      {a = 1, b = 1},      Dynamic[       Module[        { x = Refresh[verySlowFunction[a], TrackedSymbols :> {a}] },        Column[{          Slider[Dynamic[a]],          Slider[Dynamic[b]],          {a, b , x + x + b}           }]]]]      I expect "SLOW" to be printed only when I drag "a" slider, but it is printed when I'm dragging "b" slider as well. I know that Dynamic clones whole expression tree on its evaluation, that's why `x` is always different, but this one doesn't work as well:               Module[      {x},      DynamicModule[       {a = 1, b = 1},       Dynamic[         x = Refresh[verySlowFunction[a], TrackedSymbols :> {a}] ;        Column[{          Slider[Dynamic[a]],          Slider[Dynamic[b]],          {a, b , x + x + b}           }]]]]


title: How could I obtain real numbers for the following integration instead of imaginary ones?

text: As shown in the following codes,               lamda1 = 1.875; L = 0.2; bL = 0.015; hL = 0.005; rouL = 2550; mL = rouL*bL*hL*L; roL =     mL/L; gama1 = (Cosh[lamda1] + Cos[lamda1])/(Sinh[lamda1] + Sin[lamda1]);      phi1 = Cosh[lamda1*(x/L)] - Cos[lamda1*(x/L)] - gama1*(Sinh[lamda1*(x/L)] - Sin[lamda1*     (x/L)]);      fe1 = Cosh[lamda1*(sigmma/L)] - Cos[lamda1*(sigmma/L)] - gama1*(Sinh[lamda1*(sigmma/L)] -     Sin[lamda1*(sigmma/L)]); z1 = D[fe1, sigmma]; z21 = z1^2;      fec1 = -0.5*Integrate[z21, {sigmma, 0, x}]; ux = fec1*q4[t]^2; uy = phi1*q4[t]; uf =      {{ux}, {uy}}; AL = {{Cos[q3[t]], -Sin[q3[t]]}, {Sin[q3[t]], Cos[q3[t]]}}; r0 = {{q1[t]},     {q2[t]}};      u0 = {{x}, {0}}; RL = r0 + AL . (u0 + uf); REy = Take[RL /. x -> L, -1]; vRL = D[RL, t];     Print["vRL=", MatrixForm[vRL]]; intTL = ExpandAll[Transpose[vRL] . vRL]; Print["intTL=",     intTL];      FullSimplify[Re[Integrate[intTL, {x, 0, L}]], Assumptions -> Element[{q1[t], q2[t],      q3[t], q4[t], Derivative[1][q1][t], Derivative[1][q2][t], Derivative[1][q3][t],          Derivative[1][q4][t]}, Reals]]      How could I get real numbers instead of imaginary ones?


title: Edge finite elements in Mathematica

text: I am wondering if it's possible to extend the Finite Element capabilities of Mathematica so as to include other types of elements such as edge vector elements (Nedelec) which can be used in electromagnetic problems. If possible, how would one proceed?


title: Solving a differential Equation

text: I am trying to solve               -D[((α + γ/2)*a + β/(2*a) - R*a^3)*p[a], a] + 0.5*D[(γ*a^2 + β)*p[a], {a, 2}] == 0      with `DSolve`, but it does not work. If I let `R = 0`, then I am able to obtain an explicit solution for `p[a]`.               DSolve[         -(-3 a^2 R + α - β/(2 a^2) + γ/2) p[a] -          (-a^3 R + β/(2 a) + a (α + γ/2)) Derivative[1][p][a] +          0.5 (2 γ p[a] + 4 a γ Derivative[1][p][a] + (β + a^2 γ) (p^′′)[a]) == 0,        p[a], a]      Can someone kindly help me on this.


title: Prevent graphics render inside held expression

text: Assuming each odd line is input I would like the even lines to be the output of the following lines. ![enter image description here](http://i.stack.imgur.com/WZx4t.png) In the above the `Graphics` are inside `Hold`/`HoldForm` therefore IMO it doesn't make sense to have Mathematica try and render such expressions. For example `Hold[Graphics[{Red, Circle[]}]]` throws an error because built in colors don't get replaced. How might I prevent `Graphics` from being rendered and instead print the Graphics code? The following code works at reassigning Graphics inside Hold/HoldForm, but it prints something like `Graphics[{Circle[{0, 0}]}]` without the `HoldForm`/`Hold`.               Unprotect[Graphics]     Graphics /: HoldForm[Graphics[x___]] := (        InputForm[Graphics[x]]        );     Graphics /: Hold[Graphics[x___]] := (        InputForm[Graphics[x]]        );      Ideally the code should be generalize to work with irregular constructs like `HoldForm["a",Graphics[{Circle[{0, 0}]}]]`. More importantly how might you insure `HoldComplete` doesn't render Graphics either. As rm-rf pointed out the Villegas–Gayley trick will likely be needed. * * * Simplifying John Fultz's answer slightly, you get the following:               Map[      (        Unprotect[#];        # /: MakeBoxes[#[expr_], fmt : StandardForm | TraditionalForm] :=          Block[{Graphics, Graphics3D},          RowBox[{ToString[#], "[", MakeBoxes[expr, fmt], "]"}]          ];        Protect[#]        ) &, {Hold, HoldForm, HoldComplete}      ]


title: Mathematica outliner's capabilities

text: As my notebooks get larger, I often try to organize them with titles/subtitles etc, structuring them as an outliner (http://en.wikipedia.org/wiki/Outliner) This also helps me as I try to structure a notebook trying to produce an article, see http://reference.wolfram.com/mathematica/tutorial/NotebooksAsDocuments.html Unfortunately, I find that Mathematica's outliner capabilities are not so developed... a major source of irritation is that the markers indicating closed groups are very hard to see, and so small I often click on the wrong bracket level trying to open/close them. For me the ideal way would be a doubleclick on the block header to open/close it. Also, it is not easy at all to take a block and shift it upper or lower in a hierarchy of levels. Do you know if there is a way to enhance M's capabilities in this field? Maybe through some specialized stylesheet? (edit ------) I see by the help you are kindly offering that there is indeed some way to enhance the outliner capabilities - so to rise the bar a bit, knowing that this is a typical outliner feature: do you know a way to ask your notebook to "show everything down to level x" - that is e.g. keep anything under the level Subsection (or Subsubsection, or ...) closed?