Skip to main content

Posts

Showing posts from October, 2015

Generate a sample from a multivariate Cauchy distribution

I want to generate a random sample from a multivariate Cauchy distribution, however I couldn't find a function for the multivariate Cauchy in Mathematica . I know how to define a distribution in 1D and tried to do this in a similar way MultivariateCauchy[x_, μ_, Σ_, k_] := Gamma[(1 + k)/2]/(Gamma[1/2] π^(k/2) Sqrt[Det[Σ]] (1 +(Transpose[x -μ].Inverse[Σ].(x -μ))^((1 + k)/2))) MCdist[μ_, Σ_, k_] := ProbabilityDistribution[MultivariateCauchy[x, μ, Σ, k], {x, -∞, ∞}] where $\mu$ is the location vector, $\Sigma$ a positive definite covariance matrix and a free scalar parameter $k$. However, this does not work with RandomVariate . Is there a way to do this?

function construction - Composition of mappings not working as expected

I have two functions $f,g:\mathbb{R}^2 \to \mathbb{R}^2$ and I define a third one $h:\mathbb{R}^2 \to \mathbb{R}^2$ as the composition $$h(x,y) = g(f(x,y))$$ I'm trying to get this function into Mathematica as a composition because I still want the functions $f,g$ and I don't want to have to manually update $h$ when I change $f$ or $g$. So here is what I'm currently doing : 1. Define f[x_, y_] := {E^x + y, Sin[2 x]} 2. Define g[x_, y_] := {2 x + Cos[y], E^(x + y)} 3. Try the obvious definition of h[x_, y_] := g[f[x, y]]. This doesn't seem to work. I'll just get things like h[0, 0] returning g[{1, 0}] . I could write $h$ using the projection of $f$ onto the standard basis for $\mathbb{R}^2$ with the Projection function but this seems needlessly cumbersome and adds conjugate statements everywhere. Can anybody point out a better direction for defining $h$ as a composition? Also I have tried the Mathematica function Composition and it behaved the same way. Answer ...

parallelization - Effective parallel processing of large items

When trying to parallelize a task which involves items of larger sizes , I cannot achieve efficient parallelization. To demonstrate this, we launch some kernels: LaunchKernels[12]; I am facing this problem with real-world data which I cannot share here. Instead, we generate some random data and adjust the following parameters to a) reflect the problem and b) get some reasonable timings: itemsize = 20000; (* The size of an individual item *) numberofitems = 200; (* Number of items to process *) difficulty = 500;(* Processing diffculty: the part of an individual item that is actually processed *) Now let's generate the random values: randomValues = Parallelize@Table[ Transpose@{RandomReal[1, itemsize], RandomReal[1, itemsize]}, {numberofitems} ]; An individual item has 320 kB, the full dataset is 64 MB in size: ByteCount /@ {randomValues[[1]], randomValues} (* {320152, 64032072} *) Now we compare Map and ParallelMap with an arbitrary function that takes a reasonable amount ...

programming - How to create a variable List

I need, given "n", create a list {a1,a2,...,an}. For example: Given n=3, the list that must be created is composed by the symbolic variables {a1,a2,a3}. Sorry if this question is simple. Does anybody knows how to do it? Thanks. Answer For example, for n=5 Table[Symbol["a" ToString[i]], {i, 5}] but consider that in any case it may not be optimal for what you need to do. If you want to share what you are planning to use this list for, we may help you with a better construct.

graphics - Grid ItemSize is smaller than expected

If I execute MatrixPlot@IdentityMatrix@100 , the result is a good size. However, if I evaluate Grid[{{200!}, {MatrixPlot@IdentityMatrix@100}}, ItemSize -> Automatic] the MatrixPlot is much smaller, even when the page is wide. How can I make the MatrixPlot appear at its original size in the Grid ? I'd prefer not to hard-code the size. The picture shows that the second MatrixPlot is too small. Answer If you set ImageSizeMultipliers -> 1 then the graphics will not be downsized when appear inside list-like constructs: Style[ Grid[{{200!}, {MatrixPlot@IdentityMatrix@100}}, ItemSize -> Automatic], ImageSizeMultipliers -> 1] Alternatively, Grid[{{200!}, {MatrixPlot@IdentityMatrix@100}}, ItemSize -> Automatic, BaseStyle -> ImageSizeMultipliers -> 1] or Grid[{{200!}, {MatrixPlot@IdentityMatrix@100}}, ItemSize -> Automatic, ItemStyle -> ImageSizeMultipliers -> 1] give the same output.

