summaryrefslogtreecommitdiff
path: root/75/DEPENDENCIES/eigenvectors.sce
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /75/DEPENDENCIES/eigenvectors.sce
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '75/DEPENDENCIES/eigenvectors.sce')
-rwxr-xr-x75/DEPENDENCIES/eigenvectors.sce30
1 files changed, 30 insertions, 0 deletions
diff --git a/75/DEPENDENCIES/eigenvectors.sce b/75/DEPENDENCIES/eigenvectors.sce
new file mode 100755
index 000000000..a8ce16cf0
--- /dev/null
+++ b/75/DEPENDENCIES/eigenvectors.sce
@@ -0,0 +1,30 @@
+function [x,lam] = eigenvectors(A)
+
+//Calculates unit eigenvectors of matrix A
+//returning a matrix x whose columns are
+//the eigenvectors. The function also
+//returns the eigenvalues of the matrix.
+
+[n,m] = size(A);
+
+if m<>n then
+ error('eigenvectors - matrix A is not square');
+ abort;
+end;
+
+lam = spec(A)'; //Eigenvalues of matrix A
+
+x = [];
+
+for k = 1:n
+ B = A - lam(k)*eye(n,n); //Characteristic matrix
+ C = B(1:n-1,1:n-1); //Coeff. matrix for reduced system
+ b = -B(1:n-1,n); //RHS vector for reduced system
+ y = C\b; //Solution for reduced system
+ y = [y;1]; //Complete eigenvector
+ y = y/norm(y); //Make unit eigenvector
+ x = [x y]; //Add eigenvector to matrix
+end;
+
+endfunction
+//End of function \ No newline at end of file