# Unable to define linear variational problem

**URL:** <https://fenicsproject.discourse.group/t/unable-to-define-linear-variational-problem/3941>\
**Category:** variational formulation\
**Created:** [August 14, 2020, 1:02pm UTC](https://fenicsproject.discourse.group/t/unable-to-define-linear-variational-problem/3941 "2020-08-14T13:02:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaa](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@Kaa](https://fenicsproject.discourse.group/u/Kaa)\
**Post date:** [August 14, 2020, 1:02pm UTC](https://fenicsproject.discourse.group/t/unable-to-define-linear-variational-problem/3941/1 "2020-08-14T13:02:31Z")

</div>

Hi, this is the error:

```
*** Error: Unable to define linear variational problem a(u, v) = L(v) for all v.
*** Reason: Expecting the right-hand side to be a linear form (not rank 2).
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0

```

here is my code:

```
from dolfin import *

import matplotlib.pyplot as plt

# Mesh

mesh = UnitSquareMesh(32, 32)

# Finite Element

V = FunctionSpace(mesh, 'Lagrange', 1)

# Boundary

def boundary(x):

return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS

# Condition

u10 = Constant(2.0)

bc = DirichletBC(V, u10, boundary)

#Problem

mixed1 = Constant(0.1)

dif1 = Constant(0.1)

u1 = TrialFunction(V)

v1 = TestFunction(V)

a = dif1*dot(grad(u1), grad(v1))*dx

f = mixed1*u1

L = f*v1*dx

# Solution

u = Function(V)

solve(a == L, u, bc)

# Save solution in VTK format

file = File("project1_minimized1.pvd")

file << u

# Plot solution

plot(u)

plt.show()

```

I read similar topics, and I guess my problem somehow related to `f = mixed1*u1` (because when ` f = mixed1` there is no error).

How can I fix it?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 14, 2020, 1:36pm UTC](https://fenicsproject.discourse.group/t/unable-to-define-linear-variational-problem/3941/2 "2020-08-14T13:36:02Z")

</div>

You cannot have a TrialFunction on the right hand side.  
What you can do is to move the term to the LHS, and add a zero term on the RHS

```auto
a = dif1*dot(grad(u1), grad(v1))*dx - f*v1*dx
L = Constant(0)*v1*dx 

```

---

<div class="post-metadata">

**Author:** ![Kaa](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@Kaa](https://fenicsproject.discourse.group/u/Kaa)\
**Post date:** [August 14, 2020, 1:59pm UTC](https://fenicsproject.discourse.group/t/unable-to-define-linear-variational-problem/3941/3 "2020-08-14T13:59:55Z")

</div>

> [@dokken](#):
>
> ```auto
> a = dif1*dot(grad(u1), grad(v1))*dx - f*v1*dx
> L = Constant(0)*v1*dx 
> 
> ```

Good that I learned that, thanks!
