This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

dot product of two-dimensional expression

+1 vote

Hello,

I am trying to calculate the dotproduct of a vector (-1,-1) and an Expression at a point:

from dolfin import *
import numpy

r1=Expression(('-0.2+x[0]*0.2','0.4'))
n=Constant((-1,-1))

sol=dot(n,r1(0.3))

print sol

The value of the Expression at 0.3 is an array with two entrys, I assume the array-representation is the problem here.

The Errormessage I get is:

Invalid type conversion: can not be converted
to any UFL type. The representation of the object is: array([-0.14,
0.4 ])

How can I write it the right way? Thank you very much for your time!

I am using Fenics on Ubuntu with python.

asked Nov 2, 2013 by Lollwies FEniCS Novice (230 points)

1 Answer

+1 vote
 
Best answer
from dolfin import *
import numpy

r1 = Expression(('-0.2+x[0]*0.2', '0.4'))
n = numpy.array((-1.0, -1.0))

sol = numpy.dot(n, r1(0.3))

print sol
answered Nov 2, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Nov 2, 2013 by Lollwies

Thanks a lot, that solved my question! =)

...