This is a matlab program which models a finite difference equation, I am having big problems with the three loops.
clear
dimension=48;
a=400;
Tzero=-30;
Q1=0; Q2=0; Q3=500; Q4=0;
Q3case(1)=100;
Q3case(2)=300;
Q3case(3)=500;
Q3case(4)=700;
figure(2)
hold off
for iQcase=1:4
Q3=Q3case(iQcase);
maxk=10; oneoverdt=10;
mcase=1;
max=4*mcase+1; maxmat=max*max;
delta=dimension/(max-1);
gamma=delta*delta/a;
beta=gamma*oneoverdt;
alpha=4+beta;
A=speye(maxmat);
x=zeros(maxmat,1);
r=x;
for i=1:maxmat
x(i)=Tzero;
r(i)=Tzero;
for j=1:maxmat
A(i,j)=0.0;
end;
A(i,i)=1.0;
end;
m=max-1;
for j=2:max-1
m=m+2;
for i=2:max-1
m=m+1;
A(m,m-max)=-1.0;
A(m,m-1)=-1.0;
A(m,m)=alpha;
A(m,m+1)=-1.0;
A(m,m+max)=-1.0;
end;
end;
m3=1+(max+1)*mcase;
m4=m3+2*mcase;
m2=maxmat-(max+1)*mcase;
m1=m2-2*mcase;
for k=1:maxk
m=max-1;
for j=2:max-1
m=m+2;
for i=2:max-1
m=m+1;
r(m)=beta*x(m);
end;
end;
Matlab problem; can anybody explain what is happening in these three loops?
What's the problem? Does it not run at all? Does it crash partway through? Does it return the wrong result? Does it return the correct result, but only after a long time?
What problem is this solving, and what is the expected result?
Loose Teeth
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment