New answers tagged

4

Here is my modest attempt: qdMat[n_Integer?Positive] := Module[{id, mm}, id = Riffle @@ Reverse[MapAt[Reverse, TakeDrop[Range[n - 1], Quotient[n - 1, 2]], -1]]; mm = TakeList[Array[f, Binomial[n, 2]], id][[InversePermutation[id]]]; mm = PadRight[PadLeft[Reverse[Flatten[mm, {{2}, {1}}], 2], {Automatic, n}], {n, n}]; mm + Transpose[mm]] For instance, ...


4

If we determine the elements in the first row, the remaining rows are obtained by simple rotation + padding and adding 1 to the previous rotated/padded row: ClearAll[firstRow, rotatePad, spiralMat] firstRow = Module[{rng = Range[0, Floor[(# - 1)/2]]}, 1 + Join[# If[OddQ @ #, Most @ rng, rng] , (# - 1) Reverse @ Rest @ rng]] &; rotatePad = Fold[...


3

Because the diagonals switch from the corner to close to the diagonal there is no pretty solution (or at least no easy one). The following code will do the trick. You will have to do the lower triangle by yourself though. n=9; m = ConstantArray[0, {n, n}]; initialxLeft = 2; initialxRight = n; leftOrRightToggle = "Left"; counter = 1; While[...


0

This is just a revision of @Bob Hanlon's code above with two adjustments: the use of Callout instead of Tooltip and the use of Manipulate instead of Module. One can then play with different polynomial degrees denoted by n as a control. Clear["Global`*"]; SeedRandom[11]; data = RandomReal[{0, 300}, {40, 2}]; Manipulate[ (*Determine the point that ...


1

Clear["Global`*"] data = {{525.48, 37.02}, {525.2, 36.86}, {528.44, 36.995}, {533.27, 36.795}, {534.31, 36.59}, {536.26, 36.53}, {535.66, 36.52}, {534.24, 36.515}, {534.71, 36.5}, {535.41, 36}}; For a quadratic fit poly[x_] = With[{n = 2}, NonlinearModelFit[data, Total@Table[a[k] x^k, {k, 0, n}], a /@ Range[0, n], x] // Normal] ...


2

A streamlined way to construct the desired rectangular table using Outer: countryList = (SeedRandom[777]; RandomSample[countLst, 20]); propList = {"Name", "PopulationGrowth", "GDP", "TotalFertilityRate", "GrossInvestment", "MedianAge"}; propLabels = {"country", "pop. growth"...


1

Following @C.E's suggestion, I retrieved selected variables without strings: Text[Grid[ Prepend[data = {CountryData[#, "Name"], QuantityMagnitude@CountryData[#, "PopulationGrowth"], QuantityMagnitude@CountryData[#, "GDP"], QuantityMagnitude@CountryData[#, "TotalFertilityRate"], QuantityMagnitude@...


3

My answer below merely revises the Code given in the question with @kglr's comments to achieve the objective stated in the question. I thought this might be useful for others in this forum, who aim to automatically print out output cells or input cells in either PNG or PDF or any other format of interest. Below, I show the cases for PDF and PNG. SetDirectory[...


4

SeedRandom[0] NearestNeighborGraph[RandomReal[{0, 5}, {10, 2}], 2, VertexLabels -> {_ :> Last[vlist = RotateLeft[vlist]]}] Alternatively, SeedRandom[0] NearestNeighborGraph[vl = RandomReal[{0, 5}, {10, 2}], 2, VertexLabels -> Thread[vl -> vlist]] same picture and SeedRandom[0] Block[{i = 1}, NearestNeighborGraph[RandomReal[{0, 5}, {10, 2}...


0

Manipulate[ With[{f = ReIm[-I (-1.)^(2/n #)] &}, Graphics[{Circle[], Table[{Circle[#, .015], Text[Style[If[Mod[i, 10] == 0, i, ""], 14], 1.1 #]} & @ f@i, {i, 0, n - 1}], Magenta, Arrow@Table[f@{i, k i}, {i, x - 1}]}]], {n, 60, 200, 10}, {x, 1, n, 1}, {k, 2, 9, 1}] The following picture generated with Mathematica and POV-...


1

A more streamlined way to produce the matrices in OP (not an answer): ClearAll[toStates] toStates[t_, s_, m_] := Map[s[[Total[1 - UnitStep[t - #]]]] &, m, {2}] thresholds = {0, .5, 1., 1.5}; states = {s1, s2, s3}; m1S = toStates[thresholds, states, matT1]; m2S = toStates[thresholds, states, matT2]; {m1S, m2S} == {matT1S, matT2S} True maP[m1_, m2_, ...


1

I am not sure I understand the question. It seems to me that you can make the transition matrix by making the graph adjacency matrix row stochastic. Here is an example with question’s matT1: matT1rs = DiagonalMatrix[1/Total[matT1, {2}]].matT1; Total[matT1rs, {2}] (* {1., 1., 1., 1., 1.} *) MarkovProcessProperties[DiscreteMarkovProcess[{1, 0, 0, 0, 0}, ...


Top 50 recent answers are included