文档介绍:Introduction to puting-- A Matrix Vector Approach Using Matlab Written by Charles Loan
陈文斌
复旦大学
Chapter 5 putations
Setting Up Matrix Problems
Matrix Operations
Once Again, Setting Up Matrix Problems
Recursive Matrix Operations
Distributed Memory Matrix Multiplication
Matrix-vector multiplication
Matrix- Matrix multiplication
Often the amount of work that is required to initialize an n-by-n matrix is as much as the work required to solve for x
Fast Fourier transform and fast Strassen matrix multiply algorithm
Ax=b
Setting up Matrix problems
Hilbert matrix
A=zeros(n,n);
for i=1:n
for j=1:n
A(i,j)=1/(i+j-1);
end
end
A=zeros(n,n);
for i=1:n
for j=i:n
A(i,j)=1/(i+j-1);
A(j,i)=A(i,j);
end
end
Simple ij Recipes
function H = hilb(n)
%HILB Hilbert matrix.
% This is also a good example of efficient MATLAB programming
% style where conventional FOR or DO loops are replaced by
% vectorized statements. This approach is faster, but uses
% more storage.
% C. Moler, 6-22-91.
% Copyright 1984-2001 The MathWorks, Inc.
% $Revision: $ $Date: 2001/04/15 12:02:29 $
J = 1:n; J = J(ones(n,1),:); I = J';
E = ones(n,n); H = E./(I+J-1);
The setting up of a matrix can often be made more efficient by exploiting relationships that exist between the entries.
O(n3) flops
O(n2) flops
P=zeros(n,n);
P(:,1)=ones(n,1);
for i=2:n
for j=2:i
P(i,j)=P(i-1,j-1)+P(i-1,j);
end
end
O(n2) flops
Matrix defined by a vector of parameters
n=length(x,y);
V(:,1)=ones(n,1);
for j=2:n
V(:,j)=x.*V(:,j-1);
end
Circulant matrices
function C = Circulant1(a)
n = length(a); C = zeros(n,n);
for i=1:n
for j=1:n
C(i,j) = a(rem(n-i+j,n)+1);
end
end
function C = Circulant2(a)
n = length(a);C = zeros(n,n);
C(1,:) = a;
for i=2:n
C(i,:) = [ C(i-1,n) C(i-1,1:n-1) ];
end