Element by element multiplication of a matrix
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a function f = e^(tH), where H is a square matrix. I want to compute this function for each value of t = 0:10:100 so I can plot f against t. Using .* is giving an error (sizes not compatible). What can I do?
댓글 수: 0
답변 (2개)
Paul
2021년 6월 4일
For the matrix exponential:
% example data
H = [1 2;3 4];
t = 0:5;
f = cell2mat(cellfun(@expm,mat2cell(H.*reshape(t,1,1,[]),2,2,ones(1,6)),'UniformOutput',false));
% compare a few cases by hand
f(:,:,2) - expm(H*t(2))
f(:,:,end) - expm(H*t(end))
If f is supposed to be element-by-element exponential:
f = exp(H.*reshape(t,1,1,[]))
댓글 수: 0
Star Strider
2021년 6월 4일
I have absolutely no idea what result you want.
Try this —
H = [1 2; 3 4]*0.01;
t = 0:10:100;
for k = 1:numel(t)
f{k} = exp(t(k)*H);
end
figure
hold on
for k = 1:numel(t)
plot(t(k)*[1 1; 1 1], f{k}, '.-')
end
hold off
grid
Also, consider the expm function, since ‘element-by-element’ is not precisely clear in this context.
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!