Skip to main content

Posts

Showing posts from February, 2015

parallelization - How can we implement "Sleep Sort"?

Inspired by Implement Sleep Sort : Sleep Sort is an integer sorting algorithm I found on the Internet. It opens an output stream, and for each input numbers in parallel, delay for the number seconds and output that number. Because of the delays, the highest number will be outputted last. I would like to know if it is possible to implement this in Mathematica . As a version 7 user I would of course like to see a solution that works there, but I think that RunScheduledTask may be needed to accomplish this. Answer Here is an implementation that uses the scheduled tasks in version 8: sleepSort[l_, t_:0.1] := Scan[RunScheduledTask[Print[#];RemoveScheduledTask[$ScheduledTask], {t #}]&, l] In a notebook environment, output will appear in the messages window. The time interval is specified as the optional second argument, defaulting to 1/10th of a second (I'm impatient). Don't set it too low, though -- the vagaries of the timing might produce results out of order.

parallelization - Efficient way to utilise Parallel features to make use of many cores

Let's say I have 100 cores/kernels as my disposal and want to compute a function of two variables f[x,y] over {x,1,10} , {y,0,59} . So in total 600 data points. Ideally I would like to utilize all 100 cores giving each core 6 data points to compute. How can I achieve this? ParallelTable[f[x, y], {y, 0, 59 }, {x, 1, 10 }] Would only parallelize on the first 60 cores and give each core a workload of 10 points and ParallelTable[f[x, y], {x, 1, 10 }, {y, 0, 59 }] would do even worse- parallelizing on the first 10 cores and giving each a workload of 60 points. I think doing ParallelTable[f[x, y], {y, 0, 59 }, {x, 1, 3 }]; ParallelTable[f[x, y], {y, 0, 59 }, {x, 4, 6 }]; ParallelTable[f[x, y], {y, 0, 59 }, {x, 7, 10}]; Would only evaluate the three calls sequentially when the previous ParallelTable had finished so would also do not better? Is there a way around this? Answer I usually work around this by first generating all argument combinations, then using ParallelMap : ParallelMap[...

front end - Automatically scroll along with currently evaluating cell?

If I'm evaluating an entire large notebook, I usually just press Alt-V Y to find the currently evaluating cell. Is there a way to keep the currently evaluating cell automatically in focus so that the notebook automatically scrolls there without me having to press any keys? Answer I just tried this, and it seems to work. See if it works for you. Type this in first cell (thanks to Kuba suggestion, changed it to use SelectionMove[EvaluationCell[] ) SetOptions[EvaluationNotebook[], CellProlog :> SelectionMove[EvaluationCell[], All, Cell]] You can make the above an initialization cell. Then Evaluation->Evaluate notebook. now it will scroll down, keeping current evaluating cell in view all the time. reference: how-to-make-cursor-jump-automatically-to-next-input-cell-after-evaluating-previo

calculus and analysis - Integrating a difficult function (Numerically ?)

I've been trying to make the following integral but I get no results : Integrate[ (3/(16 + r^2)- 4/(6.25 + r^2)) E^(-2r^2) Sin[k r] r, {r, 0, Infinity}] I am new in Mathematica and I have tried with the function Integrate and NIntegrate . Is there any command so that I can get a result of the above integral? Thanks :D Answer The exact integration fails in this case. One can do this numerically. As much as I understand, you need to have the result as a function of k . If you do this numerically, the result may only be an approximate function. If this is what you agree to have, the following approach may be undertaken. First, note that because of the factor Sin[k r] your integral is highly oscillating at large values of k . In this case, it can be easily circumvented by the replacement k r->R . Let us introduce your expression staying under the integral as Clear[expr]; expr[k_, R_] := Simplify /@ (((3/(16 + r^2) - 4/(6.25 + r^2)) Exp[(-2 r^2)] Sin[k r]* r) /. r -> R...

list manipulation - How to repeat the nonblank string?

As the title, if I have a list: {"", "", "", "2$70", ""} I will expect: {"", "", "", "2$70", "2$70"} If I have {"", "", "", "3$71", "", "2$72", ""} then: {"", "", "", "3$71", "3$71", "2$72", "2$72"} And {"", "", "", "3$71", "","", "2$72", ""} should give {"", "", "", "3$71", "3$71", "", "2$72", "2$72"} This is my try: {"", "", "", "2$70", ""} /. {p : Except["", String], ""} :> {p, p} But I don't know why it doesn't work. Poor ability of pattern match. Can anybody give some advice? Answer As I presently interpret...

image processing - Measure perimeter of black edge in Mathematica

I have a pattern like the one below. How could I measure the total length of the perimeter of the black/white edge? This would give me a measure of spatial frequency. Any tips would be great! Thanks! Answer Edit You should be aware that there are 2 basic ways of counting perimeter pixels: 4-ways neighbors or 8-ways neighbors. The difference is about whether counting or not the yellow pixels in this figure: If you want to count them, then almost manually: i = Import["http://i.stack.imgur.com/7jt0I.gif"]; mask = Complement[Partition[#, 3] & /@ ({0, 0, 0, 0, 1, 0, 0, 0, 0} - RotateLeft[{1, 0, 0, 0, 0, 0, 0, 0, 0}, #] & /@ Range[9]), {Array[0 &, {3, 3}]}]; ip = ImagePad[i, 10, RGBColor[0.4980 {1, 1, 1}]]; is = Binarize@ ImageSubtract[ HitMissTransform[ColorConvert[ip, "Grayscale"], mask, .1], ImageSubtract[HitMissTransform[ColorConvert[ip, "Grayscale"], mask, .1], HitMissTransform[ColorConvert[ip, "Grayscale...

calculus and analysis - Neglect higher order derivatives in expression

Say I have an expression of this sort: Derivative[5][x1][t]+Derivative[3][x2][t]+x1[t]+Derivative[2][x1][t] and so on... I would like to ask Mathematica to neglext all expressions having derivatives higher than a given order (say N). What would be a good solution for that? Answer Derivative[5][x1][t] + Derivative[3][x2][t] + x1[t] + Derivative[2][x1][t] /. Derivative[k_][x_][t_] /; k >= 3 :> 0 x1[t] + (x1^[Prime][Prime])[t] For understanding /; see the documentation of Condition .

image processing - Nontrivial background removal

I have an image of a product on a poorly made green screen and need to segment out just the product: The problem is that it contains a mirror, so simple color-based methods are not enough. I tried playing with the function RemoveBackground using markers, but no luck. Here's what I tried so far: RemoveBackground[img, {"Background", Green}] RemoveBackground[img, {"Background", {"Uniform", 0.1}}] Update: With python and opencv can do it easily using the Grabcut algorithm referenced in the comments, but I can't find the way to do it with MMA. %matplotlib inline import numpy as np import cv2 import skimage from matplotlib import pyplot as plt img = cv2.imread(path_to_img) print "img", img.shape # resize side = 600 ratio = float(side) / max(img.shape) img = skimage.img_as_ubyte( skimage.transform.resize( img, (int(img.shape[0] * ratio), int(img.shape[1] * ratio)))) s = (img.shape[0] / 10, img.shape[1] / 10) rect = (s[0], s[1], img....

performance tuning - Radial distribution function

I have tried to rewrite my old IDL code to calculate the radial correlation function for a regular 2D crystal structure. The theory behind this function is given here: https://en.wikipedia.org/wiki/Radial_distribution_function Update 1: The radial density distribution counts the number of points in a distance between $r$ and $r +\Delta r$ from each considered central point (below one marked as red). The area of such a "shell" is $2\pi r \Delta r$. The density distributions are averaged for all center points and then normalized by the total point density times the ring area for each radius. Update 2: It is important that the maximum radius (the maximum shell) for each center point does not cross the edges of the available point coordiantes (corresponding to the range defined by the smallest and largest x and y point value). That means that a point close to the edges has a maller maximum radius (smallest distance to the next edge) than a center point (for a square: maximum rad...

Thread Part ([[]]) over two lists

When I try to Thread Part function over two nested arrays, the operation is performed as expected but i get a warning. I'm not sure if (and what) am I doing wrong. The code example is below. lst1 = {{5, -9, 15}, {12, -15, 4}} indices={{2,1,3},{1,3,2}} Thread[Part[lst1,indices]] and the output is {{-9, 5, 15}, {12, 4, -15}} as expected. However, the following warning was thrown. Part::pkspec1: The expression {{2,1,3},{1,3,2}} cannot be used as a part specification. >> Shouldn't Part be threaded over the list as described in the help under Thread function? Answer RunnyKine already explained in detail the source of the message. I would like to offer a couple of alternative formulations of a solution and comment on your attempt to use Hold . You commented: I tried Thread[Hold[Part[lst1,indices]]]//ReleaseHold . Apparently placed Hold at wrong place. Indeed, for two reasons. In this expression Hold is the active head of the argument of Thread so, if it were possible, ...

calculus and analysis - How to find the period of an arbitrary mathematical function?

Is there a function to find the period of an arbitrary (possibly complex) function in Mathematica ? Answer You can check out this one. I don't know how well it works Periodic`PeriodicFunctionPeriod[E^(I 2 Pi t) + Cos[3/9 Pi t], t] 6 Perhaps you are also interested in the other functions in that context. Check Names["Periodic`*"] EDIT As @Artes notes in the comments, in v10 there's a documented version of this function called FunctionPeriod

front end - How to change default notebook background color?

How does one change the default notebook background color? Answer You can SetOptions for the current notebook as: SetOptions[EvaluationNotebook[], Background -> LightGreen] to change the background to whatever colour you like. You can also supply an RGB colour as: SetOptions[EvaluationNotebook[], Background -> RGBColor[0.9, 0.7, 0.7]] Other possibilities for the first argument of SetOptions are $FrontEnd which will change the background for all notebooks and last across restarting Mathematica. $FrontEndSession which will change the background for all notebooks but won't be saved if you restart Mathematica.

plotting - In version 9 PlotLegends, how can I remove the strange edges that appear around LegendMarkers?

I'm running Mathematica version 9. I am using ListPlot to plot two sets of data. For each data set, I am using different PlotMarkers : for the first data set, I use red disks, while for the second data set, I use red rectangles. To do this, I define Graphics objects redDisk and redRectangle as shown below. (I have found that it is necessary to define nonzero ImagePadding to prevent the edges of the Graphics from being cut off.) Next, I want to display a plot legend describing the two different PlotMarkers . To do this, I want to use the PlotLegends option that is newly implemented in Mathematica version 9. I define a PointLegend called legend . Within PointLegend , I use pass in the objects redDisk and redRectangle to the LegendMarkers option. Then I give legend to the PlotLegends option of ListPlot and use the Placed function to position the legend in the plot. The code to do all of this is the following: (* Define PlotMarkers *) pm = 8; (* size of PlotMarkers *) re...

calculus and analysis - Generating evenly spaced points on a curve

In the KnotData package a simple command such as points = Table[KnotData[{3, 1}, "SpaceCurve"][t], {t, 0, 2 Pi, 0.1}]; will generate a series of points that comprise a knot (here, a trefoil, if successive points are connected). However, the distance between points is not constant; is there a way to generate evenly spaced points? (I.e. evenly spaced arc lengths between points).

Plotting the sum of curves without recalculation

I want to plot several curves of functions which are hard to calculate on the same plot. I would like to add to the same plot the sum of these functions without recalculating them twice at each point. So instead of Plot[{Sin[x], Sin[2 x], Sin[x] + Sin[2 x]}, {x, 0, 6 Pi}] I would like somthing like Plot[{aa = Sin[x], bb = Sin[2 x], aa + bb}, {x, 0, 6 Pi}] Answer How about this: f[x_] := Sin[x] Plot[{#1, #2, #1 + #2} &[f[x], f[2 x]], {x, 0, 4}] Strangely enough, this solution is slower that expected: f[x_] := NIntegrate[Sin[1/y^2], {y, -x, x}] (*slow function*) AbsoluteTiming[Plot[{f[x], f[2 x], f[x] + f[2 x]}, {x, 0, 1}]] (*naïve approach*) AbsoluteTiming[Plot[{#1, #2, #1 + #2} &[f[x], f[2 x]], {x, 0, 1}]] (*my solution*) AbsoluteTiming[Plot[With[{aa=f[x],bb=f[2x]},{aa,bb,aa+bb}],{x,0,1},Evaluated->False]] (*Szabolcs' comment*) (*65.7*) (*106.2*) (*102.0*) We do get a substantial improvement with memoization: f[x_] := f[x] = NIntegrate[Sin[1/y^2], {y, -x, x}] Absolut...

import - Importing FITS file from HEALPix

I am trying to read FITS file created by HEALPix software. The file contains a spherical map of a scalar field. There is the online support on how to use the file in IDL, but not for Mathematica. I understand FITS is partly binary format, but I expect it is still standardised and contains readable description on how the data is stored. I tried reading Elements from the file in this way Import["test.fits", #] & /@ Import["test.fits", "Elements"] but the output is quite short and mainly empty lists, especially for Import["test.fits", "Data"] Import["test.fits", "TableData"] The size of my file is 12.6 MB. Here is a link to the file. Is there another way to read the content of FITS file, besides these general 'Elements'? Do I need to know something about the structure of my FITS file in order to be able to read it with Mathematica? Could it be the problem is that Mathematica does not read all types of FIT...

neural networks - Has the usage of CrossEntropyLossLayer changed?

Reading this answer about CrossEntropyLossLayer , I find the following. But when I evaluate the same code, I get errors. CrossEntropyLossLayer[][ {1}, "Target" -> 1|>] CrossEntropyLossLayer[][ {2}, "Target" -> 1|>] CrossEntropyLossLayer[][ {20}, "Target" -> 1|>] CrossEntropyLossLayer[][ {200}, "Target" -> 1|>] So has the usage of CrossEntropyLossLayer changed? I am using Version 11.1.0 for Microsoft Windows (64-bit) (March 13, 2017)

function construction - How to pass a list of arguments into HoldAll

I have a list of arguments (which in reality is lengthy): arguments = {a, b, c} arguments2 = {a_, b_, c_} f[Sequence@@arguments2] := a + b + c Note : It seems awkward to define two lists here, there should be a better way to do this. And I want to numerically integrate a function of those arguments: int[Sequence@@arguments2] := NIntegrate[f[Sequence@@arguments], {x, 0, 1}] This does not work because of the HoldAll property of NIntegrate . Is there a way to do this correctly? Answer If your question is a duplicate of Injecting a sequence of expressions into a held expression the simplest solution is the same, the so-called "injector pattern": {a, b, c} /. _[args__] :> NIntegrate[f[args], {x, 0, 1}] NIntegrate[f[a, b, c], {x, 0, 1}] I did not close this as a duplicate however because it seems you would like to approach this problem differently. You could store your symbols in a single object, e.g.: syms = Hold[a, b, c]; Then create the Pattern sequence from these: toPat...

plotting - Calculate and plot the tangent hyperplane to a function of three variables

If f:= x^3 + y*x*z - z^2 + x*z and if {{1,2,1},{2,7,8},{6,0,2},{9,1,1}} are points, how can I find the tangent plane to f at the four points in the same time. I saw some codes to calculate the tangent , for example, tg[f_, x_, p_] := (f'[x] /. x -> p) (x - p) + f[p] q = #^3 - 3 #^2 &; Manipulate[ Plot[{q[x], tg[q, u, m] /. u -> x}, {x, -3, 3}, PlotRange -> {-5, 5}, Epilog -> {Red, PointSize[0.02], Point[{m, q[m]}]}], {m, -1, 1, 0.01}] but I am confused this did not answer my question. Thanks for any help.

replacement - How to replace the symbol n in DifferenceRoot

I'd like to employ another symbol (say alpha or k ) instead of n in the following (type of) function: DifferenceRoot[ Function[{\[FormalY], \[FormalN]}, {2 + 3 \[FormalN] - 2 \[FormalN]^2 - \[FormalN]^3 - (1 + \[FormalN]) (2 + \[FormalN]) \[FormalY][\[FormalN]] + \[FormalN] (1 + \[FormalN]) (2 + \[FormalN]) \[FormalY][1 + \[FormalN]] == 0, \[FormalY][1] == 0} ] ][n]

differential equations - Nonlinear PDE solver

I would like to solve the following nonlinear PDE: $$ \frac{\partial^2 \phi}{\partial x^2} - \frac{\partial^2 \phi}{\partial t^2} = \lambda |\phi|^2 \phi $$ I was trying: NDSolve[{D[f[x, t], x, x] - D[f[x, t], t, t] == f[x, t]^3, f[x, 0] == Sin[2*Pi*x], f[0, t] == 0, f[1, t] == 0}, f, {x, 0, 1}, {t, 0, 1}] but, I am consistenly getting NDSolve::femnonlinear: Nonlinear coefficients are not supported in this version of NDSolve . Is there any solver for non-linear PDEs? Answer The error message is misleading. NDSolve fails, because not enough boundary conditions in t have been supplied. If, for instance, (D[f[x, t], t] /. t -> 0) == 0 is added, then sol = First@NDSolve[{D[f[x, t], x, x] - D[f[x, t], t, t] == f[x, t]^3, f[x, 0] == Sin[2*Pi*x], (D[f[x, t], t] /. t -> 0) == 0, f[0, t] == 0, f[1, t] == 0}, f, {x, 0, 1}, {t, 0, 1}]; yields Plot3D[f[x, t] /. sol, {x, 0, 1}, {t, 0, 1}, AxesLabel -> {x, t, f}, LabelStyle -> Directive[Black, Bold, 12]]

packages - Strange behaviour of order of execution or bug?

In[1] and In[3] are identical but the output is different. Answer ? name is a special input form with nonstandard parsing behavior, just like >>> as explained here. When you write a line starting with ? the item following it is not a Symbol, contrary to appearances. Instead it is a String with implicit delimiters. This is not simply a matter of a hold attribute. For example HoldComplete[a^] is incomplete syntax and cannot be entered, yet: ?a^ Information::nomatch: No symbol matching a^ found. >> Using the same method as for the linked question we can take a look at parsing itself: parseString[s_String, prep : (True | False) : True] := FrontEndExecute[FrontEnd`UndocumentedTestFEParserPacket[s, prep]] parseString["?a^"] parseString["HoldComplete[a^]"] {BoxData[RowBox[{"?", "a^"}]], StandardForm} {BoxData[RowBox[{"HoldComplete", "[", RowBox[{"a", "^"}], "]"}]], StandardForm...

linear algebra - Find NullSpace of a very sparse symbolic matrix

Below is a matrix diagram, produced in Mathematica. In this case it's a $956\times 950$ rectangular matrix. The white parts are all zero. sa = Import["https://pastebin.com/raw/fiErKrhU", "Package"]; MatrixPlot[sa] I'm wondering if there is a way to efficiently compute the null space of this matrix. From a different calculation entirely (using a Molien series), I know in advance there should be 6 linearly independent vectors in this null space, and I already know one of them. The NullSpace routine takes too long to be feasible. I am hoping that there is a better way. I know that using NullSpace[N[m]] will return the answer rather quickly, but I am hoping to be able to do this symbolically. Any help would be appreciated. Update Added SparseArray data for this matrix. It was too large for this message so I put it on pastebin. https://pastebin.com/raw/fiErKrhU Answer Turns out this can be done with exact methods and a good option setting. And a dose of pati...

core language - Why can't a string be formed by head String?

Since everything is an expression in Mathematica , why must a string object be formed by "abc" but not by a String[abc] expression? You can look at a string's head by: Head["abc"] String But you can not produce the same string by String String[abc] which, from my point of view, seems inconsistent with the principle that Everything Is an Expression . However, I noticed that the basic Symbol object, on the other hand, can be formed by something like Symbol["a"] . The same question goes for four number objects ( Integer , Real , Rational , and Complex ). You can't say an integer 1 by something like Integer[1] , can you? Edit: Rational and Complex can be produced by their respective heads. So The question is valid only for String and two number objects, i.e. Integer and Real . Answer String and Integer are what I termed "implicit heads" while writing: Rather than being part of the standard expression itself, at least as I unders...

recursion - Solving problem using recursive functions

Attached below is a question posed by the Canadian Mathematical Society, and I have my code and answer. Is there a better way of writing the code, and will the answer be different as a result? My code and possible answer (edited): jk[0] = 0; jk[1] = 0; jk[2] = 1; jk[3] = 2; tr[n_] := If[n > 3, LengthWhile[Range[3, 20], Divisible[n, #1] & ] + 3, jk[n]] Sum[tr[tr[tr[m]]], {m, 1, 2006}] (* 2672 *) Let me know if you get an answer that differs. Answer You made a few mistakes. jk[0] should be 0 in your code and your function tr is wrong. Corrected version: t[0] = 0; t[1] = 0; t[2] = 1; t[n_] := t[n] = LengthWhile[Range[1, 11], Divisible[n, #1] &] + 1 Sum[Nest[t, m, 3], {m, 1, 2006}] 1171 10x faster version: t[n_] := t[n] = Module[{i = 1}, While[MemberQ[Divisors[n], i], i++]; i];

calculus and analysis - Finding the 1st three derivatives of a function and plotting all four curves

Plot all three; the function, its derivative and its tangent line at a given point. Then, find the second and third derivative of the function. f(x)= x^(3)-2x, x= -1 I know its something like this, but I kept getting the wrong answer or error messages. f[x_] := [[x^(3)-2x, x],{x-> -1}] f'[] f''[] f'''[] Plot[{f[x],f'[x],f''[x], f'''[x]},{x},PlotLegends->"Expressions"] Not sure about the tangent line Answer I like David Stork's answer, but I also think an answer more focused on the specific example give by the OP might be helpful. The given function f[x_] := x^3 - 2 x Its 1st derivative d1F[x_] = f'[x] -2 + 3 x^2 Note that I use Set ( = ), not SetDelayed ( := ), because I want the d1F to the specific derivative of x^3 - 2 x and not just a synonym for f'[x] . The tangent line At a given point, say x0 , the tangent line is the line passing through {x0, f[x0]} having slope f'[x0] and is given by f[x0]...

Association of Associations : how to permute level 1 and level 2 keys?

I have a ragged Association of Association , say : assoc = Association[ "1" -> Association["a" -> "x", "b" -> "y"], "2" -> Association[ "b" -> "z", "c" -> "k"] ] I would like to transform it into a Association where level 1 and level 2 keys are reversed, that is to say : Association[ "a" -> Association["1" -> "x"], "b" -> Association["1" -> "y", "2" -> "z"], "c" -> Association[ "2" -> "k"] ] My solution is : keysExplodedList = Reap[MapIndexed[Sow[Reverse[#2] -> #1] &, assoc, {2}]][[2, 1]] groupedLevel1 = GroupBy[#[[1, 1]] &] @ keysExplodedList groupedLevel2 = GroupBy[#[[1, 2]] &] /@ groupedLevel1 result = Map[#[[1, 2]] &, groupedLevel2, {2}] ...

scripting - Installing WolframScript (12) on OSX (Catalina)

I did a clean install of Catalina (OSX 10.15) and Mathematica 12.0 installation was flawless. However I can't install WolframScript which I greatly need. During the installation, after typing my password, I get the follong error: This package is incompatible with this version of macOS. The package is trying to install content to the system volume. Contact the software manufacturer for assistance. And I'm left with only a "Quit" button to click on. I can't find any mention of this issue on Google or here. Actually Google shows: No results found for "This package is incompatible with this version of macOS" mathematica. Thanks in advance for any help or hint on where/what to look into !

plotting - How can I use procedure, circle3D, to make an animation of the osculating circle of a parametric curve?

I try to use circle3D procedure, shown below, to make an animation of the osculating circle of a parametric curve. (* circle3D PROCEDURE *) (* Let's create circle3D that is something we would expect from Circle but with an extra argument for its normal vector *) circle3D[centre_: {0, 0, 0}, radius_: 1, normal_: {0, 0, 1}, angle_: {0, 2 Pi}] := Composition[ Line, Map[RotationTransform[{{0, 0, 1}, normal}, centre], #] &, Map[Append[#, Last@centre] &, #] &, Append[DeleteDuplicates[Most@#], Last@#] &, Level[#, {-2}] &, MeshPrimitives[#, 1] &, DiscretizeRegion, If][First @ Differences @ angle >= 2 Pi, Circle[Most @ centre, radius], Circle[Most @ centre, radius, angle]] I am a new user of this site and also of Mathematica . I found this procedure on the site. It works perfectly with Graphics3D , but when I try to use it o make an animation I receive an error with the following content: Coordinate Transformation...

simplifying expressions - Remove multiplicative constant A in equation A*f(x)=0

I would like to find x in the equation A*f(x)=0 for A>0. Since A is a very large expression, I would save time by solving f(x)=0 instead. Is there a way to let Mathematica "cancel out A" (even if it is an expression that not explicitly specified)? Note that FullSimplify does not do this job correctly (and certainly not fast enough) Example: Solve[(Q (-1 + A + Sqrt[x]))/B == 0] I would like to obtain the expression (without manual inspection): A + Sqrt[x] == 1

plotting - Nested Integrate and NIntegrate: Analytic and Numeric solutions?

Here is a function $F(r)$ which contains double integrations $$F(r)=\exp\left[ \int_{0}^r dw \,\exp\left(-\int_{0}^w ds \frac{s^2}{s^2+1} \left(1-\exp(- s)\right) \right) \right]$$ I am fine for either/both obtaining (1) a analytic solutions $F(r)$ (say, in terms of just a function of $r$), or (2) a numerical function of $r$ (say, a x-y plot of x=$r$ v.s. y=$f(r)$, even just a selection of points running from $\{r, 0, 100, 1\}$) I find the most challenge part is that the choices we can make for doing the Integrate and NIntegrate. How to wisely choose NIntegrate and Integrate to obtain the answer. For example, what will be the plot of Plot[F(r),{r,0,100}] or ListPlot[F(r),{r,0,100,1}] looks like? Answer The inner integral can be performed symbolically by si = Integrate[s^2 (1 - Exp[-s])/(s^2 + 1), {s, 0, w}, Assumptions -> w > 0] (* w - ArcTan[w] + 1/2 (-2 + 2 E^-w - I E^I ExpIntegralEi[-I] + I E^-I ExpIntegralEi[I] + I E^I ExpIntegralEi[-I - w] - I E^-I ExpIntegralEi[I - w...

graphics - Plot points shifted (a lot) in output and PNG export but not in PDF export

Bug introduced in 8 or earlier and fixed in 12.0.0 Consider the following code: Needs["SciDraw`"] Needs["PolygonPlotMarkers`"] plotData = {{1, 0}}; markers[size_] := Graphics[{PolygonMarker["Disk", Offset[size]]}]; plotA = ListPlot[plotData, PlotMarkers -> markers[8]]; plot = Figure[FigurePanel[{FigGraphics[plotA]}], CanvasSize -> {3, 2}] The plotted point is not where it's supposed to be, that is, at {1,0} . In fact, it is shifted by precisely {-0.5,0.5} . Only when exported to pdf (last panel) does the point appear at the right position. What could be the reason for this behavior? Note that both SciDraw and PolygonPlotMarkers seem to influence the result. At least I can't reproduce the phenomenon when not using both of those packages. However, independent of what those packages do, what could possibly lead to a different output in these two file formats? If it matters, I have tested this using version 11.0.1 and version 10.4.1 on 64 bit L...

options - Increasing notebook magnification pushes output onto a new line

When I increase the notebook magnification beyond a certain level, it pushes the output of a command onto a newline. It does this normally when you enter something like foo // FullForm , because Out[n]= gets replaced by Out[n]//FullForm= , which is so much wider that it has to start a newline for the output. But it's a shame that once n enters double-digits that at a certain magnification, the usual Out[n]= is just barely too wide, and this behavior occurs. Setting the magnification with SetOptions[EvaluationNotebook[], Magnification -> 1.65] is enough to get this behavior, but a magnification of 1.6 is still fine. Is there an easy way to avoid this behavior? Can we slightly increase the size of the margin where In[n]:= and Out[n]= live to avoid this issue? I'm running Mathematica 11.0 in Linux x86 (64-bit), and apparently this is an issue on OS X too, but not on Windows. Answer You can increase the CellMargins for the styles "Input" and "Output...