Info

この質問は閉じられています。 編集または回答するには再度開いてください。

3-D Thermal Problem

2 ビュー (過去 30 日間)
Yattapu Yaswanth
Yattapu Yaswanth 2014 年 5 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I'm working on my Home Work Problem, it took more than 9 weeks still I'm not able to solve. There are many errors, can anyone help me on this please and most important thing is I'M NEW TO MATLAB.
  2 件のコメント
Star Strider
Star Strider 2014 年 5 月 8 日
There must be hundreds of lines of code here.
  1. What are you doing? Please describe your homework assignment. What were you given, and what are you supposed to accomplish? What are your constraints?
  2. What is not working? (What is it not doing that it should do? What is it doing that it shouldn’t do?)
  3. Where is the problem? If there is an error, what is the error and what line does it refer to? (Copy the entire red error message from the Command Window and paste it to your question.)
Yattapu Yaswanth
Yattapu Yaswanth 2014 年 5 月 8 日
how to preallocate for speed for a line "Ttot might be growing inside a loop. consider preallocating for speed" can you explain on this how to preallocate for speed
I have seen these errors for every line so can you explain in preallocating for speed for these type of issues

回答 (1 件)

Star Strider
Star Strider 2014 年 5 月 8 日
‘Preallocating for speed’ means creating a matrix of zeros before you calculate the elements of the matrix in a loop. The reason is that MATLAB can then simply fill the preallocated matrix in the loop, and not have to create memory space for each element as it is created. The ‘preallocating for speed’ isn’t an error, but a (quite valuable) suggestion.
For example without preallocating:
tic
for k1 = 1:500
for k2 = 1:500
A(k1, k2) = k1.^(k2/100);
end
end
toc
Elapsed time is 0.142800 seconds.
Preallocating:
A = zeros(500,500);
tic
for k1 = 1:500
for k2 = 1:500
A(k1, k2) = k1.^(k2/100);
end
end
toc
Elapsed time is 0.063392 seconds.
Even including the preallocation step in the time interval: Elapsed time is 0.066296 seconds.
So preallocating definitely saves time.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by