Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. clear
  2. clc
  3. Nx = 5;
  4. Ny = 6;
  5. %Dieu kien sai so
  6. tol = 1d-6;
  7. %Sai so
  8. err =1;
  9. k = 0;
  10. T = [ 0 300 300 300 0; 75 0 0 0 100; 75 0 0 0 100; 75 0 0 0 100; 75 0 0 0 100; 0 50 50 50 0 ];
  11. Tkp1 = T;
  12. fprintf( ' k|')
  13. for j = 1 : Ny -2
  14. for i = 1 : Nx -2
  15. fprintf(' T(%li,%li) |',j,i)
  16. end
  17. end
  18. fprintf(' error\n')
  19. while err > tol
  20. k = k + 1;
  21. fprintf('%4i |',k);
  22. % Tính T(i,j) theo phuong pháp sai phân trung tâm
  23. for j = 2: Ny -1
  24. for i = 2 : Nx -1
  25. Tkp1(j,i) = 0.25*(T(j+1,i) + T(j,i+1) + T(j-1,i) + T(j,i-1));
  26. fprintf( '%10.6f |', Tkp1(j,i));
  27. end
  28. end
  29. %Tính sai so
  30. err = sqrt(sum(sum(Tkp1 - T).^2));
  31. fprintf( '%10.6f \n', err);
  32. T =Tkp1;
  33. surf(T);
  34. getframe();
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement