I have this very simple ODE-contrained optimization problem:

 1. $h(x,x',p,t) = x'-A(p)x-b(p) = 0$, the constraint
 2. $g(x(0)) = x_0$, the initial condition with no parameters involved
 3. $F = \int (X-X_{obs})^2 dt$, the objective equation 

According to adjoint method, I need to 

 1. Integrate constraint equation: 
$$x'=A(p)x+b(p)$$
	
 2. Integrate adjoint equation and reverse $\lambda$ in $t$: 
$$\lambda'= A(p)^T \lambda-(X-X_{obs})$$
	
 3. Calculate $\frac{dF}{dp}$: 
$$\frac{dF}{dp} = \int \lambda^T \frac{\partial h}{\partial p} dt,$$
since 
$$\frac{\partial f}{\partial p} = \frac{\partial g}{\partial p}=0$$

But for parameters only show up in $\mathbf{b(p)}$ term, derivatives from adjoint method is inconsistent with derivatives estimated using $\frac{\partial F}{\partial p}$ directly while derivatives for other parameters seem OK.

I’m thinking that this inconsistency maybe due to the fact that parameters in $b(p)$ doesn’t affect the calculation of $\lambda$ directly, namely it doesn’t show up in the adjoint equation? But there is also the possibility that I did something wrong in coding.

Any body have any similar experience? Thanks!