[sage-support] Re: Function defined with matrices won't plug in values for function
On Friday, November 30, 2018 at 1:59:40 PM UTC-8, saad khalid wrote: > > However, when I try to compute this h(.1), the function doesn't plug in .1 > in for s in the function, and it returns: > > [ s + 1 0] > [ 0 -s + 1] > > > What exactly is happening? > > The problem is that a matrix over SR is not a symbolic expression itself: sage: parent(M1+s*Mx) Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring The effect of "h(s)=..." is (you can check by calling 'preparse("h(s)=...")'): h = symbolic_expression(M1+s*Mx).function(s) which "forces" the sage object M1+s*Mx into the symbolic ring. Nearly everything can be stuffed into the symbolic ring, but in this case it basically becomes a constant: sage: symbolic_expression(M1+s*Mx).variables() () sage: symbolic_expression(M1+s*Mx).is_constant() True Once stuffed into SR, it's an opaque entity, and the occurrence of s in it is not visible. So turning it into a function of s is straightforward: it's a constant function! The solution here is to use that matrices over symbolic rings do inherit some properties of symbolic expressions. One is substitution, so sage: h=M1+s*Mx sage: h(s=1.0) [ 2.00 0] [0 0.000] works just fine. If you want to turn it into something for which h(1.0) works, you can do h=lambda s0: (M1+s*Mx)(s=s0) -- 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.
Re: [sage-support] Function defined with matrices won't plug in values for function
I'm quite confused, why do you think this is not implemented? It seems like the kind of thing that is so simple, it should "just work." Is there some strange complication that could arise by defining it over SR that I'm not thinking of? I feel like it should be possible to define the function and have it at least try to plug in the input value. On Friday, November 30, 2018 at 5:44:28 PM UTC-5, Dima Pasechnik wrote: > > It seems that doing this kind of thing over SR is not implemented. > However, you can do something like this: > R.=QQ[] > Mz = matrix(R,[[0,1],[1,0]]) > Mx = matrix(R,[[1,0],[0,-1]]) > M1 = matrix(R,[[1,0],[0,1]]) > h = M1 + s*Mx > > sage: h(s=1/2) > [3/2 0] > [ 0 1/2] > > Here h is a matrix with entries in R, and substitution works... > > On Fri, Nov 30, 2018 at 9:59 PM saad khalid > wrote: > > > > Hi all, > > > > 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) > > However, when I try to compute this h(.1), the function doesn't plug in > .1 in for s in the function, and it returns: > > > > [ s + 1 0] > > [ 0 -s + 1] > > > > > > What exactly is happening? > > > > -- > > 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...@googlegroups.com . > > To post to this group, send email to sage-s...@googlegroups.com > . > > Visit this group at https://groups.google.com/group/sage-support. > > For more options, visit https://groups.google.com/d/optout. > -- 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.
[sage-support] Re: Weird behavior in sagecell
Thanks! On Friday, November 30, 2018 at 5:02:27 PM UTC-8, slelievre wrote: > > > Fri 2018-11-30 23:43:00 UTC, David Guichard: >> >> In this page, >> >> http://skink.whitman.edu/~guichard/sage/two_plots_clean.html >> >> I have two sagecells, each to do a 3d plot. If I evaluate the first one, >> it works as expected. If I then evaluate the second, it graphs correctly, >> but it also replaces the first plot with a copy of the second. Neither of >> them is "live", that is, I can't rotate either version. >> >> If I first evaluate the second cell, it works as expected. If I then >> evaluate the first one, it also works as expected: I end up with two >> (different) plots, both live. >> >> I'd appreciate knowing how to fix this, if it's possible. I have tried a >> few things, such as changing the outputLocation, but nothing has worked so >> far. >> >> Thanks, >> David >> > > Not sure how to explain what happens there, > or how to really fix it if sticking to jsmol is important. > > If you do the 3D-plotting with three.js however, > the problem goes away. > > This just amounts to adding viewer='threejs' > at the end of the plotting commands: > > > # Trefoil knot tube > t, u = SR.var('t u') > assume(t, u, 'real') > # First define the Trefoil knot spacecurve > r = vector((sin(3 * t), 2 * sin(2 * t) + sin(t), cos(t) - 2 * cos(2 * > t))) > # Next compute the T, N, and B vectors > rp = diff(r, t) > T = rp / rp.norm() > Tp = diff(T, t) > N = Tp / Tp.norm(2) > B = T.cross_product(N) > # Define the function to use for the radius of the circle > radius(t) = 1/2 > # Define the vector function for the surface and plot it > tube = r + radius(t) * cos(u) * N + radius(t) * sin(u) * B > parametric_plot3d(tube, (t, 0, 2 * pi), (u, 0, 2 * pi), > plot_points=[100, 30], aspect_ratio=[1, 1, 1] > viewer='threejs') > > > # The cone > u, v = var('u v') > assume(u, v, 'real') > # Define the surface as a vector function > r = vector((v * cos(u), v * sin(u), v)) > # Plot it > parametric_plot3d(r, (u, 0, 2*pi), (v, 0, 5), aspect_ratio=[1, 1, 1], > viewer='threejs') > > -- 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.
Re: [sage-support] Re: Weird behavior in sagecell
Sat 2018-12-01 01:02 UTC, slelievre: > > Fri 2018-11-30 23:43 UTC, David Guichard: >> >> In this page, >> >> http://skink.whitman.edu/~guichard/sage/two_plots_clean.html >> >> I have two sagecells, each to do a 3d plot. If I evaluate the first one, it >> works as expected. If I then evaluate the second, it graphs correctly, but >> it also replaces the first plot with a copy of the second. Neither of them >> is "live", that is, I can't rotate either version. >> >> If I first evaluate the second cell, it works as expected. If I then >> evaluate the first one, it also works as expected: I end up with two >> (different) plots, both live. >> >> I'd appreciate knowing how to fix this, if it's possible. I have tried a few >> things, such as changing the outputLocation, but nothing has worked so far. >> >> Thanks, >> David > > > Not sure how to explain what happens there, > or how to really fix it if sticking to jsmol is important. > > If you do the 3D-plotting with three.js however, > the problem goes away. > > This just amounts to adding viewer='threejs' > at the end of the plotting commands. See a similar report on the sage-cell mailing list: https://groups.google.com/d/topic/sage-cell/BL9h7xLiwG4/discussion In the discussion there, Andrey Novoseltsev points out that SageMathCell uses only one jsmol instance, and if there are several plots using it, they might conflict in hard to predict ways. He recommends using three.js. three.js (called "threejs" in Sage) is a javascript 3D-plotting library. https://threejs.org/ -- 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.
[sage-support] Re: Weird behavior in sagecell
Fri 2018-11-30 23:43:00 UTC, David Guichard: > > In this page, > > http://skink.whitman.edu/~guichard/sage/two_plots_clean.html > > I have two sagecells, each to do a 3d plot. If I evaluate the first one, > it works as expected. If I then evaluate the second, it graphs correctly, > but it also replaces the first plot with a copy of the second. Neither of > them is "live", that is, I can't rotate either version. > > If I first evaluate the second cell, it works as expected. If I then > evaluate the first one, it also works as expected: I end up with two > (different) plots, both live. > > I'd appreciate knowing how to fix this, if it's possible. I have tried a > few things, such as changing the outputLocation, but nothing has worked so > far. > > Thanks, > David > Not sure how to explain what happens there, or how to really fix it if sticking to jsmol is important. If you do the 3D-plotting with three.js however, the problem goes away. This just amounts to adding viewer='threejs' at the end of the plotting commands: # Trefoil knot tube t, u = SR.var('t u') assume(t, u, 'real') # First define the Trefoil knot spacecurve r = vector((sin(3 * t), 2 * sin(2 * t) + sin(t), cos(t) - 2 * cos(2 * t))) # Next compute the T, N, and B vectors rp = diff(r, t) T = rp / rp.norm() Tp = diff(T, t) N = Tp / Tp.norm(2) B = T.cross_product(N) # Define the function to use for the radius of the circle radius(t) = 1/2 # Define the vector function for the surface and plot it tube = r + radius(t) * cos(u) * N + radius(t) * sin(u) * B parametric_plot3d(tube, (t, 0, 2 * pi), (u, 0, 2 * pi), plot_points=[100, 30], aspect_ratio=[1, 1, 1] viewer='threejs') # The cone u, v = var('u v') assume(u, v, 'real') # Define the surface as a vector function r = vector((v * cos(u), v * sin(u), v)) # Plot it parametric_plot3d(r, (u, 0, 2*pi), (v, 0, 5), aspect_ratio=[1, 1, 1], viewer='threejs') -- 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.
Re: [sage-support] Function defined with matrices won't plug in values for function
It seems that doing this kind of thing over SR is not implemented. However, you can do something like this: R.=QQ[] Mz = matrix(R,[[0,1],[1,0]]) Mx = matrix(R,[[1,0],[0,-1]]) M1 = matrix(R,[[1,0],[0,1]]) h = M1 + s*Mx sage: h(s=1/2) [3/2 0] [ 0 1/2] Here h is a matrix with entries in R, and substitution works... On Fri, Nov 30, 2018 at 9:59 PM saad khalid wrote: > > Hi all, > > 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) > However, when I try to compute this h(.1), the function doesn't plug in .1 in > for s in the function, and it returns: > > [ s + 1 0] > [ 0 -s + 1] > > > What exactly is happening? > > -- > 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. -- 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.
[sage-support] Function defined with matrices won't plug in values for function
Hi all, 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) However, when I try to compute this h(.1), the function doesn't plug in .1 in for s in the function, and it returns: [ s + 1 0] [ 0 -s + 1] What exactly is happening? -- 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.
[sage-support] Pauli matrices
Hey everyone: Perhaps I am missing something very obvious, but is there an implementation of the pauli spin matrices in Sage? They are simple enough to define, but ubiquitous enough that I would have assumed they were predefined. -- 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.