How to write this matrix in matlab, -


i want write matrix in matlab,

s=[0  .....        0    b    0   ....   0    ab    b   ....  0    .  .   .    .     .    .    .        .    . 0                  ....    a^(n-1)*b ... ab    b ] 

i have tried below code giving error,

n = 50; a=[2 3;4 1]; b=[3 ;2]; [nx,ny] = size(a);  s(nx,ny,n) = 0; n=1:1:n     s(:,:,n)=a.^n; end s_x=cat(3, eye(size(a)) ,s);  ii=1:1:n-1     su(:,:,ii)=(a.^ii).*b ; end  z= zeros(1,60,1); su1 = [z;su] ; s_u=repmat(su1,n); 

seems concatenation of matrix not being done. beginner having serious troubles,please help.

use cell arrays , answer previous question

a = [2 3; 4 1]; b = [3 ;2 ]; n = 60; [cs{1:(n+1),1:n}] = deal( zeros(size(b)) ); %// allocate space, setting top triangle 0 %// work on diagonals x = b; ii=2:(n+1)     [cs{ii:(n+2):((n+1)*(n+2-ii))}] = deal(x); %//deal diagonal     x = a*x; end  s = cell2mat(cs); %// convert cells single matrix     

for more information can read deal , cell2mat.


important note difference between matrix operations , element-wise operations

in question (and in previous one) confuse between matrix power: a^2 , element-wise operation a.^2:

  • matrix power a^2 = [16 9;12 13] matrix product of a*a
  • element-wise power a.^2 takes each element separately , computes square: a.^2 = [4 9; 16 1]

in yor question ask matrix product a*b, code write a.*b element-by-element product. gives error since size of a , size of b not same.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -