Le mercredi 15 décembre 2021 à 20:43:07 UTC+1, juanlui...@gmail.com a 
écrit :

> See this example:
>
> f(x)=(x+sin(3*x))*exp(-3*x*I)
> g(x)=f(x).expand()
> integral(f(x)-g(x),(x,0,2*pi))
>
> The answer is I*pi, but it should be 0.
>

Huh ?

f has no poles ; therefore, the value of the integrate beteen two given 
points is independent of the integration path. In particular, 
f(x).integrate(x,a,b)==real(f(x)).integrate(x,a,b)+I*imag(x).integrate(x,a,b)). 
You can therefor check your affirmation by executing :

sage: numerical_integral(lambda 
u:f(u).real(),0,2*pi)[0]+I*numerical_integral(lambda u:f(u).imag(),0,2*pi)[0]
-3.2262783606579845e-15 - 1.0471975511966007*I

which raises some doubts about your affirmation….
​

>
> Many other examples (related to Fourier coefficients) give similar errors. 
> For instance:
>
> f(x)=(x+cos(x))*exp(-x*I)
> g(x)=f(x).expand()
> integral(f(x)-g(x),(x,0,2*pi))
>
> The answer is -pi, and it should be 0.
>

The previous reasoning also applies here :

```
sage: g(x)=(x+cos(x))*exp(-x*I)
sage: numerical_integral(lambda 
u:g(u).real(),0,2*pi)[0]+I*numerical_integral(lambda 
u:g(u).imag(),0,2*pi)[0]
3.1415926535897913 + 6.283185307179586*I
 ```
However, the answers given by the various available algorithms may still be 
questioned :

sage: table([[alg,f(x).integrate(x,0,2*pi, algorithm=alg)] for alg in 
("maxima", "giac", "sympy", "fricas", "mathematica_free")])
  maxima             2/3*I*pi
  giac               -1/3*I*pi
  sympy              -1/3*I*pi
  fricas             -1/3*I*pi
  mathematica_free   -1.04720000000000*I
sage: table([[alg,g(x).integrate(x,0,2*pi, algorithm=alg)] for alg in 
("maxima", "giac", "sympy", "fricas", "mathematica_free")])
  maxima             2*I*pi
  giac               (2*I + 1)*pi
  sympy              (2*I + 1)*pi
  fricas             (2*I + 1)*pi
  mathematica_free   3.14159000000000 + 6.28319000000000*I

​
HTH,

It can be easily with sagemath 9.4 in https://sagecell.sagemath.org
>
> Thanks in advance,
>
> Yours,
>
> Juan Luis Varona
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/19143436-d58f-4830-bb77-daab8674d823n%40googlegroups.com.

Reply via email to