You might have copied `a**2 + b**2 + c**2` and called them `p`? You can check by typing `type(p)`. If it is an Add then that is what happened somehow. It's always best to show the actual self-verifying code snippet. Here is what I used and everything work for me: ``` >>> from sympy.vector import dot >>> from sympy.vector.coordsysrect import CoordSys3D >>> O = CoordSys3D('O') >>> r = O.x*O.i + O.y*O.j + O.z*O.k >>> dot(r,r) # this works O.x**2 + O.y**2 + O.z**2 >>> from sympy import symbols >>> a, b, c = symbols("a, b, c") >>> p = a*O.i +b*O.j + c*O.k >>> dot(p,p) # this does not work a**2 + b**2 + c**2 >>> p.dot(p) a**2 + b**2 + c**2 ``` /c On Monday, October 25, 2021 at 10:17:09 AM UTC-5 Andreas Schuldei wrote:
> p.dot(p) > a**2 + b**2 + c**2 > dot(p,p) > Traceback (most recent call last): > File "<input>", line 1, in <module> > File "C:\Users\Andreas > Schuldei\PycharmProjects\lissajous-achse\venv\lib\site-packages\sympy\physics\vector\functions.py", > > line 31, in dot > raise TypeError('Dot product is between two vectors') > TypeError: Dot product is between two vectors > > > i am confused. why does this happen? > > Oscar schrieb am Montag, 25. Oktober 2021 um 12:35:47 UTC+2: > >> I don't see the exception that you showed: >> >> In [9]: O = CoordSys3D('O') >> ...: r = O.x*O.i + O.y*O.j + O.z*O.k >> ...: dot(r,r) # this works >> ...: O.x**2 + O.y**2 + O.z**2 >> ...: from sympy import symbols >> ...: a, b, c = symbols("a, b, c") >> ...: p = a*O.i +b*O.j + c*O.k >> ...: p >> ...: a*O.i + b*O.j + c*O.k >> ...: dot(p,p) # this does not work >> Out[9]: >> 2 2 2 >> a + b + c >> >> -- >> Oscar >> >> On Mon, 25 Oct 2021 at 11:28, Andreas Schuldei <and...@schuldei.org> >> wrote: >> > >> > >> > I am trying to figure out the basics here. >> > I understand O.x, O.y and O.z have special meaning, first because they >> magically appear, just by instanciating O, and also because they seem to >> distinguish themselves from other generic symbols/skalars: >> > >> > O = CoordSys3D('O') >> > r = O.x*O.i + O.y*O.j + O.z*O.k >> > dot(r,r) # this works >> > O.x**2 + O.y**2 + O.z**2 >> > from sympy import symbols >> > a, b, c = symbols("a, b, c") >> > p = a*O.i +b*O.j + c*O.k >> > p >> > a*O.i + b*O.j + c*O.k >> > dot(p,p) # this does not work >> > Traceback (most recent call last): >> > File "<input>", line 1, in <module> >> > File "C:\Users\Andreas >> Schuldei\PycharmProjects\lissajous-achse\venv\lib\site-packages\sympy\physics\vector\functions.py", >> >> line 31, in dot >> > raise TypeError('Dot product is between two vectors') >> > TypeError: Dot product is between two vectors >> > p = a*O.x*O.i + b*O.y*O.j + c*O.z*O.k >> > dot(p,p) # this does not work, either! >> > Traceback (most recent call last): >> > File "<input>", line 1, in <module> >> > File "C:\Users\Andreas >> Schuldei\PycharmProjects\lissajous-achse\venv\lib\site-packages\sympy\physics\vector\functions.py", >> >> line 31, in dot >> > raise TypeError('Dot product is between two vectors') >> > TypeError: Dot product is between two vectors >> > >> > Why is this? What factors are allowed with vector components and unit >> vectors? >> > >> > I feel a little restricted if my only vector component variables >> allowed are O.x, O.y, and O.z. >> > Oscar schrieb am Samstag, 23. Oktober 2021 um 16:49:10 UTC+2: >> >> >> >> A SymPy Vector is constructed algebraically from the unit vectors i, j >> >> and k of the coordinate system. For a vector field you also use the >> >> coordinate system base scalars x, y and z. >> >> >> >> In [11]: from sympy.vector import CoordSys3D, dot >> >> >> >> In [12]: O = CoordSys3D('O') >> >> >> >> In [13]: r = O.x*O.i + O.y*O.j + O.z*O.k >> >> >> >> In [14]: r >> >> Out[14]: (x_O) i_O + (y_O) j_O + (z_O) k_O >> >> >> >> In [15]: dot(r, r) >> >> Out[15]: >> >> 2 2 2 >> >> x_O + y_O + z_O >> >> >> >> I often see confusion about this so clearly this is not very intuitive >> >> and maybe it is not very clearly documented: >> >> https://docs.sympy.org/latest/modules/vector/index.html >> >> >> >> I think there should be an easier way where you can just use a >> >> "standard" coordinate system and just do: >> >> >> >> from sympy.vector.stdcoords import x, y, z, i, j, k >> >> r = x*i + y*j + z*k >> >> print(dot(r, r)) >> >> >> >> The vector docs should just begin by showing how to do that and then >> >> how to do simple calculations in a single coordinate system. >> >> >> >> -- >> >> Oscar >> >> >> >> On Sat, 23 Oct 2021 at 07:11, Andreas Schuldei <and...@schuldei.org> >> wrote: >> >> > >> >> > I am putting together the components of a vector field (a magnetic >> field, caused by a current in several conductors) in cartesian coordinates. >> The field is derived from calculating the rotation of its magnetic vector >> potential, which can be expressed as >> >> > >> >> > A_z = -Const * dot(r,a)(dot(r,r) >> >> > A =(0,0,A_z >> >> > and then the rot(A): >> >> > B = curl(A) >> >> > >> >> > gives me (after some simplifications) >> >> > u = (2 * C * r2 * (a1 * r1 + a2 * r2)) / np.square(r1*r1 + r2*r2) - >> (C * a2) / (r1*r1 + r2*r2) >> >> > v = (C * a1) / (r1*r1 + r2*r2) - (2 * C * r1 * (a1 * r1 + a2 * r2)) >> / np.square(r1*r1 + r2*r2) >> >> > w = 0 >> >> > >> >> > with B(u,v,w) being the vector field I am interested in. >> >> > >> >> > My initial question ("How to create a vector") is mostly a sympy >> syntactical one. I look for a function like >> >> > >> >> > Sys = CoordSys3D("Sys") >> >> > O = Sys.origin >> >> > u = (2 * C * r2 * (a1 * r1 + a2 * r2)) / np.square(r1*r1 + r2*r2) - >> (C * a2) / (r1*r1 + r2*r2) >> >> > v = (C * a1) / (r1*r1 + r2*r2) - (2 * C * r1 * (a1 * r1 + a2 * r2)) >> / np.square(r1*r1 + r2*r2) >> >> > w = 0 >> >> > V = O.vector(u,v,w) >> >> > ^^^^^^^^^^^^^^^^^^^ >> >> > where I can specify a vector, relative to a coordinate system, by >> its components. The O.vector() function would return a vector that can then >> safely be transformed into other (resting) coordinate systems. >> >> > >> >> > brombo schrieb am Freitag, 22. Oktober 2021 um 19:06:03 UTC+2: >> >> >> >> >> >> You might want to look at this link - >> >> >> >> >> >> https://galgebra.readthedocs.io/en/latest/ >> >> >> >> >> >> Also if you could show me symbolically (not code) what you are >> doing perhaps I could give you an example of how to do it in galgebra. >> >> >> >> >> >> On 10/22/21 3:15 AM, Andreas Schuldei wrote: >> >> >> >> >> >> I saw this >> https://stackoverflow.com/questions/46993819/how-to-create-a-vector-function-in-sympy >> >> which uses Matrix() as a workaround to create a vector. The author says, >> that it can not be transformed between coordinate systems, like real >> vectors, though. >> >> >> >> >> >> I need to transform my input and output vector from one coordinate >> system to another (and back). How are vector functions done in that case? >> My function is simple: >> >> >> >> >> >> def B_el(r_vec, I): >> >> >> mu_0 = 4 * np.pi * 1e-7 >> >> >> a1 = -0.05 >> >> >> a2 = 0.0 >> >> >> C = mu_0 * I / np.pi >> >> >> r1 = r_vec.i >> >> >> r2 = r_vec.j >> >> >> u = (2 * C * r2 * (a1 * r1 + a2 * r2)) / np.square(r1*r1 + r2*r2) - >> (C * a2) / (r1*r1 + r2*r2) >> >> >> v = (C * a1) / (r1*r1 + r2*r2) - (2 * C * r1 * (a1 * r1 + a2 * r2)) >> / np.square(r1*r1 + r2*r2) >> >> >> return Matrix([u, v, 0]) >> >> >> >> >> >> -- >> >> >> You received this message because you are subscribed to the Google >> Groups "sympy" group. >> >> >> To unsubscribe from this group and stop receiving emails from it, >> send an email to sympy+un...@googlegroups.com. >> >> >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/8db840a8-20f9-47ac-a1c3-11b6658f00bfn%40googlegroups.com >> . >> >> > >> >> > -- >> >> > You received this message because you are subscribed to the Google >> Groups "sympy" group. >> >> > To unsubscribe from this group and stop receiving emails from it, >> send an email to sympy+un...@googlegroups.com. >> >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/9797a914-06a6-4f8e-a99f-5403504862bfn%40googlegroups.com >> . >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "sympy" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an email to sympy+un...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/49cefd33-34db-4c97-9010-cc9be4f1f131n%40googlegroups.com >> . >> > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d79cb31f-6a86-4bd1-8fd2-5bdc6dc03dafn%40googlegroups.com.