- #1
robby991
- 41
- 1
Hi, I had developed some Matlab code to solve the heat equation using central difference. I was having issues with my code because I was running out of memory trying to keep the algorithm stable. I need to reconfigure my code so to use single vectors in the time/space stepping, rather than initializing a whole matrix for plotting, so the last step in time and space is a single vector at t=tmax which is used for plotting. A simplified code of how I am currently solving the heat equation is shown below. I am confused how to solve this by vectorizing. Any suggestions would be appreciated.
Code:
nx = 30;
nt = 100000;
M = zeros(nt,nx);
M(:,nx) = M0;
for j=1:nt-1
for i=2:nx-1
M(j+1,i) = M(j,i) + (dts/dxs^2)*Ds*(M(j,i+1) - 2*M(j,i) + M(j,i-1))-((Vmax*dts*M(j,i))/(Km+M(j,i)));
end
M(j+1,1)=M(j,1)+dts*Ds*2*(M(j,2)-M(j,1))./dxs.^2-((Vmax*dts*M(j,i))/(Km+M(j,i))); %neumann BC
end