Error using oddiyxy1 (line 23) Error: The variable a in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".
Show older comments
n=91; h=1/(n-1); nt=1080; tau=0.001;
for i=1:n
x(i)=(i-1)*h; y(i)=(i-1)*h;
end
for j=1:n
for i=1:n
p0(i,j)=1;
end
end
for jt=1:nt
t(jt)=jt*tau;
for j=1:n
for i=1:n
pt(i,j)=exp(-2*x(i)*y(j)*t(jt));
end
end
end
tic
parfor jt=1:nt
for j=2:n-1
for i=2:n-1
a(i)=1; c(i)=1; b(i)=2+2*h*h/tau;
ff=h*h*(-2*(2*t(jt)*t(jt)*(x(i)*x(i)+y(j)*y(j))+x(i)*y(j))*exp(-2*x(i)*y(j)*t(jt)));
d(i)=2*h*h/tau*p0(i,j)+(p0(i,j-1)-2*p0(i,j)+p0(i,j+1))+ff;
end
aa1(1)=0; bb1(1)=1;
for i=2:n-1
aa1(i)=c(i)/(b(i)-aa1(i-1)*a(i)); bb1(i)=(d(i)+bb1(i-1)*a(i))/(b(i)-aa1(i-1)*a(i));
end
p(n,j)=exp(-2*y(j)*t(jt));
for i=n-1:-1:1
p(i,j)=aa1(i)*p(i+1,j)+bb1(i);
end
end
for i=1:n
p(i,n)=exp(-2*x(i)*t(jt)); p(i,1)=1;
end
for j=1:n
for i=1:n
p0(i,j)=p(i,j);
end
end
for i=2:n-1
for j=2:n-1
a(j)=1; c(j)=1; b(j)=2+2*h*h/tau;
ff=h*h*(-2*(2*t(jt)*t(jt)*(x(i)*x(i)+y(j)*y(j))+x(i)*y(j))*exp(-2*x(i)*y(j)*t(jt)));
d(j)=2*h*h/tau*p0(i,j)+(p0(i-1,j)-2*p0(i,j)+p0(i+1,j))+ff;
end
aa1(1)=0; bb1(1)=1;
for j=2:n-1
aa1(j)=c(j)/(b(j)-aa1(j-1)*a(j)); bb1(j)=(d(j)+bb1(j-1)*a(j))/(b(j)-aa1(j-1)*a(j));
end
p(i,n)=exp(-2*x(i)*t(jt));
for j=n-1:-1:1
p(i,j)=aa1(j)*p(i,j+1)+bb1(j);
end
end
for j=1:n
p(n,j)=exp(-2*y(j)*t(jt)); p(1,j)=1;
end
for i=1:n
for j=1:n
p0(i,j)=p(i,j);
end
end
end
toc
for j=1:n
px(j)=p0(21,j); pxt(j)=pt(21,j);
end
x=0:h:1;
y=0:h:1;
figure ('Position',[600 160 700 600]);
subplot(3,2,1);
meshc(x,y,pt)
title('АНИК ЕЧИМ 3D ГРАФИГИ')
subplot(3,2,2);
meshc(x,y,p0)
title('CОНЛИ ЕЧИМ 3D ГРАФИГИ')
subplot(3,2,3);
contour(x,y,pt,'ShowText','on','LineWidth',2);
title('АНИК ЕЧИМ КОНТУР ГРАФИГИ')
subplot(3,2,4);
contour(x,y,p0,'ShowText','on','LineWidth',2);
title('CОНЛИ ЕЧИМ КОНТУР ГРАФИГИ')
subplot(3,2,5);
plot(x,px,x,pxt);
title('КЕСИМДА АНИК ВА CОНЛИ ЕЧИМ ЎЗГАРИШИ X БЎЙИЧА')
Accepted Answer
More Answers (1)
Minimal example:
parfor jt=1:1
a(1) = 1;
end
For whatever reason, parfor is unable to determine that a is acting as a local variable. If you assign to all of a within the parfor loop, such as if you had
a = zeros(1,n-1);
then MATLAB would be able to figure it out. As it is, MATLAB worries that there might be an existing a or that a might be used after the loop.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!