All pastes #800085 Raw Edit

Untitled

public text v1 · immutable
#800085 ·published 2007-11-28 02:29 UTC
rendered paste body
%Part A
a = zeros(n-1);
a(1,1) = 2048; % top
a(1,2) = 256; %Right
a(2,1) = 256; %Bottom

for i = 2: n-1
    a(i,i)=a(i-1,i-1)./2;
    a(i,i+1)=a(i-1,i)./2;
    a(i+1,i)=a(i,i-1)./2;
end
a(n,n)=a(n-1,n-1)./2;
a

%To solve this efficiently we use the tri method

%Part B

a = zeros(n);
a(1,1) = 64;
a = a + diag(ones(n-1,1),1) + diag(ones(n-1,1),-1)

 for i = 2: n-1
     a(i,i)=a(i-1,i-1)./2;
 end
 a(n,n)=a(n-1,n-1)./2;
a

%To solve this efficiently we use the tri method

%Part C

a = zeros(n);
a(1,1) = 64;

 for j = 1:n-1
    a = a + diag(ones(n-j,1),-j);
 end
 
 for i = 2: n-1
      a(i,i)=a(i-1,i-1)./2;
 end
 a(n,n)=a(n-1,n-1)./2;
a

%To solve this efficiently we use the back-substitution method if it is
%upward triangular dominant and forward-substitution if it is lower triangular
%dominant.