format long e x x = 9.500000000000000e-001 diary off z z = 1.140000000000000e+000 diary off % to suspend the diary or just to flush the % buffers we do diary off and then diary on % The file created by diary is just a text file, % only good for us, users. To save the variables % in the workspace, we do save: save 'matdata1' clear load 'matdata1' uiimport('C:\Documents and Settings\janv\My Documents\matdata1.mat') x x = 9.500000000000000e-001 % by default, all variables are of type double format short x x = 0.9500 pi ans = 3.1416 format long ans ans = 3.141592653589793 % There is only one working precision: % hardware machine precision. % It is very easy and convenient to work % with matrices in MATLAB a = rand(3,4) a = Columns 1 through 2 0.814723686393179 0.913375856139019 0.905791937075619 0.632359246225410 0.126986816293506 0.097540404999410 Columns 3 through 4 0.278498218867048 0.964888535199277 0.546881519204984 0.157613081677548 0.957506835434298 0.970592781760616 format short a a = 0.8147 0.9134 0.2785 0.9649 0.9058 0.6324 0.5469 0.1576 0.1270 0.0975 0.9575 0.9706 help rand rand('seed',123) rand(2,2) ans = 0.0878 0.0986 0.6395 0.6906 rand(2,2) ans = 0.3415 0.2641 0.2359 0.6044 rand('seed',123) rand(2,2) ans = 0.0878 0.0986 0.6395 0.6906 a a = 0.8147 0.9134 0.2785 0.9649 0.9058 0.6324 0.5469 0.1576 0.1270 0.0975 0.9575 0.9706 % Suppose that a contains the coefficient matrix % and righthandside vector for a linear system. A = a(:,1:3) A = 0.8147 0.9134 0.2785 0.9058 0.6324 0.5469 0.1270 0.0975 0.9575 b = a(:,4) b = 0.9649 0.1576 0.9706 x = A\b x = -2.5775 3.0365 1.0462 r = b - A*x r = 1.0e-015 * 0.4441 0.1110 -0.2220 norm(r) ans = 5.0877e-016 % The norm of the residual vector % showed that we solved a linear system % and obtained a solution with accuracy % close to the machine precision. [l,u] = lu(A) l = 0.8995 1.0000 0 1.0000 0 0 0.1402 0.0258 1.0000 u = 0.9058 0.6324 0.5469 0 0.3446 -0.2134 0 0 0.8863 [l,u,p] = lu(A) l = 1.0000 0 0 0.8995 1.0000 0 0.1402 0.0258 1.0000 u = 0.9058 0.6324 0.5469 0 0.3446 -0.2134 0 0 0.8863 p = 0 1 0 1 0 0 0 0 1 l*u ans = 0.9058 0.6324 0.5469 0.8147 0.9134 0.2785 0.1270 0.0975 0.9575 p*A ans = 0.9058 0.6324 0.5469 0.8147 0.9134 0.2785 0.1270 0.0975 0.9575 l*u ans = 0.9058 0.6324 0.5469 0.8147 0.9134 0.2785 0.1270 0.0975 0.9575 [v,d] = eig(A) v = 0.6752 -0.7134 -0.5420 -0.7375 -0.6727 -0.2587 -0.0120 -0.1964 0.7996 d = -0.1879 0 0 0 1.7527 0 0 0 0.8399 v*d ans = -0.1269 -1.2503 -0.4552 0.1386 -1.1790 -0.2173 0.0023 -0.3443 0.6715 A*v ans = -0.1269 -1.2503 -0.4552 0.1386 -1.1790 -0.2173 0.0023 -0.3443 0.6715 inv(v)*A*v ans = -0.1879 0.0000 0.0000 -0.0000 1.7527 -0.0000 -0.0000 -0.0000 0.8399 % Exploiting A*v = v*d, we obtain % a diagonalization procedure for A. diary off