On Friday, 11 February 2022 at 07:51:17 UTC-8 [email protected] wrote:

> I'm trying to do some least squares linear algebra. I built a matrix from 
> lists that I converted into column vectors and used the 'augment' function.


Small detail, but slightly more efficient (it may not matter for your 
application) is to just give sage a list of lists and create a matrix from 
that directly. It will cost less copying around than iteratively augmenting 
the matrix. For the most part, matrices are stored row-major (i.e., 
basically as an array of rows), so column augmentations require more 
fiddling internally than row operations. Better to just construct the 
matrix from rows and then transpose if required.

When I type() an entry in the vector, I get:
>
> 'sage.modules.free_module_element.FreeModuleElement_generic_dense'
>
> Important part is actually the *parent* of the vector, and more 
specifically its *base ring*, i.e., ask v.base_ring()

In your case, I think the base ring should be some type of real field (if 
you're doing least-squares ...). If it is the symbolic ring, you probably 
want to change that first.

To convert a vector to a polynomial with coefficients equal to the entries 
in the vector, you can do:

R=v.base_ring()
R['s'](v)
 
(or, if you want the leading term to be the leftmost entry, i.e., a 
reversed vector):

R['s'](v[::-1])

or

R['s'](reversed(M['0']))

If you're going to be using the ring R['s'] a lot, it will be better to 
define

Rs.<s>=R[]

and use

Rs(v).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/fa55af14-efb3-4505-b2d9-de55ca8a3f1fn%40googlegroups.com.

Reply via email to