int main() { array double a[2][2] = {2, -4, 3, -7}; array double b[3][2] = {2, -4, 3, -7, 1, 5}; array double c[2][3] = {2, -4, 3, -7, 1, 5}; array double complex d[3] = {2, -4, 3}; double anorm; /* a is nxn */ anorm = norm(a, "1"); printf("1-norm of a = %f\n", anorm); anorm = norm(a, "2"); printf("2-norm of a = %f\n", anorm); anorm = norm(a, "i"); printf("infinity-norm of a = %f\n", anorm); anorm = norm(a, "f"); printf("Frobenius-norm of a = %f\n", anorm); anorm = norm(a, "m"); printf("max(abs(a)) = %f\n\n", anorm); /* a is nxm */ anorm = norm(b, "1"); printf("1-norm of b = %f\n", anorm); anorm = norm(b, "2"); printf("2-norm of b = %f\n", anorm); anorm = norm(b, "i"); printf("infinity-norm of b = %f\n", anorm); anorm = norm(b, "f"); printf("Frobenius-norm of b = %f\n", anorm); anorm = norm(b, "m"); printf("max(abs(a)) = %f\n\n", anorm); /* a is mxn */ anorm = norm(c, "1"); printf("1-norm of c = %f\n", anorm); anorm = norm(c, "2"); printf("2-norm of c = %f\n", anorm); anorm = norm(c, "i"); printf("infinity-norm of c = %f\n", anorm); anorm = norm(c, "f"); printf("Frobenius-norm of c = %f\n", anorm); anorm = norm(c, "m"); printf("max(abs(a)) = %f\n\n", anorm); /* a is 1-dim */ anorm = norm(d, "1"); printf("1-norm of d = %f\n", anorm); anorm = norm(d, "2"); printf("2-norm of d = %f\n", anorm); anorm = norm(d, "2.1"); printf("2.1-norm of d = %f\n", anorm); anorm = norm(d, "i"); printf("infinity-norm of d = %f\n", anorm); anorm = norm(d, "-i"); printf("negative infinity-norm of d = %f\n", anorm); }
1-norm of a = 11.000000 2-norm of a = 8.828855 infinity-norm of a = 10.000000 Frobenius-norm of a = 8.831761 max(abs(a)) = 7.000000 1-norm of b = 16.000000 2-norm of b = 8.671495 infinity-norm of b = 10.000000 Frobenius-norm of b = 10.198039 max(abs(a)) = 7.000000 1-norm of c = 9.000000 2-norm of c = 9.846035 infinity-norm of c = 13.000000 Frobenius-norm of c = 10.198039 max(abs(a)) = 7.000000 1-norm of d = 9.000000 2-norm of d = 5.385165 2.1-norm of d = 5.263628 infinity-norm of d = 4.000000 negative infinity-norm of d = 2.000000