# How can I compute the difference between shape function and dual solution in dwr?

I am trying to find error estimation based on weighted residual technique:

$$Q(e_h)=\sum_{k \in {\cal T}}\eta_k,$$ where $$\eta_k=\int_kR(z-v_h)d\Omega+\int_{\partial k}J(z-v_h)ds,$$ or in the weak form $$\eta_k=\int_k l(z-v_h)d\Omega+\int_k \nabla u_h.\nabla(z-v_h)d\Omega,$$ where $u_h$ is the solution of primal problem $a(u,v)=l(v),$ and $z$ is the solution of the dual problem $a(z,v)=Q(v),$ also $Q(v)=|\Omega|^{(-1)}(1,v),$ where $v$ is the test function. Moreover $R$ and $J$ are residual and jump respectively. Using approximation $z_h=\sum_i \phi_i*z_i$ (instead of z) at Gaussian quadrature point leads to a scalar where using $\phi$ as test function at any point gives a vector, but $(z-v_h)$ should be a scalar not a vector. How can I solve this problem?

You seem to be confused about what is a vector and what is a scalar. $z_h$ and $\phi_i$ are both scalars if evaluates at quadrature points. The fact that the $z_i$ form a vector really has no relevance since you are computing integrals which you approximate via quadrature for which you need $z_h(x)$, not the individual components $z_i$ of the solution vector $Z$.
I'm going to add something to the answer that you did not ask, but should know anyway. If you approximate $z$ by a finite element solution $z_h$ that uses the same finite element space as $u_h$, then you will be out of luck because you could then choose $v_h=z_h$ and your entire error estimate would be zero. In other words, approximating $z$ by $z_h$ is not a good choice.