Skip to main content

Posts

Showing posts from January, 2017

functions - Testing for continuity over a given domain

Is there any way to use Mathematica to test whether a function is continuous over a given domain? Answer This is likely to be very slow.. isDiscontinuous[f_, low_, high_] := Resolve[Exists[del, del > 0, ForAll[eps, eps > 0, Exists[{x1, x2}, low <= x1 < x2 <= high && x2 - x1 < eps && Abs[f[x1] - f[x2]] > del]]]] Here are simple examples. ff[x_] := x^2 + x isDiscontinuous[ff, -1, 2] (* Out[334]= False *) gg[x_] := Sign[x] Resolve[isDiscontinuous[gg, -1, 2]] (* Out[331]= True *)

kernel - Generating figures over remote connection (using terminal)

Recently I've been making movies by having Mathematica create figures and then I combine all of them together using ffmpeg . The problem now is that my macbook is not fast enough to generate the figures I want in a short amount of time. I have access to a linux machine and I would like to be able to send a script to that machine so that I can generate my figures. The problem I'm facing is that Mathematica can't open display ":0.0". I also found this , but it did not solve my problem. Does anyone know how to generate figures in the terminal? All I want it to do is to write them to a file. Answer Since graphics can no longer be exported without access to a front end, even with remote connections you have to have X11 installed and working on your local machine. Therefore, the first thing you should do is: go to the web site http://xquartz.macosforge.org/landing/ and download the latest version of X11 appropriate for your OS X version. After installing it, everyt

differential equations - Kernel quits without error in NDSolveValue

The crash is fixed in version 10.3 I am using the latest 10.1. The following single line command makes the kernel quit without error message (just a beep): NDSolveValue[{-Derivative[0, 2][Φ][x, t] + Derivative[2, 0][Φ][x, t] == Sin[Φ[x, t]], Φ[x, 0] == 0, -Derivative[0, 1][Φ][0, t] + Derivative[1, 0][Φ][0, t] == 2*Sin[2*t]}, {Φ[x, t], Derivative[1, 0][Φ][x, t]}, {x, 0, 1}, {t, 0, 1}] What goes wrong with this?

plotting - How to Set the Ratio of Units of the Axes in a 2D Plot?

Consider the following plot Plot[{Sin[x]}, {x, 0, 2*Pi}, PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}}, AxesLabel -> {x, y}, AxesOrigin -> {0, 0}] It is evident that $1$ unit on the $y$ axis is not as the same length of $1$ unit on the $x$ axis. I want the ratio of these units to be one or any other desired value $r=\dfrac{y \,\, \text{axis unit}}{x \,\, \text{axis unit}}$. I searched for how to determine the scaling of these units of the axes. I encountered this post and this one . But I could not find a nice answer explaining a simple way to do the job. Also, I couldn't find a nice example in the documentation. I just learned from documentation that AspectRatio determines the ratio of PlotRange , not ImageSize . So here is my question What is a simple way to manually edit the ratio of the units of the axes? . Answer To get 1:1 unit ratio you can use Plot[{Sin[x]}, {x, 0, 2*Pi}, PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}}, AxesLabel -> {x, y}, AxesOrigin -> {0, 0},

differential equations - Implementing Picard's Iteration for solving ODEs

Picard's Iteration is a way of solving the IVP $$y'(x)=f(x,y(x)), \quad y(x_0)=y_0 $$ It consists of defining the following sequence of functions recursively: $$y_0(x):=y_0 \\ y_{n}(x):=y_0+\int_{x_0}^x f(t,y_{n-1}(t)) \mathrm dt.$$ I've tried implementing it in Mathematica , for the particular problem $$y'=y^2,y(0)=1 $$ as follows For[{n=0,y[0][x_]:=1},n<10,n++,y[n][x_]:=1+Integrate[y[n-1][t]^2,{t,0,x}]] which doesn't work at all. What am I doing wrong here, and how can I fix it? Thank you! Answer I believe that the following code does what you want For[{n = 1, y[0][x_] = 1}, n < 4, n++, y[n][x_] = 1 + Integrate[y[n - 1][t]^2, {t, 0, x}];Print[{n, y[n][t]}]]

graphics - $LaTeX$ and Mathematica

