m> diary on >"m.demo" m> a = [ 3 1 -2; 1 -1 6]; x = [ 1; 2; 3] /* (2.1.6) page 8 */ m> a a = 3 1 -2 1 -1 6 m> x x = 1 2 3 m> a*x ans = -1 17 m> a(1)*x /* row 1 of a * x */ ans = -1 m> b = [ 1 -1; 2 2; 3 -1]; b /* page 10 */ b = 1 -1 2 2 3 -1 m> a*b ans = -1 1 17 -9 m> b(2:3,:) /* rows 2 & 3 of b */ ans = 2 2 3 -1 m> q = [ 1 -1; 1 1]/sqrt(2) /* bottom of page 13 */ m> q q = 0.7071068 -0.7071068 0.7071068 0.7071068 m> q'*q /* q is an orthogonal matrix */ ans = 1 0 0 1 m> q*q' ans = 1 0 0 1 m> clear m> a = reshape(1:12,4,3) /* svd demo */ m> a a = 1 2 3 4 5 6 7 8 9 10 11 12 m> rank = svd( a, u, s, v) m> rank rank = 2 m> who VARS: v s u a rank FUNS: PROCS: m> what CMDS: clear diary disasm echo help list load quit save what who FUNS: IO abs acos all any asin atan atan2 ceil cols cos cosh diag eps exp eye fabs floor format log log10 max min norm null ones round round2 rand reshape rows sin sinh sizeof sqrt svd tan tanh tol trunc trunc2 undef zeros PROCS: debug dump exit print qr srand m> u u = -0.1408767 -0.8247144 -0.3920453 -0.3824924 -0.3439463 -0.4262639 0.2376341 0.8022032 -0.5470159 -0.02781353 0.7008678 -0.4569292 -0.7500855 0.3706369 -0.5464566 0.03721841 m> s s = 25.46241 0 0 0 1.290662 0 0 0 0 0 0 0 m> v v = -0.5045331 0.7607757 0.4082483 -0.5745157 0.05714052 -0.8164966 -0.6444983 -0.6464946 0.4082483 m> u'*u ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 m> v'*v ans = 1 0 0 0 1 0 0 0 1 m> u*s*v' ans = 1 2 3 4 5 6 7 8 9 10 11 12 m> u1=u(:,1:2); s1=s(1:2,1:2); v1=v(:,1:2) /* compact svd form */ m> u1 u1 = -0.1408767 -0.8247144 -0.3439463 -0.4262639 -0.5470159 -0.02781353 -0.7500855 0.3706369 m> s1 s1 = 25.46241 0 0 1.290662 m> v1 v1 = -0.5045331 0.7607757 -0.5745157 0.05714052 -0.6444983 -0.6464946 m> u1*s1*v1' ans = 1 2 3 4 5 6 7 8 9 10 11 12 m> a*v(:,3) /* v(:,3) is basis for N(A) */ ans = 0 0 0 0 m> u(:,3:4)'*a /* u(:,3:4) is basis for N(A') */ ans = 0 0 0 0 0 0 m> load pinv /* pinv() demo */ m> ai=pinv(a) m> ai ai = -0.4833333 -0.2444444 -0.005555556 0.2333333 -0.03333333 -0.01111111 0.01111111 0.03333333 0.4166667 0.2222222 0.02777778 -0.1666667 m> ai*a ans = 0.8333333 0.3333333 -0.1666667 0.3333333 0.3333333 0.3333333 -0.1666667 0.3333333 0.8333333 m> a*ai ans = 0.7 0.4 0.1 -0.2 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 -0.2 0.1 0.4 0.7 m> b=[1:4]' m> x=ai*b m> x x = -0.05555556 0.1111111 0.2777778 m> a*x ans = 1 2 3 4 m> b=rand(4,1) m> b b = 0.9297191 0.7109395 0.8852128 0.9816734 m> x=ai*b m> x x = -0.3990102 0.003668179 0.4063465 m> a*x ans = 0.8273658 0.8603794 0.893393 0.9264066 m> ans-b ans = -0.1023533 0.1494399 0.008180227 -0.05526677 m> norm(ans) ans = 0.1895516 m> trunc(.99999,2) /* trunc() demo */ ans = 0.99 m> trunc([1 2 3 4 5]/3,3) ans = 0.333 0.666 1 1.33 1.66 m> trunc(2/3,0:5) ans = columns 1 to 5 0 0.6 0.66 0.666 0.6666 column 6 0.66666 m> echo on m> load series sum = 1; /* exp(x) = 1 + x + x^2/2! + x^3/3! + ... */ n = 1; /* example from page 40, 5-digit rounded decimal arith */ x = -5.5; inc = x; while( round(sum + inc, 5) != sum) { sum = round( sum + inc, 5); ++n; inc = round( round(inc*x,5)/n, 5); print(inc); } inc = 15.125 inc = -27.729 inc = 38.127 inc = -41.94 inc = 38.445 inc = -30.207 inc = 20.767 inc = -12.691 inc = 6.98 inc = -3.49 inc = 1.5996 inc = -0.67675 inc = 0.26586 inc = -0.09748 inc = 0.033509 inc = -0.010841 inc = 0.0033125 inc = -0.00095889 inc = 0.00026369 inc = -6.9062e-05 inc = 1.7265e-05 inc = -4.1286e-06 inc = 9.4613e-07 inc = -2.0815e-07 inc = 4.4031e-08 m> sum sum = 0.0034601 m> n n = 26 m> exp(-5.5) ans = 0.004086771