Hi Dimitry!

On 12 Jan., 10:43, Dmitry Shkirmanov <[email protected]> wrote:
> Hello, i need  to assign the elements of matrix in the cycle, for
> example here is the code (in a notebook):
> #
> var('a,b,c,d,e,f')
> v1=vector([a,b,c])
> v2=vector([d,e,f])
> v3=matrix(1,3)
> j=0
> while j<=2:
>     v3[0,j]=v1[j]*v2[j]
>     j=j+1
> print(v3)

Any matrix in Sage (and many other objects) know the algebraic
structure over which it is defined. Here, it is the ring of integers:
sage: v3=matrix(1,3)
sage: v3
[0 0 0]
sage: v3.base_ring()
Integer Ring

The error comes from the fact that the symbolic variables a,b,... have
no interpretation as integers, and so v3 complains.

You need to inform Sage that v3 is supposed to belong to the "symbolic
ring", SR:

sage: v3=matrix(SR,1,3)
sage: v1=vector([a,b,c])
sage: v2=vector([d,e,f])
sage: for j in range(3):
....:     v3[0,j]=v1[j]*v2[j]
....:
sage: v3
[a*d b*e c*f]

Best regards,
Simon

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to