ATLAB Lecture 3 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr 令 MATLAB Ax=b Cholesky >>A=fix(10*rand(3)) >>d= linspace (1, 50, 3); %Generates a row vector of 3 linearly equally spaced points between 1 and 50 > Diag d= diag(d) %o Generate a diagonal matrix with the input arguments >>A=A*Diag d(A) %o Generate a symmetric matrix >>b=fix(10 rand (3, 1)); >>R= chol(A) >>X= RIRIb >>A=fix(10°rand(3) >>b=fx(10*rand(3,1) >>[L,U]=lu(A) >>X=U(L\b) QR >>A=fix(10*rand(3)) >>b=fx(10°rand(3,1) >>[Q,R]=qr(a) >>X=RYQIb) >>A=fx(10*rand(100) >>d= linspace(1, 50, 100); %Generates a row vector of 100 linearly equally spaced points between I and 50 >> Diag d=diag(d) Generate a diagonal matrix with the input arguments >>A= A Diag d°(A) >>b=fix(10 rand(100, 1)) >>tic, R=chol(A) x chol= RMR\b) t chol=toc Compute the time spent > tic, [ L, U=lu(A) x LU=U\LIb); t LU=toc >>tic;Q, R]=qr(A); x QR= RYQ\b); t QR=toc Lec3-4MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec34 ² MATLAB Ax = b Cholesky >> A = fix (10*rand(3)); >> d = linspace (1, 50, 3); %Generates a row vector of 3 linearly equally spaced points… between 1 and 50 >> Diag_d = diag(d); % Generate a diagonal matrix with the input arguments >> A = A*Diag_d*(A’); % Generate a symmetric matrix >> b = fix (10*rand(3,1)); >> R = chol(A); >> x = R\(R'\b) LU >> A = fix (10*rand(3)); >> b = fix (10*rand(3,1)); >> [L, U] = lu(A) >> x = U\(L\b) QR >> A = fix (10*rand(3)); >> b = fix (10*rand(3,1)); >> [Q, R] = qr (a) >> x = R\(Q\b) >> A = fix (10*rand(100)); >> d = linspace (1, 50, 100); %Generates a row vector of 100 linearly equally spaced… points between 1 and 50 >> Diag_d = diag(d); % Generate a diagonal matrix with the input arguments >> A = A*Diag_d*(A’); >> b = fix (10*rand(100,1)); >> tic; R = chol(A); x_chol = R\(R’\b); t_chol=toc % Compute the time spent >> tic; [L, U] = lu(A); x_LU = U\(L\b); t_LU=toc >> tic; [Q, R] = qr(A); x_QR = R\(Q\b); t_QR=toc