Why is it taking so long to execute program?
Ältere Kommentare anzeigen
Hello,
I have two similar programs, but their execution time is so different. This one executes very fast:
n(N_go)=ninf;
n(N_go-1)=ninf-epsi;
for m=(N_go-1):-1:2
n(m-1)=h^2/D*(B*n(m)^2-G)+2*n(m)-n(m+1);
end;
And this one takes very very long:
n(1)=n0;
n(2)=C/(2*D)*n(1)*h+n(1);
for m=2:1:N_go
n(m+1)=h^2/D*(B*n(m)^2-G)+2*n(m)-n(m-1);
end;
N_go=10000000 in both cases. Other parameters are also equal. Can someone explain to me, why second code is taking so long to execute?
1 Kommentar
John D'Errico explains the difference in some detail. You can also read what The Mathworks (MATLAB) have to say about array preallocation here:
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!