# Problem with variational formulation

**URL:** https://community.freefem.org/t/problem-with-variational-formulation/1193
**Category:** General Discussion
**Created:** [September 6, 2021, 5:49pm UTC](https://community.freefem.org/t/problem-with-variational-formulation/1193 "2021-09-06T17:49:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Aicha](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aicha](https://community.freefem.org/u/Aicha)
#### Post date: [September 6, 2021, 5:49pm UTC](https://community.freefem.org/t/problem-with-variational-formulation/1193/1 "2021-09-06T17:49:45Z")

</div>

Hi,  
i have to program the following system  
du1/dt =D1_d^2u1/dx^2 +a1_u1\*(1-u1-u2)  
du2/dt=D2_d^2u2/dx^2 +a2(u2+eps_u1)\*(1-u1-u2)  
in the space and time intervals: 0\<x\<L, 0\<t\<T  
with bounadry conditions  
x=0,L: du1/dx=du2/dx=0  
initial conditions:  
u1(x,0)=1, 0\<x\<x\_0, u\_1(x,0)=0: x\_0\<x\<L; u2(x,0)=0:0\<x\<L  
So i write the variational formulation like this, but the cod mark an  
error in the variational formulation (line 45).  
I don’t udnderstand where is the problem in my variational formulation.

Thank you in advance for the help

> // Parameters  
> real L=20.;  
> real T=1000.;  
> real a1=1.;  
> real a2=1.;  
> real D1=1.e-3;  
> real D2=1.e-3;  
> real x0=0.1;  
> int Nbx=1e4;  
> real dt=0.1;  
> int Nbt=1e2;  
> real eps=0.1;
> 
> real Dx=L/Nbx; // calcul de dx
> 
> load “msh3”  
> meshL Th=segment(Nbx,[x\*L,0.]);  
> fespace Vh(Th,typeFE);  
> Vh Id = (x\<=x0) ? 1. : 0.;
> 
> Vh u1,u2;  
> Vh u1H,u2H;
> 
> Vh oldu1=Id;  
> Vh oldu2=0.0;
> 
> Vh nith1=0.0; //l’intération de la non linéarité  
> Vh nith2=0.0; //l’intération de la non linéarité  
> Vh g1,g2;
> 
> ```
> problem systemU1(u1,u1H,solver=LU)=
> int1d(Th)(u1*u1H/dt + D1*dx(u1)*dx(u1H))
> - int1d(Th)(oldu1*u1H/dt+a1*(u1-(g1-u1*u2))*u1H)
> ;
> 
> problem systemU2(u2,u2H,solver=LU)=
> int1d(Th)(u2*u2H/dt + D2*dx(u2)*dx(u2H))
> - int1d(Th)(oldu2*u2H/dt-a2*[u2-u2*u1-g2+eps*u1-eps*g1-eps*u1*u2]*u2H)
> ;
> 
> ```

---

<div class="post-metadata">

### Author: ![sumantkr](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumantkr/32/2681_2.png) [@sumantkr](https://community.freefem.org/u/sumantkr)
#### Post date: [September 13, 2021, 11:23am UTC](https://community.freefem.org/t/problem-with-variational-formulation/1193/2 "2021-09-13T11:23:16Z")

</div>

Here you have non-linear terms in coupled equations. So, first linearized it using Newton’s method which is also given here ( [Newton Method for the Steady Navier-Stokes equations](https://doc.freefem.org/tutorials/navierStokesNewton.html#newton-method-for-the-steady-navier-stokes-equations)).
