Why do I have differnt answers every time!
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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'
Answers (2)
Azzi Abdelmalek
on 20 Oct 2013
Edited: Azzi Abdelmalek
on 20 Oct 2013
Start your code with
clear T
% Or better, pre-allocate
T=zeros(6,50)
CHANG CHUN
on 20 Oct 2013
Edited: CHANG CHUN
on 20 Oct 2013
0 votes
1 Comment
Image Analyst
on 20 Oct 2013
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.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!