function outprod.m
2 次查看(过去 30 天)
显示 更早的评论
Cannot run this coding. Please help me
function [X]=outprod(V,D)
n=3;
A=randn(n); %random square matrix
A=A'*A;
[V,D]=eig(A);%find eigenvalue and eigenvector
X=zeros(n); %define the matrix
for i=1:n
X=X+D(i,i)*outprod(V(:,i),V(:,i));
display(X);
display(A');
end
end
1 个评论
Jan
2022-12-14
移动:Matt J
2022-12-14
You forgot to mention, what the problem is. The error message should mention this already.
This function overwrites the inputs V and D and calls itself recursively until the recursion limit is exhausted. The readers cannot guess reliably, what the intention of the function is. Therefore it is fragile to suggest a modification of the code.
Please explain, what you want to calculate. In future questions attach a copy of the complete error message.
回答(1 个)
Matt J
2022-12-14
编辑:Matt J
2022-12-14
Perhaps this is what you want?
n=3;
A=randn(n); %random square matrix
A=A'*A;
[V,D]=eig(A);%find eigenvalue and eigenvector
X=outprod(V,D);
display(X);
display(A');
function [X]=outprod(V,D)
n=length(D);
X=0; %define the matrix
for i=1:n
X=X+D(i,i)*V(:,i)*V(:,i)';
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Eigenvalues & Eigenvectors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!