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

add two `Expression`s with a different number of components

0 votes

I have two Expressions, one with two components, another with three, e.g.,

e1 = Expression(('1.0', '2.0', '3.0'))
e2 = Expression(('1.0', '2.0'))

I would now like to add those two in such a way that

e_new[0] = e1[0] + e2[0]
e_new[1] = e1[1] + e2[1]
e_new[2] = e1[2]

What would be the appropriate way to do so?

asked Nov 26, 2013 by nschloe FEniCS User (7,120 points)

1 Answer

+2 votes
 
Best answer
e_new = e1 + as_vector((e2[0], e2[1], 0.0))

(not tested)

answered Nov 26, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Nov 26, 2013 by nschloe
...