Hi Saad,

as an algebraist I may be biased, but I have never understood why so
many people try to use symbolics when they are not doing calculus.
Calculus is a pancake, not a panacea (sorry for the bad joke).

Without a joke: Quite many user questions can be answered in that way:
"You try to achieve xy by using symbolic variables, but that's not what
they are made for; use one of the following specialised tools for xy:
..."

On 2018-12-02, saad khalid <saad1...@gmail.com> wrote:
> Why can't matrices be allowed in SR in a nontrivial way?

I guess the shortest answer is: A matrix knows what to answer when the user
does "M[x,y]". SR is the ring of symbolic variables, and symbolic variables
don't know what a user expects from a matrix. In fact, matrices are a
construction taken from linear algebra, not from calculus. So, it isn't a
surprise that SR can't handle it.

Let's get back to your original post:

>> I'm not sure what is happening, but I defined some matrices:
>> Mz = matrix([[0,1],[1,0]])
>> Mx = matrix([[1,0],[0,-1]])
>> M1 = matrix([[1,0],[0,1]])
>>
>> And then I tried defining a function where I multiply these matrices by 
>> some variable and add them together:
>>
>> h(s) = M1 + s*Mx
>> h(.1)

Apparently what you want is not a function that maps a number s to a
matrix. What you want is a matrix with a parameter s. And in fact all
matrix entries are polynomial in s.

SR is a very general tool, but being "very general" implies being
"sub-optimal for most purposes". So, when you work with polynomials then
define a polynomial ring, and when you work with matrices then define
matrices over that polynomial ring:

    sage: R.<s> = QQ[]
    sage: Mx = matrix(R,[[1,0],[0,-1]])
    sage: M1 = matrix(R, [[1,0],[0,1]])
    sage: h = M1 + s*Mx

Calling that matrix specialises the parameter s in the way you expected
(in particular, the syntax h(s=.1) isn't needed):

    sage: h(.1)
    [ 1.10000000000000 0.000000000000000]
    [0.000000000000000 0.900000000000000]

And you can still do calculus, to some extent:

    sage: h.derivative(s)
    [ 1  0]
    [ 0 -1]

Summary: If you use tools that were designed to work with the mathematical
notions you are using (matrices over polynomial rings),...
    sage: type(h)
    <type 'sage.matrix.matrix_polynomial_dense.Matrix_polynomial_dense'>
... then things are more likely to work in the way you expect it.

Best regards,
Simon


-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to