## Int takes forever, integral2 and quad2d give Warning: Reached the maximum number of function evaluations ...

### Ali SeyedKavoosi (view profile)

on 13 Aug 2018
Latest activity Commented on by Walter Roberson

### Walter Roberson (view profile)

on 13 Aug 2018
Hello, I have a function to integrate which is a function of 0<phi<pi/2; 0<thata<pi*2 . Int takes forever, I tried integral2 and quad2d and both give the Warning: Reached the maximum number of function evaluations ... Thank you for your help!
-(23503160555339776*(57204934906771638889613863663249962571101372416000000*cos(theta)^2*sin(phi)^4 - 13937965749081639463459823920405225941237760000000*cos(theta)^2*sin(phi)^2 + 78765759757611175061297882993861509807860822835200000*cos(phi)^2*cos(theta)^2*sin(phi)^2 - 323274589773865885454138397827218294342801615560376320000*cos(phi)^2*cos(theta)^2*sin(phi)^4 - 93091477073443938594843114033316303605848122243153920000*cos(phi)^4*cos(theta)^2*sin(phi)^2 + 382070955132922735149640946552211232499033951675741110272000*cos(phi)^4*cos(theta)^2*sin(phi)^4 + 191906513388638138735886556629670355266421349416960000*cos(theta)^2*sin(phi)^4*sin(theta)^2 - 1022416358370623195458502017337821467909100303586164736000*cos(theta)^2*sin(phi)^6*sin(theta)^2 + 900900021593807336707907087797780813612678679330029568000*cos(theta)^2*sin(phi)^6*sin(theta)^4 + 498733765067912380903587029366726978402539654471387761868800*cos(theta)^2*sin(phi)^8*sin(theta)^4 - 498733765067912380903587029366726978402539654471387761868800*cos(theta)^2*sin(phi)^8*sin(theta)^6 + 3175631958239434636099115122426186625754651263238144000*cos(phi)^2*cos(theta)^2*sin(phi)^4*sin(theta)^2 + 1313767042853786871975715452591133275018918341220821815281600*cos(phi)^2*cos(theta)^2*sin(phi)^6*sin(theta)^2 - 382070955132922735149640946552211232499033951675741110272000*cos(phi)^4*cos(theta)^2*sin(phi)^4*sin(theta)^2 - 1159021406158036816868070926604828097738287686486810213238720*cos(phi)^2*cos(theta)^2*sin(phi)^6*sin(theta)^4 - 635115212194475318436405470008061140390449604243829938116842733*cos(phi)^2*cos(theta)^2*sin(phi)^8*sin(theta)^4 + 635115212194475318436405470008061140390449604243829938116842733*cos(phi)^2*cos(theta)^2*sin(phi)^8*sin(theta)^6))/(2047103229781890592533930849402327953462909744012063981026305638400000*cos(phi)^4 - 1732077374482088365938714638196069137295080846319790067810304000000*cos(phi)^2 - 1257949821923292149612612088329530093138454882444474916536320000000*sin(phi)^2 + 7108883408417638469199905415811788968218801929460638760206493286400000*cos(phi)^2*sin(phi)^2 - 8401829156082618779456396961711263744344080251089676621726564682301440000*cos(phi)^4*sin(phi)^2 - 5324188961672485112408815310915984881222895547097337204572160000000*cos(theta)^2*sin(phi)^2 + 21851817436407062328328399257562295319563975545985750639319187456000000*cos(theta)^2*sin(phi)^4 - 5478018680258457302119203024856819227883957923478878079365939200000*sin(phi)^2*sin(theta)^2 + 22483173489137881454762403274833757125408252439993595183044986142720000*sin(phi)^4*sin(theta)^2 + 2672172505017068361461558491739642535493492561957380474447184527360000*sin(phi)^4*sin(theta)^4 - 10967271477133470182268934247525805889535007433204483097400995034955776000*sin(phi)^6*sin(theta)^4 + 27906073111715082856801874073050208486322481253177152334790970572800000*cos(phi)^2*cos(theta)^2*sin(phi)^2 - 114533578615262037849399460011821982432909470543277390875705853062676480000*cos(phi)^2*cos(theta)^2*sin(phi)^4 - 26902962826381330607286058679245915669176147627664391326203699687063552000*cos(phi)^4*cos(theta)^2*sin(phi)^2 + 110416560421225269617088389411027045135221476582707669268491905203325580083200*cos(phi)^4*cos(theta)^2*sin(phi)^4 + 7039050523145211924562079570229148288632964778763715032643031531520000*cos(phi)^2*sin(phi)^2*sin(theta)^2 - 28890042796132583039435964288413470084012175651010551863694464156434432000*cos(phi)^2*sin(phi)^4*sin(theta)^2 - 3402892537891553223052958713367566747114449286848754737452730315020697600*cos(phi)^2*sin(phi)^4*sin(theta)^4 + 13966331215704944048965362429338273046248682091332569057267422028852531036160*cos(phi)^2*sin(phi)^6*sin(theta)^4 + 47575848515003671206861730961152767133334789781791338228178338447360000*cos(theta)^2*sin(phi)^4*sin(theta)^2 - 284948692153388473610354422596350405076364732625381985001022117040357376000*cos(theta)^2*sin(phi)^6*sin(theta)^2 + 251444585625534298614524415262654996519685937736785529823972451187425280000*cos(theta)^2*sin(phi)^6*sin(theta)^4 + 137509322919790067903656681493170580956600632912161893940726377834016774553600*cos(theta)^2*sin(phi)^8*sin(theta)^4 - 137509322919790067903656681493170580956600632912161893940726377834016774553600*cos(theta)^2*sin(phi)^8*sin(theta)^6 + 34583447615406887663596796776805860539796352906088536717058412026160742400*cos(phi)^2*cos(theta)^2*sin(phi)^4*sin(theta)^2 + 328135548757244286579733796122536246591638723860693627415323811169090166100160*cos(phi)^2*cos(theta)^2*sin(phi)^6*sin(theta)^2 - 110416560421225269617088389411027045135221476582707669268491905203325580083200*cos(phi)^4*cos(theta)^2*sin(phi)^4*sin(theta)^2 - 289717035172258798754758079014765553509817407456169927689034561870285696176320*cos(phi)^2*cos(theta)^2*sin(phi)^6*sin(theta)^4 - 157679291828423612548377145145525998886869751059994708492367700557712644845471769*cos(phi)^2*cos(theta)^2*sin(phi)^8*sin(theta)^4 + 157679291828423612548377145145525998886869751059994708492367700557712644845471769*cos(phi)^2*cos(theta)^2*sin(phi)^8*sin(theta)^6 + 306499108173177771671669405430061836723747824436720435200000000) % code

