On 11/13/13 9:45 PM, Jotace wrote:
Hello to everyone,
I was trying to make some camputational tool for my students, to allow
them to compute powers of matrices quickly. I made a tiny htm page with
some text giving explanations, and the following code embedden in a
one-cell script
DEF=[[0.25,0.55,0.2],[0.35,0.15,0.1],[0.45,0.3,0.7]];
@interact
def _(T=input_grid(3,3, default = DEF, label='Transition matrix $T=$',
to_value=matrix), d=input_box(3, width=5, label="number of digits "),
n=input_box(2,width=5,label="power of $T$, $n=$")):
T = T.apply_map(RealField(d*log(10)/log(2)))
M=T^n
html('$T^n = \displaystyle %s$'%latex(M))
I happen to have a page which background is blue, so the standard
output, in black is not very adapted... Anyone can tell how to change
the output color of html(...) to white?
Here are two ways:
* since you have all math, you can use the latex \color command:
html('$\color{white}{T^n = \displaystyle %s}$'%latex(M))
* In general, you can set a CSS style using a div or span tag:
html('<div style="color: white;">$T^n = \displaystyle
%s$</div>'%latex(M))
And I have a second question : I would like to round the matrices ut to
some desired precision. What I did here is not exactly that. I don'n
know why M.round(3) didn't worked... I spent more time that I should
have trying to figure out this... I someone could help, that would be
very nice!
You could still use apply_map with the round function:
T = T.apply_map(lambda x: round(x,d))
Also, if your matrix was an RDF matrix, you could use .round(3). (Yes,
this is inconsistent; Here, I use the to_value to convert the matrix
specifically to an RDF matrix:
@interact
def _(T=input_grid(3,3, default = DEF, label='Transition matrix $T=$',
to_value=lambda x: matrix(RDF, x)), d=input_box(3, width=5,
label="number of digits "),
n=input_box(2,width=5,label="power of $T$, $n=$")):
T = T.round(3)
M=T^n
html('$T^n = \displaystyle %s$'%latex(M))
If you really only wanted the matrix in a field with that precision
(instead of in 53-bit precision RDF), you could do:
T = T.n(digits=3)
with any matrix.
Thanks,
Jason
--
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.