-3
Enter n: 3
Enter range: 50  // range of prime numbers



A =  1 12 37 
     24 45 11
     2  34 10

matrix sum = 48

solution submatrix = 37   //largest rectangle of primes
                     11


coordinates are= 1 3 2 3

First program gives a random matrix and finds largest rectangle consists of primes(submatrix) and then displaying their sum and coordiantes.

how can i write a program like this in matlab?

beaker
  • 16,331
  • 3
  • 32
  • 49

1 Answers1

0

I assume you are looking at a 3 x 3 matrix:

 1 12 37
24 45 11
 2 34 10

Start by finding all the prime numbers in the matrix. In this case 37, 11, 2.

Quite what you want to do then is not clear from your question. Do you want a submatrix with those three number and others or do you want submatrices with all prime numbers?

It is not clear where you get the sum of 48 from. 37 + 11 = 48, but that leaves out the prime 2. The sum on the three primes is 50.

You need to clarify your question if you want more help.

rossum
  • 15,344
  • 1
  • 24
  • 38