# How to interpolate a 1D function along the desired axis of 2D function

**URL:** <https://fenicsproject.discourse.group/t/how-to-interpolate-a-1d-function-along-the-desired-axis-of-2d-function/15074>\
**Category:** General\
**Created:** [June 25, 2024, 11:04am UTC](https://fenicsproject.discourse.group/t/how-to-interpolate-a-1d-function-along-the-desired-axis-of-2d-function/15074 "2024-06-25T11:04:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Tiwari](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/vishal_tiwari/32/7024_2.png) [@Vishal\_Tiwari](https://fenicsproject.discourse.group/u/Vishal_Tiwari)\
**Post date:** [June 25, 2024, 11:04am UTC](https://fenicsproject.discourse.group/t/how-to-interpolate-a-1d-function-along-the-desired-axis-of-2d-function/15074/1 "2024-06-25T11:04:22Z")

</div>

Hi, I am facing a problem with the interpolation of the following function `u_init`  
**MWE Code** for `u_init`

```auto
mesh = UnitIntervalMesh(256)
V = FunctionSpace(mesh, 'P', 1)
def u0_boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, Constant(0.0), u0_boundary)
u = TrialFunction(V)
v = TestFunction(V)
A = inner(nabla_grad(u), nabla_grad(v))*dx
RHS = v*dx
u_init = Function(V)
solve(A == RHS, u_init, bc)
plot(u_init)

```

I am getting the following plot of the `u_init`

 ![velocity_profile_fenics](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/a/a0421765e4b854c005846a8f50d7635c366ad7f3.png)  
I am using the following **code** for interpolating the 1D function `u_init` to a 2D function `p`

```auto
mesh1 = UnitSquareMesh(256, 256)
V1 = FunctionSpace(mesh1, "P", 1)
p = Function(V1)
p = interpolate(u_init, V1)
plot(p)

```

The plot of `p` is the following

 ![fenics_plot](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/b/be8660810ec041507df849557f08024babc5e6d8.png)  
But I need the interpolation of the same function `u_init` in the `x` direction and it should look like  
 ![fenics_plot_flip](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/2/2020bf74fc3cf1264747836a70a567c5abc51373.png)  
What should I do? Please help.  
I am using FEniCS 2019.
