(* AdjointFinder: If you use this in your research or teaching, please cite the webpage: 
https://gokulhari.github.io/webpage/AdjointFinder.html
and the paper:
G.Hariharan, S.Kumar, and M.R.Jovanovic, Well-conditioned ultraspherical and spectral integration methods for resolvent analysis of channel flows of Newtonian and viscoelastic fluids, Phys.Rev.Fluids, 2020, note:Submitted}
Written by Gokul Hariharan (harih020@umn.edu)
*)

Once[Get["~/Desktop/AdjointFinder.wl"]] (* Call this once *)
(* Call Clear[AdjointFinder`] to clear all functions in this context *)

(*Define the equations for linearized Navier-Stokes equations *)
ueq = omega*u[y] +U'[y]v[y] +I kx U[y] u[y] -(1/R)(u''[y] - k2 u[y]) + I kx p[y];
veq = omega*v[y] +I kx U[y] v[y] -(1/R)(v''[y] - k2 v[y])  + p'[y];
weq = omega*w[y] +I kx U[y] w[y] -(1/R)(w''[y] - k2 w[y]) + I kz p[y];
{eqAd,eqBc} = Adjoint[{ueq,veq,weq,-I kx u[y] - v'[y] - I kz w[y]},{u[-1],v[-1],w[-1],v'[-1]},{u[1],v[1],w[1],v'[1]},{y,-1,1},{u,v,w,p,2}];
Print["Adjoint Equations: "]
Print[eqAd]
Print["Adjoint Boudary conditions: "]
Print[eqBc]