Skip to main content

Posts

Showing posts from June, 2015

implementation details - How does Mathematica solve a certain differential equation?

I was trying to solve a nonlinear differential equation with the following code. DSolve[3*x^2/D[u[x, y], x] + 3*y^2/D[u[x, y], y] == -1, u, {x, y}] And I got the following output: {{u -> Function[{x, y}, x^3/(-1 + C[1]) - y^3/C[1] + C[2]]}} I would like to see steps. So, I used the following code: WolframAlpha["DSolve[3*x^2/D[u[x,y],x]+3*y^2/D[u[x,y],y]\[Equal]-1,u,{\ x,y}]", IncludePods -> "Input", AppearanceElements -> {"Pods"}, PodStates -> {"Input__Show steps"}] But this did not give steps. Is it possible to understand how mathematica solved this differential equation? Answer @Nasser's method seems to be what Mathematica does internally. The following gives hints of the steps taken, and one can see the elements of Nasser's solution. Some is left to the user to guess. The first code modifies Integrate to print itself out; the second uses Trace to see the calls to Integrate . Block[{DSolve`print = Print}, ...

bugs - Authentication dialog for URLDownload / URLSave

Bug introduced in 11.0 and persists through 11.3 The original problem is was fixed in V11.2 but since then it returns File[path/to/file/that/does/not/exits] instead of 401 Failure/HTTPResponse like URLRead does. CASE:3877019 - confirmed The second one prompts the dialog: URLRead["https://httpbin.org/status/401", Interactive -> False] URLDownload["https://httpbin.org/status/401", Interactive -> False] but both should return 401 HTTPResponse since ref/URLDownload: URLDownload takes the options as URLRead . ref/URLRead Interactive - True - whether to allow interactive authentication dialogs Have I missed something? Is there a workaround? It probably can be narrowed to URLSave broken for "DisplayProxyDialog" -> False , but this is undocumented so I can't complain. related: How to omit the authentification dialog during URLRead? Inconsistent Authorization Dialog (401) handling Answer Before it is fixed one can use this quick workaround bas...

list manipulation - How to assign EdgeWeight to a multigraph?

I'm trying to make a program to illustrate the simplify process of a complex resistence network. I create a graph to represent the structure of the network and trying to use EdgeWeight to symbolize the value of resistence. but sometimes I'll need to deal with parallel resistence, so assigning EdgeWeight to them will be a problem. In simple graphs, one can use: gg=Graph[{1 2,2 3,3 1},EdgeWeight->{1,2,3}] to specify the weight of each edge. Then we can use PropertyValue to extract them: PropertyValue[{gg,#},EdgeWeight]&/@EdgeList@gg {1,2,3} But in a non-simple graph: gg=Graph[{1 2,1 2,2 3},EdgeWeight->{1,2,3}] It seems that EdgeWeight simply ignored the weight assignment for parallel edges and consider all parallel edges to be the same: PropertyValue[{gg, #}, EdgeWeight] & /@ EdgeList@gg {1,1,3} This put a great barrier on my programming, so how to solve this problem? How to allow multiple EdgeWeight assigned to parallel edges?

front end - Combine InputAlias with InputString to parse expressions from a string

My knowledge of low-level notebook programming is very limited so I would be very grateful for any input regarding the following issue: I would like to define an input alias (via InputAliases ) that evaluates parse[InputString[]] in-place (like selecting it and then performing Menu → Evaluation → Evaluate in Place or Cmd + Return ). The function parse will translate my textual input into an expression (and insert it at the current cursor position). Currently, I am using the following alias, SetOptions[EvaluationNotebook[], InputAliases->{"parse"->RowBox[{"parse","[","InputString","[","]","]"}]}] and the workflow looks like this ESC parse ESC to produce parse[InputString[]] Press Ctrl + . a few times to select parse[InputString[]] Evaluate in place via Cmd + Return Type something into the input field and press Return Basically, I would like to get rid of steps 2 and 3. I would appreciate any othe...

output formatting - Converting string representation of boxes into explicit boxes

It is very easy and convenient to write textual labels as Strings in the WYSIWYG mode. For example, I define a short form describing a linear model: "2D3O" , which means "two descriptors of type D and tree descriptors of type O". Everything is good so far. Now I wish to add superscripts and use standard palette to add them. I get Looks nice. But at some point I have a lot of such labels and wish to apply some formatting to all of them at once. For example, I wish to make all the digits Bold and all the letters Gray . FullForm shows internal structure and I see the string representation of boxes : This is not a format easy to deal with. The tutorial explains how to convert ordinary boxes to its string representation using ToString . But what is the general way to convert string representation of boxes into explicit boxes?

polynomials - Eliminating variables from system of equation using Eliminate or Solve

I have a system of equations for algebraic curve given by the zero locus of some polynomial encoded in the system of equations (I want to eliminate variable z and get algebraic curve in terms of x and y, C12 and C22 can be assumed to be integers and even positive if that helps): Eliminate[{y == z^(2 + 2 C12)/(-x^2 + z^2), 1 == ((x - z) (x/z)^(2 C12) z^(-2 - 2 C12 + 2 C22) (x + z))/(-1 + z^2)}, {z}] Eliminate::ifun: Inverse functions are being used by Eliminate, so some solutions may not be found; use Reduce for complete solution information. However Mathematica can't eliminate z. When I use Solve I get: Solve::nsmet: This system cannot be solved with the methods available to Solve. Maple gives some answers but they aren't very useful, for instance they don't give algebraic curve that I want. Is there any smart way to do what I want?

output formatting - How to make rational expressions formatted using FractionBox

This is what I get using Mathematica 9.0.1. Instead I want this: I know how to use MakeBoxes, Format and I thought this code would work: MakeBoxes[(1/2)(expr_), StandardForm]:= FractionBox[ MakeBoxes[expr, StandardForm], MakeBoxes[2, StandardForm]] But the code above and all variations that I tried have no effect. This has to be automated to get the look I want. My actual application is much more complicated. Answer There are multiple internal forms of x / 2 . I ran into the same problem here (with 1/4 ): Using Hold correctly with Simplify and ComplexityFunction This appears to work in all cases: MakeBoxes[expr_ / 2 | Rational[1, 2] expr_, fmt_] := FractionBox[MakeBoxes[expr, fmt], "2"] (3 + Sin[t])/2 You can better see what is going on with FullForm : HoldForm @ FullForm[expr_/2] HoldForm @ FullForm[Rational[1, 2]*expr_] Times[Pattern[expr,Blank[]],Power[2,-1]] Times[Rational[1,2],Pattern[expr,Blank[]]] You need to cover both the Power[2,-1] and Rational[1, 2] cases wi...

table - issue with Animate

I want to make a animation based on the dataset like data = Flatten[Table[{x, y, x^2 - y^2}, {x, -3, 3}, {y, -3, 3}], 1]; I show this data using a ListPlot3D. p2[θ_] := RotationTransform[θ, {0, 0, 1}] When I use Table to generate the different images, it works fine. test11 = Table[ ListPlot3D[p2[a][data] /. {x_, y_, z_} -> {x, y, z*a}, Mesh -> 5, MeshStyle -> White, Axes -> {False, False, True}, PlotRange -> {{-4, 4}, {-4, 4}, {-10, 10}}], {a, -1, 1, 0.1}] Export["anigraf2.GIF", test11, "DisplayDurations" -> 1] When I use 'Animate' to create the same output, Mathematica stops responding en I have to restart the software. Animate[ListPlot3D[p2[a][data] /. {x_, y_, z_} -> {x, y, z*a}, Mesh -> 5, MeshStyle -> White, Axes -> False, PlotRange -> {{-4, 4}, {-4, 4}, {-10, 10}}], {a, -1, 1, 0.1}, AnimationDirection -> ForwardBackward, AnimationRunning -> True, SaveDefinitions -> True] Is there somebody who has ...

programming - How to implement FittedModel like objects

In the course of making some RLink wrappers I want to have some richer containers like Mathematica does with its FittedModel code. I thought I had a good idea of how this might be done, i.e make a custom Format specification that hides some arguments and use DownValues to give different parts of the code. In looking at actual FittedModel objects this does not seem to be what is being done, as it has no DownValues . Also when you look at the FullForm it doesn't seem to have enough data to give back all the "Properties" available. My question is, is their documentation for making rich data objects like Mathematica is commonly doing these days? I do really want to understand how to use DownValues / SubValues to actually implement the type of behavior something like FittedModel has. ... Is there a way to make it clear that this is not covered by the linked to question (which just deals with the Format/Boxes issue)? Answer After some work and clarification from Leoni...

code request - Import camera parameters and data from *.sif image files?

By default, Andor 's line of scientific cameras saves data in an apparently undocumented *.sif format. Are there any Mathematica packages or code that can help import these data? I've inherited an archive of experimental data stored in this format, and I'd like to seamlessly process it in Mathematica . It seems that someone has managed to reverse engineer a limited portion of the format for Matlab ( sifread.m ), and there is also an ImageJ plugin for reading .sif images ( OpenSIF_.java ), but so far I haven't gotten these working with Mathematica .

How to find the non-differentiable point(s) of a given continuous function?

For example, the non-differentiable point of the function $f(x)=|x|$ is at $x=0$. How to find the non-differentiable points of a continuous function that is defined numerically? Answer If we define f[x] e.g. like this: f[x_] := Abs[x] the following returns interesting points: Reduce[ Limit[(f[x + h] - f[x])/h, h -> 0, Assumptions -> x ∈ Reals, Direction -> -1] != Limit[(f[x + h] - f[x])/h, h -> 0, Assumptions -> x ∈ Reals, Direction -> 1], x] x == 0 Let's try another function defined with Piecewise , e.g. g[x_] := Piecewise[{{x^2, x x > 0}, {1, 2 >= x >= 1}, {Cos[x - 2] + x - 2, x > 2}}] then we needn't use Assumptions in Limit : Reduce[ Limit[ (g[x + h] - g[x])/h, h -> 0, Direction -> -1] != Limit[ (g[x + h] - g[x])/h, h -> 0, Direction -> 1], x] x == 0 || x == 1 || x == 2 pts = {x, g[x]} /. {ToRules[%]}; Plot[ g[x], {x, -5/4, 3}, PlotStyle -> Thick, Epilog -> {Red, PointSize[0.023...

formatting - How does MakeBoxes handle an n-ary operator?

I want to format results from Reduce using the $\cup$ symbol instead of the $\lor$ symbol. For example, Reduce[x^2 > 4, x, Reals] produces $x 2$ while I would like it to produce $x 2$. My current solution is to add the head xO to use in place of the Or head and associate the appropriate formatting with the xO head using MakeBoxes . xO /: MakeBoxes[xO[x_, y_], form_] := RowBox[{MakeBoxes[x, form], "\[Union]", MakeBoxes[y, form]}]; When I want to invoke the special formatting, I simply substitute xO for Or . Reduce[x^2 > 4, x, Reals] /. Or -> xO This produces the desired result of $(x 2)$. I am feeling like a master bit-twiddler at this point. Of course, my next test case didn't work. Reduce[x^3 + 2 x^2 - x - 2 == 0] /. Or -> xO (* xO(x==-2,x==-1,x==1) *) My MakeBoxes[xO[x_, y_]] definition above does not match the case when xO has three arguments. I added the following to limp along a littl...

Plotting piecewise function with distinct colors in each section

I have a piecewise function that I would like to plot but I was wondering if it is possible that each part of the function that is plotted when its corresponding condition is true be plotted with a different color from the other parts. That is, if I have a Piecewise function Piecewise[{{val1, cond1},{val2,cond2},{val3,cond3}}] then I want val1 , val2 , and val3 to be plotted with different colors so that I can differentiate each case in the plot. Answer Here's an alternative approach than Spartacus' answer. What he did is splitting up the piecewise function into many different functions valid in only a small domain; what I am doing here is directly plotting the piecewise function as given, while the coloring is done using ColorFunction . I'll use the same function as Spartacus, f = Piecewise[{{#^2, # Now let's create a ColorFunction that does the desired thing out of this. I'll do this using Part , i.e. double brackets [[ ]] , which is not limited to lists only...

calculus and analysis - Center of mass of 2D region

The problem states: Find the center of mass of a thin plate covering the region between the​ x-axis and the curve $$y=20/x^2, 5 \leq x \leq8$$ if the​ plate's density at a point​ (x,y) is $\delta(x)=2x^2$. If the density were uniform I would find the center of mass using RegionCentroid : In[1]:= reg = ImplicitRegion[{5 Is there an "easy" way like this to compute the center of mass when the density function is given? I'm trying to avoid setting up integrals manually. It seems to me that what I need is Geometric Centroid. " http://mathworld.wolfram.com/GeometricCentroid.html " says: The centroid is center of mass of a two-dimensional planar lamina or a three-dimensional solid. The mass of a lamina with surface density function $\sigma(x,y)$..."*. "The geometric centroid of a region can be computed in the Wolfram Language using Centroid[reg] . However it doesn't work for me. Does this function still exist in Mathematica 11 or do I need to use Nee...

custom notation - Can we use letter with a subscript as a variable in Mathematica?

I tried Subscript[a, 0] = 1 (* 1 *) Clear[Subscript[a, 0]] During evaluation of Clear::ssym: Subscript[a, 0] is not a symbol or a string. >> Clear[a] Subscript[a, 0] (* 1 *) Any idea? Answer Yes you can, with limitations. You have at least three different ways to make an assignment to a subscripted symbol a 0 : make a rule for Subscript make a rule for a "symbolize" a 0 using the Notation package/palette In each case below, when I write e.g. Subscript[a, 1] this can also be entered as a 1 by typing a then Ctrl + _ then 1 . When you write: Subscript[a, 1] = "dog"; You make an assignment to Subscript : DownValues[Subscript] {HoldPattern[a 1 ] :> "dog"} You make a rule for a by using TagSet : a /: Subscript[a, 2] = "cat"; UpValues[a] {HoldPattern[a 2 ] :> "cat"} If you use the Notation palette you mess with underlying Box forms behind the scenes, allowing for assignment to OwnValues : Each of these can be cleare...

graphics - On drilling holes with minimal redundancy (and with colors!)

The old Mathematica package Graphics`Shapes` featured the function PerforatePolygons[] , which drilled a hole in any Polygon[] primitive present in a Graphics3D[] object. One would usually use it on the output of ParametricPlot3D[] or Polyhedron[] from the Graphics`Polyhedra` package, like so: Here is a slightly simplified implementation of PerforatePolygons[] which I used in generating the pictures above: perforateaux[points_, ratio_] := Block[{test = TrueQ[First[points] == Last[points]], center, q}, center = Mean[If[test, Most, Identity][points]]; q = 1 - 2 Boole[test]; MapThread[Polygon[Join[#1, Reverse[#2]]] &, Partition[#, 2, 1, {1, q}] & /@ {points, (center + ratio (# - center)) & /@ points}]] PerforatePolygons[shape_, ratio_: 0.5] := shape /. Polygon[p_] :> perforateaux[p, ratio] (I elected to remove the additional EdgeForm[] directive in the original implementation so that the images clearly show what is going on with each polygon. A prop...

matrix - How to accelerate combinations and sum calculations here?

I have a 4d matrix H defined as below (embedded with combinations and sums) H[n1_, n2_, n3_, n4_] := (1/(4*Sqrt[n1*(n1 + 1)*n2*(n2 + 1)*n3*(n3 + 1)*n4*(n4 + 1)]))* Sum[(-1)^(m1 + m2 + m3 + m4)*Binomial[n1 + 1, m1 + 2]*Binomial[n2 + 1, m2 + 2]*Binomial[n3 + 1, m3 + 2]*Binomial[n4 + 1, m4 + 2]* Binomial[m1 + m3, m1]*Binomial[m2 + m4, m2]*(m1 + m3 + 1)*(m2 + m4 + 1)* (((m1 + m3 + 2)/2^(m1 + m3))*Sum[Binomial[m1 + m3 + k + 2, k]/2^k, {k, 0, m2 + m4 + 1}] + ((m2 + m4 + 2)/2^(m2 + m4))*Sum[Binomial[m2 + m4 + l + 2, l]/2^l, {l, 0, m1 + m3 + 1}]), {m1, 0, n1 - 1}, {m2, 0, n2 - 1}, {m3, 0, n3 - 1}, {m4, 0, n4 - 1}] Here n1, n2, n3, n4 are indices that range from 1 to N . When N = 6, it takes my Mac (2.7 GHz Intel Core i5) about 30s to figure out the whole 4d matrix. However, it takes 1.5hrs for N=11. The time scaling is highly nonlinear.. The problem is that when N is big (N>20), it takes forever to run. Anyone has some good suggestion to accelerate the calculation? T...

output formatting - Real and/or improved CForm of expressions

I'd quite like to be able to automatically generate C++ versions of certain mathematical expressions that I've manipulated in Mathematica. The resultant C++ code fragment is then going to be used independently of Mathematica. Mathematica provides a CForm function, which almost seems like what I want, but I can't get it to do basic conversions nor tell it how to convert Mathematica symbols into my C++ identifiers. For example, I would like the output from CForm[x[0]^2] or ToString[x[0]^2, CForm] to be "std::pow(obj.x_[0], 2)" . This can be a string; it doesn't need to be usable in Mathematica any more. Of course, my actual expressions of interest are a lot more complicated than this. But: I don't have a way of telling Mathematica that symbol x is to be renamed to obj.x_ (not a valid symbol name in Mathematica so can't use it directly). String manipulation after conversion is too unreliable for this so a more direct method is preferred. I can't...

manipulate - Question about making TabView remember what tab to open

Background: Consider the following ( for the purpose of illustrating this question ) simplified, but working snippet of code. TabView[ { {patt, "Pattern" -> 1}, {motif, "Motif" -> Column[{ Button["Type", Print[" NOT IMPLEMENTED YET"], ImageSize -> 100], Button["New shape", Print[" NOT IMPLEMENTED YET"], ImageSize -> 100], Button["Pixel", Print[" NOT IMPLEMENTED YET"], ImageSize -> 100]}]} }, Dynamic[tab]] I have a GUI in a Module / Manipulate construction which contains a tabview that displays several views of the same data on its tabs. Each tab contains a series of buttons to further specify the particular view on that tab. Each tab consists several buttons and other controls, i.e. setterbars, 2D sliders. After each click or other action on a control the data is modified and all views are recalculated and displayed on the tabs. The issue is that after each tab ...

plotting - Plot3D: ColorFunction depending on (x,y) or z

While trying to answer this question I found out "weird" behavior of ColorFunction Plot3D[x y, {x, -10, 10}, {y, -10, 10}, PlotRange -> Full, ColorFunction -> Function[{x, y, z}, Hue@(x y)]] gives incorrect colors the virtually identical code (from naive point of view) Plot3D[x y, {x, -10, 10}, {y, -10, 10}, PlotRange -> Full, ColorFunction -> Function[{x, y, z}, Hue@z]] gives correct plot Also if you disable ColorFunctionScaling as many posts (e.g. this ) suggest Plot3D[x y, {x, -10, 10}, {y, -10, 10}, PlotRange -> Full, ColorFunction -> Function[{x, y, z}, Hue@(x y)], ColorFunctionScaling -> False] the colors are really messed up So the question - why are the first two plots different? A bug? I'm using Mathematica 11.1 on Linux. Answer As the documentation on ColorFunctionScaling says, ColorFunctionScaling is an option for graphics functions that specifies whether arguments supplied to a color function should be scaled to lie between 0 and...

Importing malformed XML: Import[... "XMLObject"] vs ImportString[..., "XML"]

It appears that Import[ url , "XMLObject" ] is more forgiving of improperly formatted XML than ImportString[ string, "XML"] . For example, Mathematica is happy to do this popNamesXML = Import["http://uscode.house.gov/popularnames/popularnames.htm", "XMLObject"]; but complains about this popNames = URLFetch["http://uscode.house.gov/popularnames/popularnames.htm"]; xml = ImportString[popNames, "XML"]; and barks about utf8 encoding for this ImportString[popNames, {"HTML", "XMLObject"}] In the Trace of the first snippet it appears these options are being passed to XMLGetString : {"NormalizeWhitespace"->True,"IncludeNamespaces"->Automatic, "ValidateAgainstDTD"->Automatic,"IncludeEmbeddedObjects"->None, "AllowRemoteDTDAccess"->True,"ReadDTD"->True,"IncludeDefaultedAttributes"->False, "AllowUnrecognizedEnti...

Passing a function as an argument to another function using the same variables

I define a function with two variables and an argumment which is a function of this two first variables. For example the function Ttrho below (the two variables are T and Rho and pTt is a function of T or Rho or both): getAllVariables[expr_] := Union@Cases[expr, Except[__Symbol?(Context@# === "System`" &), _Symbol], {1, ∞}, Heads -> True]; Ttrho[T_, ρ_, pTt_] := With[{var = getAllVariables[pTt]}, Print[var]; If[Length@var > 0, Apply[pTt, var /. Thread[var -> {T, ρ}]] 5 0.069/ρ, pTt*5 0.069/ρ]] I would like that the three results below must have the same value: Ttrho[1, 0.1, Function[{T, ρ}, T]] Ttrho[1, 0.1, Function[{ρ, T}, T]] Ttrho[1, 0.1, Function[T, T]] But I obtain actually the following results: During evaluation of In[1]:= {T,ρ} Out[1]= 3.45 During evaluation of In[2]:= {T,ρ} Out[2]= 0.345 During evaluation of In[3]:= {T} During evaluation of In[3]:= Thread::tdlen: Objects of unequal length in {T}->{1,0.1} cannot be combined. Out[3]= 3.45 Thank yo...

special functions - Visualizing vector spherical harmonics

I have painstakingly derived the vector-spherical harmonics $\mathbf{V}_{J,\,M}^\ell(\theta, \phi)$, which are the generalization of ordinary spherical harmonics $Y_\ell^m(\theta, \phi)$ to vector fields. But now, I would like to visualize them. The vector-spherical harmonics takes three integers ($\ell$, $J$, $M$), and yields a 3D vector field on the surface of a sphere ($\theta$, $\phi$). The integers are subject to the constraints: $J\geq0$, $\ell\geq0$, $|J-\ell|\leq 1$, $|M|\leq J$. The function VectorSphericalHarmonicV below generates a 3-component complex vector. Clear[ϵ]; (*Polarization vector*) ϵ[λ_] = Switch[λ, -1, {1, -I, 0}/Sqrt[2], 0, {0, 0, 1}, 1, {1, I, 0}/Sqrt[2] ]; Clear[VectorSphericalHarmonicV]; VectorSphericalHarmonicV[ℓ_, J_, M_, θ_, ϕ_] /; J >= 0 && ℓ >= 0 && Abs[J - ℓ] Sum[ If[Abs[M - λ] SphericalHarmonicY[ℓ, M - λ, θ, ϕ]*ϵ[λ], {λ, -1, 1} ] (*Examples*) VectorSphericalHarmonicV[1, 1, -1, θ, ϕ] VectorSphericalHar...

Explaining error when using Part inside Module in Dataset

I have a vague recollection of seen an explanation for this, but I can not find it, so it may be a false memory. Will delete if duplicated. Let ds be a simple Dataset ds = Dataset@Table[ i, "data" -> RandomReal[1, 4]|> , {i, 3}] This does NOT work (error message: k is not a valid part specification, Tag: dataset) ds[All, Module[{k = 2, l}, l = #data[[k]]; l|>] &] But these very similar expression do work fine ds[All, Module[{k = 1, l}, #data[[k + 1]]|>] &] (* Example 1 *) ds[All, Module[{k = 2, l}, l = #data[[k]]]|> &] (* Example 2 *) ds[All, Module[{k = 1, l},l = Extract[#data, {k + 1}]; l|>] &] (* Example 3 *) Using Block instead of Module gives the same result. Where does this error come from? Using Mathematica 11.0.1 on Windows 7 64 bit. Answer Cause The problem is caused by a type-inferencing failure. When presented with a complex expression, the type inferencer will sometimes give up and tag the expression as being of ty...

plotting - Discrete-time Lyapunov exponent plot

I am trying to create a Lyapunov exponent plot as a function of $\alpha$ for two functions: $$ f(x) = (\alpha + 1)x - \alpha x^{3} $$ and a piecewise function given by following Mathematica code: f[x] = Piecewise[{{-1, x 1}, {x * (1 - alfa) + alfa, 1 >= x > alfa}, {x * (1 - alfa) - alfa, -alfa > x >= -1}, {x * (2 - alfa), alfa >= x >= -alfa}}] Here you have an appropriate manipulation plot for second function: Manipulate[Plot[Piecewise[{{-1, x 1}, {alfa + (1 - alfa) x, 1 >= x > alfa}, {-alfa + (1 - alfa) x, -alfa > x >= -1}, {(2 - alfa) x, alfa >= x >= -alfa}}, 0], {x, -2, 2}], {alfa, 0, 1}] There is already a similar post here but I don't know how to apply that solution to my case. Is it even possible for discontinuous functions like my second piecewise function? I would like to achieve a plot similar to those made for logistic map found on the internet: Answer Something like this? g[x_, alfa_] := (alfa + 1) x - alfa x^3; p[x_, alfa_] := ...

dataset - DeleteMissing level spec confusion

Given: titanic = ExampleData[{"Dataset", "Titanic"}] Why does this correctly delete Missing[] elements: titanic[GroupBy@Key@"class", DeleteMissing[#, 1] &, "age"] // Normal but not the default level spec? Seems to violate key transparency in Associations/Datasets . titanic[GroupBy@Key@"class", DeleteMissing, "age"] // Normal (* {29, 1, 2, 30, 25, 48, 63, 39, 53, 71, 47, 18, 24, 26, 80, Missing[], 24, 50, 32,... |> *) DeleteMissing also works on the bare list, as would any function applied at that Dataset slot. On the other hand: {29, 1, 2, 30, 25, 48, 63, 39, 53, 71, 47, 18, 24, 26, 80, Missing[], 24, ... |> // DeleteMissing[#, 2] & Level 2 is the minimum needed to delete missing element? Answer UPDATE The described behaviour is not a bug as DeleteMissing is explicitly listed as a descending operator in the documentation. See the response by @TaliesinBeynon. I will delete this response after the ...

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

graphics3d - How to generate random non-overlapping cylinders of fixed radius and height in a fixed cube?

I have seen these two questions ( first ) ( second ) which are related to generating non-overlapping cylinders in a cube. I am trying to adapt them to my goal which is to generate random non-overlapping fixed cylinders (radius=10nm and height=20nm) in a cube of (100*100*100 nm) . The number of cylinders would be 20, 40 and 60 for the three cases that I would like to build. This makes the volume fraction in the range of around 0.1, 0.2 and 0.3 for the three cases. Then at the end I would like to export the coordinates of each cylinders (x1,y1,z1) &(x2,y2,z2) in a file. I have been using the following reference code as an example and trying to modify this. p1.p1 + p2.p2 - 2 p1.p2 ((p1.p1 + p2.p2 - 2 p1.p2) /. {p1 -> p1i + dp1 t1, p2 -> p2i + dp2 t2}) // tf // Expand (* p1i.p1i - 2 p1i.p2i + p1i.(dp1 t1) - 2 p1i.(dp2 t2) + p2i.p2i + p2i.(dp2 t2) + (dp1 t1).p1i - 2 (dp1 t1).p2i + (dp1 t1).(dp1 t1) - 2 (dp1 t1).(dp2 t2) + (dp2 t2).p2i + (dp2 t2).(dp2 t2) ...