ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 13 Feb 2020 03:25:04 -0600AttributeError when defining a metric on a differentiable manifoldhttps://ask.sagemath.org/question/49889/attributeerror-when-defining-a-metric-on-a-differentiable-manifold/ Hello everyone,
I am getting started with SageMath and try to define a metric on a differential manifold. Despite tutorials, search online and asking questions to colleagues, I cannot understand the following error.
Here is the code, with Kernel SageMath 9.0
FM = Manifold(2,'FM', structure='Riemannian', start_index=1)
K = FM.metric('K')
K[1,1]=1
which generates the following error
AttributeError Traceback (most recent call last)
<ipython-input-17-f83570b8b1cf> in <module>()
1 K = FM.metric('K')
----> 2 K[Integer(1),Integer(1)]=Integer(1)
/ext/sage/sage-9.0/local/lib/python3.7/site-packages/sage/tensor/modules/free_module_tensor.py in __setitem__(self, args, value)
1629 else:
1630 basis = self._fmodule._def_basis
-> 1631 self.set_comp(basis)[args] = value
1632
1633 def copy_from(self, other):
/ext/sage/sage-9.0/local/lib/python3.7/site-packages/sage/manifolds/differentiable/tensorfield_paral.py in set_comp(self, basis)
883 self._is_zero = False # a priori
884
--> 885 if basis._domain == self._domain:
886 # Setting components on the tensor field domain:
887 return FreeModuleTensor.set_comp(self, basis=basis)
AttributeError: 'One' object has no attribute '_domain'
It seems that the index type in the metric is wrong. Is that the problem? Have you some ideas to solve the problem?
Thanks
Wed, 12 Feb 2020 08:36:37 -0600https://ask.sagemath.org/question/49889/attributeerror-when-defining-a-metric-on-a-differentiable-manifold/Answer by eric_g for <p>Hello everyone,</p>
<p>I am getting started with SageMath and try to define a metric on a differential manifold. Despite tutorials, search online and asking questions to colleagues, I cannot understand the following error.</p>
<p>Here is the code, with Kernel SageMath 9.0</p>
<p>FM = Manifold(2,'FM', structure='Riemannian', start_index=1)</p>
<p>K = FM.metric('K')</p>
<p>K[1,1]=1</p>
<p>which generates the following error
AttributeError Traceback (most recent call last)
<ipython-input-17-f83570b8b1cf> in <module>()
1 K = FM.metric('K')
----> 2 K[Integer(1),Integer(1)]=Integer(1)</p>
<p>/ext/sage/sage-9.0/local/lib/python3.7/site-packages/sage/tensor/modules/free_module_tensor.py in __setitem__(self, args, value)
1629 else:
1630 basis = self._fmodule._def_basis
-> 1631 self.set_comp(basis)[args] = value
1632
1633 def copy_from(self, other):
/ext/sage/sage-9.0/local/lib/python3.7/site-packages/sage/manifolds/differentiable/tensorfield_paral.py in set_comp(self, basis)
883 self._is_zero = False # a priori
884
--> 885 if basis._domain == self._domain:
886 # Setting components on the tensor field domain:
887 return FreeModuleTensor.set_comp(self, basis=basis)
AttributeError: 'One' object has no attribute '_domain'</p>
<p>It seems that the index type in the metric is wrong. Is that the problem? Have you some ideas to solve the problem?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/49889/attributeerror-when-defining-a-metric-on-a-differentiable-manifold/?answer=49903#post-id-49903Although the error message is not very informative, an error is expected here because when you write
K[1, 1] = 1
you are setting some component of `K` in the default frame of the manifold and no such frame has been defined yet (`FM` is a "bare" manifold). For instance, if you set up a chart on the manifold, by the command
X.<x,y> = FM.chart()
prior to introducing `K`, then everything is OK because the manifold `FM` is then endowed with a default frame, namely the coordinate frame $\left( \frac{\partial}{\partial x}, \frac{\partial}{\partial y}\right)$ associated with the chart $(x, y)$.
To summarize, the following code works:
sage: FM = Manifold(2,'FM', structure='Riemannian', start_index=1)
sage: X.<x,y> = FM.chart()
sage: K = FM.metric('K')
sage: K[1,1] = 1
sage: K[2,2] = 3
sage: K.display()
K = dx*dx + 3 dy*dy
Thu, 13 Feb 2020 03:25:04 -0600https://ask.sagemath.org/question/49889/attributeerror-when-defining-a-metric-on-a-differentiable-manifold/?answer=49903#post-id-49903