I quite often would like to draw graphics in my $\LaTeX$ documents using Mathematica. I have encountered three problems. I would like to know if there are any workarounds to these problems I would like to make my graphics homogeneous with my document. That means that I would like to use the same font in the graphics (labels for axis etc) as the main text. Mathematica does not support Computer Modern. I found a workaround using PSFrag, saving graphics as EPS. It is possible using PSfrag to rename the text in the graphic into $\LaTeX$ code. A big downside is that this method does not allow me to use pdflatex. Many other packages (hyperlink) therefore do not work. Graphics3D objects are extremely big. If I save it using a bitmap, the picture usually becomes horrible. I often would like to use transparency. If I use Opacity to make some part of the graphic transparent, the exported file in Mathematica is horrible. Answer There are a few different parts to your question. I'll just a

map - Application of # for the $n^{th}$ derivative

Let's say that I have x^2+x Is there a way to map $x$ to the first derivative of a function and $x^2$ to the second derivative of the same function? According to http://reference.wolfram.com/language/ref/Slot.html , I know that I can change x /. x -> D[#, {y, 1}] &[a[y, z]] x^2 /. x^2 -> D[#, {y, 2}] &[a[y, z]] to yield the first and second derivatives of $a(y,z)$, respectively. I also know that I can use x^2+x/. x^2 -> D[#, {y, 2}] &[a[y, z]] /. x -> D[#, {y, 1}] &[a[y, z]] but if I have say, a polynomial of degree 70, manually telling Mathematica to do this is highly inefficient. Is there a method, such that, for $x^n$, I can tell Mathematica to map $x^n$ to the $n^{th}$ derivative of a function? Answer {x, x^2, x^2 + x} /. x^n_. :> Derivative[n, 0][a][y, z]

differential equations - Numerical resolution of non-linear coupled ODEs

