Why do I have differnt answers every time!
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
As title. This is my code. I don't understand why the answers will change each time I run it! Please tell me if there is any wrong! Thx!!
DelT = 0.1;
DelX = 0.2;
for i = 1:6
for j = 1:50
T(i,1) = 100;
T(6,j) = 100;
if j > 1
T(1,j) = 30;
else
T(1,j) = 100;
end
end
end
for i = 2:5
for j = 1:49
T(i,j+1) = T(i,j) + (0.1*DelT / (DelX^2) )* (T(i+1,j)-2*T(i,j)+T(i-1,j)) ;
end
end
T'
0 个评论
回答(2 个)
Azzi Abdelmalek
2013-10-20
编辑:Azzi Abdelmalek
2013-10-20
Start your code with
clear T
% Or better, pre-allocate
T=zeros(6,50)
0 个评论
CHANG CHUN
2013-10-20
编辑:CHANG CHUN
2013-10-20
0 个投票
1 个评论
Image Analyst
2013-10-20
The value of T(2,3) is 57.5. It is that value the first time and every time - it does not change after repeated runs. I don't know why you think it should. It did before but you didn't like that so Azzi gave you code to correct that and now it will not change every time. We don't know what you want or why you think 82.5 is the correct value. By the way, your "Answer" is not an answer so it should have been a comment to Azzi.
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!