Ask Your Question
0

Gram-Schmidt with arbitrary inner product?

asked 2017-12-12 03:48:50 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi,

I'd like to find an orthonormal basis of polynomials using an arbitrary inner product. I know how to do this in Maxima:

ip(f, g) := integrate(f * g, x, -1, 1); /* for example */
y : gramschmidt([1, x, x^2], ip);

But is there a nice way to do this in sage?

Thanks! -Andrew

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-13 03:29:12 -0600

dan_fulea gravatar image

In sage, there is a method gram_schnidt associated to a matrix.

After the matrix is declared, the method can be immediately called. The following defines a matrix A , computes the Gram-Schnidt matrices G.M as in the examples from

A.gram_schmidt?

and does a check for the relation $A=MG$, it is a possible starting point:

var( 'x' )
def ip(f, g):
    return integrate( f * g, x, -1, 1 )

f_list = [1, x, x^2, x^3, x^4]
A = matrix( QQ, len(f_list),
            [ ip( f, g ) for f in f_list for g in f_list ] )

print "A is\n%s\n" % A

G, M = A.gram_schmidt()

print "G is\n%s\n" % G
print "M is\n%s\n" % M

print "Is MG = A? %s" % bool( M*G == A )

Results:

A is
[  2   0 2/3   0 2/5]
[  0 2/3   0 2/5   0]
[2/3   0 2/5   0 2/7]
[  0 2/5   0 2/7   0]
[2/5   0 2/7   0 2/9]

G is
[         2          0        2/3          0        2/5]
[         0        2/3          0        2/5          0]
[ -424/5439          0  1376/9065          0   248/1813]
[         0    -12/595          0      4/119          0]
[ 64/112035          0 -128/22407          0    64/9603]

M is
[       1        0        0        0        0]
[       0        1        0        0        0]
[675/1813        0        1        0        0]
[       0   75/119        0        1        0]
[425/1813        0 950/1067        0        1]

Is MG = A? True
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-12-12 03:48:50 -0600

Seen: 33 times

Last updated: Dec 13 '17