# HP Forums

Full Version: Promblem with integration
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In CAS, cannot integrate sin(x^2) or any other trigonometric function that involves x^(number): int(sin(x^2),x,0,8) Calculator gives out "integrate(...)" instead of answer. What's wrong?
(03-16-2016 02:14 PM)Annaguseva Wrote: [ -> ]In CAS, cannot integrate sin(x^2) or any other trigonometric function that involves x^(number): int(sin(x^2),x,0,8) Calculator gives out "integrate(...)" instead of answer. What's wrong?

in Home environment you find the answer , doesn't work in CAS but just press SHIFT>>ENTER to get the answer, some of the nifty tricks!!! Temperament Prime

[attachment=3233]
[attachment=3234]
Since there is no exact closed form answer here (not without using some stuff not supported in any calculator), it returns the input unevaluated. Two ways to get a numeric approximation.

1. Press SHIFT-ENTER (to run approx( ) on your last input)
2. Put a "." in one of your limits. int(sin(x^2),0.,8) <-- note the 0. and not just 0

Both of those will immediately evaluate a decimal result.

The reason it works in HOME as stated already is that the X variable is an approximate valued number. Hence, it is just like putting the "0." in the second option as it triggers the approximate numerical calculation.
Thank You!
(03-16-2016 06:34 PM)Tim Wessman Wrote: [ -> ]Since there is no exact closed form answer here (not without using some stuff not supported in any calculator), it returns the input unevaluated. Two ways to get a numeric approximation.

1. Press SHIFT-ENTER (to run approx( ) on your last input)
2. Put a "." in one of your limits. int(sin(x^2),0.,8) <-- note the 0. and not just 0

Both of those will immediately evaluate a decimal result.

The reason it works in HOME as stated already is that the X variable is an approximate valued number. Hence, it is just like putting the "0." in the second option as it triggers the approximate numerical calculation.

there is a close form to these integrations (Mathematically) but not for someone who just want numerical answer directly.

give a little push to Prime, and one can find the close form..or they shd be implemented into Prime if there is a need...
http://www.wolframalpha.com/input/?i=int...9,x,0,8%29
[attachment=3235]
The closed form for int(sin(x^2)x,0,x) is the Fresnel integral S(x) function or just S(x).

S(x) is a variation of the Gauss error function (erf = int(e^-x^2)) and the imaginary error function (erfi = int(e^x^2)) that can be formulated in terms of erf(x) and erfi(x) with some complex math. However, S(x) is not supported on any handheld calculator that I am aware of. Given the limited flash memory on the Prime (or any calculator for that matter), I am not sure this is a top candidate to make it into the Prime's flash memory in some future release - there are many more important functions not yet implemented that have higher utility value. But if there is space then, sure go ahead. But implement erfi(x) first then S(C) and also the Fresnel integral C(x) function which is = int(cos(x^2)x,0,x).
If you add more special functions, then of course you can compute more antiderivatives symbolically, but this requires more work than just adding a table lookup for sin/cos(x^2), because you must also integrate expressions that can be reduced to these forms. This is an endless quest and I'm not convinced it is really usefull. My programming time is finite, I have to make choices, Fresnel integrals are not on the top list.
(03-16-2016 10:07 PM)Anders Wrote: [ -> ]The closed form for int(sin(x^2)x,0,x) is the Fresnel integral S(x) function or just S(x).

Since S(x) is itself defined as an integral, I would not have considered it a "closed form" solution. I realize that "closed" does not have a hard & fast definition, so that's just my opinion.

You may or may not find this helpful: https://en.wikipedia.org/wiki/Closed-form_expression
Yes I used the "closed form" much more loosely defined than Wiki. I was thinking to express the result using named standard functions like erf, erfc, gamma... (these particular once are already implemented in Prime but are nonetheless not in closed form per Wiki).

Anyway, I took another pass at this integration...

You could express int(sin(x^2)x,0,x) only in terms of erf(x) (avoiding erfi(x), S(x) and C(x) altogether). After some complex math you get:

int(sin(x^2),x,0,x) =
(1+i)*√(pi/32)*( erf( (1+i)/√(2) * x) - i*erf( (1-i)/√(2) * x) )

So int(sin(x^2)x,0,8) =
(1+i)*√(pi/32)*( erf( (1+i)/√(2) * 8.0) - i*erf( (1-i)/√(2) * 8.0))
should come out as 0.601721644935

[attachment=3244]
Not sure if it's enough closed form though.
Seems to plot, the imaginary part cancels nicely. I'll have a look...
parisse,
That would be great!

To complete the picture with cos(x^2), using Euler and variable substitution you can do a similar complex math calculation and derive int(cos(^2)x,0,x) in terms of erf(x) symmetrically as:

int(cos(x^2),x,0,x) =
(1-i)*√(pi/32)*( erf( (1+i)/√(2) * x) + i*erf( (1-i)/√(2) * x) )

It turns out that the signs in front of the two i's are swapped otherwise the same. Very nice actually.

[attachment=3255]
http://www-fourier.ujf-grenoble.fr/%7epa...sin(x^2))&
This will only work for finite boundaries in definite integration.
(03-16-2016 10:07 PM)Anders Wrote: [ -> ]The closed form for int(sin(x^2)x,0,x) is the Fresnel integral S(x) function or just S(x).

S(x) is a variation of the Gauss error function (erf = int(e^-x^2)) and the imaginary error function (erfi = int(e^x^2)) that can be formulated in terms of erf(x) and erfi(x) with some complex math. However, S(x) is not supported on any handheld calculator that I am aware of. Given the limited flash memory on the Prime (or any calculator for that matter), I am not sure this is a top candidate to make it into the Prime's flash memory in some future release - there are many more important functions not yet implemented that have higher utility value. But if there is space then, sure go ahead. But implement erfi(x) first then S(C) and also the Fresnel integral C(x) function which is = int(cos(x^2)x,0,x).

(03-17-2016 06:54 AM)parisse Wrote: [ -> ]If you add more special functions, then of course you can compute more antiderivatives symbolically, but this requires more work than just adding a table lookup for sin/cos(x^2), because you must also integrate expressions that can be reduced to these forms. This is an endless quest and I'm not convinced it is really usefull. My programming time is finite, I have to make choices, Fresnel integrals are not on the top list.

I apologise if I reopen this post, but after a bit of time I wonder if there are some developments or thoughts about the implementation of Fresnel integrals S(x) and C(x) and erfi() in CAS (in the Prime) or if there is already any custom program (or App) to handle them simply and friendly.
Thank you!

Salvo

EDIT: could it be so simple? There are warnings with the below code, therefore I'm wondering...

Code:
```#cas erfi(x):= return -i*erf(i*x) #end```
***
Code:
```EXPORT Fresnel_S(x) // Fresnel integral S(x) BEGIN local t; RETURN int(SIN(t^2),t,0,x); END; EXPORT Fresnel_Sn(x) // Fresnel integral S(x) normalized π/2 BEGIN local t; RETURN int(SIN((π/2)*t^2),t,0,x); END; EXPORT Fresnel_C(x) // Fresnel integral C(x) BEGIN local t; RETURN int(COS(t^2),t,0,x); END; EXPORT Fresnel_Cn(x) // Fresnel integral C(x) normalized π/2 BEGIN local t; RETURN int(COS((π/2)*t^2),t,0,x); END;```
(above Fresnel integral S(x) and C(x) with and without normalisation with π/2 factor, following some authors...)
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :