0
$\begingroup$

I have a matrix, and I want to multiply all the values in each element by Sqrt[2/3]. Here is the code.

    m = Table[
    If[(n)^2 + (j)^4 + (k)^3 + (l) == 0, {n, j, k, l}, Nothing], {n, 
    0, 10, 1}, {j, 0, 10, 1}, {k, -10, 0, 1}, {l, -10, 0, 1}] // 
    Flatten[#, 3] & // Select[Length@# > 0 &]; m // MatrixForm

So the columns of the matrix correspond to the values of (n,j,k,l). Now I want to create a new matrix, where I introduce a counter value that starts at say 0.01 and increments by 0.01 with each iteration, call it a++.

The new 3 column matrix will take the value of (n,j,a) and put it into the matrix as the first row, and also (while keeping the same value of a) will also add (k,l,a) as the second row and then move the next row of the original matrix and so the same process, with the counter a incremented.

This code, with the help of people here, is:

    Join @@ MapIndexed[Partition[#1, 2] /. x_?VectorQ :> Join[x, 0.01 #2] &, m]
    ListPlot3D[%, PlotStyle -> PointSize[0.02]]

However, before plotting this, I want to also update each element of the value of a to the value of a times 1/Sqrt[3].

The previous post is here: Create a new matrix from an existing matrix and then plot it

Any help would be appreciated.

$\endgroup$
  • 1
    $\begingroup$ So, ListPlot3D[% / Sqrt[3], PlotStyle -> PointSize[0.02]]? $\endgroup$ – march Jan 31 at 5:54
1
$\begingroup$

Using an alternative method suggested in this answer to generate the two matrices:

ClearAll[l, n, k, j]
m2 = Values @ Solve[{Total[{l, n, k, j}^Range[4]] == 
      0, -10 <= l <= 0 && -10 <= k <= 0 && 0 <= n <= 10 && 
      0 <= j <= 10}, {n, j, k, l}, Integers];

m2 == m

True

new2 = ArrayReshape[MapIndexed[Riffle[#, .01 #2[[1]], {3, -1, 3}] &, m2], 
  {2 Length@m2, 3}];

You can get the desired result by using .01 /Sqrt[3] instead of .01 as the increment:

new2a = ArrayReshape[MapIndexed[Riffle[#, .01 #2[[1]] / Sqrt[3], {3, -1, 3}] &, m2], 
  {2 Length@m2, 3}];

Alternatively, you can scale the matrix new2 by multiplying each row with {1,1, 1/Sqrt[3]} or using ScalingTransform[{1,1,1/Sqrt[3]}] on new2:

new2b = {1, 1, 1/Sqrt[3]} # & /@ new2;
new2c = ScalingTransform[{1, 1, 1/Sqrt[3]}]@new2;

new2a == new2b == new2c

True

ListPlot3D[new2a]

enter image description here

| improve this answer | |
$\endgroup$
0
$\begingroup$

just multiply your matrix by 1/Sqrt[3]

aa = RandomInteger[5, {2, 2}];

$$ \left( \begin{array}{cc} 1 & 5 \\ 1 & 0 \\ \end{array} \right) $$

1/Sqrt[3] aa // MatrixForm

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ that is okay for the first part - but I do not know how to multipy the new matrix represented by this code Join @@ MapIndexed[Partition[#1, 2] /. x_?VectorQ :> Join[x, 0.01 #2] &, m] ListPlot3D[%, PlotStyle -> PointSize[0.02]] $\endgroup$ – Betty Jan 31 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.