From d7dcbdf32f7d55a002a9015b785fdadba0124f6c Mon Sep 17 00:00:00 2001 From: "Per.Andreas.Brodtkorb" Date: Thu, 4 Oct 2012 11:33:12 +0000 Subject: [PATCH] Added check on n --- pywafo/src/wafo/demos.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pywafo/src/wafo/demos.py b/pywafo/src/wafo/demos.py index 97b70f7..b2406c7 100644 --- a/pywafo/src/wafo/demos.py +++ b/pywafo/src/wafo/demos.py @@ -36,6 +36,9 @@ def magic(n): [30, 5, 34, 12, 14, 16], [ 4, 36, 29, 13, 18, 11]]) ''' + if (n<3): + raise ValueError('n must be greater than 2.') + if np.mod(n,2)==1: # odd order ix = np.arange(n) + 1 J, I = np.meshgrid(ix, ix) @@ -69,10 +72,10 @@ def magic(n): M[i][j] = M[i+p][j] M[i+p][j] = temp; - j=i; - temp=M[i+p][j]; - M[i+p][j]=M[i][j]; - M[i][j]=temp; + j=i + temp=M[i+p][j] + M[i+p][j]=M[i][j] + M[i][j]=temp return M