# Expressions depending on spatially varying coefficients and their derivatives in advection-diffusion-PDE

**URL:** <https://fenicsproject.discourse.group/t/expressions-depending-on-spatially-varying-coefficients-and-their-derivatives-in-advection-diffusion-pde/4441>\
**Category:** variational formulation\
**Created:** [October 30, 2020, 7:16am UTC](https://fenicsproject.discourse.group/t/expressions-depending-on-spatially-varying-coefficients-and-their-derivatives-in-advection-diffusion-pde/4441 "2020-10-30T07:16:48Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [October 30, 2020, 4:39pm UTC](https://fenicsproject.discourse.group/t/expressions-depending-on-spatially-varying-coefficients-and-their-derivatives-in-advection-diffusion-pde/4441/4 "2020-10-30T16:39:37Z")

</div>

As there was so much other code in your last code, I did not get what your actual issue was.  
Your actual issue can be solved as follows (no need to wrap an expression inside an expression):

```auto
from fenics import *

X = 0.5
Z = 1.0
num_steps = 400 # number of time steps

# Create mesh and define function space
nx = nz = 50
mesh = RectangleMesh(Point(0,0),Point(X,Z),nx,nz)

alpha = Expression(("(0.01*(x[0]+1))+(0.01*(x[1]+1))"), domain=mesh, degree = 2)
beta = Expression(("(x[1])","(-x[0]-0.5)"), domain=mesh, degree = 2)
alphax = alpha.dx(0)
alphaz = alpha.dx(1)
beta_s = as_vector((alphax-beta[0], alphaz-beta[1]))
assemble(inner(beta_s, beta_s)*dx)

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/expressions-depending-on-spatially-varying-coefficients-and-their-derivatives-in-advection-diffusion-pde/4441)._
