How to perform matrix pencil operations on matlab? Is there a toolbox or a function?
조회 수: 24 (최근 30일)
이전 댓글 표시
I need to perform matrix pencil operations but unable to find any function or toolbox that performs the same. Please help.
댓글 수: 0
답변 (2개)
Ced
2016년 3월 16일
편집: Ced
2016년 3월 16일
Do you just need to evaluate a matrix pencil? You can just write your own little function.
Let's say you want to compute the pencil of degree l. This is one possible way of about doing it:
1. save the l+1 matrices in a big 3D matrix.
2. multiply each "plane" i (3rd dimension) with one pencil weight lambda i
3. sum it all up
Note: A more efficient way to do this would be to stack the matrices in columns (i.e. stay in 2D rather than 3D). If speed is not an issue, then I find the 3D version "safer" and clearer, but that's a personal choice.
Little dummy example:
Let's say l = 2 and A0,A1,A2 are nxn matrices. lambda is an (l+1)x1 vector.
M3D = cat(3,A0,A1,A2); % stack in 3rd dimension
% iterative way:
pencil_it = zeros(n,n);
for i = 1:l+1
pencil_it = pencil_it + lambda(i)*M3D(:,:,i);
end
% direct way:
% turn lambda in 3rd dimension, adjust it to size of matrices, multiply, sum up
pencil_direct = sum(M3D.*repmat(permute(lambda,2,3,1),n,n),3);
EDIT: Forgot to say:
The lambda vector can easily be obtained from your lambda weight by
lambda = lambda_weight.^(0:l)';
댓글 수: 0
Matthew Wade
2020년 8월 1일
편집: Matthew Wade
2020년 8월 1일
Typo in direct solution:
pencil_direct = sum(M3D.*repmat(permute(lambda,2,3,1),n,n),3);
should be square brackets in second argument for permute
pencil_direct = sum(M3D.*repmat(permute(lambda,[2,3,1]),n,n),3);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!