I have problem with my code in Mathematica. I have introduced the set of coupled non-linear ODES. This is the resolution part: (*Initial parameters*) A = 0.5; a = 0.9; Ω = 0.24; (*Initial conditions*) υ0 = 0.22; α0 = Pi; ψ0 = Pi/2; r0 = 20; θ0 = Pi/8; φ0 = 0; Needs["DifferentialEquations`NDSolveProblems`"]; \ Needs["DifferentialEquations`NDSolveUtilities`"]; (*Systems to integrate*) system = {x1'[t] == Eq1[A, a, Ω, x1[t], x2[t], x3[t], x4[t], x5[t]], x2'[t] == Eq2[A, a, Ω, x1[t], x2[t], x3[t], x4[t], x5[t]], x3'[t] == Eq3[A, a, Ω, x1[t], x2[t], x3[t], x4[t], x5[t]], x4'[t] == Eq4[A, a, Ω, x1[t], x2[t], x3[t], x4[t], x5[t]], x5'[t] == Eq5[A, a, Ω, x1[t], x2[t], x3[t], x4[t], x5[t]], x6'[t] == Eq6[A, a, Ω, x1[t], x2[t], x3[t], x4[t], x5[t]], x1[0] == υ0, x2[0] == α0, x3[0] == ψ0, x4[0] == r0, x5[0] == θ0, x6[0] == φ0}; sol = NDSolve[system, {x1, x2, x3, x4, x5, x6}, {t, 0, 14000}, Method -> {&q

web access - Parsing JavaScript Script from XML Trees

I've been trying to parse some script written in JavaScript while scraping a website, and am a little confused what functions are needed to get this done in Mathematica . I imported the data using Import["url","XMLObject"] . The website I am trying to scrape is https://www.msn.com/en-us/money/stockdetails/history/fi-126.1.AAPL.NAS . I am basically trying to scrape historical data prices of certain dates, all of which are hidden in javascript. Any help would be of great appreciation! The XML for the desired part looks like this: XMLElement["script", {"type" -> "text/javascript"}, {"\n require([\"jqLoadTemplate\", \ \"dateFormat\", \"ChartsConfig\", \"chartUtils\", \ \"ChartModeController\", \"utils\", \"LocaleSettings\", \ \"NumberFormatter\", \"c.deferred\"], function ($, dateFormat, \ chartsConfig, chartUtils, ChartModeController

output formatting - How to apply multiple format to a list

I have a nested list like matrix = {{1.2345664, 2.38673956, 3.567846}, {0.00034554, 124.4554654, 6.34543}, {0.0000233, 244.34454, 2}} and I want to apply MatrixForm , but also NumberForm[,{5,4}] , because I want that in every element of the matrix the numbers are properly padded. Is this possible in some way? Interestingly perhaps, I want eventually write the resulting output list in a file. P.S.: Now I write with Export["my_file.dat",Flatten[matrix]] , and after I obtain the proper padding using a C program. But there must be a clever way... Answer You can do this a couple of different ways. This is easiest: NumberForm[MatrixForm @ matrix, {5, 4}] This works because NumberForm affects sub-expressions including ones wrapped in MatrixForm . You can do it the other way but it's more complicated: Map[NumberForm[#, {5, 4}] &, matrix, {2}] // MatrixForm You mention that you eventually want to export this. You should not need (or use) MatrixForm for export. The question

computational geometry - How do I get ConvexHullMesh to return polygons instead of triangle as surface mesh?

I would need to identify the types of regular polygons forming the surface of a convex hull of 3D points. If I e.g. take the following example of a regular polyhedron ConvexHullMesh[N[PolyhedronData["Dodecahedron", "VertexCoordinates"]]] The convex hull routine returns a triangulated mesh surface. Is there any simple way to convince Mathematica to return the surface as polyhedrons (in this case pentagons) instead of a triangulation. To illustrate the issue further, e.g if one applies MeshCells[ConvexHullMesh[N[PolyhedronData["Dodecahedron", "VertexCoordinates"]]], 2] Mathematica only returns triangles. If one applies ConvexHullMesh[N[PolyhedronData["Dodecahedron", "VertexCoordinates"]]] // FullForm There is the option "CoplanarityTolerance" . But I do not know how to use it. Any ideas? Answer The procedure groups triangles based on the same unit normal vector, then uses the vertices in each group to form a new po

probability or statistics - Why does conditional NExpectation fail for a multivariate distribution?

To give an example for a multiparametric distribution let us take a binormal distribution: binormalDist = With[ { μ = { 0, 0 }, σ = { 1, 1 }, ρ = 7/10 }, BinormalDistribution[ μ, σ, ρ ] ]; Calculating the conditional expectation in simple cases works out: NExpectation[2 x + 3 \[Conditioned] x < 1., {x, y} \[Distributed] binormalDist ] 2.4248 and so does this too: NExpectation[2 x + 3 \[Conditioned] y == 2., {x, y} \[Distributed] binormalDist ] 5.8 but NExpectation[2 x + 3 \[Conditioned] (x < 1 && y == 2.), {x, y} \[Distributed] binormalDist ] is returned unevaluated (as is Expectation with identical args) NExpectation[ 3+ 2 x [Conditioned] x < 1 && y == 2., {x, y} [Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]] Why? And how can it be solved? Answer Since Probability[x < 1 && y == 2, {x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]] 0 and the PDF of the purported conditional

graphics - Animating mathematica.se logo

As we all know our site's logo was completely generated by Mathematica . I suppose it is quite natural to make the next step -- to generate the animated version of this logo. There's a lot of space for creativity here, and I suggest to consider the following options. Animated process of construction from scratch, as it is described in Verbeia's blog post. Animated morphing of original pentagonal star to the current heptagonal one (J.M.'s idea in the comment) Some less fussy, a neutral animation of the logo itself, more suitable for placing on webpages.

Series with a specified number of terms

I'm doing calculations with Series where I don't know the power of the leading order term. I would like to keep a specified number of terms, but since I don't know the leading order this is proving difficult. For instance, suppose I want only 3 terms in a series of some complicated function func[x]. I can call Series[func[x],{x,0,3}] This may return something like (* 1/x^3 + 1/x^2 + 1/(2 x) + 1/6 + x/24 + x^2/120 + x^3/720 + O(x^4) *) But, since I didn't know it was going to start at x^-3, I have computed more terms than I needed. (Or worse, it might have started at x^2 and I would not have computed enough terms.) So, the question is, can I write a function that will expand an expression and only keep N terms (without over-expanding and truncating, which is computationally wasteful)? It seems like this should be a simple task, but I'm finding it remarkably difficult. Any ideas? Answer The leading-order power in your series should be the limit as $x \to 0$ of $x f&

regions - How to extrude a planar mesh to a volume slice?

Is there an easy way to extrude a planar 2D-mesh to a volume slice? ring = RegionDifference[Disk[{0, 0}, 1], Disk[{0, 0}, 1/2]]; DiscretizeRegion[ring] The thickness of the slice is assumed to be small and should have only some element layers. Thanks! Answer If you want some control over the extruded mesh, under Applications in RegionProduct , there is a nice example. ring = RegionDifference[Disk[{0, 0}, 1], Disk[{0, 0}, 1/2]]; dr = DiscretizeRegion[ring]; pointsToMesh[data_] := MeshRegion[Transpose[{data}], Line@Table[{i, i + 1}, {i, Length[data] - 1}]]; data = Table[Exp[x], {x, 0., 0.5, 0.1}]; r1 = pointsToMesh[data]; rp = RegionProduct[dr, r1]; MeshRegion[rp, PlotTheme -> "Lines"] You can use Subdivide in place of data if you just want a uniform mesh like so rUniform = pointsToMesh[Subdivide[0, 0.1, 5]] rpUniform = RegionProduct[dr, rUniform]; MeshRegion[rpUniform, PlotTheme -> "Lines"]

formatting - SetPrecision with indexed variables

I have an expression as below: Equations = 2.0799361919940695` x[1] + 3.3534325557330327` x[1]^2 - 4.335179297091139` x[1] x[2] + 1.1989715511881491` x[2]^2 - 3.766597877399148` x[1] x[3] - 0.33254815073371535` x[2] x[3] + 1.9050048836042945` x[3]^2 + 1.1386715715291826` x[1] x[4] + 2.802846492104668` x[2] x[4] - 0.6210244597295915` x[3] x[4] + 4.943369095158792` x[4]^2 I want to write it in an output file. So I use the below code: removebracketvar[x_] := StringReplace[ StringReplace[ ToString[x], {"[" -> "", "]" -> "", "," -> "", "*^" -> "e", ".*" -> ".0*"}], Whitespace -> ""]; SetDirectory["C:\\folder"]; WriteString["eqfile.txt", removebracketvar[ ToString[Equations , InputForm, NumberMarks -> False]] ]; Close["eqfile.txt"] The slight problem with the code for me is that it inserts the floati

Custom operators; custom pattern matching with pure functions

What I'm trying to achieve in Mathematica is the creation of a binary operator whose operands are both pure functions over the natural numbers. The result of the operator should be another pure function over the natural numbers. To demonstrate concretely what I want, suppose I have the following functions defined: f[n_Natural]:=2*n; g[n_Natural]:=n-1; (There is no Head called "Natural" so the above pattern matching won't work. But I want f and g to accept only natural numbers. This is problem No. 1 [SOLVED]) I then want a binary operator defined like so: Needs["Notation`"]; CombinedFunction[f_NaturalFunction,g_NaturalFunction]:={#}/.{{x_Natural}:>f[#]+g[#]}}&; InfixNotation[ParsedBoxWrapper["\[CirclePlus]"], CombinedFunction]; Operating $f$ $\oplus$ $g$ yields a pure function $h$ that only takes a natural number as an argument. I have found a way of enforcing the domain of $h$ thanks to this thread , but I want to extend this to ensure t

mathematical optimization - Unexpected slowness of FindShortestTour through 9 points

This a very useful function, but it is very slow: FindShortestTour[{{0, 0}, {0.2`, 0}, {2, 1}, {2, 2}, {2, 2.5`}, {1.5`, 6}, {1.6`, 7}, {1.4`, 8}, {1.9`, 10}}]; // AbsoluteTiming {1.80721, Null} I tested just 9 points, which cost me almost $2s$. I think there is a bug is behind this behavior. So I reported to Wolfram Support ( CASE:3847386 ), but I received a response like: Thank you for contacting Wolfram Technical Support. I followed your example and evaluated it on my machine: FindShortestTour[{{0, 0}, {0.2`, 0}, {2, 1}, {2, 2}, {2, 2.5`}, {1.5`, 6}, {1.6`, 7}, {1.4`, 8}, {1.9`, 10}}]; // AbsoluteTiming (* {0.0847348,Null} *) Please consider resetting Mathematica and see if the issue can be resolved. My processor is a Intel® Core™ i5-6500 Processor , and when I run Needs["Benchmarking`"]; Benchmarking`BenchmarkReport[] , my system scored $1.29$ WolframMark points. Many time show it is a very low efficency function: Table[ First[ FindShortestTour[ {{0, 0}, {0.2

Sectional averages of a list

I am working in Mathematica. I have a table of 200 elements. I want to calculate the mean value for the first 20 elements, for the second 20 elements and so on, up to 200. I will get a table (matrix) of 10 elements. How I can solve this problem? Thanks for helping.

numerical integration - Animating the Lorenz Equations

I am trying to use the Animate command to vary a parameter of the Lorenz Equations in 3-D phase space and I'm not having much luck. The equations are: $\begin{align*} \dot{x} &= \sigma(y-x)\\ \dot{y} &= rx-y-xz\\ \dot{z} &= xy-bz \end{align*}$ Where $\sigma, r, b > 0$ are parameters to be varied. Insofar, I am using the NDSolve command to numerically integrate these equations, then ParametricPlot3D and the Evaluate command to plot them. Just for starters, I am trying to create an animate command to vary $\sigma$ for example from 0 to 10. Can anyone guide me in the right direction? My code looks like this so far: σ = 10; NDSolve[{x'[t] == σ (y[t] - x[t]), y'[t] == 28 x[t] - y[t] - x[t] z[t], z'[t] == x[t] y[t] - 8/3 z[t], x[0] == z[0] == 0, y[0] == 2}, {x, y, z}, {t, 0, 25}] Animate[ParametricPlot3D[ Evaluate[{x[t], y[t], z[t]} /. solution], {t, 0, 25}], {σ, 0, 25}, AnimationRunning -> False] This will generate an animated plot

