system of equations runs slow

조회 수: 2 (최근 30일)
Conrado Garcia
Conrado Garcia 2020년 4월 23일
댓글: darova 2020년 4월 23일
Hi to everyone!
Here I present a problem that occurs to me when running a simulation
I have to solve a system of equations multiple times. The system is linear and can be solved by x=A\b. there are 273 variables. The system has to be solved 87600 times. Since every iteration depends on the results of the previous time step (t) the matrix A is changing. In the code below you have my approach. R(j,i) and C(j,i) are previously calculated.
The problem is that for every iteration of t it takes about 1 minute.
syms T [length(depth) length(r)]
syms Tbor
k=1;
t=1;
Tsol=Tm*ones(length(depth),length(r),tsimulation);
for t=1:tsimulation
for j=1:length(depth)
tic
for i=1:length(r)
Tprev=Tm;
if i==1 && j==1
% eqns(k)= 2*(Tf0(t)-Tb)/Rb + (T(j,1)-Tb)/R(j,1)== 0;
% k=k+1;
eqns(k)= (Tb(t)-T(j,i))/R(j,i) +(T(j,i+1)-T(j,i))/R(j,i+1) + (Tsurface(t)-T(j,i))/Rprima + (T(j+1,i)-T(j,i))/Rprima - C(j,i)*(T(j,i)-Tprev)/paso ==0;
end
if i==1 && j>1 && j<length(depth)
% eqns(k)= 2*(Tf0(t)-Tb(t))/Rb + (T(j,1)-Tb(t))/R(j,1)== 0;
% k=k+1;
eqns(k)= (Tb(t)-T(j,i))/R(j,i) +(T(j,i+1)-T(j,i))/R(j,i+1) + (T(j-1,i)-T(j,i))/Rprima + (T(j+1,i)-T(j,i))/Rprima - C(j,i)*(T(j,i)-Tprev)/paso ==0;
end
if i>1 && j==1 && i<length(r)
eqns(k)= (T(j,i-1)-T(j,i))/R(j,i) +(T(j,i+1)-T(j,i))/R(j,i+1) + (Tsurface(t)-T(j,i))/Rprima + (T(j+1,i)-T(j,i))/Rprima - C(j,i)*(T(j,i)-Tprev)/paso ==0;
end
if i>1 && j>1 && i<length(r) && j<length(depth)
eqns(k)= (T(j,i-1)-T(j,i))/R(j,i) +(T(j,i+1)-T(j,i))/R(j,i+1) + (T(j-1,i)-T(j,i))/Rprima + (T(j+1,i)-T(j,i))/Rprima - C(j,i)*(T(j,i)-Tprev)/paso ==0;
end
if i==length(r) || j==length(depth)
eqns(k)= T(j,i)==Tm;
end
k=k+1;
end
end
[A b]=equationsToMatrix(eqns,T);
Tb(t)=(-2*R(j,1)*Tf0(t)-Rb*Tsol(j,1,t))/(-2*R(j,1)-Rb);
if t==1
Tprev=Tm;
else
Tprev=Tsol(j,i,t-1);
end
Tcalc=A\b; toc;
Tcalc=double(Tcalc);
% Tcalc=[Tcalc{:}];
% Tcalc=double(Tcalc);
for j=1:length(depth)
for i=1:length(r)
Tsol(j,i,t)=Tcalc(i);
end
end
t
end
  댓글 수: 1
darova
darova 2020년 4월 23일
Can you tell which part of your code takes more (solving the system or creating using syms)?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by