Ask Your Question

Babacool51's profile - activity

2023-01-22 23:15:38 +0200 received badge  Famous Question (source)
2021-06-18 19:27:05 +0200 received badge  Notable Question (source)
2020-08-21 16:28:55 +0200 received badge  Good Question (source)
2020-08-21 16:28:53 +0200 received badge  Popular Question (source)
2017-02-21 19:52:47 +0200 commented answer How to make a symbolic function of a matrix ?

I works perfectly i'm actually gratefull, believe me :)

There is my code, if eventually it can serve to someone :

Qf = 1000000*matrix([[0,0],[0,1]]);
Xf = matrix([[1],[1675]]);
X = matrix(SR, [[var('X'+str(1+i)+str(1+j)) for j in range(1)] for i in range(2)]);
f = ((X-Xf).transpose()*Qf*(X-Xf))[0,0];

Xt = matrix([[1],[1]]);
print f;
print f.substitute([X[i,0]==Xt[i,0] for i in range(2)]);

-1000000.0*(X21 - 1659.0)*(-1.0*X21 + 1659.0)
-0.0
2017-02-21 15:03:30 +0200 commented answer How to make a symbolic function of a matrix ?

Just one last thing, is there any way to make elegant evaluation of f, as something like :

M = matrix([[1,2],[3,4],[5,6],[7,8]]);
print f(M);

Or eventually :

M = matrix([[1,2],[3,4],[5,6],[7,8]]);
print f(xij = M[i][j]);

You see the idea ^^

2017-02-21 14:37:45 +0200 commented answer How to make a symbolic function of a matrix ?

Ty so much :)

2017-02-21 12:28:34 +0200 received badge  Supporter (source)
2017-02-21 09:07:36 +0200 received badge  Nice Question (source)
2017-02-21 07:37:07 +0200 received badge  Student (source)
2017-02-21 03:25:24 +0200 asked a question How to make a symbolic function of a matrix ?

Hi,

I'm beginning with Sage. I've got two matrix Qf and Xf defined by :

Qf = 1000000*matrix([[0,0],[0,1]]);
Xf = matrix([1],[1675]);

I would like to write a symbolic function "f" which would take a matrix X with 2 rows & 1 column.

X = var('X');
f(X) = ((X-Xf).transpose()*Qf*(X-Xf));

I easily wrote it with python non-symbolic function syntax, but i didn't find a way to make it symbolic. Because I'll need his gradient later (which is easy to calculate by hand, that I conceed ^^).

Maybe, it's related with SR matrix, no idea, i'm beginning with Sage and that's why I'm asking for help x)

Thank you in advance.

2017-02-21 02:33:30 +0200 received badge  Organizer (source)