Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

extracting the coefficients of a linear combination

asked 13 years ago

Menny gravatar image

Let me just say that I'm quite new to sage (although I'm making a progress!)

I wish to input a number field (in my case real quadratic field), a basis w1,w2 over Q and an element v of this number field and get the coefficient of v as a linear combination of w1 and w2. I.e., if v=aw1+bw2 I wish to get (a,b).

I tried doing this with just solving equations in matrices but I didn't find a way to make it solve the equations over the base field Q.

Thanks a lot for helping! Menny

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 13 years ago

Volker Braun gravatar image

I take it you understand how to get the coefficients in the standard basis, e.g.:

sage: var('x')
x
sage: K.<a> = NumberField(x^2+1)
sage: 3+5*a+a^2                 
5*a + 2
sage: (3+5*a+a^2).vector()
(2, 5)

Then going to your preferred basis is just a linear algebra problem. For example, if your preferred QQ-basis is (1,1) and (2,0) then you could do:

sage: Q2 = (QQ^2).span_of_basis([(1,1), (2,0)]);  Q2
Vector space of degree 2 and dimension 2 over Rational Field
User basis matrix:
[1 1]
[2 0]
sage: Q2.coordinates([2,5])                         
[5, -3/2]

Check that this is correct:

sage: 5*vector([1,1]) + (-3/2)*vector([2,0])        
(2, 5)
Preview: (hide)
link

Comments

thanks a lot! this is an act of pure giving... Menny

Menny gravatar imageMenny ( 13 years ago )

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: 13 years ago

Seen: 2,299 times

Last updated: Aug 31 '11