differential equations - Limitations of ParametricNDSolve family w.r.t objective functions

Observation: I can see even for very simple modification in case of an scalar objective involving an definite integral in time ParametricNDSolve fails. Here is an example! eqns = {y''[t] + y[t] == 3 a Sin[y[t]], y[0] == y'[0] == 1}; pfun =ParametricNDSolveValue[eqns,Integrate[y[s] - a s, {s, 0, 5}], {t, 0, 5}, {a}, Method -> {"ParametricSensitivity" -> "ForwardSensitivity"}]; pfun[1.5] Meaningless output! Same kind of output for pfun'[1.5] but from pfun''[1.5] onwards for higher derivatives we get numerical values which I guess are totally wrong. However everything will be fine if one uses Integrate[y[s], {s, 0, 5}] ! So I tried {"ParametricSensitivity" -> "AdjointSensitivity"} which is most suitable for integrated objective functions. Again failure but this time for both the cases. We get the following error ParametricNDSolveValue::adjsens: The adjoint sensitivity method cannot be used for the output function...

plotting - Remove the extra white-space padding introduced by implicit use of Inset in GraphicsColumn

Simple Context This is a question about understanding how Inset really works and how GraphicsColumn and the like automatically calculate pos , opos , and size (and what those really mean) in Inset[fig, pos, opos, size] . Related posts that I have perused at (variable) length include I am still digesting the first, and the second doesn't solve the particular problem I am facing (although it is exceedingly useful). Greater Context I have an established workflow that allows me to generate journal-ready figures with correct widths, correct font sizes, good quality, and small-enough file size. The journals in which I publish are usually two-column format, so I often have multiple figures that include (at least) two plots in a column format. An archetypical example is shown Frame d below on the right: (By the way, the color function was adapted from the seaborn color schemes as worked out in the answers to this question .) The workflow typically involves something like the following....

list manipulation - Using Gather to rearrange my data

I have a list of elements: {{1, 2}, {1, 5}, {2, 6}, {3, 7}, {4, 8}, {5, 6}, {5, 9}, {9, 13}, {10,11}, {11, 12}, {11, 15}, {15, 16}} I have to divide it into sublists, so that: #1[[1]] == #2[[1]] || #1[[1]] == #2[[2]] || #1[[2]] == #2[[1]] || #1[[2]] == #2[[2]] & i.e. at the end I need to obtain: {{{1, 2}, {1, 5}, {2, 6}, {5, 6}, {5, 9}, {9, 13}}, {3, 7}, {4, 8}, {{10,11}, {11, 12}, {11, 15}, {15, 16}}} However, I cannot find a solution to do it with Gather . How can I accomplish this task?

Why isn't my Stream code plotting multiple solution curves?

My code is: VectorPlot[ {1, y*(1 - y) - 0.2 + 0.1*Cos[2*x]}, {x, 0, 15}, {y, 0, 1.2}, FrameLabel -> {x, y}, Axes -> True, VectorScale -> {Small, Small, None}, VectorStyle -> Gray, StreamPoints -> Coarse, StreamStyle -> {Blue, Thin, "Line"}, StreamScale -> Full ] and my image is I'd like more than one blue line following my solution curve... Thanks!

How to set return type of `InterpolatingFunction ` in compile

Consider this s = C1 /. First@NDSolve[{I C1'[t] == C2[t] E^(-I t), I C2'[t] == C1[t] E^(I t), C1[0.] == 1., C2[0.] == 0.}, {C1, C2}, {t, 0., 10.}] sol[t_] := Piecewise[{{s[t], t On["CompilerWarnings"] f3 = Compile[{{t, _Real}}, Evaluate@sol[t]] I get warnings because compile doesn't know the return type of InterpolatingFunction Compile::noinfo: No information is available for compilation of InterpolatingFunction[{{0.,10.}},{4,31,1,{107},{4},0,0,0,0,Automatic}, >,{Developer`PackedArrayForm,{0,2,4,6,8,10,12, >,90,92,94,96,98, >},{1. +0. I,0. +0. I,1. +0. I,-0.000102139+0. I,1. +1.06555*10^-12 I, >,-0.5557+0.183522 I,0.767381 +0.0556081 I,-0.598783+0.22247 I, >}},{Automatic}][t] . The compiler will use an external evaluation and make assumptions about the return type. >> and it failed to use the compiled version f3[5.] During evaluation of In[38]:= CompiledFunction::cfex: Could not complete external evaluation at instruction 3; proceeding...

plotting - Select one among multiple solutions that satisfies a certain condition and 3D Plot it with varying simulation values

My function is as follows: $$f(x)=ax^5+bx^4+cx^3+dx^2+ex+g=0$$ Since it does not generate an analytical solution, I tried to do a simulation exercise as follows. Simulation values: $a=-2$ , $b=3$ , $c=5$ , $g=3.5$ . And for $0\leqslant d\leqslant 1$ and $0\leqslant e\leqslant 1$ , among five different solutions, I would like to pick the one that is real and positive, and 3DPlot it against $d$ and $e$ . My Mathematica code is as follows: Plot3D[x/.sol=Select[{Solve[ax^5+bx^4+cx^3+dx^2+ex+f==0,x]},#>0&,1],{d,0,1},{e,0,1}] And the result I get is this: Any help would be greatly appreciated!

export - Exporting files while running .m file from command line

I have the following code in a .m file which is called test.m: Export["test.csv",0]; Exit[] I would like to run this .m file from the command line. I found that I can do that with the command "math -initfile test.m". It seems to work, but when I check out the produced .csv file (it does get produced), I find that it's empty (so does not contain 0). When I run the .m file using the GUI it produces the .csv file with 0. Anyone know how I can get this working from the command line? Thanks Answer I can reproduce something similar to your issue but I cannot fully understand why. However, if you want an alternative command, that works at least on Windows 7, here is how to do. Add the mathematica installation folder in the system's path variable. From the command line, move to the folder where the test.m file is saved (I have it in "C:\temp\") and run the following math using -initfile seems to have a different behavior because it asks to me the mathker...

pattern matching - position of sequence of elements in list

Possible Duplicate: Finding a subsequence in a list Question The position of {3, 5} is the list {1, 3, 4, 3, 5, 5, 1} is 3. How can such a position be found fast when dealing with large lists? Attempt This is what I could think of: list = Table[RandomInteger[3], {200}] ToString[FromDigits[%]] StringPosition[%, "123"][[1, All]] Out put example: {1, 3, 2, 3, 1, 2, 2, 0, 0, 1, 0, 2, 3, 0, 2, 1, 2, 2, 3, 3, 1, 0, 1, 3, 1, 1, 0, 3, 1, 3, 2, 2, 2, 1, 2, 0, 2, 0, 2, 2, 3, 1, 3, 1, 1, 1, 1, 3, 3, 1, 3, 1, 0, 2, 3, 1, 0, 3, 2, 3, 0, 1, 1, 3, 3, 3, 2, 1, 3, 0, 1, 0, 1, 0, 3, 1, 1, 2, 0, 0, 2, 0, 1, 3, 1, 2, 0, 2, 0, 2, 2, 2, 2, 2, 3, 1, 0, 3, 1, 2, 0, 3, 3, 2, 3, 1, 2, 3, 0, 0, 1, 2, 1, 2, 3, 2, 0, 1, 3, 1, 1, 1, 3, 2, 3, 3, 2, 0, 2, 3, 0, 3, 0, 3, 3, 2, 3, 2, 3, 1, 0, 1, 3, 0, 1, 1, 2, 2, 1, 2, 3, 3, 2, 3, 0, 2, 0, 3, 3, 2, 2, 0, 2, 3, 3, 2, 2, 0, 2, 2, 2, 3, 1, 3, 2, 0, 2, 0, 3, 3, 1, 0, 1, 2, 1, 2, 0, 0, 1, 0, 1, 0, 0, 2, 0, 3, 2, 1, 2, 2} "132312200102302122331013110313222120...

machine learning - How to visualize attention?

In the articles about sequence attention we can see images like this: Here we see that while translating from French to English, the network attends sequentially to each input state, but sometimes it attends to two words at time while producing an output, as in translation “la Syrie” to “Syria” for example. Here is the Mathematica code: attend = SequenceAttentionLayer[ "Input" -> {"Varying", 2}, "Query" -> {"Varying", 2} ] // NetInitialize attend[ "Input" -> {{1, 2}, {3, 4}, {5, 6}}, "Query" -> {{1, 0}, {0, 1}, {0, 0}, {1, 1}} |>] {{2.24154,3.24154},{1.55551,2.55551},{3.,4.},{1.29312,2.29312}} My question is: "How to visualize it?" Yes, I can use ArrayPlot . But I don't understand the output. Why it has such dimension? According to the documentation it's okay. But I expected the output 3x4 or 4x3. Because dimension 2 in "Input" and "Query" is the size 2 embedd...

output formatting - What's the difference between 56 and Integer[56]?

I'm trying to grasp how to Wolfram Language uses symbolic expressions for everything. The concept of doing so makes sense to me, but the language doesn't behave how I predict. I understand how writing x + y is really writing Plus[x, y] . But my understanding then predicts that writing 56 is really writing Integer[56] . And that writing something like 2 + 3 is really writing Plus[Integer[2], Integer[3]] . FullForm says otherwise, though. If I do FullForm[56] I just get back 56 . And if I do FullForm[Integer[56]] I get back Integer[56] . TreeForm agrees with FullForm . Here is what predict I should see when doing TreeForm[Integer[56] + 56 * 2] : And here's what I actually get: So what's happening to cause these difference between my prediction and what I actually see? Edit: The answer may have something to do with "atomic objects", which are briefly discussed here: https://reference.wolfram.com/language/tutorial/BasicObjects.html#15871 It's not ve...

export - Why do I sometimes get errors when exporting 3D graphics which have been translated or scaled?

Update notice: The expression returned by "Faces" changed in V11, so an alternative for V11 has been included. When I try and export 3D graphics, I get an error if some of the graphics complexes are translated. For example: r1 = PolyhedronData["RhombicDodecahedron", "Faces"]; (* works in V10 *) r1 = PolyhedronData["RhombicDodecahedron", "GraphicsComplex"]; (* fix for V11 *) trans = 2 Table[ Mean[PolyhedronData["RhombicDodecahedron", "VertexCoordinates"][[ n]]], {n, PolyhedronData["RhombicDodecahedron", "FaceIndices"]}]; r2 = Table[ Translate[r1, n], {n, Table[Accumulate[RandomChoice[trans, m]], {m, 6}]}]; exp = Graphics3D[r2, Boxed -> False, SphericalRegion -> True]; Export["rhomdod2.obj", exp] gives the errors Export::type: Graphics3D cannot be exported to the OBJ format. >> Export::type: RuleDelayed cannot be exported to the OBJ format. >> ...

How to display colored graphics object in the same color space?

Consider, I have a disk colored in " LAB " color space. When I convert the graphics into image object it is by default getting converted into " RGB " color space. ImageColorSpace@Image[Graphics[{LABColor[0.4, 0.6, 0.8], Disk[]}]] "RGB" If I now convert it back to " LAB " color space, ColorConvert[ Image[Graphics[{LABColor[0.4, 0.6, 0.8], Disk[]}]], "LAB"] The color value that I get is {0.40047, 0.603491, 0.548764} (* Sorry, this was a mistake on my part. Duely corrected after following the answer by Theelepel *) How can I get the original color value in the " LAB " color space? Updated question: If the original color value is not known and I am given only with the final Graphics object showing RGB color value, How can I retrieve the original LAB color value? Updation 2: Following the answer of corey979 to this question, I can see Table[data = ImageData[ ColorConvert[Graphics[{LABColor[0.4, 0.6, b], Disk[]}], ...

list manipulation - Replace values which obey certain criteria

I'd like to replace all values in a list which obey one or more criteria with another value. Example: Replace all values>30 by $30$. data={{3,35},{2,7}} Afterwards it should be: {{3,30},{2,7}} Example #2: aa= {300., 150., 100., 76.8421, 64.0909, 55.567, 49.1935, 44.2262, 40.2247, 36.9355, 34.1667, 31.8138, 29.7887, 28.0087, 26.4537, 25.0612, 23.8186, 22.7059, 21.6854, 20.7663, 19.9265, 19.1519, 18.4323, 17.7739, 17.1672, 16.6007, 16.0648, 15.5605, 15.098} If a value of aa is greater than 100 I want to replace it with an arbitrary value, e.g. 50. Answer Up front you have a choice between pattern-based and numeric manipulation of an array. Pattern-based is more general; numeric is usually fastest when applicable. a = {{21, 95, 50}, {39, 32, 76}, {9, 12, 75}}; Examples of pattern based methods: a /. n_Integer /; n > 30 -> 30 a /. n_?NumericQ /; n > 30 -> 30 Replace[a, n_?(#>30&) -> 30, {2}] Examples of numeric methods: Clip[a, {-∞, 30}] (a - 30...

differential equations - Should DSolve always return solution with constant of integration?

Bug introduced in 10.0.0 and fixed in 10.0.2 Clear[y,x]; DSolve[D[y[x], x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0, y[x], x, GeneratedParameters -> C] or DSolve[D[y[x], x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0, y[x], x] both return a solution that does not include C[1] , the constant of integration. {{y[x] -> Sin[x]}} The question is: Should DSolve always return an arbitrary constant? Even though the answer is correct, it is missing C[1] hence this is a particular solution. If DSolve does not have to generate a constant of integration in the solution of a differential equation, then what caused it not to generate it in this specific case? Update: Let me add a solution found by Maple for this, which does include a constant of integration: Clear[C,y,x]; eq = Derivative[1][y][x] - y[x]^2 + y[x]*Sin[x] - Cos[x] == 0; eq /. y -> (- Exp[-Cos[#]]/(C[1] + Integrate[ Exp[-Cos[#]], x]) + Sin[#] &); Simplify[%] (* True *) So, the above is a general solution with a constant of in...

Kernel Management

I would like to run a computation in one NoteBook that will take 2 hours. Could I assign this Notebook a specific Kernel so I can run computation in other Notebooks ? Answer You can select which kernel is used by your notebook from the menu item Evaluation -> Notebook's Kernel. By default you will probably only have one kernel called Local available. If your Mathematica license allows for it (typically licenses allow for two simultaneous kernels on a machine), you can add new kernels by selecting the Evaluation -> Kernel Configuration Options... menu item. Select "New" to add a new Kernel, give the kernel any name you want and accept the default options. This new kernel will now be selectable from the Evaluation -> Notebooks Kernel menu.

plotting - How to write Morse code into Plot Dashing?

How can we define a dashing pattern in a plot such that it reads arbitrary text in Morse code? For instance Graphics[{DotDashed, Line[{{0, 0}, {5, 0}}]}] this could be interpreted as " .- " that is " a " in Morse code. Proper spacing would be desirable in order to distinguish " .- " ( a ) from " -. " ( n ). ( Inspired by @rcollyer's comment to my answer to this question .) Answer First define the Morse code (from rosettacode.org with corrections by @evanb) morsecode = (#1 -> Characters[#2]) & @@@ { {"a", ".-"}, {"b", "-..."}, {"c", "-.-."}, {"d", "-.."}, {"e", "."}, {"f", "..-."}, {"g", "--."}, {"h", "...."}, {"i", ".."}, {"j", ".---"}, {"k", "-.-"}, {"l", ".-.."}, {"m", ...

machine learning - How to export an MXNet?

I was hoping there was some way to generate the .params and .json file needed to define an MXNet model, from a network trained using NetTrain[] in Mathematica. I was hopeful because I found these functions in the NeuralNetworks` package: NeuralNetworks`ToMXNetSymbol NeuralNetworks`ToMXNetJSON You can use them on a net link this: net = NetInitialize@NetChain[{ ConvolutionLayer[20, {5, 5}], ElementwiseLayer[Ramp], PoolingLayer[{2, 2}, {2, 2}], FlattenLayer[], DotPlusLayer[500], ElementwiseLayer[Ramp] }, "Input" -> NetEncoder[{"Image", {32, 32}}]]; ImportString[Normal@NeuralNetworks`ToMXNetJSON[net][[1]], "RawJSON"] NeuralNetworks`ToMXNetSymbol[net] Now, ToMXNetJSON[] returns a tuple, and it looks like the first element is the JSON for the symbol file . But I don't know what the second element is, and I don't have a clue as to what ToMXNetSymbol[] is returning. Motivation: A solution to this would enable one t...

graphics - General techniques for creating complex animations

I love good animations of abstract concepts, and when I try to create them myself, I prefer doing so in code to make sure they are exact (and because some things are just way too fiddly to do by hand). In general, Mathematica seems like a nice tool for this, because of its powerful plotting capabilities. My problem is that this tends to get quite annoying once my animation consists of multiple "phases", which cannot all be easily described by a single continuous function. To give you an idea of what I mean, here are some examples from a very popular question over on Math.SE : Source Source Note that I'm specifically not talking about animations like the one in the top-voted answer, which can easily be expressed as a large number of graphics primitives whose parameters are continuous functions of some time parameter t . In the two examples above there are lots of different steps to the animation. Objects appear, disappear or undergo qualitatively different motions over th...

plotting - How to properly plot a response of a transfer function in Mathematica?

I'm trying to display the output response of a transfer function in Mathematica with and without a compensator. The problem is very strange: while the transfer function compensate is showing well, the other is not. The plot seems incomplete and no matter what PlotRange I set, the graph always stays incomplete at the same point. Here is a screenshot: Anybody have an idea of what is wrong? I'm pretty sure the math itself is okay, because I get the second transfer function from the first. But when I want to compare the two responses graph, the first always stays incomplete. Answer o1 isn't always real - it has a small imaginary component. For example o1 /. t -> 4 gives 0.995493 - 5.18448*10^-7 I . What you could do is Chop the output response: o1 = Chop @ OutputResponse[tfm, UnitStep[t], t]; This gives you a nice smooth graph. But on the other hand if you look at the unchopped version o1 /. t-> 8 you get 831840. + 332820. I . Not a small imaginary component at all...

list manipulation - Linear regression in a chosen range of points

Hi I'm absolutely newbie in Mathematica and have following problem: My list looks like {{50, 0.75}, {51, 0.76}, ... , and I want to choose a range out of my x-values (I don't want so say: from point 150 to ... , I want to choose with values like from x value 50 to 60 ), with only these points a linear regression has to be done. I tried with LinearModelFit[data, x, x] , and Mathematica made a linear regression with all values, now I want to choose a range but I can't find a solution =( Has somebody an idea? Answer As suggested by @b.gatessucks you can use Select . data = Table[{x, Sin[x] + RandomReal[{-0.5, 0.5}]}, {x, 0, 15, 0.25}]; pl = ListPlot[data]; ff = LinearModelFit[data, Sin[x], x] Show[pl, Plot[ff[x], {x, 0, 15}]]; and after selection over the range [2,8]: ff2 = LinearModelFit[Select[data, #[[1]] > 2 && #[[1]] Show[pl, Plot[{ff[x],ff2[x]}, {x, 0, 15}]];

plotting - How can I change the default font used in ALL plots and legends in Mathematica?

Forgive me, but I cannot for the life of me figure out how to do this no matter how much I research. I really want to change the default font for all graphics, such as ArrayPlot, ContourPlot, DiscretePlot3D, etc. as well as the fonts used in any legends / axes / labels / (everything) to Times New Roman (I'm in Mathematica 10 so everything is sans serif by default). I know that I can set all of these manually usually by using something like Directive[FontFamily -> "Times New Roman"] , but it's killing me to do this for every single graph. I've tried to use stylesheets to do this but I cannot figure out how to get them working. I'm sorry that this is so basic, but if you could just provide a simple, step-by-step solution to achieve this, I would be eternally grateful. Thank you very much.

coefficients - How to locate a list within a list?

for example f[{1,2,3,4},{2,3}]=True , f[{1,2,3,4},{2,3,4}]=True but f[{1,2,3,4},{2,4}]=False . Which function should I use because I don't want to reinvent the wheel. Thanks in advance Answer We may use pattern matching: f[a_, {ss__}] := MatchQ[a, {___, ss, ___}] Testing: f[{1, 2, 3, 4}, {2, 3}] (* True *) f[{1, 2, 3, 4}, {2, 3, 4}] (* True *) f[{1, 2, 3, 4}, {2, 4}] (* False *) This should work in any version of Mathematica and it is nearly equivalent in performance to SequencePosition : (as measured in version 10.1 under Windows) f1[Range[10000], {5000, 5001, 5002}] // RepeatedTiming f[Range[10000], {5000, 5001, 5002}] // RepeatedTiming {0.000444, True} {0.000475, True}

Convert a string to hex number?

How can I convert a string containing a hex number such as "6b" to a hex digit that mathematica can use to do math with? I have tried using ToExpression["6b"] but that just give me another string. Note: Java's BigInteger class can construct hex integers from strings. Is there something like this in mathematica ? Answer The function converting strings to integer is FromDigits . It is the counterpart of IntegerString and both functions can be used with whatever basis you like. Therefore, if you want to convert from base 16 you do FromDigits["6b", 16]

differential equations - Looking for examples of numerically solving coupled PDE and ODE

I am about to solve a system of coupled PDE and ODE in thermodynamics. My system is a bit complicated, so I would like to learn from some examples before coding my own system. I searched this site and found several cases as following Solving coupled PDE and ODE Couple a PDE and ODE in NDSolve And I would like to know if there are more of them, with topic like "Solving coupled PDE and ODE numerically". If you know a good example, please post its link, and I would appreciate your help. Answer Here are six more (too many for a comment): NDSolve: Couple ODE and PDE NDSolve two PDE plus one ODE, together NDSolve a system of one PDE coupled with an ODE Simulating a combination of PDEs and ODEs PDE: Specify AccuracyGoal, StepSize, and WorkingPrecision interval-wise Unfortunately, most do not have answers.

export - Mathematica and POV-Ray workflow (Q&A)

A couple of years ago, Alexey Popkov asked this question: Which ray tracing software is compatible with Graphics3D? It is my opinion, for various reasons, that out of the many ray tracing programs that exist today, POV-Ray is most compatible with Mathematica-generated 3D graphics. During the past few months I've developed and gradually improved a Mathematica and POV-Ray workflow, and I think it would be interesting and useful to describe it here in some detail. Should any of the users or moderators object to this "question", which of course isn't really a question at all, then I'd be willing to remove it or to post it as an answer to Alexey Popkov's question instead. My main reasons for not doing the latter are, first, that it is a rather long answer, and, secondly, that the matter at hand is slightly different from the one implied in Mr. Popkov's question.

cdf format - Problem with PlayerPro recognizing a proprietary package

This question follows on from my earlier question Can Wolfram's Player Pro Use Proprietary Packages . That question appeared to have established that, yes, PlayerPro can use proprietary packages. Hmmm....? I've got two problems (to start) one of which I'll describe here and the second in a separate question. I purchased a PlayerPro license ($200 USD) for OS X to evaluate what it really can and does do. I installed it on a machine that had no other Mathematica installation. I tested its installation and functionality by running a couple of simple completely self-contained CDF s on it without any trouble. I then transferred copies of three files to the PlayerPro equipped machine and located them in the following directories: /Users/username/Library/MathematicaPlayerPro/Applications. myPackage.m /Users/username/Library/MathematicaPlayerPro/Applications. myNotebook.nb /Users/username/Library/MathematicaPlayerPro/Kernel. init.m myPackage.m holds proprietary functions. myNo...