Integrating a multivariable function one variable at a time

I have a function which depends on x and y, f(x,y) (returns a scalar) and I need to integrate it so that for a particular point (x0,y0), I get a function p(theta), I basically convert it to polar, change the origin and integrate over r, so the remaining function only depends on theta:
%fun = @(x,y) Some function
fun = @(x,y) fun(x+x0,y+y0);
polarfun = @(r,theta) fun(r.*cos(theta),r.*sin(theta)).*r;
p = @(theta) integral(@(r)polarfun(r,theta),0,Inf);
After I get this function, I need to integrate it again (w.r.t theta). This doesn't work (a and b are the limits of the integral)
value = integral(p,a,b);
I need to set ArrayValued = true for it to work
value = integral(p,a,b,'ArrayValued',true);
I don't understand why I need to specify it's an ArrayValued function when it's not meant to be, also the integral takes much more time, and I need it to be calculated as fast as possible. Can you explain me why it is ArrayValued, and whether there is a way to make it without the ArrayValued set to true?

2 comentarios

Is there anything that prevents you from using "integral2" ?
Take a look at the example
"Evaluate double integral in polar coordinates"
under
Best wishes
Torsten.
Hi Torsten
Well I put what I was doing before I figured out what I had to do, but I don't need to integrate it right after. After I get the p function, I need to perform some operations on it, creating a new function (which adds one variable), integrate the new function with respect to theta and then find a minimum with respect to the other variable.
Best
Pere

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 13 de Jul. de 2016

Comentada:

el 14 de Jul. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by