How do I update a matrix in a for loop MATLAB -
this question has answer here:
- power method in matlab 1 answer
i have matrix , vector u. want run loop update vector u. operation easy, multiple u (result vector denoted z). pick largest element in z (result scalar denoted m). update u dividing vector z m. don't know how index matrix used cell notation might not correct.
a=[1 2 3 4; 5 6 7 8 ; 9 10 11 12; 13 14 15 16]; u= ones (4,1); s=1:10 z{s}= a*u{s}; m(s)= max(z{s}); u{s} = z{s}/m(s); end
any suggestions helpful.
you don't have index anything. remove indices. should read docs learn when index , when not to. have matrix operations.
a=[1 2 3 4; 5 6 7 8 ; 9 10 11 12; 13 14 15 16]; u= ones (4,1); s=1:10 z = a*u; m = max(z); u = z/m; end
the final value u
0.2028 0.4685 0.7343 1.0000
Comments
Post a Comment