Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: need help of block tridiagonal matrix???
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
dfd ssss

Posts: 2
Registered: 11/17/12
need help of block tridiagonal matrix???
Posted: Nov 17, 2012 11:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I want to create a block tridiagonal matrix,so I used spdiags(),however, everytime I receive the "Error using horzcat CAT arguments dimensions are not consistent.
Error in spdiags (line 114) a((len(k)+1):len(k+1),:) = [i i+d(k) B(i+(m>=n)*d(k),k)];"I don't know why, hope someone can give me a hand, thanks!
clc;
clear;
NT=10;
Len=15;
lm=0.1;
t=1;
T=5;
MT=500;
detX=Len/NT; % at detT time how many detX should be,to some extent, it is fixed.
detT=T/MT; %control how many times to do this system
Fu=zeros(1,NT-1);
Fv=zeros(1,NT-1);
u=zeros(1,NT-1);
i=1;
while i<=NT-1;

%X=i*detX;
%T=i*detT;
u(i) = (i/NT)*(1-i/NT)*exp (10*(i/NT-1));
% u[i]=(i/N)*(1-i/N)*(exp (-10*(i/N)));
% u[i]=(0.1)*(1+ cos (360.0*PI*(i/N-0.5)/180));
i=i+1;
end
vpa(u,10)
disp('u=');
disp(u);
%u
v=zeros(1,NT-1);
i=1;
while i<=NT-1;

v(i) = (i/NT)*(1-i/NT)*exp (-10*(i/NT));
%v[i]=(i/N)*(1-i/N)*(exp (10*(i/N-1)));
%v[i]=(0.1)*(1+ cos (360.0*PI*(i/N-0.5)/180));
i=i+1;
end
vpa(v,10)
disp('v=');
disp(v);
%v
M = cell(1,NT-1);

for i = 1:NT-1 % L changable parameter

M{i} = [(1+(detT/(5*detX*detX))-detT+2*detT*u(i)+4*detT*v(i)),(4*detT*u(i));(-4*detT*v(i)),(1+2*detT/(detX*detX)+0.25*detT-4*detT*u(i)+5*detT*lm*exp(-5*v(i)))];

end
disp(blkdiag(M{:}));
%disp(size(M{1}));
UP = cell(1,NT-1);
for i = 1:NT-1 % L changable parameter

UP{i} =[-detT/(10*detX*detX),0;0,-detT/(detX*detX)];

end

DOWN=cell(1,NT-1);
for i = 1:NT-1 % L changable parameter

DOWN{i} =[-detT/(10*detX*detX),0;0,-detT/(detX*detX)];

end
RR=spdiags(M{i},0,NT-1);
disp(RR);
%A = blktridiag(DOWN{i},M{i},UP{i},NT-1);%+blkdiag(M{:});

A = spdiags(repmat([DOWN M UP],NT,1),-1:1,NT,NT);
vpa(A,10)
disp(A);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.