sagemath : ZeroDivisionError: input matrix must be nonsingular - math

I want to calculate the below matrix calculation, but it produces a "ZeroDivisionError: input matrix must be nonsingular". Can someone provide some ideas to solve this issue ? thank you
matrix.options(precision=3)
PT=Matrix([[0.0,1,0,0],[10/64,27/64,27/64,0],[0,44/125,54/125,27/125],[0.0,0,0,1]])
I=Matrix.identity(4)
print((I-PT).inverse())

Related

Creating an array of iterated values

I have read through a lot of julia-posts, but haven't found anything concerning this very special problem.
We are iterating eigenvalues and corresponding eigenvectors via Power-Iteration.
The algorithm is working and calculating the approximate eigenvalue, but we are asked to save the values of our approximate values after each iteration in a seperate vector.
I tried:
collect(lambda_k)
in a while loop:
l_end = []
push!(l_end,lambda_k)
But it doesn't work, are you able to help me?
Greetings!
Mass_Matics

Understanding vector/mean functions in R

Hi, I was looking to see if anyone could help me.
So I am new to using R and I'm following through a workbook provided by my univesity and have been trying the functions out in R and changing various numbers to see how this changed the information.
Generally, I have been understanding most of it but I dont quite understand some of the following code.
Could anyone explain to me what
vec.mean <- numeric(N)
means as im not entirely sure what this is doing.
Thanks in advance for the help.
If you read the help file with help(numeric):
Description -
Creates or coerces objects of type "numeric".
Arguments -
length
A non-negative integer specifying the desired length. Double values will be coerced to integer: supplying an argument of length other than one is an error.
The first argument of numeric() is length =. Therefore, numeric(500) creates a numeric vector of length 500.
This is theoretically a best practice because running the for loop later on a vector that has already been created will have subtly improved performance.

Convert from matrix to list matrix

Sorry for the noob question but I can't seem to get this to work!
X=cbind(rep(1,m), h2(x), h3(x)) #obs
So I have a 17*3 matrix X I have to create a matrix(list(),17,3) version of this matrix. I did manually below so you can see the desired result, but there must be an easier way to do this?
Z=matrix(list(X[1,1],X[2,1],X[3,1],X[4,1],X[5,1],X[6,1],X[7,1],X[8,1],X[9,1],X[10,1],X[11,1],X[12,1],X[13,1],X[14,1],X[15,1],X[16,1],X[17,1],X[1,2],X[2,2],X[3,2],X[4,2],X[5,2],X[6,2],X[7,2],X[8,2],X[9,2],X[10,2],X[11,2],X[12,2],X[13,2],X[14,2],X[15,2],X[16,2],X[17,2],X[1,3],X[2,3],X[3,3],X[4,3],X[5,3],X[6,3],X[7,3],X[8,3],X[9,3],X[10,3],X[11,3],X[12,3],X[13,3],X[14,3],X[15,3],X[16,3],X[17,3]),17,3)
I tried this (amongst others)
Z2=list(X[1:17,1],X[1:17,2],X[1:17,3])
Z3=matrix(Z2[1:3],17,3)
But it doesn't give the correct results! It just repeats the three column vectors over and over.
Can someone please explain how to do this correctly.
Apparently you want Z <- matrix(as.list(X), ncol = 3). However, I don't see how this structure could be useful.

Every nth column from in matlab to R

I am trying to translate some matlab code to R.
This is the code:
v_i = vfull(:,i:ns:k*ns);
I think this means take every ns_th column from i to k*ns in the matrix v_i, right? If I am wrong, can someone please tell me what it means?
Regardless, how would one implement this in R?
You interpretation of what Matlab is doing is correct. Here is how to do the equivalent in R
v_i = vfull[ ,seq(i,(k*ns),ns)]

R or MATLAB: permute a large sparse matrix into a block diagonal matrix

I have a large sparse matrix, and I want to permute its rows or columns to turn the original matrix into a block diagonal matrix. Anyone knows which functions in R or MATLAB can do this? Thanks a lot.
I'm not really set up to test this, but for a matrix m I would try:
p = symrcm(m);
block_m = m(p,p);
If that doesn't work, look through the other functions listed in help sparfun to see if any will help you out.
The seriation package in R has a number of tools for problems related to this one.
Not exactly sure if this is what you want, but in MATLAB this is what I have used in the past. Probably not the most elegant solution.
I go from sparse to full and then chop the thing into square blocks.
A=full(A);
Then:
blockedmatrix = mat2cell(A, (n*ones(1,size(A,1)/n)), ...
(n*ones(1,size(A,1)/n))); %found somewhere on internetz
This returns a cell, where each entry is of size nxn.
It's easy to extract the blocks of interest, manipulate them, and then restore them to a matrix with cell2mat.
Maybe a bit late to the game, but since there are available commands, here is a simple one. If you have a matrix H and the block diagonal form is needed, you can obtain it through the following lines (MATLAB):
[p,q] = dmperm(H);
H(p,q)
which is equivalent to Dulmage - Mendelsohn permutation.

Resources