matrice.m 1.5 KB

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