0

Essentially what I'd like to do is

fun=@(x,y) x.*y
integral2(fun,-5,5,-5,5)

However, I want to ignore portions of my integration range where x*y is negative. Basically, adjust my bounds of integration such that x*y is guaranteed to be greater than zero for the entire range. For the x*y example I gave, its easy to solve for the appropriate bounds, but I'm actually working with a more complicated function where it's not so obvious.

My actual code is below. I want to select bounds on integration such that "de" is always positive. Any ideas? Thanks!

tau=@(r) (tauMax+ r.*(tauMin-tauMax)/(radius));
d= @(r) (height^2+r.^2).^(.5);
cosTheta= @(r) height./ d(r);
cosXi= @(r,psi) -r.*cos(psi)*2^.5/2+height*2^.5/2;

de= @(r,psi) (Esun*tau(r)/pi).*cosTheta(r).*cosXi(r,psi)./(d(r)).^2;
integral2(de,0,275,0,360) 
Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
user1707675
  • 21
  • 1
  • 2
  • 9

1 Answers1

1

Instead of changing the domain, it is easier to define an auxiliary function that returns zero when the original function is negative:

fun2=@(x,y) max(0,fun(x,y));
integral2(fun2,-5,5,-5,5);

In this case we have

>> integral2(fun,-5,5,-5,5)
ans=
  -4.2633e-14
>> integral2(fun2,-5,5,-5,5)
ans=
  312.5000
Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52