genius r692 - in trunk: . help/C lib lib/linear_algebra
- From: jirka svn gnome org
- To: svn-commits-list gnome org
- Subject: genius r692 - in trunk: . help/C lib lib/linear_algebra
- Date: Wed, 19 Nov 2008 06:29:23 +0000 (UTC)
Author: jirka
Date: Wed Nov 19 06:29:23 2008
New Revision: 692
URL: http://svn.gnome.org/viewvc/genius?rev=692&view=rev
Log:
Wed Nov 19 00:29:04 2008 Jiri (George) Lebl <jirka 5z com>
* lib/linear_algebra/linear_algebra.gel: Add Eigenvectors.
Currently only for 2x2 matrices where computing eigenvectors is
relatively easy
* help/C/gel-function-list.xml: add Eigenvectors
Modified:
trunk/ChangeLog
trunk/help/C/gel-function-list.xml
trunk/help/C/genius.txt
trunk/lib/library-strings.c
trunk/lib/linear_algebra/linear_algebra.gel
Modified: trunk/help/C/gel-function-list.xml
==============================================================================
--- trunk/help/C/gel-function-list.xml (original)
+++ trunk/help/C/gel-function-list.xml Wed Nov 19 06:29:23 2008
@@ -2778,12 +2778,32 @@
</para>
<para>
See
+ <ulink url="http://en.wikipedia.org/wiki/Eigenvalue">Wikipedia</ulink> or
<ulink url="http://planetmath.org/encyclopedia/Eigenvalue.html">Planetmath</ulink> or
<ulink url="http://mathworld.wolfram.com/Eigenvalue.html">Mathworld</ulink> for more information.
</para>
</listitem>
</varlistentry>
+ <varlistentry id="gel-function-Eigenvectors">
+ <term>Eigenvectors</term>
+ <listitem>
+ <synopsis>Eigenvectors (M)</synopsis>
+ <synopsis>Eigenvectors (M, &eigenvalues)</synopsis>
+ <synopsis>Eigenvectors (M, &eigenvalues, &multiplicities)</synopsis>
+ <para>Get the eigenvectors of a square matrix. Optionally get also
+the eigenvalues and their algebraic multiplicities.
+ Currently only works for matrices of size up to 2 by 2.
+ </para>
+ <para>
+ See
+ <ulink url="http://en.wikipedia.org/wiki/Eigenvector">Wikipedia</ulink> or
+ <ulink url="http://planetmath.org/encyclopedia/Eigenvector.html">Planetmath</ulink> or
+ <ulink url="http://mathworld.wolfram.com/Eigenvector.html">Mathworld</ulink> for more information.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="gel-function-GramSchmidt">
<term>GramSchmidt</term>
<listitem>
Modified: trunk/help/C/genius.txt
==============================================================================
--- trunk/help/C/genius.txt (original)
+++ trunk/help/C/genius.txt Wed Nov 19 06:29:23 2008
@@ -1917,6 +1917,15 @@
11.2. Basic
+ AskString
+
+ AskString (query)
+
+ Asks a question and lets the user enter a string which it then
+ returns. If the user cancels or closes the window, then null is
+ returned. The execution of the program is blocked until the user
+ responds.
+
Compose
Compose (f,g)
@@ -1937,6 +1946,12 @@
genius> f(f(f(7)))
= 5764801
+ Evaluate
+
+ Evaluate (str)
+
+ Parses and evaluates a string.
+
GetCurrentModulo
GetCurrentModulo
@@ -2021,6 +2036,13 @@
Check if argument is a number.
+ Parse
+
+ Parse (str)
+
+ Parses but does not evaluate a string. Note that certain
+ precomputation is done during the parsing stage.
+
SetFunctionFlags
SetFunctionFlags (id,flags...)
@@ -2056,12 +2078,6 @@
Display a string and an expression with a colon to separate them.
- eval
-
- eval (str)
-
- Parses and evaluates a string.
-
error
error (str)
@@ -2098,13 +2114,6 @@
can be any expression. It is made into a string before being
printed.
- parse
-
- parse (str)
-
- Parses but does not evaluate a string. Note that certain
- precomputation is done during the parsing stage.
-
printn
printn (str)
@@ -3898,7 +3907,21 @@
matrices of size up to 4 by 4, or for triangular matrices (for
which the eigenvalues are on the diagonal).
- See Planetmath or Mathworld for more information.
+ See Wikipedia or Planetmath or Mathworld for more information.
+
+ Eigenvectors
+
+ Eigenvectors (M)
+
+ Eigenvectors (M, &eigenvalues)
+
+ Eigenvectors (M, &eigenvalues, &multiplicities)
+
+ Get the eigenvectors of a square matrix. Optionally get also the
+ eigenvalues and their algebraic multiplicities. Currently only
+ works for matrices of size up to 2 by 2.
+
+ See Wikipedia or Planetmath or Mathworld for more information.
GramSchmidt
Modified: trunk/lib/library-strings.c
==============================================================================
--- trunk/lib/library-strings.c (original)
+++ trunk/lib/library-strings.c Wed Nov 19 06:29:23 2008
@@ -109,6 +109,7 @@
char *fake = N_("Direct sum of matrices");
char *fake = N_("Direct sum of a vector of matrices");
char *fake = N_("Get the eigenvalues of a matrix (Currently only for up to 4x4 or triangular matrices)");
+char *fake = N_("Get the eigenvalues and eigenvectors of a matrix (Currently only for up to 2x2 matrices)");
char *fake = N_("Apply the Gram-Schmidt process (to the columns) with respect to inner product given by B (if not given use hermitian product)");
char *fake = N_("Hankel matrix");
char *fake = N_("Hilbert matrix of order n");
Modified: trunk/lib/linear_algebra/linear_algebra.gel
==============================================================================
--- trunk/lib/linear_algebra/linear_algebra.gel (original)
+++ trunk/lib/linear_algebra/linear_algebra.gel Wed Nov 19 06:29:23 2008
@@ -440,6 +440,69 @@
SetHelpAlias ("Eigenvalues", "eig")
protect ("eig")
+SetHelp("Eigenvectors", "linear_algebra", "Get the eigenvalues and eigenvectors of a matrix (Currently only for up to 2x2 matrices)")
+function Eigenvectors(M, evsmults...) = (
+ evs := null;
+ mults := null;
+
+ if not IsNull(evsmults) then
+ evs := evsmults@(1);
+ if elements(evsmults) > 1 then
+ mults := evsmults@(2);
+ if not IsMatrix (M) or not IsMatrixSquare (M) then
+ (error("Eigenvectors: argument not a square matrix");bailout);
+ if columns (M) == 1 then (
+ if IsFunctionRef(evs) then
+ *evs = [ev];
+ if IsFunctionRef(mults) then
+ *mults = [2];
+ `[[1]]
+ ) else if columns (M) == 2 then (
+ b := - trace (M) ; c := det (M);
+ if b^2-4*c == 0 then (
+ ev := -b/2;
+ if IsFunctionRef(evs) then
+ *evs = [ev];
+ if IsFunctionRef(mults) then
+ *mults = [2];
+ if IsZero (M-ev*I(2)) then (
+ `[[1;0], [0;1]]
+ ) else (
+ row := [M@(1,1)-ev, M@(1,2)];
+ if IsZero(row) then
+ row := [M@(2,1), M@(2,2)-ev];
+ if row@(2) == 0 then (
+ `[[0;1]]
+ ) else (
+ `[[1;-row@(1)/row@(2)]]
+ )
+ )
+ ) else (
+ k := 1;
+ levs = [ ( -b - sqrt (b^2 - 4*c) ) / 2 ; ( -b + sqrt (b^2 - 4*c) ) / 2 ];
+ if IsFunctionRef(evs) then
+ *evs = levs;
+ if IsFunctionRef(mults) then
+ *mults = [1;1];
+ out := `[0];
+ for ev in levs do (
+ row := [M@(1,1)-ev, M@(1,2)];
+ if IsZero(row) then
+ row := [M@(2,1), M@(2,2)-ev];
+ if row@(2) == 0 then (
+ out@(k) := [0;1]
+ ) else (
+ out@(k) := [1;-row@(1)/row@(2)]
+ );
+ k = k+1;
+ );
+ out
+ )
+ ) else
+ (error("Eigenvectors: Currently only implemented for up to 2x2");bailout)
+)
+protect ("Eigenvectors")
+
# Written by David W. Hutchison, dahutchi indiana edu for Genius 0.7.1
# Copyright (C) 2004 David W. Hutchison (GPL)
# LU decomposition of a matrix, aka Crout and/or Cholesky reduction.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]