fork download
  1. % 1. Matrix Creation
  2. A = zeros(4, 4);
  3. for i = 1:4
  4. for j = 1:4
  5. A(i, j) = i + j;
  6. end
  7. end
  8.  
  9. % 2. Polynomial Definition
  10. % q(x) = x^3 - 4x^2 + 2x + 1
  11. coeffs = [1 -4 2 1];
  12.  
  13. % 3. Matrix Transformation
  14. B = zeros(4, 4);
  15. for i = 1:4
  16. for j = 1:4
  17. B(i, j) = polyval(coeffs, A(i, j));
  18. end
  19. end
  20.  
  21. % 4. Minimum Search using a WHILE loop
  22. min_val = B(1, 1);
  23. min_row = 1;
  24. min_col = 1;
  25.  
  26. i = 1;
  27. while i <= 4
  28. j = 1;
  29. while j <= 4
  30. if B(i, j) < min_val
  31. min_val = B(i, j);
  32. min_row = i;
  33. min_col = j;
  34. end
  35. j++;
  36. end
  37. i++;
  38. end
  39.  
  40. % 5. Output
  41. disp("Matrix B:");
  42. disp(B);
  43. printf("Minimum value: %d\n", min_val);
  44. printf("Position of minimum value: Row %d, Column %d\n", min_row, min_col);
  45.  
Success #stdin #stdout 0.12s 46564KB
stdin
Standard input is empty
stdout
Matrix B:
    -3    -2     9    36
    -2     9    36    85
     9    36    85   162
    36    85   162   273
Minimum value: -3
Position of minimum value: Row 1, Column 1