matrice.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. function A=matrice(n,i_mat)
  2. %
  3. % function [A] = matrice(n,i_mat)
  4. %
  5. % This function allows to choose the coefficient matrix of
  6. % the linear system A*x=b.
  7. %
  8. % Input :
  9. % n : the size of the coefficient matrix of
  10. % the linear system A*x=b
  11. % i_mat : integer (i_rhs = 1 or 2 or 3 or 4)
  12. % if i_mat = 1 then A(i,j) = (alpha*j-beta) / (n-i+j) if j <= i
  13. % and A(i,j) = (alpha*i-beta) / (n-i+j) if j > i
  14. % if i_mat = 2 then A(i,j) = i if j <= i
  15. % and A(i,j) = j if j > i
  16. % if i_mat = 3 then A(i,j) = abs(i-j)+1/(i-j) if (j < i and j > i)
  17. % and A(i,j) = 0 if i=j \n')
  18. % if i_mat = 4 then A(i,j)= i+j
  19. %
  20. % Output :
  21. % A : the coefficient matrix of the linear system A*x=b
  22. %
  23. %
  24. if (i_mat==1)
  25. a=input('Enter alpha : ');
  26. b=input('Enter beta : ');
  27. for i=1:n
  28. for j=1:i
  29. A(i,j)=(a*j-b)/(n-i+j);
  30. end
  31. for j=i+1:n
  32. A(i,j)=(a*i-b)/(n-i+j);
  33. end
  34. end
  35. end
  36. if (i_mat==2)
  37. for i=1:n
  38. for j=1:i
  39. A(i,j)=i;
  40. end
  41. for j=i+1:n
  42. A(i,j)=j;
  43. end
  44. end
  45. end
  46. if (i_mat==3)
  47. for i=1:n
  48. for j=1:i-1
  49. A(i,j)=abs(i-j)+1/(i-j);
  50. end
  51. for j=i+1:n
  52. A(i,j)=abs(i-j)+1/(i-j);
  53. end
  54. A(i,i)=0;
  55. end
  56. end
  57. if (i_mat==4)
  58. for i=1:n
  59. for j=1:n
  60. A(i,j)=i+j;
  61. end
  62. end
  63. end