numerical integration - How to improve accuracy of NIntegrate over ImplicitRegion

I'm trying to compute the area of a implicit region given as R = ImplicitRegion[ 0 < Sinh[u]/Cosh[v] < 1 && 0 < Sinh[v]/Cosh[u] < 1, {{u, 0, Infinity}, {v, 0, Infinity}} ] The region looks like this: RegionPlot[ 0 < Sinh[u]/Cosh[v] < 1 && 0 < Sinh[v]/Cosh[u] < 1, {u, 0, 2}, {v, 0, 2} ] I used NIntegrate (Mathematica 10.4) like this: NIntegrate[1, Element[{u, v}, R]] (* Out: 0.884886 *) However I happen to know that the correct answer should be $\pi^2/8 = 1.2337$. I'm reading the documentation for NIntegrate , but I'm quite overwhelmed by the amount of possible options. How can I improve the result of NIntegrate in this case?

plotting - How to change the default ColorData used in Mathematica's Plot?

This question leads on from the recent question What are the standard colors for plots in Mathematica? There it was determined that the default color palette used by Plot is equivalent to ColorData[1] (see the note at the end). This can be changed through the use of the option PlotStyle . My question is how can we make, e.g., the default color palette be ColorData[3] and have this default survive manual changes to other aspects of the plot styling? So, for example, let's make a list of monomials and some dashing settings fns = Table[x^n, {n, 0, 5}]; dash = Table[AbsoluteDashing[i], {i, 1, 6}]; Note that the default plot colors survive other choices to styling: GraphicsRow[{Plot[fns, {x, -1, 1}], Plot[fns, {x, -1, 1}, PlotStyle -> dash]}] The colors in the plot may be changed by locally setting PlotStyle , such as Plot[fns, {x, -1, 1}, PlotStyle -> ColorData[3, "ColorList"]] or by setting the default options. Let's do that and run the GraphicsRow command ag

