How to represent the following matrix multiplication in Mathematica? - wolfram-mathematica

I have a matrix A={{a,b,c},{d,e,f},{g,h,i}}, a square 3X3 function which is piecewise constant.. I want to compute J'AJ, where J is a column vector of all ones and J' is the transpose of J. I use the following codes:
PiecewiseExpand[J.A.J]. However, I fail to obtain the result. How should I amend it?

Related

Is there a build in function that calculates eigenvectors in Julia

I would like to find the eigenvector q of following equation:
Q * q = 0
where Q is a square matrix with known values.
Like shown in the image below I used an example where I already calculated q.
I thought that the function eigvecs() would calculate the vector q and not a new sqaure matrix.
Is there another function or perhaps a different way to calculate q?
Eigenvectors are not uniquely defined.
If u is an eigenvector of Q corresponding to eigenvalue a (0 in your case) then for any non-zero scalar x x*u is also an eigenvector of Q corresponding to the same eigenvalue.
If you look at the third column of eigvecs(Q) above, you will see that it is (1/2 1/3 1/6) scaled by ~ 1.603568

Using WolframAlpha, in matrix multiplication, why are "squared" and ^2 giving me different results?

"squared" input: {{0,1,0,0},{0.325,0,0.2875,0.3875},{0,1,0,0},{0,1,0,0}} squared
output:
"^2" input: {{0,1,0,0},{0.325,0,0.2875,0.3875},{0,1,0,0},{0,1,0,0}} ^2
output:
The squared operation simply squares all matrix elements.
(cubed works in a similar way)
Example:
The ^2 operation performs a matrix multiplication as expected.

Why does Multiplying a column stochastic matrix with a vector that sums to one result in vector that again has sum one

Suppose I have a nxn coulmn stochastic matrix. If I multiply it by a vector of length n that has elements that sum to one I get a resultant vector of length n that again sums to one Why does this happen? What if I give the vector of lenght n sum =0.8 or some 1.2?
Edit:
What happens if one of the columns of the matrix dosent add up to 1?
Consider matrix B=4x4 and vector A=4x1. Now when we are calculating the output vector sum it can be broken as
a1*(b11+b21+b31+b41)+a2*(b12+b22+b32+b42)+a3*(b13+b23+b33+b43)+a4*(b14+b24+b34+b44)
Now since all columns sum to 1 since it's column stochastic the
sum=a1*1+a2*1+a3*1+a4*1=1
since the vector was 1. Now if one of the cols is not 1 we will have that column's contribution reduced for the jth entry of vector A. For eg. if
b13+b23+b33+b43=0.8
then
sum=a1*1+a2*1+a3*(0.8)+a4*1=a1*1+a2*1+a3*1+a4*1 -0.2*a3
So there is a leak of -0.2a*3 from the original sum of 1

ilu of Matlab gives column or row permutation?

I run into this question because I will apply the preconditioner to my iterative method.
Matlab says [L, U, P] = ilu(A, setup) gives L, U, and a permutation matrix P. I wanna know this P is either column or row permutation matrix. In other words, is PA=LU or AP = LU? Does it matter if I use ilutp or Crout method?
I looked into Matlab carefully and just found the LU function gives row permutation matrix. My guess P is a row permutation matrix because Q is the letter we normally use for column permutation.

find the values greater than x in N dimensional Matrix, where x is sum of index

We are given an N dimensional matrix of order [m][m][m]....n times where value position contains the value sum of its index..
For example in 6x6 matrix A, value at position A[3][4] will be 7.
We have to find out the total number of counts of elements greater than x. For 2 dimensional matrix we have following approach:
If we know the one index say [i][j] {i+j = x} then we create a diagonal by just doing [i++][j--] of [i--][j++] with constraint that i and j are always in range of 0 to m.
For example in two dimensional matrix A[6][6] for value A[3][4] (x = 7), diagonal can be created via:
A[1][6] -> A[2][5] -> A[3][4] -> A[4][3] -> A[5][2] -> A[6][2]
Here we have converted our problem into another problem which is count the element below the diagonal including the diagonal.
We can easily count in O(m) complexity instead spending O(m^2) where 2 is order of matrix.
But if we consider N dimensional matrix, how we will do it, because in N dimensional matrix if we know the index of that location,
where sum of index is x say A[i1][i2][i3][i4]....[in] times.
Then there may be multiple diagonal which satisfy that condition, say by doing i1-- we can increment any of {i2, i3, i4....in}
So, above used approach for 2 dimensional matrix become useless here... because there is only two variable quantity i1 and i2 is present.
Please help me to find solution
For 2D: count of the elements below diagonal is triangular number.
For 3D: count of the elements below diagonal plane is tetrahedral number
Note that Kth tetrahedral number is the sum of the first K triangular numbers.
For nD: n-simplexial (I don't know exact english term) number (is sum of first (n-1)-simplexial numbers).
The value of Kth n-simplexial is
S(k, n) = k * (k+1) * (k+2).. (k + n - 1) / n! = BinomialCoefficient(k+n-1, n)
Edit: this method works "as is" for limited values of X below main anti-diagonal (hyper)plane.
Generating function approach:
Let's we have polynom
A(s)=1+s+s^2+s^3+..+s^m
then it's nth power
B(s) = An(s) has important property: coefficient of kth power of s is the number of ways to compose k from n summands. So the sum of nth to kth coefficients gives us the count of the elements below kth diagonal
For a 2-dimensional matrix, you converted the problem into another problem, which is count the elements below the diagonal including the diagonal.
Try and visualize it for a 3-d matrix. In case of a 3-dimensional matrix, the problem will be reduced to another problem, which is to count the elements below the diagonal plane including the diagonal

Resources