### Walter Roberson (view profile)

on 13 Aug 2018

The function is a ratio of values, and the denominator can pass through 0 along a curve. The function is therefore singular. The constants involved are quite large, approximately 10^76, which makes it completely impractical for any numeric approach to be taken.
For example, when theta = 5*Pi/8, then the denominator becomes 0 near phi = 1.541254727322524303906000 leading to infinity and -infinity across the dividing curve.

Ali SeyedKavoosi

### Ali SeyedKavoosi (view profile)

on 13 Aug 2018
Thank you for your response. Do you know how can I find the singularities and how to remove them from my integration?
Walter Roberson

### Walter Roberson (view profile)

on 13 Aug 2018
You cannot do that.
The formula is the ratio of two functions that can be transformed into polynomials (all of the sin() can be transformed into cos() and then all of the cos() can be replaced by simple linear variables over 0 to 1.) The two polynomials that result both have total degree 18 -- cos(theta)^8 * cos(phi)^10 . The numeric coefficients involved are fairly large, being in the range 10^79 to 10^81, so you would probably have to compute to at least 85 decimal places to find the zeros.
With the denominator having larger numeric coefficients, and the high degrees of the polynomials, you end up with a result that is fairly small (_approximately_ zero) over most of the range, except where the denominator nears zero, at which locations the results become large.
The locations where the denominator near zero follow roughly two branches of a hyperbola, so there are an infinite number of locations at which the denominator becomes zero, and so an infinite number of discontinuities in the overall curve. Approach the branches from the "inside" and the function goes to +infinity; approach from the "outside" and the function goes to -infinity.
I saw hints there might be additional discontinuities near the axes.
So there are an infinite number of locations of positive infinity and an infinite number of negative infinity.
You will not be able to integrate this in any meaningful sense.
It looks like you can solve the denominator for cos(theta), and when you do that you get +/- of the roots of a quartic. Over the range cos(phi) = 0 to cos(phi) = 1, two of the eight roots are complex only, but there are up to 6 real valued roots, 3 positive and 3 negative. The roots with higher absolute value are sort of paired up, so you would get two discontinuities close together in places. You can discard the negative roots because cos(theta) is non-negative over that range. So there is a discontinuity near cos(theta) = 0.1, and a pair of discontinuities near cos(theta)=1. Ah, looks like one of the two is cos(theta) > 1 mostly, so that gets us down to two discontinuities for most of the range. But the situation is more complicated for 0.0275 < cos(phi) < 0.03 approximately, with discontinuities in where the discontinuities are.