Jump to content

can you vectorize this?

mansoor_

something like...

create a vector V of size n

if a(i,i) = 0, then V(i) = 0, otherwise 1

transpose the matrix

multiply the matrix by V

transpose the result

 

i think it could even work

hope this is what you needed

Link to comment
Share on other sites

Link to post
Share on other sites

something like...

create a vector V of size n

if a(i,i) = 0, then V(i) = 0, otherwise 1

transpose the matrix

multiply the matrix by V

transpose the result

 

i think it could even work

hope this is what you needed

 

i need to keep the rows, its a linear system, i want them to be arranged in a way such that the matrix has no zeros on it leading diagonal.

i think your solution would just delete the column.

Link to comment
Share on other sites

Link to post
Share on other sites

i need to keep the rows, its a linear system, i want them to be arranged in a way such that the matrix has no zeros on it leading diagonal.

i think your solution would just delete the column.

oh pardon, i misunderstood, i thought you needed to fill the row with zeroes

 

how would you choose the value to put where the zero is? (i have no idea how to read matlab code)

Link to comment
Share on other sites

Link to post
Share on other sites

i dont want to replace values, if a row has a zero on the element which corresponds to the diagonal of the matrix then i need swap that row for one that doesnt have a zero there, also the row that i am replacing must not have a zero in the element in the leading diagonal of where it is to be moved to. 

Link to comment
Share on other sites

Link to post
Share on other sites

You could create an identity matrix which has just ones along the diagonal and zeros everywhere else. Then find the rows in question with a simple boolean check and compress that into a list of your rows. like such:

identity = eye(n,n);    %Identity matrixidentity = identity == 0;    %Swap ones for zerosmat = a == identity;    %You now have ones anywhere there are zeros on the diagonalmat = max(mat,[],2);    %Now you have a single column with a one where it is needed

That is about as far as I'm getting right now, hopefully it helps.

My rig: 2600k(4.2 GHz) w/ Cooler Master hyper 212+, Gigabyte Z68-UD3H-B3, Powercolor 7870 xt(1100/1500) w/AIO mod,

8GB DDR3 1600, 120GB Kingston HyperX 3K SSD, 1TB Seagate, Antec earthwatts 430, NZXT H2

Verified max overclock, just for kicks: http://valid.canardpc.com/show_oc.php?id=2609399

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×