This is my question.
Mostra commenti meno recenti
Hi. I face a problem during my coding. Let say I get my matrix in this form, And I need to arrange all the entries as row echelon form.
a= [ 1 2 3 4 0 ]
[ 5 0 6 0 1 ]
[ 7 0 0 0 8 ]
[ 9 2 5 5 0 ]
Here is my coding:
a=[1 2 3 4 0]
[5 0 6 0 1]
[7 0 0 0 8]
[9 2 5 5 0]
r=rref(a);
dis(r)
but I = receive my answer like this
r=
1.0000 0 0 0 1.1429
0 1.0000 0 0 15.7500
0 0 1.0000 0 -0.7857
0 0 0 1.0000 -7.5714
I don't want the entries other than diagonal become zero(except the lower triangular part)
I would like my answer to be in this form(x=any number except 0) after the elimination process.
x x x x x
0 x x x x
0 0 x x x
0 0 0 x x
Is it possible to do so?
2 Commenti
you want to push the zeros down the bottom? or down and right?
by the way, in your question you have 4 matrices, not 1, let me explain;
this
a= [ 1 2 3 4 0 ]
[ 5 0 6 0 1 ]
[ 7 0 0 0 8 ]
[ 9 2 5 5 0 ]
does this
a= [ 9 2 5 5 0 ]
the previous 3 lines? wasted, gone down the drain.
if you really want to assign those 4 lines as a single matrix to the variable a, perhaps you'd like to consider the following:
a= [ 1 2 3 4 0 ;
5 0 6 0 1 ;
7 0 0 0 8 ;
9 2 5 5 0 ]
David Fletcher
il 3 Mar 2018
Modificato: David Fletcher
il 3 Mar 2018
I've deleted my answer since it is no longer relevant because question is now completely different to the one that was originally posed.
Risposte (1)
If the order of the other elements is not important then just use sort. If you want the rest of the elements to keep the same order, then try this simple code:
>> a = [1,2,3,4,0;5,0,6,0,1;7,0,0,0,8;9,2,5,5,0]
a =
1 2 3 4 0
5 0 6 0 1
7 0 0 0 8
9 2 5 5 0
>> [~,R] = sort(a==0,1);
>> S = size(a);
>> X = sub2ind(S,R,repmat(1:S(2),S(1),1));
>> b = a(X)
b =
1 2 3 4 1
5 2 6 5 8
7 0 5 0 0
9 0 0 0 0
Categorie
Scopri di più su Downloads in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!