
format compact
format long

fprintf('Tests to determine how the tolerance parameter is handled for determining real numbers\n');
fprintf('How is the default tolerance used?\n');
for j = 80:400
z=1+j*eps*1i;
try
cplxpair(z);
catch
break;
end
end
fprintf('Was real until 1 + %d*eps*i\n', j-1);
fprintf('abs(z) = %g\n', abs(z));

fprintf('Do we get the same results by passing 100*eps for the tolerance?\n');
for j = 80:400
z=1+j*eps*1i;
try
cplxpair(z,100*eps);
catch
break;
end
end
fprintf('Was real until 1 + %d*eps*i\n', j-1);
fprintf('abs(z) = %g\n', abs(z));

fprintf('Does doubling the tolerance work as expected?\n');
for j = 80:400
z=1+j*eps*1i;
try
cplxpair(z,200*eps);
catch
break;
end
end
fprintf('Was real until 1 + %d*eps*i\n', j-1);
fprintf('abs(z) = %g\n', abs(z));

fprintf('Tests with default tolerance\n');
fprintf('Determine how real numbers are found\n');
for j = 80:400
  z=1+j*eps*1i;
  try
    cplxpair(z);
  catch
    break;
  end
end
fprintf('Was real until 1 + %d*eps*i\n', j-1);
fprintf('abs(z) = %g\n', abs(z));

fprintf('If the real part is doubled how does it compare\n');
for j = 80:400
  z=2+j*eps*1i;
  try
    cplxpair(z);
  catch
    break;
  end
end

fprintf('Was real until 2 + %d*eps*i\n', j-1);
fprintf('abs(z) = %g\n', abs(z));

fprintf('What if there is another real value of large magnitude\n');
for j = 80:400
z=[2+j*eps*1i, 400];
try
cplxpair(z);
catch
break;
end
end
fprintf('Was real until 2 + %d*eps*i\n', j-1);
absz = abs(z);
fprintf('abs(z) = %g\n', absz(1));

fprintf('Tests for complex pairs\n');
fprintf('What if there is error in the real part, but imaginary parts are equal\n');
for j = 80:400
z=[1+j*eps+1i,1 - 1i];
try
cplxpair(z);
catch
break;
end
end
fprintf('Pairing was successful until (1 + %d*eps) + 1i, 1 - 1i\n', j-1);
absz = abs(z);
fprintf('abs(z) = %g\n', absz(1));


fprintf('if the imaginary part is doubled what happens\n');
for j = 80:400
z=[1+j*eps+2i,1 - 2i];
try
cplxpair(z);
catch
break;
end
end
fprintf('Pairing was successful until (1 + %d*eps) + 2i, 1 - 2i\n', j-1);
absz = abs(z);
fprintf('abs(z) = %g\n', absz(1));




fprintf('how are errors in the imaginary part handled\n');
for j = 80:400
z=[1+j*eps*1i+1i,1 - 1i];
try
cplxpair(z);
catch
break;
end
end
fprintf('Pairing was successful until 1 + (%d*eps*1i + 1i), 1 - 1i\n', j-1);
absz = abs(z);fprintf('abs(z) = %g\n', absz(1));


fprintf('scale the real part\n');
for j = 80:400
z=[2+(j*eps*1i)+1i,2 - 1i];
try
cplxpair(z);
catch
break;
end
end
fprintf('Pairing was successful until 2 + (%d*eps*1i + 1i), 2 - 1i\n', j-1);
absz = abs(z);fprintf('abs(z) = %g\n', absz(1));

fprintf('scale the imaginary part\n');
for j = 80:400
z=[1+j*eps*1i+2i,1 - 2i];
try
cplxpair(z);
catch
break;
end
end
fprintf('Pairing was successful until 1 + (%d*eps*1i + 2i), 1 - 2i\n', j-1);
absz = abs(z);fprintf('abs(z) = %g\n', absz(1));

fprintf('Add a larger pair of cojugates to make sure it is being done per pair\n');
for j = 80:400
z=[1+j*eps*1i+2i,1 - 2i, 400 + 100i, 400 - 100i];
try
cplxpair(z);
catch
break;
end
end
fprintf('Pairing was successful until 1 + (%d*eps*1i + 2i), 1 - 2i, 400 + 100i, 400 - 100i\n', j-1);
absz = abs(z);fprintf('abs(z) = %g\n', absz(1));

fprintf('sort order with a real, and error in the imaginary part\n');
z=[1;1+80*eps*i+1i;1-1i]
cplxpair(z)
z=[1;1+1i;1-80*eps*1i-1i]
cplxpair(z)

fprintf('does the input order matter for the real part\n');
z=[1+80*eps*i+1i;1-1i;1]
cplxpair(z)
z=[1+1i;1+80*eps*1i-1i;1]
cplxpair(z)

fprintf('does the input order matter for the cplx pairs\n');
z=[1+80*eps+1i;1-1i]
cplxpair(z)
z=[1-1i;1+80*eps+1i]
cplxpair(z)

fprintf('If value is real, with imaginary component less than tolerance, is result real?');
z=1+80*eps*1i
cplxpair(z)
isreal(ans)
