-1

I want to calculate a function p of x,y: p(x,y) which is defined by the integral of another function of x and y:

p(x,y) = Integral(indefinite) of v(x,y) dx

Now, if I have a matrix expressing p on a uniform grid x and y, how do I construct the function p (which should be a matrix).

Obviously if I integrated using trapz, I would obtain a vector:

x=linspace(-1,1,10); v=magic(10);
p=trapz(x,v);
size(p)

gives 1 10 and not 10 10.

usumdelphini
  • 213
  • 1
  • 11
  • 2
    Your formula `p(x,y) = Integral of v(x,y) dx` doesn't make sense mathematically: how can you integrate over the `x` variable, and the result still depend on `x`? Is your integral indefinite, i.e. the anti-derivative? –  May 15 '15 at 14:18

1 Answers1

1

Assuming that

  1. the formula for p is actually defined like:

p(x,y) = Integral[x0 .. x] v(ξ,y) dξ;

  1. the integration grid x × y is uniform, with the norm dx × dy;

  2. the rows of the matrix v have x constant, first row corresponding the the smallest x;

then the integral is:

p = cumtrapz(v) * dx;