function outprod.m

2 visualizaciones (últimos 30 días)
NOR AZIERA
NOR AZIERA el 14 de Dic. de 2022
Editada: Matt J el 14 de Dic. de 2022
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 comentario
Jan
Jan el 14 de Dic. de 2022
Movida: Matt J el 14 de Dic. de 2022
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.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 14 de Dic. de 2022
Editada: Matt J el 14 de Dic. de 2022
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);
X = 3×3
0.2455 0.1739 0.6999 0.1739 0.8567 1.4576 0.6999 1.4576 3.4055
display(A');
0.2455 0.1739 0.6999 0.1739 0.8567 1.4576 0.6999 1.4576 3.4055
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

Categorías

Más información sobre Eigenvalues & Eigenvectors en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by