Skip to main content

Posts

Showing posts from January, 2015

plotting - ColorFunction and/or ColorScaling issue with ParametricPlot3D

My goal is to use ColorFunction to color a cylinder based on the $z$ value of a separate Plot3D . I'm not sure if I am making a mathematical error somewhere or if I am just messing up some snippet of the following code. a = Pi; b = 2; f[x_, y_] = y; u[x_, y_, t_] = -((8 E^(-((π^2 t)/20)) (2 - π) Cos[(π y)/4])/π^2) - (8 E^(-((π^2 t)/5)) (2 + 3 π) Cos[(3 π y)/4])/(9 π^2) - (8 E^(-((9 π^2 t)/20)) (2 - 5 π) Cos[(5 π y)/4])/(25 π^2); Table[ContourPlot[u[x, y, t], {x, -a, a}, {y, 0, b}, ColorFunction -> ColorData["TemperatureMap"], Contours -> 8], {t, {0, .1, .3, .5, 1, 2, 3, 4}}] Now, I want to wrap each contour plot onto a cylinder by gluing the $x=-a$ edge to the $x=a$ edge; the bottom of the cylinder is then at $y=0$ and the top at $y=b$. Table[ParametricPlot3D[{Cos[theta], Sin[theta], rho}, {theta, -Pi, Pi}, {rho, 0, 2}, AxesLabel -> {x, y, z}, ColorFunctionScaling -> False, ColorFunction -> Function[{x, y, z, theta, rho}, ColorDat...

geography - Loading data from a shapefile

After saving (with QGis) the part of the map I´m interested in for a local visualization, I have the .zip file where you can see 5 files. I load the map in Mathematica with e1 = Import["Estrada.zip"] all works fine. But the problem is... when I want to list the name of every region, I can´t find the names, but I can see LayerNames if I type e2 = Import["Estrada.zip","Elements"] zip file at https://we.tl/t-NqBdMYcOSN (sorry for not attanching to the message, if I must upload the file to another site, please tell me) I´m doing bad anything or is not available the LayerName in this zip file? Answer It does appear that "LayerNames" does not work correctly with Shapefile zips - I would recommend emailing WRI support about this, as I think it's a bug. As a workaround, you can unzip the shapefile zip and import the .shp inside instead of importing the zip file. I uncompressed the zip file locally (just by double-clicking the zip file), and then...

How do I create a package from an existing notebook?

I have a notebook containing some functions, for example: f[x_] := 2*x g[x_] := x^2 Now I would like to convert this notebook to a package, functions.m , which I can call with Get["functions.m"] inside other notebooks, making the functions f[x] and g[x] available. How can I do this without writing the package from scratch? In the File menu there is a sub-menu Save As -> Package, but if I save it, and load it with Get["functions.m"] , nothing seems to happen in the new notebook; i.e., when I try to use the functions, I get: f[x] f[x] I guess there is something else that I need to do besides simply saving the notebook containing the function definitions as a package? Answer When you save a notebook as a package, the only cells that are setup to be evaluated when the package is loaded are Initialization cells. If you change the cell style to the code style, the initialization property is set automatically (this style has the shortcut alt + 8 ) and the cells ar...

webdriver - Capturing the entire webpage with WebExecute's "CapturePage"

It seems that "CapturePage" in WebExecute only captures the currently visible portion of a website: Is there some way to capture the whole image of a WebSessionObject ? Or to print it to PDF?

graphics3d - Polygon mesh: Compute vertex normals for smooth shading

MeshRegion has a "SmoothShading" PlotTheme which automatically computes the VertexNormals to create a nice smooth rendering. For example: reg = BoundaryDiscretizeRegion[Ball[], PlotTheme -> "SmoothShading", PrecisionGoal -> 1, MaxCellMeasure -> 0.1] Suppose that the only data I have available is this: gr = GraphicsComplex[MeshCoordinates[reg], MeshCells[reg, 2]]; It looks like this: Graphics3D[{EdgeForm[None], gr}] Is there built-in functionality which will compute the vertex normals for a mesh like this? I know that I can make a MeshRegion called reg , set "SmoothShading" on it, convert to Graphics3D using Show , then extract the options from the contained GraphicsComplex : Cases[Show[reg], GraphicsComplex[_, _, opt___] :> opt, Infinity] . But this is a hack and probably unreliable. What I am looking for is a built-in and easy way to return the vertex normals in a structured form. I am hoping that this functionality is exposed, I just...

