Hot answers tagged

7

With[{x = Array[x, Dimensions[mA]]}, Solve[mA .x - x. mB + mC == 0, Flatten@x]] Or With[{x = Array[x, Dimensions[mA]]}, x /. Solve[mA .x - x. mB + mC == 0, Flatten@x]] {{{3, 1}, {0, 3}}}


4

dataset2 = RandomReal[1, {5, 7}]; (* this stands for dataset[[All,2;;]] in your case*) dataset2 // MatrixForm output = Outer[NormalizedSquaredEuclideanDistance, dataset2, dataset2, 1]; output // MatrixForm


4

Your cube file had a very large grid ( 117*117*130 = 1779570), and 2 million points is just far too many for testing a function. So I created cube files for the electron density and electrostatic potential for the molecule furan, using a much sparser grid (around 8000 grid points instead). Here they are: Density cube file Potential cube file Now that ...


3

If you have Mathematica 10.3 or above you can use DistanceMatrix: DistanceMatrix[dataset2, DistanceFunction -> NormalizedSquaredEuclideanDistance] I'm assuming the same data as defined by kglr, you have not given us an example. If you don't have Mathematica 10.3 there's still HierarchicalClustering`DistanceMatrix which is used in the same way.


3

Array size/shape agnostic, takes care of edge cases automagically, call with player identifier, position, and current array, returns changed array: fn = With[{cv = #1, cp = #2, cm = #3}, ReplacePart[cm, Select[Position[cm, cv], ChessboardDistance[#, cp] <= 1 &] -> 0]] &; Use example: fn[a, {5, 3}, mat]


2

Clear[arrayH] arrayH[n_Integer] := Partition[ Flatten[Array[H, {n + 1, n + 1, n + 1, n + 1}, {0, 0, 0, 0}]], (n + 1)^2 ] arrayH[3] Then define an appropriate function H that calculates the value of each item using the indices. By way of example, if you had defined a function: Clear[H] H[i_, j_, k_, l_] := StringJoin @@ (ToString /@ {i, j, k, l}) ...


2

makeBrackMat[mat_?MatrixQ] := DisplayForm[ RowBox[{StyleBox["[", SpanMaxSize -> \[Infinity]], GridBox[mat], StyleBox["]", SpanMaxSize -> \[Infinity]]} ] ]; Exact numbers: mat1 = Partition[Range[12], 3]; makeBrackMat[mat1] Machine-precision numbers: mat2 = {{1.3, 2.9}, {9.5, 8.4}, ...


2

The answer is as you suspect - when you evaluate Dot[m1, m2, m3, m4, m5, ......m1000] the process is something like this: Look at the input: Dot[m1, m2, m3, m4, m5, ......m1000] Evaluate the first matrix product, m12=m1.m2 Look at the input: Dot[m12, m3, m4, m5, ......m1000] Evaluate the first matrix product, m123=m12.m3 Look at the input: Dot[m123, m4, ...


2

Here is one way to do it, although I feel like there is probably an even more elegant solution: MapIndexed[ If[ # === clicked && ChessboardDistance[#2, {row, col}] <= 1, 0, # ] &, board, {2} ] E.g. with row = col = 4 on your above example you'd get: {{0, 0, 0, 0, 0, 0}, {0, a, a, b, 0, 0}, {0, a, 0, b, 0, 0}, ...


2

Perhaps this, which converted to exact fractions trying to avoid roundoff errors: {ToRules[N[Reduce[Simplify[{vals[[3]]/vals[[1]] == ((112/100)/(1735/10)), vals[[2]]/vals[[1]] == ((29/10*10^-3)/(1735/10))}]]]]} which gives you eight solutions.


2

mat = RandomInteger[{0, 1}, {5, 10}]; v = RandomInteger[{100, 110}, 5]; (mat1 = Join[List /@ v, mat, 2]) // MatrixForm ds=Dataset[mat1] colnames=CharacterRange["a","z"][[;;11]]; ds2=Dataset[AssociationThread[colnames->#]&/@mat1]


1

ClearAll[fn2] fn2 =With[{cp = #1, p = Position[#2, #2[[## & @@ #]]]}, MapAt[0 &, #2, Select[p, ChessboardDistance[#, cp] <= 1 &]]] & Row[MatrixForm /@ {board, fn2[{3, 3}, board], fn2[{3, 4}, board]}]


1

Completely different approach, so I'm making it a separate answer: board[[row - 1 ;; row + 1, col - 1 ;; col + 1]] = board[[row - 1 ;; row + 1, col - 1 ;; col + 1]] /. clicked -> 0; This has the advantage of only updating the neighbourhood of the clicked cell instead of mapping a function over the entire grid. I also think it's quite clear and ...


1

In principle you can create an entirely real formulation and use FindMinimum like this: exp = Abs[vals[[3]]/vals[[1]] - 1.12/173.5]^2 + Abs[vals[[2]]/vals[[1]] - 2.9*10^-3/173.5]^2 /. {\[Delta] -> dr + I di , \[Epsilon] -> er + ei I}; sol = FindMinimum[exp , {{dr, -5.7}, {di, 6.1}, {er, -1.4}, {ei, 1.2}}] {1.67033*10^-7, {dr -> ...



Only top voted, non community-wiki answers of a minimum length are eligible