I want to multiply a 2*2 matrix with a vector with shape (2,) in Fenics. It doesn’t work with inner(,). Then I found a solution like this

# Create matrix and vector in UFL:
mat = as_matrix([[1,1],
[1,1]])
vec = as_vector([2,3])
# Multiplication operator is overloaded:
mat_vec = mat*vec

But I don’t know how to check if the value of mat_vec is exactly (5,5) or if this multiplication operator really realizes my aim. Does anyone know how to do it?

Please note that you need to define a mesh and then project the multiplication on a VectorFunctionSpace as the output result is a vector. In order to perform the multiplication, you can use dot symbol.

\Rightarrow More information about different types of multiplications are available in UFL User Manual

Here is an example of what you want to do:

from fenics import *
mesh = RectangleMesh(Point(0., 0.),Point(1, 1),1,1)
mat = as_matrix([[1,1],
[1,1]])
vec = as_vector([2,3])
result = dot(mat,vec)
V = VectorFunctionSpace(mesh, 'CG', 1)
component = project(result, V)
print("The first component is: " , component.vector().get_local()[0])
print("The second component is: " , component.vector().get_local()[1])

Where the output is:

The first component is: 5.000000000000007
The second component is: 5.000000000000007