Ich musste in der Schule ein Programm schreiben wie dieses habe ich im Internet gefunden.
Code:
%EIGSVDGUI Demonstrate computation of matrix eigenvalues and singular values.
% EIGSVDGUI shows three variants of the QR algorithm.
%
% EIGSVDGUI(A) for square, nonsymmetric A, or EIGSVDGUI(A,'eig'), reduces % A to Hessenberg form, then applies a double-shift, eigenvalue-preserving % QR algorithm. The result is the real Schur block upper triangular form, % with one-by-one diagonal blocks for real eigenvalues and two-by-two % diagonal blocks for pairs of complex eigenvalues.
%
% EIGSVDGUI(A) for square, symmetric A, or EIGSVDGUI(A,'symm'), reduces % the symmetric part, (A+A')/2, to tridiagonal form, then applies a % single-shift, eigenvalue-preserving QR algorithm. The result is % a diagonal matrix containing the eigenvalues, which are all real.
%
% EIGSVDGUI(A) for rectangular A, or EIGSVDGUI(A,'svd'), reduces A to % bidiagonal form, then applies a single-shift QR algorithm that preserves % the singular values. The result is a diagonal matrix containing the % singular values.
%
% If A is symmetric and positive definite, the three variants compute % the same final diagonal matrix by three different algorithms.
%
% D = EIGSVDGUI(...) returns the diagonal or Schur result.
% Introduce zeros below the subdiagonal in the k-th column.
u = A(:,k);
u(1:k) = 0;
sigma = norm(u);
if sigma ~= 0 if u(k+1) ~= 0, sigma = sign(u(k+1))*sigma; end
u(k+1) = u(k+1) + sigma;
rho = 1/(sigma'*u(k+1));
v = rho'*A*u;
w = (rho*u'*A)';
gamma = rho/2*u'*v;
v = v - gamma*u;
gamma = rho/2*u'*w;
w = w - gamma*u;
A = A - v*u' - u*w';
A(k+2:n,k) = 0;
if issymm, A(k,k+2:n) = 0; end end set(imageh,'cdata',ceil(scale*abs(A))+1) pause(.1) end
% Complex eigenvalues of real matrices. % 2-by-2 convergence test.
if k == 2
k = 0;
elseifabs(A(k-1,k-2)) <= 2*eps*(abs(A(k-2,k-2)) + abs(A(k-1,k-1)))
A(k-1,k-2) = 0;
if issymm, A(k-2,k-1) = 0; end
k = k-2;
else
% Sum and product of eigenvalues of lower 2-by-2.
t = A(k-1,k-1) + A(k,k);
d = A(k-1,k-1)*A(k,k) - A(k,k-1)*A(k-1,k);
% Double QR step.
I = eye(k,k);
[Q,R] = qr(A(1:k,1:k)^2 - t*A(1:k,1:k) + d*I);
A(1:k,1:k) = triu(Q'*A(1:k,1:k)*Q,-1);
it = it+2;
end end end if issymm, A(1:k,1:k) = tril(A(1:k,1:k),1); end set(imageh,'cdata',ceil(scale*abs(A))+1) set(titleh,'string',num2str(it)) pause(.1) end if issymm, A(1,1) = real(A(1,1)); end
% -------------------------------------------
function A = svdgui(A)
%SVDGUI Demonstrate the computation of the SVD.
% SVDGUI(A) shows the steps in the computation of the % singular value decomposition of any real or complex matrix.
% Introduce zeros below the diagonal in the k-th column.
u = A(:,k);
u(1:k-1) = 0;
sigma = norm(u);
if sigma ~= 0 if u(k) ~= 0, sigma = sign(u(k))*sigma; end
u(k) = u(k) + sigma;
rho = 1/(sigma'*u(k));
v = rho*(u'*A);
A = A - u*v;
A(k+1:m,k) = 0;
end set(imageh,'cdata',ceil(scale*abs(A))+1);
pause(.1)
% Introduce zeros to the right of the superdiagonal in the k-th row.
u = A(k,:);
u(1:k) = 0;
sigma = norm(u);
if sigma ~= 0 if u(k+1) ~= 0, sigma = sign(u(k+1))*sigma; end
u(k+1) = u(k+1) + sigma;
rho = 1/(sigma'*u(k+1));
v = rho*(A*u');
A = A - v*u;
A(k,k+2:n) = 0;
end set(imageh,'cdata',ceil(scale*abs(A))+1);
pause(.1) end
% Bidiagonal SVD QR iteration.
it = 0;
titleh = title('0');
k = min(m,n);
while k > 1
% One step of single shift QR iteration. % Wilkinson shift, eigenvalue of lower 2-by-2 of A'*A.
T = A(1:k,1:k)'*A(1:k,1:k);
r = (T(k,k)-T(k-1,k-1))/(2*T(k,k-1));
s = sqrt(r^2 + T(k-1,k)/T(k,k-1));
if r < 0, s = -s; end if r+s ~= 0, s = T(k,k) + T(k-1,k)/(r+s); end
I = eye(k,k);
[Q,R] = qr(T-s*I);
A(1:k,1:k) = A(1:k,1:k)*Q;
[Q,R] = qr(A(1:k,1:k));
A(1:k,1:k) = tril(R,1);
it = it+1;
end
In diesem Fall hab ich eine graphische Oberfläche dich nicht unbedingt benötige. Ich brauchte auch eine 16x16 Matrix aber nur rot und grün und ich muss das selbst einstellen können. Danke schon jetzt einmal
erstmal is das viel zu viel code. das liest ja keiner. 2. hast du keine konkrete frage gestellt ^^. wenn das n programmier auftrag sein soll dann sollte das auch in dem thread gepostet werden. falls nicht solltest du uns die teile deines codes posten die nicht klappen oder die nicht machen was sie sollen und uns sagen was sie machen sollten. dann können wir dir auch helfen.
Wenn ich das richtig sehe, hast Du den Code von Cleve Moler gepostet. Der Code wurde auf dem MathWorks-Seiten unter der BSD-Lizenz veröffentlicht, deshalb muss der Autor unbedingt genannt werden! Ich habe das eingefügt.
Zur Lösung Deines Problems trägt der gezeigte Code allerdings gar nicht bei. Es wäre hilfreicher, wenn Du eine konkrete Frage stellst.
Gruß, Jan
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.