ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 30 Sep 2020 17:20:26 -0500Plot for vectorshttps://ask.sagemath.org/question/53675/plot-for-vectors/ V1 = vector([3,2,1])
V2 = vector([2,3,5])
V3 = vector([1,2,3])
plot(V1, color='red', gridlines='minor') + plot(V2, color='yellow') + plot(V3, color='blue')
What's up with the graph? Why are the lines not shown as vectors and why do they not change color?Alex89Wed, 30 Sep 2020 17:20:26 -0500https://ask.sagemath.org/question/53675/Concatenation of symbolic vectors.https://ask.sagemath.org/question/52838/concatenation-of-symbolic-vectors/ This
NB_0=vector(var('x', n=3, latex_name='x'))
B_0=vector(var('y', n=4, latex_name='ϵ'))
show(LatexExpr(r"NB_0 =" + latex(NB_0)),LatexExpr(r"\, \text{ et }\, B_0 =" + latex(B_0)))
gives me two vectors.
But I need to concatenate them -- i.e. to create a vector `$V1= [x_1, x_2, x_3, x_4, \epsilon_1, \epsilon_2, \epsilon_3, b]$` (I need the `$b$`) and `$V2= [\epsilon_1, \epsilon_2, \epsilon_3, z]$` (I need the `$z$`). And when I call them in a table I want to create I need the Latex names not the sagemath one. How could I do ?
CyrilleMon, 03 Aug 2020 12:53:17 -0500https://ask.sagemath.org/question/52838/Absence of column vectorshttps://ask.sagemath.org/question/48860/absence-of-column-vectors/ I'm curious as to why column vecotrs seem to be non-existent in sage. To give you some context, I work with the following system:
R3 = IntegerModRing(3)
c_7_4 = [
[1, 0, -2, 0, 0, 0, 1],
[1, 1, 0, 0, -2, 0, 0],
[0, 1, 1, 0, 0, -2, 0],
[0, 0, 1, 1, 0, 0, -2],
[0, -2, 0, 1, 1, 0, 0],
[-2, 0, 0, 0, 1, 1, 0],
[0, 0, 0, -2, 0, 1, 1]
]
C3 = Matrix(R3, c_7_4)
B3 = C3.right_kernel().basis()
Clearly, the right kernel of C3 is a column vector, but if you run this code, you would find that
print(B3[0]) # returns a row vector
print(B3[0] * C3) # returns an answer
print(C3 * B3[0]) # returns an answer
Given that a column matrix should reasonably be written
[[a],[b]]
Why is this not the case? Specifically, is there a coding limitation to what the programmers can do which forces them to implement it in this way, or is there some mathematical usefulness to this which is beyond my understanding?
Thanks!
KraigSat, 23 Nov 2019 11:44:38 -0600https://ask.sagemath.org/question/48860/maximizing sum over feasible set of vectorshttps://ask.sagemath.org/question/48630/maximizing-sum-over-feasible-set-of-vectors/Let $[5]$ be the set of the first 5 positive integers. We let $\underline{\alpha} =(\alpha_A)_{A\neq \emptyset, A\subseteq [5]}$ consist of a vector with $31$ real entries, where each $\alpha_A$ is associated with a subset $A \subseteq [5]$.
Define $\displaystyle OBJ(\underline{\alpha})=\sum_{A\subseteq [5], A\neq \emptyset} \alpha_A \log(|A|)$, $\quad \displaystyle v(\underline{\alpha})=\sum_{A\subseteq [5], A\neq \emptyset} \alpha_A$, $\quad$ and $\quad \displaystyle E(\underline{\alpha})=\sum_{ {A,B}: A\cap B\neq \emptyset} \alpha_A \alpha_B$,
where the sum for $E(\underline{\alpha})$ is taken over all unordered pairs of disjoint nonempty sets $A$ and $B$, where $A, B \subseteq [5]$.
Also define $FEAS(1/4)$ to be the set of all such vectors $\underline{\alpha}$ with nonnegative real entries such that $v(\underline{\alpha})=1$ and $E(\underline{\alpha})\geq 1/4$.
I want to learn how to program the following optimization problem:
$$\displaystyle OPT(1/4):=\max_{\underline{\alpha} \in FEAS(1/4)} OBJ(\underline{\alpha})$$
I was told that I can do this in SageMath. I have some basic knowledge of how to use Sage. How could I create the set $FEAS(1/4)$? I think that from there I may be able to figure out how to maximize $OBJ(\underline{\alpha})$ over this set.merluzaTue, 05 Nov 2019 15:28:50 -0600https://ask.sagemath.org/question/48630/Print symbolic variables like a_1 in A[1] stylehttps://ask.sagemath.org/question/43838/print-symbolic-variables-like-a_1-in-a1-style/Because of Sagemath's problem with symbolic arrays, I have defined my vectors like this:
A =[0 for j in range(4)]
for j in range(4):
A[j]=var('a_'+str(j))
I have some symbolic variables stored in another variable. Lets say I have a subroutine that works with `A[i]` and in the end, `L` becomes something such as: `L=a_1+a_2*a_3`. When I print `L`, I want to have it printed in the original vector format. So when I type `L` or `print(L)` in a cell and press enter, my desired output is `A[1]+A[2]*A[3]` and not `a_1+a_2*a_3`. I want this type of output because I am transferring SageMath outputs to C where I employ indexed arrays. How can I achieve this? DanialBaghFri, 05 Oct 2018 22:30:25 -0500https://ask.sagemath.org/question/43838/How does one detect cyclic vectors in SAGE?https://ask.sagemath.org/question/27025/how-does-one-detect-cyclic-vectors-in-sage/
Given a vector $v$ and a matrix $A$ of dimension $n$, one would say that $v$ is a cyclic vector of $A$ if the following set is linearly independent $\{ v,Av,A^2v,..,A^{n-1}v \}$.
Is there a way to test this property on SAGE given a $v$ and a $A$? PhoenixThu, 04 Jun 2015 15:12:06 -0500https://ask.sagemath.org/question/27025/define new vectorhttps://ask.sagemath.org/question/26198/define-new-vector/ hi i'm new in sage , I have two vectors
v1=vector([8,-10,12]) <br>
v2=vector([9,4,-6])
i want to create a third one which is parallel with v1 and also the scalar product of v2 and v3 is equal to 1440
(x,y,z)=var('x,y,z') <br>
v3=vector([x,y,z])
solve([v1.dot_product(v3)==1440,v2.cross_product(v3)==0],x,y,z)
i want to get something like this: [x= , y= , z= ] <br>
but the result: []
dan6252Sun, 15 Mar 2015 21:15:30 -0500https://ask.sagemath.org/question/26198/How do I create and plot a vector from the difference between two points?https://ask.sagemath.org/question/26066/how-do-i-create-and-plot-a-vector-from-the-difference-between-two-points/ Having points $a$ and $b$, how do I create a vector that goes from $a$ to $b$? I'm trying the following but I get an error:
a=[(1,0,0)]
b=[(0,-1,0)]
u=vector(b-a)
Then, how do I plot $a$, $b$ and $u$ at the position of $a$?
The error is
> File "/tmp/tmpoTA_jw/___code___.py",
> line 6, in <module>
> exec compile(u'u=vector(b-a) File "", line 1, in <module>
> TypeError: unsupported operand type(s) for -: 'list' and 'list'nardaenSat, 07 Mar 2015 15:43:41 -0600https://ask.sagemath.org/question/26066/dividing vector(a,b) by sqrt(x) gives (a/x*sqrt(x),b/x*sqrt(x))https://ask.sagemath.org/question/25980/dividing-vectorab-by-sqrtx-gives-axsqrtxbxsqrtx/ I can't seem to figure out why the behavior above is happening.
I have been trying to familiarize myself with Sage as I am both an IT person at my university and currently a Calc III student and it would seem to me to be helpful for both to know how this software works since many professors use it and I can use it to check work in my classes.
When I attempt to get the unit vector in the direction of <1,1> I divide the vector by its magnitude, and instead of the expected result of <1/sqrt(2), 1/sqrt(2)> I have been getting <1/2*sqrt(2), 1/2*sqrt(2)> and this happens the same way with a vector divided by the sqrt of anything. (i.e. <1,1> / sqrt(3) == <1/3*sqrt(3), 1/3*sqrt(3)>)
Is this a bug, or am I missing something?
EDIT - To clarify, I am dividing a vector by it's magnitude, which is a scalar number. vector{a,b} divded by c should yield vector{a/c, b/c}. This works fine for integers. but when doing so with the sqrt() function it produces odd results. So if c == sqrt(d) the answer is coming back as vector{a/(d*c), b/(d*c)} and I don't understand why the denominator is being multiplied by d.
RickySat, 28 Feb 2015 17:27:40 -0600https://ask.sagemath.org/question/25980/Solving linear matrix equationshttps://ask.sagemath.org/question/25059/solving-linear-matrix-equations/Hi everybody, I'm new to Sage and I'm pretty confused with the solving of matrix equations, I didn't fully understand the guide.
I've got these vectors:
V_fa = vector([V_f*cos(phi), V_f*sin(phi), 0])
V_ra = vector([V, 0, 0])
omega = vector([0, 0, L*psi_d])
P = vector([0, L*psi_d, 0])
And i want to implement the equation:
V_fa=V_ra+omega.cross_product(P)
to isolate and obtain the value of `psi_d`.
How can I do that?
Thank you very much
SilviaSun, 30 Nov 2014 12:35:22 -0600https://ask.sagemath.org/question/25059/problems with product of vector of symbols with square matrixhttps://ask.sagemath.org/question/24077/problems-with-product-of-vector-of-symbols-with-square-matrix/ Hi,
I am trying to do some experiments with symbols (variable vector) and multiplications with a coefficient matrix.
The code is the following:
A = matrix(QQ,[
[2,1,2,-6],
[-1,2,1,7],
[3,-1,-3,-1],
[1,5,6,0]
])
k = A.transpose().kernel()
basis = k.basis()[0]
t = 'real'
var('x1')
assume(x1,t)
var('x2')
assume(x2,t)
var('x3')
assume(x3,t)
var('x4')
assume(x4,t)
x = vector([x1,x2,x3,x4])
print "x",x
xT = x.transpose()
print "xT",xT
print "A*x",A*x
print "xT*A",xT*A
with the following output:
x (x1, x2, x3, x4)
xT [x1]
[x2]
[x3]
[x4]
A*x (2*x1 + x2 + 2*x3 - 6*x4, -x1 + 2*x2 + x3 + 7*x4, 3*x1 - x2 - 3*x3 - x4, x1 + 5*x2 + 6*x3)
xT*A
Traceback (most recent call last):
File "", line 1, in <module>
File "/tmp/tmpuVBZ96/___code___.py", line 27, in <module>
exec compile(u'print "xT*A",xT*A
File "", line 1, in <module>
File "element.pyx", line 2751, in sage.structure.element.Matrix.__mul__ (sage/structure/element.c:19587)
File "coerce.pyx", line 856, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure /coerce.c:8169)
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 4 by 1 dense matrices over Symbolic Ring' and 'Full MatrixSpace of 4 by 4 dense matrices over Rational Field'
As you can see, `A*x` was successful, but `xT*A` is giving an exception. Do you have any idea on why? How would you solve this?stablumTue, 09 Sep 2014 17:32:46 -0500https://ask.sagemath.org/question/24077/Defining a function of vector variableshttps://ask.sagemath.org/question/23758/defining-a-function-of-vector-variables/I would like to define a Sage function that takes a vector variable and computes the result of some vector function on it, something like
f(v) = v.dot_product(vector((1,1)))
However, when I try to run this in Sage, I get
AttributeError: 'sage.symbolic.expression.Expression' object has no
attribute 'dot_product'
Is there a way to achieve this effect in Sage?ajdWed, 13 Aug 2014 12:06:57 -0500https://ask.sagemath.org/question/23758/Why cant I multiply two vectors together on sage cell?https://ask.sagemath.org/question/11049/why-cant-i-multiply-two-vectors-together-on-sage-cell/Hello all. Sage noob here. My friend recently told me about sage and convinced me to give it a whirl. (My background is MATLAB).
I made an account, and went to sage cell for a quick run. I typed this in:
v = vector([3, 4]);
vC = v.column();
vC*v
I would like to simply get the outer product of those two vectors. However it errors out.
I would like to think that I am boneheading something here, because this is a legitimate operation. I have multiple tutorial/documentation tabs open but nothing really elucidating why/how this doesnt work.
Would appreciate any insight.
GravitusMon, 17 Feb 2014 05:11:18 -0600https://ask.sagemath.org/question/11049/plot arbitrary 2 vectorshttps://ask.sagemath.org/question/10739/plot-arbitrary-2-vectors/I just tried to plot these 2 vectors a and b:
sage: a = [0, 0, 0, 0, 0, 2/25, 13/20, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
sage: b = range(50,70)
sage: plot(a,b)
but an error occurs: ValueError: too many values to unpack any help ???Mohamed GaafarSat, 16 Nov 2013 02:45:10 -0600https://ask.sagemath.org/question/10739/Finding vectors from csv filehttps://ask.sagemath.org/question/10678/finding-vectors-from-csv-file/Hi!
I'm trying to find 2 vectors x and y coming from the colums of my csv file.
<br>Let's say that it looks like :
<table>
<tr>
<th>
0.30075188
</th>
<th>3.565635718
</th>
</tr>
<tr>
<th>
0.325814536
</th>
<th> 3.04256687
</th>
</tr>
<tr>
<th>
0.350877193
</th>
<th> 3.850427654
</th>
</tr>
<tr>
<th>
0.37593985
</th>
<th> 3.954295131
</th>
</tr>
<tr>
<th>
0.401002506</th>
<th> 4.265641679</th>
</tr>
</table>
<br>
Thanks a lot!
ndanveryThu, 31 Oct 2013 10:02:54 -0500https://ask.sagemath.org/question/10678/Augmenting a vectorhttps://ask.sagemath.org/question/10618/augmenting-a-vector/There are simple ways to extend a matrix to form a larger matrix: I can `augment` it to add columns or `stack` it to add rows.
Is there something similar for simple vectors? Some method of a vector object which would return the same vector with one more element added to the end? Or do I have to write that myself?MvGThu, 17 Oct 2013 05:42:32 -0500https://ask.sagemath.org/question/10618/vector division?https://ask.sagemath.org/question/10451/vector-division/given a vector in sage
sage: a,b=var('a,b')
sage: sv=vector(SR,[1,a,b^2])
then why is this a meaningful operation
sage: sv/sv
1
To my (utterly humble) understanding, I always thought, that if vector multiplication '*' is defined via the scalar product - as it seems to be in sage
sage: sv*sv
a^2 + b^4 + 1
then, division cannot be defined meaningfully?
[Just as a sideremark along that line: I have no problem with numpy's element wise array-arithmetic
In [1]: v=array([1.,2.,3.]) # vector
In [2]: e=array([1.,1.,1.]) # unity is a vector
In [3]: e*v == v # multiplication by unity
Out[4]: array([ True, True, True], dtype=bool)
In [5]: vi=v**(-1) # inverse is a vector
In [6]: e/v == vi # unity/vector == inverse
Out[7]: array([ True, True, True], dtype=bool)
In [8]: e == v*vi # vector * inverse == unity
Out[9]: array([ True, True, True], dtype=bool)
In my layman's world, this type of division makes perfect sense. (Moreover I'm curious why sage seems to not adopt this pythonic way of array arithmetic)]MarkSat, 17 Aug 2013 22:18:06 -0500https://ask.sagemath.org/question/10451/append a variable to a vectorhttps://ask.sagemath.org/question/10436/append-a-variable-to-a-vector/I would like to define a new vector in Sage $\vec{u} = [O, P, \sigma]$ using a previously defined vecotor $\vec{x} = [O, P]$ and a new variable $\sigma$.
My code looks like:
> var(O, P');
>
> var('sigma');
>
> x = vector([O,P]);
>
> u = vector([x, sigma]);
Which gives an error:
> TypeError: unable to find a common ring for all elements
Apparently this is because vector() requires the variables to be of the same ring. In my case
> x.parent()
>
> Vector space of dimension 2 over Symbolic Ring
and
> sigma.parent()
> Symbolic Ring
There is any way how to connect this two objects ($\vec{x}$, $\sigma$) together to create one vector?TomasWed, 14 Aug 2013 23:23:40 -0500https://ask.sagemath.org/question/10436/Matrix of vectorshttps://ask.sagemath.org/question/10008/matrix-of-vectors/Hi.
Suppose that I have a collection of vectors $v_1, \ldots, v_n \in \mathbb{R}^3$ and I wish to compute all cross products $v_i \times v_j \in \mathbb{R}^3$ where $1 \leq i < j \leq n$. Is it possible to store the output in a matrix, i.e. can I form a matrix M in Sage where $M(i,j) = v_i \times v_j$?DG44Wed, 10 Apr 2013 01:04:16 -0500https://ask.sagemath.org/question/10008/Generating random normal vectors and matriceshttps://ask.sagemath.org/question/9274/generating-random-normal-vectors-and-matrices/I'm new to sage, and am looking for the best ways to generate matrices and vectors with the following properties:
- Matrices with independent normal entries. The default distribution of entries in matrices generated by random_matrix seems to be uniform over [-1,1]. Can that be changed?
- Random (normal) vectors with fixed sparsity, in the sense that only a given number of the entries are non-zero.
Thanks for any assistance.staffordTue, 28 Aug 2012 15:29:21 -0500https://ask.sagemath.org/question/9274/Plot Series of 3D Direction Vectors (Not All from Origen)https://ask.sagemath.org/question/9172/plot-series-of-3d-direction-vectors-not-all-from-origen/Hi,
I'm trying to plot a series of vectors. I've pasted what I have below. The problem is that I want to plot the second vector, starting from the end of the first vector. If I run the commands below, I get two vectors plotted as I want (with arrows) but they are both from the origin.
I tried looking at MATPLOTLIB to see what to do but I got stuck.
Is there an easy way to plot a series of vectors in the way that I want?
a=vector([1,1,1])
b=vector([2,2,3])
aPlot=plot(a, legend_label='Vector a')
bPlot=plot(b, legend_label='Vector b')
AllPlot=aPlot+bPlot
AllPlot.show()
Justin1Sun, 22 Jul 2012 07:52:05 -0500https://ask.sagemath.org/question/9172/Basic vector functions in Sagehttps://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/Isn't there any inbuilt 3D vector functions in Sage?
For instance like a function to get the dot product, cross product or angle between two vectors? Or functions to get the distance from a point to a line? Find the intersections between two lines? Having such functions would be a great help and would greatly increase the speed of my workflow in school.paldepindWed, 25 Apr 2012 00:43:34 -0500https://ask.sagemath.org/question/8924/