Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 23rd, 2012  |  syntax: None  |  size: 0.99 KB  |  views: 56  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function [x] = Gs_100()
  2.  
  3. num=100;
  4.  
  5.  
  6. A=zeros(num,num);
  7. b=zeros(num,1);
  8.  
  9.  
  10. b(1)=2;
  11. b(num)=2;
  12.  
  13. for i=2:num-1
  14.     b(i)=1;
  15. end
  16.  
  17. for i=1:num
  18.     A(i,i)=3;
  19.  
  20. end
  21.  
  22. for i=2:num
  23.     A(i-1,i)=-1;
  24. end
  25.  
  26.  
  27. for i=1:num-1
  28.     A(i+1,i)=-1;
  29. end
  30.  
  31.  
  32. A
  33.  
  34. b
  35.  
  36. d=zeros(num,1);
  37. ep=zeros(num,1);
  38.  
  39.  
  40. d(1)=A(1,1);
  41. ep(1)=b(1)/d(1);
  42.  
  43.  
  44. for i=2:num-1
  45.    
  46.     d(i)=A(i,i)-A(i-1,i)*ep(i-1);
  47.     ep(i)=b(i)/d(i);
  48.    
  49. end
  50.  
  51. d(num)=d(num)-A(num-1,num)*ep(num-1);
  52.  
  53.  
  54. L=zeros(num,num);
  55. U=zeros(num,num);
  56.  
  57.  
  58. for i=1:num
  59.  L(i,i)=d(i);
  60. end
  61.  
  62. for i=1:num-1
  63.     L(i+1,i)=A(i+1,i);
  64. end
  65.  
  66. for i=1:num
  67.     U(i,i)=1;
  68. end
  69.  
  70. for i=1:num-1
  71.     L(i+1,i)=A(i+1,i);
  72. end
  73.  
  74.  
  75. for i=2:num
  76.     U(i-1,i)=A(i-1,i);
  77.    
  78. end
  79.  
  80. fprintf('Aνάλυση LU του πίνακα Α.O U θα είναι άνω τριγωνικός με μονάδες στην κύρια διαγώνιο και ο L κάτω τριγωνικός\n')
  81.  
  82. U
  83. L
  84.  
  85. y=GaussSeidelFunction(L,b);
  86.  
  87. x=GaussSeidelFunction(U,y);
  88.  
  89. end