The easiest way to come up with a system of linear equations that requires partial pivoting to solve them is to:
Nice multiples are those z such that |z|<1 where each component has at most one digit after the decimal point, thus including:
0 0.1j 0.2j 0.3j 0.4j 0.5j 0.6j 0.7j 0.8j 0.9j 0.1 0.1+0.1j 0.1+0.2j 0.1+0.3j 0.1+0.4j 0.1+0.5j 0.1+0.6j 0.1+0.7j 0.1+0.8j 0.1+0.9j 0.2 0.2+0.1j 0.2+0.2j 0.2+0.3j 0.2+0.4j 0.2+0.5j 0.2+0.6j 0.2+0.7j 0.2+0.8j 0.2+0.9j 0.3 0.3+0.1j 0.3+0.2j 0.3+0.3j 0.3+0.4j 0.3+0.5j 0.3+0.6j 0.3+0.7j 0.3+0.8j 0.3+0.9j 0.4 0.4+0.1j 0.4+0.2j 0.4+0.3j 0.4+0.4j 0.4+0.5j 0.4+0.6j 0.4+0.7j 0.4+0.8j 0.4+0.9j 0.5 0.5+0.1j 0.5+0.2j 0.5+0.3j 0.5+0.4j 0.5+0.5j 0.5+0.6j 0.5+0.7j 0.5+0.8j 0.6 0.6+0.1j 0.6+0.2j 0.6+0.3j 0.6+0.4j 0.6+0.5j 0.6+0.6j 0.6+0.7j 0.7 0.7+0.1j 0.7+0.2j 0.7+0.3j 0.7+0.4j 0.7+0.5j 0.7+0.6j 0.7+0.7j 0.8 0.8+0.1j 0.8+0.2j 0.8+0.3j 0.8+0.4j 0.8+0.5j 0.9 0.8+0.1j 0.8+0.2j 0.8+0.3j 0.8+0.4j
I would suggest the following code:
Get a multiplier that is of the form z=±0.m±0.nj such that |z|≤0.75. This second condition ensures that it is reasonably easy to determine the maximum entry in absolute value.
function z = multiplier() do z = (round( rand()*19 ) - 10)*0.1 + (round( rand()*19 ) - 10)*0.1*j; until abs( z ) < 0.75 end
Get an entry of the matrix that is non-zero on the diagaonal entries and possibly zero on the strictly upper-triangular entries.
function z = entry( nonzero ) do z = round( rand()*19 - 9.5) + round( rand()*19 - 9.5 )*1j; until ~nonzero || abs( z ) > 0; end
Code to find the matrices is as follows, but we check to make sure that, for example, at most one entry of the solution vector is zero, and that no component in the target vector has more than two digits in the significand.
N = 3; % This can be any positive integer A = zeros( N, N ); for i = 1:N for j = i:N A(i, j) = entry( i == j ); end end for j = (N - 1):-1:1 for i = (j + 1):N A(i,:) += multiplier()*A(j,:); end end do do u = 0.1*round( 19*rand( N, 1 ) - 9.5 ) + 0.1j*round( 19*rand( N, 1 ) - 9.5 ); until sum( u == 0 ) <= 1; b = A*u; found = true; arb = abs(real(round( 100*b ))); aib = abs(imag(round( 100*b ))); % Make sure no entry in the target vector has more than % two digits in the significand, so mn.00, m.n0 or 0.mn. if any( arb >= 100 & 10*round( arb/10 ) ~= arb ) ... || any( aib >= 100 & 10*round( aib/10 ) ~= aib ) ... || any( arb >= 1000 & 100*round( arb/100 ) ~= arb ) ... || any( aib >= 1000 & 100*round( aib/100 ) ~= aib ) found = false; end; until found; A u b
In order to introduce required row swaps, start with Row n−1 going down to Row 1, and at each step, optionally swap Row i with any Row k where k>i:
for i = (N - 1):-1:1 k = i + floor( rand()*(N - i + 1) ); A([i,k],:) = A([k,i],:); b([i,k]) = b([k,i]); end
Without row swaps, some examples for N=2 are:
(−4−3j5+4j−3.4−1.3j11.3+10.8j)(0.6+0.5j0.7+0.4j)=(1+j2.2+9.6j)
(−1−2j6−9j1.3−0.9j2.9+7.3j)(−0.2j−0.6+0.6j)=(1.4+9.2j−6.3−2.9j)
(4+8j2+2j−2.8+0.4j1.2−0.6j)(0.9+0.9j−0.4−0.4j)=(−3.6+9.2j−3.6−2.4j)
(−6+5j−6−4j4.1+3.7j−1.2+13.6j)(0.2+0.6j0.1−0.2j)=(−5.6−1.8j1.2+4.8j)
Note that because the multipliers are of the form 0.m+0.nj, it follows that all the ratios −3.4−1.3j−4−3j=(−3.4−1.3j)(−4+3j)25=17−5j25=0.7−0.2j, 1.3−0.9j−1−2j=(1.3−0.9j)(−1+2j)5=0.5+3.5j5=0.1+0.7j, −2.8+0.4j4+8j=(−2.8+0.4j)(4−8j)80=−8+24j80=−0.1+0.3j and 4.1+3.7j−6+5j=(4.1+3.7j)(−6−5j)61=−6.1−42.7j61=−0.1−0.7j must simplify to such a value.
Again, without row swaps, some examples for N=3 are:
(−2−8j−9−1j9+5j0.8−3.6j−0.4−0.2j2.6+10.8j−3.4j−1.2−0.2j−5.2+11.8j)(0.6−0.5j−0.6+0.4j0.5j)=(−1.9−2.3j−6.4−1.3j−6.8−5j)
(−9−8j−2+4j8−1j−2.2−8.4j−11.8−3.4j7.2−2.4j1.2−8.6j0.4+2.4j10+2.4j)(0.9+0.1j0.5−0.7j0.5+0.3j)=(−1.2−2.8j−5.1−0.26j8.1−2.5j)
(1+3j2+9j−1−2j−0.3−1.9j−3.3+2.4j−3.6+2.3j−0.4−1.2j−1.7−1.2j−8.8−1.9j)(−0.7−0.5j0.3+0.4j−0.2+0.1j)=(−1.8+1.2j−2.2+0.06j1.6−0.5j)
(−4−4j5+2j−7−6j3.6+0.4j−8.3+5j−1.1+1.2j4+0.8j−4.8−2.5j5.5−5.9j)(−0.4−0.2j0.3−0.6j0.9−0.2j)=(−4−4j−1.6+6.9j−0.61−5.4j)
Finally, again without row swaps, two examples from N=4 are:
(5+5j4j−9+1j7+9j2−2j9.6−7j2.4+10.6j11.6−1.8j3.5−0.5j−0.6+0.3j−8.1+3.8j14.1−1.8j4.5−2.5j−1+1.3j1.6+7.3j−1.3−15.5j)(0.4+0.8j−0.7+0.8j−0.7−0.5j−0.3−0.4j)=(3.1+1.5j0.7+0.66j4.6−1.8j0.18+0.15j)
(7+7j1+9j4−8+9j2.8+2.8j−5.6+8.6j4.6+9j−6.2−5.4j3.5+2.1j4.3+1j−8.9−8.9j−6.8−0.1j−4.2+1.4j−7.5−3.4j−9.4+8.2j4.6−17j)(−0.3−0.4+0.7j0.1+0.3j−0.4−0.3j)=(−2.5−5j−6−1.9j1+0.5j−3.7−0.89j)