Detecting and correcting gradational brightness variations in a grayscale image

I am trying to quantify the proportions of various components in a greyscale image (backscattered electron image of a polished rock sample). Here is the original image: bse = Import@"http://i.stack.imgur.com/eQece.png"; The image is comprised of components (minerals) that should have the same intensity response. For example, the abundant 'mid-grey' component (plagioclase) should have a fixed grey-level across the entire image. It doesn't. By masking the other components of the image and adjusting the contrast, the gradations in brightness become more obvious: bsek = ImageSubtract[bse, ColorNegate@Binarize[bse, {0.16, 0.24}]]; ImageAdjust[bsek, {3, 1.1}] There seems to be two effects: a first order decrease in brightness towards the bottom corners and a second-order periodic vertical striping (comprised of short wavelength gradients). Why bother? - Correcting for variations in brightness is an important step prior to segmentation analysis of the image By approximat

graphics - How to texturize a Disk/Circle/Rectangle?

The documentation for Texture states that " other filled objects " can be texturized: Texture[obj] is a graphics directive that specifies that obj should be used as a texture on faces of polygons and other filled graphics objects. And also: Texture can be used in FaceForm to texture front and back faces differently. Though I fail to apply a simple texture to any of the following objects. It seems like that "other filled objects" only include Polygon s and FilledPolygon s, and FaceForm does not work with those. img = Rasterize@ DensityPlot[Sin@x Sin@y, {x, -4, 4}, {y, -3, 3}, ColorFunction -> "BlueGreenYellow", Frame -> None, ImageSize -> 100, PlotRangePadding -> 0]; { Graphics[{Texture@img, Disk[]}], Graphics[{FaceForm@Texture@img, Disk[]}], Graphics[{Texture@img, Rectangle[]}], Graphics[{FaceForm@Texture@img, Rectangle[]}], (* Only this one works *) Graphics[{Texture@img, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, Ve

export - Problem with Exporting Grid to PDF

Grid[ArrayReshape[ Item[#, Background -> If[FreeQ[IntegerDigits@#, 3], White, Yellow]] & /@ Range@1000, {34, 30}], Dividers -> All] Export["1000-3.pdf", %] The Grid looks fine on the screen in MMA. But when exported, it became this The rest of the cells are all good part from the "fat" 1000. Answer Easy with ItemSize : gr = Grid[ArrayReshape[Item[#, Background -> If[FreeQ[IntegerDigits@#, 3], White, Yellow]] & /@ Range@1000, {34, 30}], Dividers -> All, ItemSize -> All]; Export["1000-3.pdf", gr]

scoping - Module and Manipulate: Why the Red Highlighting?

If I define a function that returns a Manipulate object, and the Manipulate has a local variable inside of it, the local variable is highlighted in red. Here's an example of what I mean: MyTrigDemo[f_] := Module[{plot}, plot[A_] := Plot[A Sin[2 \[Pi] f x], {x, 0, 1}, PlotRange -> {-3, 3}]; Manipulate[plot[A], {A, 0, 2}] ] displays as (v10.0.0.0) Despite the scary highlighting, the function seems to work as I expect. Is this structure inadvisable for some reason?

calculus and analysis - Solution to a specific problem caused by generic simplification

I'm trying to get MMA to help me evaluate certain integrals of trig functions. Here is an example: (The actual expressions I want to evaluate are more complicated than this one, but this illustrates the problem.) Assuming[ n ∈ Integers && m ∈ Integers, Integrate[Cos[n π x] Cos[m π x], {x, 0, 1}] ] (* 0 *) This answer is of course wrong, strictly speaking. The correct answer is $\frac{1}{2}\left(\delta_{n,m}+\delta_{n,-m}\right)$. As discussed here , for instance, MMA aims to produce generically correct results, and the special case $m=\pm n$ ends up being overlooked. I understand all that. My question is whether anyone can suggest a straightforward workaround to get MMA to produce a more generally correct result for slightly more complex cases such as Integrate[Sin[k π x] Cos[n π x] Sin[m π x], {x,0,1}] . To clarify, I will add that there is no difficulty evaluating the special cases, if you know what they are. For instance: Assuming[ n ∈ Integers, Integrat

plotting - Logarithmic scale in a DensityPlot and its legend

I was recently faced with the task of creating a DensityPlot with a logarithmic colour scale, and with providing it with an appropriate legend. Since I could not find any resources to this effect on this site, I'd like to document my solution here. For definiteness, suppose that I want a plot of the function $$ f(x,y)=\mathrm{sinc}^2(x)\mathrm{sinc}^2(y)=\frac{\sin^2(x)\sin^2(y)}{x^2y^2}, $$ which is the diffraction pattern of a square aperture , over a box of side 20. The problem with such a function, and the reason a logarithmic scale is necessary, is that the function has lots of detail over a wide range of orders of magnitude of $f$. Thus, doing a naive DensityPlot of it will produce either whited-out parts with a sharp boundary with the region where the contrast is acceptable, or one bright spot and lots of detail completely lost: (Images produced by DensityPlot[Sinc[x]^2 Sinc[y]^2, {x, -20, 20}, {y, -20, 20}, ColorFunction -> ColorData["DeepSeaColors"], PlotPoin

performance tuning - Combining list elements

I am doing the following: SeedRandom[1]; n = 3; data = {RandomInteger[10], RandomInteger[10, {4, 5}]} & /@ Range[n] {{1, {{4, 0, 7, 0, 0}, {8, 6, 0, 4, 1}, {8, 5, 1, 1, 1}, {3, 2, 10, 1, 6}}}, {0, {{2, 6, 4, 5, 4}, {3, 0, 1, 3, 5}, {3, 0, 3, 2, 3}, {9, 5, 1, 5, 2}}}, {3, {{9, 1, 0, 4, 4}, {1, 5, 2, 7, 9}, {9, 8, 10, 0, 10}, {10, 7, 4, 9, 2}}}} The result should be: Flatten[Table[Append[#, data[[i, 1]]] & /@ data[[i, 2]], {i, n}], 1] {{4, 0, 7, 0, 0, 1}, {8, 6, 0, 4, 1, 1}, {8, 5, 1, 1, 1, 1}, {3, 2, 10, 1, 6, 1}, {2, 6, 4, 5, 4, 0}, {3, 0, 1, 3, 5, 0}, {3, 0, 3, 2, 3, 0}, {9, 5, 1, 5, 2, 0}, {9, 1, 0, 4, 4, 3}, {1, 5, 2, 7, 9, 3}, {9, 8, 10, 0, 10, 3}, {10, 7, 4, 9, 2, 3}} Can you propose another FAST solution instead of using Table ? Answer Append @@@ Join @@ (Thread /@ Reverse /@ #) & @ data {{4, 0, 7, 0, 0, 1}, {8, 6, 0, 4, 1, 1}, {8, 5, 1, 1, 1, 1}, {3, 2, 0, 1, 6, 1}, {2, 6, 4, 5, 4, 0}, {3, 0, 1, 3, 5, 0}, {3, 0, 3, 2, 3, 0}, {9, 5, 1, 5, 2, 0}, {9, 1, 0, 4, 4,

mathematical optimization - What is wrong with my ArgMin expression?

I need to find the minimum of a function $mj_1^2+mj_2^2$ where my $mj$ are constrained. I wrote this expression: ArgMin[ {mj1^2 + mj2^2, mj1 == (M1 + 1)*p1, p1 ∈ Integers, mj2 == (M2 + 1)*p2, p2 ∈ Integers, MemberQ[{mj1, mj2} , couplesm]}, {mj1, mj2}] Indeed, my mj 's must be multiples of Mj + 1 , and they musn't be part of a list given by couplesm . When I evaluate it, I get the following message; ArgMin::infeas: There are no values of {mj1, mj2} for which the constraints False are satisfied and the objective function mj1^2 + mj2^2 is real valued. I even added p1 and p2 to the variables of minimization, but it still didn't work. How can I find the minimum of: $mj_1^2+mj_2^2$, where $mj_i$ is a multiple of $M_i+1$ and where the pairs $(mj_1,mj_2)$ can't be inside of the list couplesm ? Edit I wrote the following and the code still doesn't work. couplesm = {{0, 0}} {{0, 0}} ArgMin[ {mj1^2 + mj2^2, IntegerQ[mj1/(M1 + 1)], IntegerQ[mj2/(M1 + 1)], mj1

packages - PacletInfo.m documentation project

Packages can be made into paclets , which provides easy distribution and versioning. The paclet metadata is in the PacletInfo.m file. The PacletInfo settings also determine how the paclet can extend Mathematica: e.g. provide new functions for the kernel (a usual package), new palettes or stylesheets for the Front End, etc. What settings and extensions can be used in a PacletInfo.m file and what are their effects? Documenting these will be very useful for people who develop and publish packages. Related posts: Answer This is a community project to produce useful documentation for PacletInfo.m . Feel free to edit and improve this answer. While the Paclet Manager is loaded from .mx files, its plain text .m sources are also available. Much of the information in this post comes from the comments in those source files. See SystemOpen@Lookup[PacletInformation["PacletManager"], "Location"] , especially Extension.m and Paclet.m . Some other information comes from Pacl