ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 28 Oct 2019 04:39:17 -0500vector equation solvehttp://ask.sagemath.org/question/48532/vector-equation-solve/How to solve this?:
F = vector([cos(alpha),sin(alpha),z])
G = vector([z,cos(alpha),sin(alpha)])
A = vector([0,0,0])
solve(F-G == A)
Answer must be:
[cos(asin(cos(alpha))),
sin(asin(cos(alpha))),
sin(alpha)]dimonbavlyMon, 28 Oct 2019 04:39:17 -0500http://ask.sagemath.org/question/48532/Polynomial interpolation given a mathematic function f(x), an interval [a,b] and a natural number nhttp://ask.sagemath.org/question/43927/polynomial-interpolation-given-a-mathematic-function-fx-an-interval-ab-and-a-natural-number-n/Hi, i'm a computer science bachelor 's student and i'm having some trouble with this exercice, i'd like to get some help since it's my first course using sagemath, thanks, the exercice:
Write a function that takes as input a mathematical function f, an interval [a, b] and a natural n and return the interpolative polynomial of the function in the n + 1 points resulting from dividing the interval into subinterval n of equal length. That is to say, a polynomial p (x) of degree ≤ n such p (xi) = f (xi), where xi = a + i * ((b-a)/n) for all i = 0, ... n.
I'm stuck in the way of transforming a list into a matrix. This is what i've tried so far:
def list1(a,b,n):
r=(b-a)/n
return [a+i*r for i in range(n+1)]
def list2(a,b,n):
r=(b-a)/n
l=[]
for i in range(n+1):
l.append(a+i*r)
return l
def functionlist(f,llista):
return[f(i) for i in llista]
px=matrix(7, 1,list2(1, 5, 6))
show(px)
py=matrix(7, 1, functionlist(sin, list1(1, 5, 6)))
show(py)
points= zip(px,py); points
A=matrix(RDF,[[1,px[0],px[0]^2,px[0]^3],[1,px[1],px[1]^2,px[1]^3],[1,px[2],px[2]^2,px[2]^3],[1,px[3],px[3]^2,px[3]^3]]); A
And gives me this error:
NotImplementedError Traceback (most recent call last)
<ipython-input-112-a1670df9c827> in <module>()
19 points= zip(px,py); points
20
---> 21 A=matrix(RDF,[[Integer(1),px[Integer(0)],px[Integer(0)]**Integer(2),px[Integer(0)]**Integer(3)],[Integer(1),px[Integer(1)],px[Integer(1)]**Integer(2),px[Integer(1)]**Integer(3)],[Integer(1),px[Integer(2)],px[Integer(2)]**Integer(2),px[Integer(2)]**Integer(3)],[Integer(1),px[Integer(3)],px[Integer(3)]**Integer(2),px[Integer(3)]**Integer(3)]]); A
22
23
/opt/sagemath-8.3/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.__pow__ (build/cythonized/sage/modules/free_module_element.c:15842)()
2019 NotImplementedError
2020 """
-> 2021 raise NotImplementedError
2022
2023 def _repr_(self):
NotImplementedError:
Pls help, thanks.Hell_BoyFri, 12 Oct 2018 06:36:28 -0500http://ask.sagemath.org/question/43927/Quaternions Missing Important Functionality?http://ask.sagemath.org/question/34587/quaternions-missing-important-functionality/I use quaternions and Clifford algebras frequently for solving PDE boundary value problems as well as things like reflections, rotations etc. The underlying field for my quaternions is almost always either the complex numbers or the symbolic ring.
I am making an attempt to use them in Sage but I've run into a couple of obstacles that have given me pause. The absolute first things I looked for were,
1) scalar part or real part of the quaternion. Where is this function? I stumbled upon turning it into a list or vector but I presume that just taking the scalar part would be more efficient than dumping all the coefficients. For matrix representations it's often just the trace of the matrix. Correspondingly obtaining the vector part should be a standard function as well.
2) Quaternion automorphisms and anti-automorphisms? where are they? Yes we have conjugate which is both a method and an external function but what about the reversion and involution and the many other automorphisms? I don't expect to have to multiply by a bunch of unit vectors to get them for efficiency reasons. Also how do I distinguish between the quaternion conjugate and the complex conjugate of each of it's elements? This is a very important distinction that I would not know how to do without stripping out it's components and then remapping it.
3) Constructing a quaternion from coefficients. The only examples I've seen require explicit multiplications like
q = q0 + q1 * i + q2 * j + q3 * k . That doesn't seem efficient.
4) quaternions as elements of enclosing matrices and vectors. This would be very helpful since you could generate any Clifford algebra with this and it's often easier to analyze the components of said algebra that are isomorphic to Quaternions or Biquaternions in the complex case. Moreover I need to be able to do this for quaternions over the symbolic ring. It fails for me as this example from sage 7.3 shows:
<pre><code>
Q.<e1,e2,e3> = QuaternionAlgebra(SR, -1,-1)
var('x y z', domain='real')
q1 = x + x * I * e1
q2 = x - x * I * e1
v = vector([q1,q2])
</code></pre>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_36.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("US48ZTEsZTIsZTM+ID0gUXVhdGVybmlvbkFsZ2VicmEoU1IsIC0xLC0xKQp2YXIoJ3ggeSB6JywgZG9tYWluPSdyZWFsJykKcTEgPSB4ICsgeCAqIEkgKiBlMQpxMiA9IHggLSB4ICogSSAqIGUxCnYgPSB2ZWN0b3IoW3ExLHEyXSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpQ0ibdW/___code___.py", line 7, in <module>
exec compile(u'v = vector([q1,q2]) File "", line 1, in <module>
File "sage/modules/free_module_element.pyx", line 510, in sage.modules.free_module_element.vector (/data/AppData/SageMath/src/build/cythonized/sage/modules/free_module_element.c:5811)
TypeError: unsupported operand type(s) for ** or pow(): 'QuaternionAlgebra_ab' and 'int'
5) quaternion rotations. Most libraries will generate the unit quaternion that rotates in 3D space and/or have a function that applies it efficiently.
There are probably a few other things like generating a canonical matrix representation for a full quaternion and so forth. I actually wonder if the default quaternion package is the right tool for a physicist or an engineer or someone who wants to play around with the so called geometric algebra of Hestenes. It seems the perogatives of the scientist vs the algebraist are very very different. How efficient is this library? What if I had to multiply millions of quaternions? I'm guessing I'd be better off mapping it to complex matrices and invoking blas.
While most of the functionality can be added on via a little python programming, I am concerned about efficiency and consistency. Moreover item 4 is a bit of a quandary since it involves overloading a bunch of arithmetic operators and some new python classes and so forth.
I'm hoping someone will tell me that it's all there, I just wasn't able to find it in the documentation or so forth. Thanks for any help in advance.doomThu, 25 Aug 2016 21:11:21 -0500http://ask.sagemath.org/question/34587/scalar^[vector]?http://ask.sagemath.org/question/29814/scalarvector/I feel really stupid like this should be obvious, but I can't figure out how to do it.
v = vector([1,2,3])
2^v
should give me
[2, 4, 8]
I can't find any other way to do this without writing a function.drWed, 07 Oct 2015 20:00:40 -0500http://ask.sagemath.org/question/29814/How can I get an invertible matrix X with integral entries and AX=XB, where A and B are matrices with integral entries.http://ask.sagemath.org/question/24467/how-can-i-get-an-invertible-matrix-x-with-integral-entries-and-axxb-where-a-and-b-are-matrices-with-integral-entries/Let M be the set of all n by n matrices with integral entries.
For A and B in M, how can I get an invertible matrix X in M with AX=XB in Sage.
I can partially solve that problem in GAP following method.
- V={ X in Mn(QQ) | AX=XB }
(V is a vector space over QQ)
- Basis(V)={B_1,B_2, ..., B_k}
(I wonder which number k it is according to the changes of A and B.)
- Make X=a_1 * B_1 + ... +a_k * B_k , a_i in some interval in ZZ.
- Check two things which are X in Mn(ZZ) and the existence of the inverse of X in Mn(ZZ).
I can find such X for some easy matrices A,B.
How can I solve this problem in Sage?
Thanks.SeminSun, 12 Oct 2014 01:09:43 -0500http://ask.sagemath.org/question/24467/Yet another linear combinationhttp://ask.sagemath.org/question/10791/yet-another-linear-combination/Hi, I'm really new to Sage and to programming in general. I have 20 linear independent vectors of length 20, and a linear dependent vector. I would like to write this one as a linear combination of the others: I looked up on the internet all day, but nothing I found worked. The ways I tried are:
- define a vector space of dim 20 on the field I'm using, impose my vectors as a base, and use the method .coodinates(). PROBLEM: I couldn't impose the basis, I didn't find a command to do so.
- use G.solve_right(s), where G is a 20x20 matrix and s is my linear dependent vector. I thought I would have a vector as an output but instead I get something of dimension 20x8. Weird.
- I tried to do a linear system directly using equations with the vectors, in order to solve them with respect to some variables, but I got as an output that you can't do it using vectors.
So, what shall I try?
Thank you very much BubusetteteFri, 29 Nov 2013 11:49:42 -0600http://ask.sagemath.org/question/10791/How to assign matrix (vector) value to variablehttp://ask.sagemath.org/question/10599/how-to-assign-matrix-vector-value-to-variable/when I tried to assign a matrix or a vector to variables, something wrong happens:
sage: sin([1,2,3,4]).n()
Traceback (click to the left of this block for traceback)
...
TypeError: cannot coerce arguments: no canonical coercion from <type
'list'> to Symbolic Ring
what I want to achieve is that the out put gives a vector that equals to [sin(1),sin(2),sin(3),sin(4)].
Thanks in advance!chenmingTue, 08 Oct 2013 14:14:44 -0500http://ask.sagemath.org/question/10599/Can I define an n-dimensional matrix?http://ask.sagemath.org/question/10244/can-i-define-an-n-dimensional-matrix/I'm sure this is a basic question that has been asked before but I'm too stupid to find it.
What I'd like to do is something like this
k=var('n')
assume(n, 'integer')
assume(n>0)
VS = MatrixSpace(SR, n, 1)
to get the space of all *n*×1 matrices, i.e. column vectors. Is it at all possible to define a generalized *n*-dimensional vector or *n×n* matrix? Or am I just taking the completely wrong approach here?
**Edit:** Forgot to mention that the error I get is
ValueError: cannot convert n to int
mudd1Sat, 15 Jun 2013 08:52:18 -0500http://ask.sagemath.org/question/10244/