# innergrad

Inner product of gradient evaluations stored as real matrices (arrays).

## Contents

- Syntax
- Description
- Input Arguments
- Output Argument
- More About
- References
- See Also
- Code

## Syntax

    res = innergrad(gus,gvs,seti)

## Description

`res = innergrad(gus,gvs,seti)` computes the inner product of the gradient evalutations , which are stored as real matrices (arrays).

## Input Arguments

- gus : gradient(u): real matrix of size 2*dim x nInv x nInv (x nInv)
- gvs : gradient(v): real matrix of size 2*dim x nInv x nInv (x nInv)
- seti.dim : dimension of the problem
- seti.dVinv : see setGridScale.html
- seti.nInv : see setGridScale.html

Note: The name "gus" was choosen because gradient from u stored as real (squared, because ).

## Output Argument

- res : inner product, see More About for definition.

## More About

We consider the inner product of p and q (e.g. p = grad(u), q = grad(v)):

in 2D

and in 3D.

Note that the exponent is an index(!).

The real and imaginary parts are stored as real values in gus and guv, so add all parts (real and imag):

Finally, scale it with factor `dVinv`.

Corresponding notation in [1]

The function `innergrad` is defined in [1, Sec. 4.5, eq. (59)] as

with the following definitions in [1, Sec. 4.5]:

- .

- .

- So is a rewrited complex vector as real matrix, see also setIdImagReal.html.

- .

- with .

- .

## References

- [1] Florian Bürgel, Kamil S. Kazimierski, and Armin Lechleiter. A sparsity regularization and total variation based computational framework for the inverse medium problem in scattering. Journal of Computational Physics, 339:1-30, 2017. URL: https://doi.org/10.1016/j.jcp.2017.03.011.

## See Also

- setGridScale.html

## Code

    function res = innergrad(gus,gvs,seti)

    % guz = seti.T(gus);
    % gvz = seti.T(gvs);

    add = 0;
    for l = 1:2*seti.dim
        add = add + squeeze(gus(l,:,:) .* gvs(l,:,:));
    end

    if seti.dim == 2
        res = sum(sum(add))*seti.dVinv;
    elseif seti.dim == 3
        res = sum(sum(sum(add)))*seti.dVinv;
    end

    end