HP Forums
Issues with integral - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Issues with integral (/thread-15482.html)



Issues with integral - Mordicus1973 - 08-19-2020 09:03 PM

Hello,

i try to compute this integral
int(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0,pi/2)

The calculator simply hang, i can't stop computing. in the emulator it show some messages and don't do the computation.

When i do the same computation on Nspire or wolfram, i have to right answer (1/3).

I have tested with xcas on Linux (icas), it can't compute this integral.


RE: Issues with integral - Albert Chan - 08-20-2020 12:23 AM

(08-19-2020 09:03 PM)Mordicus1973 Wrote:  int(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0,pi/2)

XCas> gaussquad(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0,pi/2)     → 0.333333333333

Doing integral symbolically, let t = tan(x) → dt = sec(x)^2 dx

\(\Large{1 \over (\sqrt{\cos x}+\sqrt{\sin x})^4} = {\sec^2 x \over (1+\sqrt{\tan x})^4} \)

XCas> F := int(1/(1+sqrt(t))^4, t)      → \(\Large
\frac{2 (-3\cdot \sqrt{t}-1)}{6 \left(\sqrt{t}+1\right)^{3}}\)

Limit of x = 0 to pi/2, same as t = 0 to +inf

XCas> preval(F,0, inf, t)                     → = 0 - (-1/3) = 1/3


RE: Issues with integral - trojdor - 08-20-2020 12:44 PM

(08-19-2020 09:03 PM)Mordicus1973 Wrote:  Hello,

i try to compute this integral
int(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0,pi/2)

The calculator simply hang, i can't stop computing. in the emulator it show some messages and don't do the computation.

When i do the same computation on Nspire or wolfram, i have to right answer (1/3).

I have tested with xcas on Linux (icas), it can't compute this integral.

Interestingly...
It works perfectly fine if you enter the integral in Home mode...gives you an instantaneous .333333333... or 1/3.

It's usually the other way round for me .... CAS will frequently solve things Home won't.

I was bored and tried this problem on about 20 calculators I had within arm's reach. Every one got it right. Even the old HP-48 eats it right up.
The TI-89 CAS got it right. Same with the HP50g, 40gs, 49g, some Casios.


RE: Issues with integral - trojdor - 08-20-2020 12:52 PM

If you turn off exact mode in CAS setup, it works fine in CAS, as well.

(But it certainly does 'blow up' if exact is left checked.)


RE: Issues with integral - roadrunner - 08-20-2020 02:42 PM

In cas:

∫(1/sin2costan((sqrt(cos(x))+sqrt(sin(x)))^4),x,0,π/2) returns 1/3

-road


RE: Issues with integral - Chr Yoko - 08-20-2020 03:30 PM

(08-20-2020 02:42 PM)roadrunner Wrote:  In cas:

∫(1/sin2costan((sqrt(cos(x))+sqrt(sin(x)))^4),x,0,π/2) returns 1/3

-road

Thanks for the trick. Yes works on the Prime under XCAS exact mode now. But only after displaying a screen of scary warnings....

Prime Non exact XCAS mode works fine and get 0.3333 instantly with or without the sin2costan and with no warning page.

Any explanation on that interesting behavior of XCAS ?


RE: Issues with integral - Mordicus1973 - 08-20-2020 04:06 PM

(08-20-2020 12:52 PM)trojdor Wrote:  If you turn off exact mode in CAS setup, it works fine in CAS, as well.

(But it certainly does 'blow up' if exact is left checked.)

Yes, thank you for the tips.

Also, in the Function application, i can compute the integral (signed area i think in english) and it return 0.333333...


RE: Issues with integral - roadrunner - 08-21-2020 07:12 PM

(08-20-2020 03:30 PM)Chr Yoko Wrote:  ...Any explanation on that interesting behavior of XCAS ?

All i know is CAS frequently seems to be happier when SIN is eliminated in the equation.


RE: Issues with integral - parisse - 08-22-2020 06:12 AM

I just checked with a TI 89 and with a TI CX Nspire CAS, the integral is computed in approx mode, not in exact mode. On the Prime in CAS exact mode, the CAS tries to compute the integral exactly, and unfortunately this raises large computations that are hard to interrupt.
If you are interested in an approx value inside the CAS, just replace one boundary by an approx value, e.g. 0 by 0.0 and you will get almost instant the approx answer.
∫(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0.0,π/2)
For an exact answer, you must help the CAS, like with roadrunner trick.


RE: Issues with integral - Mordicus1973 - 08-22-2020 07:23 AM

(08-22-2020 06:12 AM)parisse Wrote:  For an exact answer, you must help the CAS, like with roadrunner trick.

Hello Parris,
Thank for your reply and the tips.

The real issue here is not getting or not the answer, the real issue is that the calculator hang.
If it happen during exam it can be catastrophic for the student. He have to push reset button but he will need a needle (the hole is realy small).

Doing the same with icas :

int(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0,pi/2)
Simplification en supposant x near 0
Simplification en supposant x near 0
Simplification en supposant x near 0
Simplification en supposant x near 0
Extension algébrique non autorisée dans un rootof
Extension algébrique non autorisée dans un rootof
Attention, on choisit une racine de [1,0,%%%{-4,[1,0]%%%},0,%%%{4,[0,2]%%%}]aux valeurs de paramètre [18,-49]
Attention, on choisit une racine de [1,0,%%%{-4,[1,0]%%%},0,%%%{4,[0,2]%%%}]aux valeurs de paramètre [-64,2]
Simplification en supposant x near pi/4
Simplification en supposant x near pi/4
Attention, on choisit une racine de [1,0,%%%{-2,[1,1]%%%}+%%%{-2,[1,0]%%%},0,%%%{1,[2,2]%%%}+%%%{-2,[2,1]%%%}+%%%{1,[2,0]%%%}]aux valeurs de paramètre [31,-21]
integration(1/(sqrt(cos(x))+sqrt(sin(x)))^4,x,0,pi/2)
// Time 0.18

If the G2 do the same, then he can try alternative method to compute the intergral


RE: Issues with integral - pinkman - 08-22-2020 04:16 PM

Nice explanations and tricks, thanks.

Bernard,
Could you please explain the first warning in the message from the console?

Simplification assuming taylorx0 near π/4
Simplification assuming taylorx0 near π/4
Warning, choosing root of [1,0,%%%{-2,[1,1]%%%}+%%%{-2,[1,0]%%%},0,%%%{1,[2,2]%%%}+%%%{-2,[2,1]%%%}+%%%{1,[2,0]%%%}] at parameters values [-72,58]
Warning, 1/4*π not checked


RE: Issues with integral - parisse - 08-25-2020 07:12 AM

@Mordicus1973: The code executed on the Prime is not always the same as on a PC. One reason is that exceptions are not enabled on the Prime, and this make keyboard interruption harder to handle. Another reason is that some optimizations are not enabled on the Prime for various reasons, e.g. it is not possible to link with the GPL libraries like on a PC.

@pinkman: this is an expert diagnostic message. Xcas handles simplification of sqrt or fractional powers by constructing a unique algebraic extension. Sometimes extracting a square root or fractional power inside an extension requires choosing a branch. For numeric sqrt, this is done by checking approx values. If the sqrt argument depends on a parameter, the system must still choose, and it does that by replacing the parameter with random numeric values. If you make assumptions on the parameter, the assumption is taken in account in the random choice.


RE: Issues with integral - pinkman - 08-25-2020 08:12 PM

Thanks for taking the time to answer. The CAS symbolic engine is really a masterpiece.