equation solving - Backslide in NSolve in V11.1?

Bug introduced in 11.1.0 and persisting through 11.1.1 In V11.1, NSolve[BesselJ[0, x] == 0 && 0 returns no solutions: But in V11.0 (and earlier), it returns all solutions: Is there anyway to get NSolve to solve this equation in V11.1? (Interestingly, Solve[BesselJ[0, x] == 0 && 0 works in both, but I was particularly interested NSolve , since I was wanting to compare it with other numerical methods.) Answer It is a bug in V11.1. As a workaround, you can put the following in your init.m file. Reduce`RealTNRoots; nonElementaryQ[f_] := Module[{x}, !ListQ[Simplify`FunctionSingularities[f[x], x, "ELEM"]]] System`TRootsDump`NIntervalRoots[f_?nonElementaryQ, ii_, prec_] := $Failed This will disable the offending code for non-elementary functions. In[4]:= NSolve[BesselJ[0, x] == 0 && 0 Out[4]= {{x -> 2.40483}, {x -> 5.52008}, {x -> 8.65373}, {x -> 11.7915}, > {x -> 14.9309}, {x -> 18.0711}}

equation solving - I can't understand why "FindRoot::nlnum:" shows up in my code

I want to solve a system of equations using Findroot as follows: Clear[a]; Clear[c]; n = 2; SysEqn1 = Table[a[i] + I Sum[(PolyLog[1, E^(I (c[j] - a[i] + 0.5))] + PolyLog[1, E^(I (c[j] - a[i] + (2 \[Pi] - 1.2)))] - PolyLog[1, E^(I (c[j] - a[i] - 0.3))] - PolyLog[1, E^(I (c[j] - a[i] - 0.4))]), {i, n}], {j, n}]; SysEqn2 = Table[c[i] + I Sum[(PolyLog[1, E^(I (c[j] - a[i] + 0.5))] + PolyLog[1, E^(I (c[j] - a[i] + (2 \[Pi] - 1.2)))] - PolyLog[1, E^(I (c[j] - a[i] - 0.3))] - PolyLog[1, E^(I (c[j] - a[i] - 0.4))]), {i, n}], {j, n}]; SysEqn = Join[SysEqn1, SysEqn2]; startingValues1 = Table[{a[i], -1 + 2 i/n}, {i, n}]; startingValues2 = Table[{c[i], -0.9 + 2 i/n}, {i, n}]; starting = Join[startingValues1, startingValues2]; FindRoot[SysEqn, starting] The error message from the above code is as fo FindRoot::nlnum: "The function value {a[i]+(0. +1.\ I)\ (1.\ Log[1. +Times[ >]]+1.\ Log[1. +Times[ >]]-1.\ Log[1. +Times[ >]]-1.\ Log[1. +Times[ >]]+1.\ Log[1. +...

manipulate - Can I disable specific items in a PopupMenu control?

I have a PopupMenu in a Manipulate with items in it that are inapplicable in some cases, and rather than removing them, I would like to disable (just) those items that are inappropriate. For example, I'd like to disable (not remove) everything in list that is, say, less than the item selected in filter : Manipulate[ {filter, list}, {{filter, 1, "Filter:"}, {1, 2, 3, 4, 5, 6}, ControlType -> PopupMenu}, {{list, 1, "List:"}, {1, 2, 3, 4, 5, 6}, ControlType -> PopupMenu} ] Is there a way to disable specific individual items in a PopupMenu , without resorting to a custom control? Answer There's no way to do this that conforms fully to UI guidelines (at least not for OS X). For example, your "disabled" items will still highlight as you hover over them and will still react to selection (thought they will do nothing). This is as close as you can get: Manipulate[ {filter, list} , {{filter, 1, "Filter:"}, {1, 2, 3, 4, 5, 6}, Cont...

computational geometry - Smooth convex hull of a large data set of 3D points

I recently needed to deal with a large data set of 600,000 points in three dimensions. My task was to find a convex hull for this data. I have Mathematica 10, so I could use the function ConvexHullMesh ; I obtained this: I was wondering if there is some way to find a smooth convex hull (maybe an ellipsoid) for my data. Answer Minimum Volume Ellipsoid Translated from here , this uses the Khachiyan algorithm, and should work for any dimension. MinVolEllipse[P_, tolerance_] := Module[{d, n, Q, count, err, u, X, M, maximum, j, stepSize, newu, U, A, c}, {n, d} = Dimensions[P]; Q = Append[1] /@ P; count = 1; err = 1; u = ConstantArray[1./n, n]; While[err > tolerance, X = Q\[Transpose].DiagonalMatrix[u].Q; M = Diagonal[Q.Inverse[X].Q\[Transpose]]; maximum = Max[M]; j = Position[M, maximum][[1, 1]]; stepSize = (maximum - d - 1)/((d + 1) (maximum - 1)); newu = (1 - stepSize) u; newu[[j]] += step...

calculus and analysis - How to evaluate the $0/0$ type limit in Mathematica?

When I use Limit to evaluate the limit $$\begin{align}\lim_{k \to 0} \frac{ (k+2)(\alpha^2 - \sqrt{\alpha^4 + k}) + k}{\alpha^2 - \sqrt{\alpha^4 + k} + 2 k}\end{align}$$ ((k + 2) (α^2 - Sqrt[α^4 + k]) + k)/(α^2 - Sqrt[α^4 + k] + 2 k) ( α and k are assumed to be real) Limit gives the answer: 2 . However, I believe the correct answer is (2 (-1 + α^2))/(-1 + 4 α^2) So, when should I trust the answer of Limit ?

How do I generate a set of n-tuples containing integral solutions to a linear equation provided certain constraints?

Let $m,k,p$ be fixed positive integers. I want to create a table of k-tuples $(x_1,x_2,\ldots,x_k)$ comprised of solutions in positive integers to the equation below: $$x_1+x_2+\cdots+x_k=m\quad\text{where }1\leq{}x_1,x_2,\ldots,x_k\leq{}p$$ For example, if I set $m=16,k=3$, and $p=6$. How can I make mathematica generate the set (table) of integer triples $(x_1,x_2,x_3)$ such that $$x_1+x_2+x_3=16$$ where $1\leq{}x_1,x_2,x_3\leq{}6$. Also, how would I seperately generate a table of positive integral triples $(x_1,x_2,x_3)$ for which $$x_1+x_2+x_3\geq{}16 \quad \text{and } 1\leq{}x_1,x_2,x_3\leq{}6.$$ Answer Try to read Documentation on functions Solve and Reduce and tutorial Solving Equations . Look through this forum, I bet this is a duplicate question. There is also a guide: Diophantine Equations . {x1, x2, x3} /. Solve[x1 + x2 + x3 == 16 && 1 1 {{4, 6, 6}, {5, 5, 6}, {5, 6, 5}, {6, 4, 6}, {6, 5, 5}, {6, 6, 4}} or alternatively Reduce[x1 + x2 + x3 == 16 && 1 ...

plotting - Make a density list plot/histogram from large, pre-binned data set?

I have a large data set consisting of $\mathcal{O}(10^9)$ two-dimensional points. In order to save memory and time I have pre-binned these into a uniform grid of $500 \times 500$ bins using Fortran. When imported into Mathematica 8.0 as a table the resulting data look like: data = {{0.388348, 0.388349, 9},{0.388348, 0.776699, 23},...} , where the first two items of each entry correspond to the $x$-$y$-coordinates of the upper-right-hand corner of the bin and the third is the count. Edit: For a sample of the raw data, raw=RandomReal[1,{1000000000,2}] is a good approximation. This is obviously unworkable. For the binned data: binned=Table[{.01*Ceiling[raw[[i,1]]/.01],.01*Ceiling[raw[[i,2]]/.01],RandomInteger[1000]},{i,1,250000}] . I would like to plot this pre-binned data set in the form of a DensityHistogram, but my data format doesn't fit into what this function is expecting. I have reviewed a similar question for one-dimensional histograms at Histograms with pre-counted data , ho...

list manipulation - Automate table to display figures

With reference to the post Automate Poisson Football Scores Prediction , I succeded in defining the Poisson probability density function for home ( μh=A ) and away ( μa=B ) teams, but cannot create a table/matrix taking into account the next matches round thanks to the vector matchesENG and the product between p[A, x]*p[B, x] because I am not able to recognize the actual home team and away team for each match and displaying the scores. Here the complete nb. ClearAll; Cl = Import["https://www.soccerstats.com/homeaway.asp?league=england", "Data"]; Chome = Drop[Drop[Cl[[2, 4, 1]]], 1]; Caway = Drop[Drop[Cl[[2, 4, 2]]], 1]; teamsENG = Chome[[All, 2]]; dataENG = Import["https://www.soccerstats.com/results.asp?league=england&\ pmtype=bydate", "Data"]; Drop[Drop[Drop[Cases[dataENG, {_, _, _, _}, Infinity], -4], -1, None], None, -1]; Take[Table[ If[StringContainsQ[%[[i, 2]], ":"] == True, %[[i]], ## &[]], {i, 1, Length...

plotting - Using Show to place a ParametricPlot on a LogLog scale

I wish to have a few plots on the same graph: ListLogLogPlot, LogLogPlot and a ParametricPlot drawing lines perpendicular to the x-axis. The problem is however that ParametricPlot doesn't seem to have the LogLog equivalent, as the other Plot functions do, and Show does not combine non-LogLog plots with LogLog plots, even when they coincide, eg.: Show[LogLogPlot[x^4, {x,10^(-10),10^10}], Plot[x^5, {x,10^(-10),10^10}]] should theoretically show two straight lines, but shows only one. Is there a way to combine such graphics without resolving to using non-LogLog plots? Answer Try this: Show[{ LogLogPlot[x^4, {x, 10^(-10), 10^10}, PlotStyle -> Red], LogLogPlot[x^5, {x, 10^(-10), 10^10}, PlotStyle -> Blue], ParametricPlot[{Log[0.01], Log[y]}, {y, 10^-26, 10^30}, PlotStyle -> Darker@Green] }]

Slider with initial value on manipulate

Consider this simple code Manipulate[n, {{n, 3}, 1, 5, 1}] It will produce If we click on Show-Animation-Controls button next to the slider, suddenly the value changes to 1. I think this is not an expected behavior of a slider with initial value on a manipulate. Or, it is? I use 10.1 on Windows 7.

plotting - GridLines in LogPlot or LogLogPlot

Suppose I have a plot like LogLogPlot[2 x^5/3, {x,0.1,10}, GridLines->Automatic] How can I achieve to get "custom" gridlines to reduce the number of horizontal lines? I know how to do it with linear scaled plot. For linear scale I do basicly: myGrid[{xmin,xmax,xstep}, {ymin,ymax,ystep}]:= GridLines->{{#&,/@Range[xmin,xmax,xstep},{#&/@Range[ymin,ymax,ystep])}

matrix - Mixing up eigenvalues with positive and negative imaginary parts

f[k_] = {{-0.001 - 2 I k, 1, -0.001, -0.501}, {0.001, -0.5 - I k, 0.001, 0.001}, {-0.001, -0.501, -0.001 + 2 I k, 1.}, {0.001, 0.001, 0.001, -0.5 + I k}}; y[k_] = Im[Eigenvalues[f[k]][[3]]]; Plot[y[k], {k, -1, 1}] 3rd and 4th eigenvalues are complex conjugates, as we can see from the graph the program mixed them, there are lots of jump discontinuities from the one with negative imaginary part to the one with positive. I suspect that the program sometimes takes as the 3rd eigenvalue (or root) the one with positive "Im" and sometime the one with negative "Im". Please help me to resolve this problem by a general approach (of course for this case one can take the Max of two as k>0 and Min otherwise to obtain the imaginary part of the desired eigenvalue). Answer I'm not sure exactly which eigenvalues you wish to display, but you can sort them in order to choose. For instance, to plot the largest eigenvalue, you can f[k_] := {{-0.001 - 2 I k, 1, -0.001, -0.5...

graphics - Generate nonoverlapping random circles

I want to distribute n circles unformly in an area(e.g. free plannar space). The circles could touch each other but cannot overlap. n = 5; r = 0.2; Table[pt[i] = RandomReal[{-1, 1}, 2], {i, 1, n}]; Graphics[{Table[Circle[pt[i], r], {i, n}]}, Axes -> True, PlotRange -> {{-1, 1}, {-1, 1}}] My method is to generate the random points firstly, and then calculate the smallest distance between all point pairs. If the smallest distance is larger than 2r, the points are kept. However, the problem with this method is that the larger the radius, the more trials have to be taken. Answer There are a bunch of Region functions that just showed up in 10. This uses RegionDistance[] to make a function that computes the shortest distance from a point to a region. The generated function runs faster than just checking all the circles. Though the creation of the function in the first place has to look at all the circles. So this still runs in $\mathrm O(n^2)$ time, but at least the inner While s...

simplifying expressions - Mathematica rule to express exponentials as multiplication

I'm sorry if this has been asked before, but it is a very simple question and I would imagine it shouldn't be terribly hard for someone that knows to answer. I'm essentially trying to tell mathematica to not simplify Exp[x] Exp[y] -> Exp[x+y] I am using an add on package which is having a hard time with some replacement rules. So, the question is, is it possible to force mathematica to express Exp[x] Exp[y] as is and not simplify it? A secondary question, which should just be an extension of the first, I would like (Exp[x] Exp[y] )^2 to be replaced as Exp[x]^2 Exp[y]^2 not Exp[2x+2y] ! Or even being left as is is ok. Answer One possibility is to execute your entire code in some dynamic environment, where certain simplification rules are permanently or temporarily blocked. Here is the generic environment generator: ClearAll[withBlockedSymbols]; withBlockedSymbols[syms : {__Symbol}] := Function[code, Block[syms, code], HoldAll]; We can now produce an environment g...

plotting - Do I have to code each case of this Grid full of plots separately?

I have written some custom functions to draw multi-panel graphs like this one: It's done by passing a matrix of (custom) plotting functions to a MultiPanelGraph function, which pulls apart the head, argument and options of those plots, adds a few of its own, and then puts it all together. There is also some funkiness to deal with plot labels and footnotes, but I've removed these from the code below for simplicity. The PanelHeightFactor type options are custom options to the custom functions for the individual plots. Likewise the MultiPanel option tells the custom functions for the individual plots to, for example, turn off ticks and tick marks on particular sub-plots so that they all fit together neatly as shown in the picture above, and to turn the PlotLabel into a panel label inside the plot frame using Prolog . Attributes[MultiPanelGraph]={HoldFirst}; MultiPanelGraph[{{l_[largs__,lopts___Rule], r_[rargs__,ropts___Rule]}}, mpopts:OptionsPattern[{MultiPanelGraph,myLineGra...

string manipulation - How to remove accents from text?

I would like to know how I can remove accents from a string. For example, how can I transform "string test áéíóú" into "string test aeiou" ? I have to normalize some text to make comparisons, and this would be very helpful. Answer To remove accents from a string I use this function: removeAccent[string_] := Module[{accentMap,l1,l2}, l1 = Characters["ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ"]; l2 = Characters["SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"]; accentMap = Thread[l1 -> l2]; StringReplace[string, accentMap] ] So, if you apply it as removeAccent["string test áéíóú"] you get: "string test aeiou" Update Now in version 10.1 we have the native function: RemoveDiacritics RemoveDiacritics["string test áéíóú"] you get "string test aeiou" Timing comparison using the new RepeatedTiming . RepeatedTiming[removeAccent["string test áéíóú"]] ...

bugs - Temporary variable not removed in Mathematica 10

Bug introduced in 10.0.1 and fixed in 10.0.2 In Mathematica 10, the documentation still states that a symbol with attribute Temporary will automatically be removed when it is no longer needed. Now consider Module[{a}, Information[a]] => (* Global\`a$105933 Attributes[a$105933]={Temporary} *) This a$ variable is not exported from the Module and therefore not needed any more. However, in Mathematica 10 it is not removed: Names["Global`a$*"] => (* {a$105933} *) This looks like a minor bug to me.

front end - How can I create some shorthand notation for a custom control?

Per this question , I have created a custom graphical control object which evaluates to a list of values. I would like to be able to create such an object quickly, rather than typing some command, pressing shift+enter, then copying the resulting object into wherever I want to use it. For example, something like typing \[Theta] which turns into θ ... is it possible to create such a custom shorthand notation? (Even better, is it possible that when I start to type in a function which takes such a list as arguments, it pops up this control object for me to type the values in?) Answer Assuming you are referring to this control . You can Evaluate in a separate cell each time and copy paste (you don't like this) Write the command and evaluate in place Copy the control once and paste it several times: remember the variables were localized so each will have its own copy and they won't interfere Create a palette CreatePalette@PasteButton["Paste control", myControl["a...

calculus and analysis - Only perform a symbolic differentiation once

I want to define a function that involves a differentiation step that Mathematica can do easily, which might be of the form f[a_,b_,z_,j_]:=D[Hypergeometric1F1[a, b, z^2], {z, 2 j}] (This will not work when given numeric z , but that is only a small part of the problem.) I will be using this for a limited set of j 's quite intensively in z . It is therefore important to me that the symbolic differentiation only take place once, so that Mathematica is not repeatedly trying to do the same symbolic manipulations when running over a plot or a numerical integration. What is the cleanest/most elegant way to do this sort of partial memoization procedure? Answer A general approach in this kind of situations is to use memoization. Here, however, some of the parameters should remain patterns (general), so you can use something like this (see this answer for a similar case): ClearAll[f]; f[a_, b_, z_, j_] := Block[{al, bl, zl}, f[al_, bl_, zl_, j] = D[Hypergeometric1F1[al, bl, zl...

parallelization - Server running WolframLightWeightGrid manager loses licensing information

"Once more into the breach..," I have 2 identical Xserves running OS X Server 10.6.8 each with 2 quad core Intel Xenon processors a total of 16 kernels. I have configured both servers identically and use them exclusively as a computing grid for Mathematica. I run the WolframLightWeightGrid manager on the servers and distribute processing jobs to them from a number of different notebooks. An earlier question Wolfram Light Weight Grid and parallel computing from when I setup this environment gives more background. This environment has pretty much run like a charm over the past four months. As a check on what goes on I run the following few lines of code when launching the grid: Needs["LightweightGridClient`"] Column[{ ParallelEvaluate[$ProcessID], ParallelEvaluate[$MachineName], RemoteServicesAgents[] // ColumnForm}] This will give me lists of the process IDs and machine names and remote service agents. But today something has gone awry: I should see 8 addition...

Show graphics content in front of frame

Consider some graphics which spill over the plot range, like these: Graphics[{Red, Disk[{0, 0}, 1]}, PlotRange -> {{-1.1, .9}, {-1.1, 1.1}}, Frame -> True, PlotRangeClipping -> False, ImagePadding -> 20, FrameStyle -> Thick] Can I make the graphics be drawn in front of the frame without drawing the frame manually? Is there a possibly undocumented option for this (maybe a Graphics Method option)? Answer A few wild guesses (trying to mimic the "GridLinesInFront" suboption of the option Method ) gave the following: Graphics[{Red, Disk[{0, 0}, 1]}, PlotRange -> {{-1.1, .9}, {-1.1, 1.1}}, Frame -> True, PlotRangeClipping -> False, ImagePadding -> 20, FrameStyle -> Thick, Method -> {"FrameInFront" -> False}] This option is documented (see under Details and Options) since version 10.

plotting - Labelling ArrayPlot Charts

I have been using ArrayPlot to show off some information. Currently, my datasets are like so: data1={2, 6, 3, 4, 8, 5, 13, 11, 33, 21, 29, 21, 42, 29, 36}; data2={0, 1, 9, 1, 3, 0, 5, 3, 20, 16, 4, 13, 7, 10, 7}; data3={10, 3, 2, 0, 2, 1, 0, 0, 14, 2, 1, 12, 6, 0, 10}; data4={0, 0, 0, 2, 0, 1, 4, 0, 0, 4, 0, 4, 1, 3, 2}; data5={0, 3, 0, 3, 0, 0, 0, 3, 3, 2, 1, 14, 4, 2, 4}; etc. The plot command ArrayPlot[{globeCHR, starCHR, telegramCHR, gazetteCHR, citizenCHR}, FrameTicks -> All] reveals the following: So far so good - it vividly shows what I am trying to visualize. The problem comes with the following. I would like to give my datasets along the y axis names: i.e. instead of "1" it might say "Cats" and instead of "2" it might say "Dogs." Similarly, the bottom axis needs to go from 1997 to 2010 (years). I have generated a list of the years as such yearlist = Range[1997, 2011, 1] , which lines up in length to the datasets. Matched pairs of da...

Solving system of equations with Root

I have this system of equations. I want to express all variables in terms of x as you can see. x is a parameter. Solve[{y (z - x) == x^6, x zg - z zg == x z^2 za zb - x z za zb zg, za zg - zb zg == z za zb - z za^2 zb, zb - zg == z za zb - z zb^2, za zb (z - zg) == zg (-zb + zg), za > 0, zb > 0, zg > 0, z > 0}, {y, za, zb, zg, z}, Reals] However Mathematica doesn't know how to solve it. Solutions show me something called Root and I can't make sense out of any of the expressions I get. What I get is: y -> ConditionalExpression[(( x^6)/(-x + Root[-x + 2 x^2 + (1 - 3 x - x^2) #1 + (1 + 2 x - 4 x^2) #1^2 + (-1 + 5 x - x^2) #1^3 + (-1 + x - x^2) #1^4 + x^2 #1^5 &, 3])) I also tried using reduce which gives me a set of solutions for y : y == Root[ x^26 + (-x^18 + x^19 - x^20 + 5 x^21) #1 + (-x^12 + x^13 + 3 x^14 - 4 x^15 + 10 x^16) #1^2 + (x^6 - x^7 + 5 x^8 + 3 x^9 - 6 x^10 + 10 x^11) #1^3 + (1 - x + 3 x^3 + x^4 - 4 x^5 + 5 x^6) #1^4 + (-1 + x) #1^5 ...

plotting - Why do I have to put Evaluate[] here

I wanted to draw some contours. I succeeded with this: W1 = {p, -2, 2, 0.5}; W2 = {p, -10, 10, 1}; P = W1; ContourPlot[ Evaluate[Union[Table[y^2 == 2 p*x, Evaluate[P]], Table[x^2 == 2 p*y, Evaluate[P]]]], {x, -5, 5}, {y, -5, 5}] P = W2; ContourPlot[Evaluate[ Union[Table[y^2 == 2 p*x, Evaluate[ P]], Table[x^2 == 2 p*y, Evaluate[P]]]], {x, -5, 5}, {y, -5, 5}] I don't like this solution. I used Evaluate[] a few times and I feel like it is unnecessary although without the function I get errors. Could anyone explain me that. I find the reference unhelpful (maybe that's my lack of language?) "causes expr to be evaluated even if it appears as the argument of a function whose attributes specify that it should be held unevaluated.". Answer ContourPlot has the attribute HoldAll . That means that it receives its arguments before they are evaluated. So, if you put as a first argument, something that evaluates to a list but it's not a list, it won't fit with th...

differential equations - NDSolve with boundary condition at infinty

I have a nonlinear set of equations with a boundary condition at infinity. Consequently I have to shoot for the boundary. This question has some good ideas but there is an extra complication in my case; my boundary conditon at infinity is the second derivative going to zero and this is approached asymptotically. I will have more problems the same and this is minimum example I can demonstrate. The equations and initial conditions at zero are here eqns = {-Derivative[3][a[0]][η] == (-(1/2))*α* (-1 + 2*Derivative[1][a[0]][η]^2 + Derivative[1][a[1]][η]^2 + Derivative[1][a[2]][η]^2 + Derivative[1][b[1]][η]^2 + Derivative[1][b[2]][η]^2 - 2*a[0][η]*Derivative[2][a[0]][η] - a[1][η]*Derivative[2][a[1]][η] - a[2][η]*Derivative[2][a[2]][ η] - b[1][η]*Derivative[2][b[1]][η] - b[2][η]*Derivative[2][b[2]][η]), Derivative[1][b[1]][η] - Derivative[3][a[1]][η] == (1/2)*(-4*α*Derivative[1][a[0]][...

charts - Retrieving PlotRange from BarChart

Consider the following data: data1={73.9377, 54.4122, 53.0826, 24.1936}; data2={76.828, 49.1673, 45.7883, 18.9015}; I defined my own BarChart as follows: MyBarCharts[list_]:= BarChart[ list, Frame -> {{True, None}, {True, None}} ] When applying MyBarCharts to data1 and data2 I get (not really surprising) two different (with regard to the coordinate system) plots. Now I would like to have for both plots the exact same coordinate system. I know that with Histogram it works as follows: Histogram[ data2, PlotRange -> Part[PlotRange /. Options[Histogram[ data1, PlotRange -> Automatic ],PlotRange], 2], Frame -> {{True, None}, {True, None}}] But the implementation of that approach in MyBarCharts does not give the desired result. Has anyone an idea? Answer Extracting the PlotRange from a BarChart is not as straightforward as it should be. If no Plot...

Best practices for using the Testing Framework

I am looking for best practices and recommended workflows for using the Testing Framework . For example, lets say I am developing a Mathematica package for other users, it is hosted on GitHub and I wish to make it easy for other developers to contribute to repository. The project includes a suite of (unit) tests that I would like to run as often as necessary. I would like to run them within FrontEnd and conveniently inspect the results (timings, which tests failed and why, etc), save them to file and also further automate testing in the future. I can think of few possible workflows but none of them ticks all the boxes. "Testing Notebook", Pro : It gives a clear overview of tests and looks nice. It can be run in FrontEnd and also programmatically with TestReport . Con : Contains even more metadata than the normal notebook (all those buttons) so it is less suitable to put under version control. Somehow the evaluation of tests is slower in testing notebook than in normal notebo...

matrix - How to force Series[] to compute expansions by considering non commutative multiplication?

I wish to compute the Taylor series expansion of the following iteration method $x_{k+1}=x_k-f'(x_k)^{-1}f(x_k)$ up to four terms of error ($e_k=x_k-\alpha$). When this is a scalar iteration, I very simply write the following ClearAll["Global`*"] f[e_] := df*(e^1 + c2 e^2 + c3 e^3 + c4 e^4 + c5 e^5); fe = f[e]; f1e = f'[e]; Series[f1e^-1, {e, 0, 4}]*df // Simplify u = e - Series[fe/f1e, {e, 0, 4}] // Simplify and obtain correct results $$f(x_k)^{-1}=[1-2 \text{c2} e_k+ \left(4 \text{c2}^2-3 \text{c3}\right)e_k^2$$ $$-4 (2 c2^3 - 3 c2 c3 + c4) e_k^3 + (16 c2^4 - 36 c2^2 c3 + 9 c3^2 + 16 c2 c4 - 5 c5) e_k^4]f'({\alpha})^{-1}.$$ But, how to do this for the multi-dimensional case. That is, when the coefficients $c2,c3,c4$, and even $df=f'({\alpha})^{-1}$ are all matrices (note that e.g. $c2=\frac{1}{2!}f'(\alpha)^{-1}f^{(2)}(\alpha)$). By hand, I obtain the following correct results: $$ f(x_k)^{-1}=\left(I-2c2e_k+(4c2^2-3c3)e_k^2+(6c3c2+6c2c3-8c2^3-4c4)e_k^3\\...

Threading elements over corresponding elements in the second list

I often need to merge two lists like the following: $A=\{\{0.1\},\{0.2\},\ldots,\{1\}\}$ $B=\{\{x_1\},\{x_{21},x_{22},x_{23}\},\{x_{31},x_{32},x_{33}\},\ldots,x_N\}$ in a way to ideally obtain a new list such as: $C = \{\{0.1,x_{1}\}, \{0.2,x_{21}\}, \{0.2,x_{22}\}, \{0.2, x_{23}\},\{0.3,x_{31}\}, \{0.3,x_{32}\}, \{0.3, x_{33}\}, \ldots, \{1, x_N\}\}$ At present I do this by inspecting the lists and manually associating them in the appropriate way. In above example, I would do Table[{A[[k]],B[[k,1]]},{k,1,N}] Table[{A[[k]],B[[k,2]]},{k,2,S}] Table[{A[[k]],B[[k,3]]},{k,2,S}] where S is the position of the last element that contains three entries in the $B$ list. These lists are typically very long, and I wonder whether there is a way to do this efficiently.

graphics - Find intersection of pairs of straight lines

I have a list of 24 points, in which two consecutive points (1st and 2nd, 3rd and 4th, …) are supposed to form a line: p1={{243.8, 77.}, {467.4, 12.}, {291.8, 130.}, {476., 210.5}, {103.2, 327.}, {245.2, 110.5}, {47.4, 343.}, {87.4, 108.5}, {371., 506.5}, {384.6, 277.}, {264.6, 525.5}, {353.8, 294.5}, {113.2, 484.5}, {296., 304.5}, {459.6, 604.5}, {320.2, 466.5}, {288.2, 630.5}, {199.6, 446.5}, {138.8, 615.5}, {81.8, 410.}, {232.4, 795.}, {461.8, 727.}, {27.4, 671.5}, {206.8, 763.5}}; I also have another list of 24 points with the same property: p2={{356.8, 32.}, {363.2, 120.}, {346., 245.}, {393.8, 158.}, {163.8, 211.5}, {230.2, 250.}, {54.6, 225.}, {139.6, 220.}, {366., 394.5}, {451.8, 372.}, {241., 398.}, {321., 411.5}, {163.2, 347.}, {213.2, 406.5}, {332.4, 596.5}, {402.4, 528.5}, {176., 585.5}, {256., 530.5}, {38.2, 553.}, {122.4, 507.}, {345.2, 774.5}, {345.2, 688.}, {104.6, 728.}, {161.8, 647.}}; My goal is to find the intersections between a line in p1 and ...