# # The $ tells MATALG to turn off paging, which is critical if # we are to easily create an input data file with which to test it. # $ # # Open a transcript file called "output" # d output # # Display the help screen. # h # # Enter a 3 by 3 matrix A, # estimate its reciprocal condition number, # change the 2,3 entry to 6, # estimate the reciprocal condition number again, # and compute B=A*transpose(A). # e a 3,3 1, 2, 3 4, 5, 10 7, 8, 9 = rcond(a) a(2,3) = 6 = rcond(a) b = a * trans(a) # # Now compute the singular value decomposition of A, # and save the factors as U, S and V. # m svd a u s v # # Now make sure that the singular value decomposition # can reproduce the original matrix A. # w = u * s * trans(v) # # Now discard the variables U, S, V and W to save space. # k u s v w # # Now compute the QR factorization of A # m qr a q r # # And now verify that A=Q*R # = q * r # # Now let's compute the PLU factorization of A # m plu a l u p # # And let's verify that P*A=L*U, that is, A = P*L*U # = p * l * u # # Now let's decide to save the value of the formula we # just calculated in a matrix C. And then let's print C # to show that it's been saved. # s c t c # # Now let's compute the characteristic polynomial of A, # and save the coefficients in CVEC. # p a cvec # # Let's see what symbols are now stored in the program. # t all # # Now clear out ALL user defined variables. # i yes # # Enter a matrix A, # # Enter a vector V (in this case, the first row of A), # # Compute B, the Householder matrix which will, # for each column of A, reflect the portion perpendicular to V. # # Compute B*A. # e a 3,3 1, 3, -4 4, 1, 1 7, -1, 0 e v 3, 1 1, 4, 7 b = house(v) c = b*a # # Compute the polynomial with roots 1, 2 and 3. # Store its coefficients in w. # Evaluate the polynomial at evenly spaced points # using the L command. # i yes e v 3 1 1,2,3 p v w x = 0 = poly(w,x) l x, 0, 4, 8 # # Compute the eigenvalues and eigenvectors of a matrix A. # i yes e a,4,4 17, -8, -12, 14 46, -22, -35, 41 -2, 1, 5, -4 4, -2, -2, 3 l = eval(a) p = evec(a) b = inv(p)*a*p # # Now let's show how we could save the 2 x 2 central block # of B using the "U" (partition) command. # u b 2 3 0 2 3 0 d no # # Show how repeated evaluation works. # i yes x = 0.734 x = 4*x*(1-x) r 10 # # Check how MATALG will handle the inverse of a singular # matrix. # i yes e a 2,2 5,10 1,2 = inv(a) # # Make some other simple checks. # i yes b = id(2) c = zeros(3) d = ran(c) # # Check the matrix norms. # e d 3,3 1, 2, 3 4, 5, 6 7, 8, 9 = norm0(d) = norm1(d) = norm2(d) # # Load the 5 by 5 Hilbert matrix, H, # have MATALG compute the inverse, G, # compute H*G. # Load the 5 by 5 Inverse Hilbert matrix, F, # compute H*F, notice that even now we don't get I! # compute F-G. # h = hilbert(5) g = inv(h) = h*g f = hilbinv(5) = h*f = f-g # # Check out the GCF and LCM functions. # = gcd(20,12) = gcd(20,17) = gcd(20,-12) = gcd(20,0) = lcm(12,4) = lcm(12,5) = lcm(12,12) = lcm(12,0) = lcm(12,-6) # # Try out the HELP facility. # ? Commands Enter a variable # # Try lots of scalar functions. # x = 1.0 y = abs(-1) y = acos(0) y = asin(1) y = atan(1) y = atan2(10,10) y = cos(pi) y = cosd(45) y = cosh(1) y = e y = eps y = exp(1) y = int(pi) y = log(10) y = log2(1000) y = log10(100) y = max(1,10) y = min(1,10) y = neg(10) y = nint(1.9) y = pi y = ran(x) y = round(1) y = round(eps) y = round(0.00000001) rtol = 0.0001 y = round(eps) y = seed y = sin(pi) y = sind(45) y = sinh(1) y = sqrt(100) y = step(10) y = tan(pi) y = tand(45) y = tanh(1) y = 10! # # Quit # quit yes