integral returns integrate instead of solving

47 views
Skip to first unread message

Mom Mam

unread,
Oct 25, 2021, 4:17:51 AM10/25/21
to sage-devel
hello, im trying to do the next integral on a vector:
L_1,L_2 = var('L_1,L_2')
f_2 = vector((-(((L_1 - L_2)^2/((L_1 - L_2)^2 + 1) - 1)^2 + (L_1 - L_2)^2/((L_1 - L_2)^2 + 1)^2)*(L_1 - L_2)/((L_1 - L_2)^2 + 1)^(3/2), (((L_1 - L_2)^2/((L_1 - L_2)^2 + 1) - 1)^2 + (L_1 - L_2)^2/((L_1 - L_2)^2 + 1)^2)/((L_1 - L_2)^2 + 1)^(3/2), 0))
f_2.integral(L_2,0,1).integral(L_1,0,1)

but im getting the next output:
(-integrate(integrate((((L_1 - L_2)^2/((L_1 - L_2)^2 + 1) - 1)^2 + (L_1 - L_2)^2/((L_1 - L_2)^2 + 1)^2)*(L_1 - L_2)/((L_1 - L_2)^2 + 1)^(3/2), L_2, 0, 1), L_1, 0, 1), -1/6*sqrt(2)*(sqrt(2) - 3) + 1/2*sqrt(2) - 1/3, 0)

how can i do so it wouldnt type "integrate(...)" and just do the integral itself?
and is that considered as a bug?
im using sage 9.2 python 3.7.7

Nils Bruin

unread,
Oct 25, 2021, 10:58:01 AM10/25/21
to sage-devel
I don't think the integration backends or sage itself deal with integrals of vector-valued functions. You can try to integrate each coordinate individually: integrals of vector-valued functions are generally defined to be the vector of integrals of each coordinate function. There will still be integrands that won't be handled because an antiderivative can't be found/expressed. In those cases you can probably get an answer through numerical integration, for which you'd still do the problem component-wise if you use general-purpose tools.

Mom Mam

unread,
Oct 25, 2021, 11:49:30 AM10/25/21
to sage-...@googlegroups.com
but integrals do work on vectors, it just didnt worked in this particular case.

i also face this problem when trying to do integral on each axis, for example:
x = var('x')
f = -(x - 1)*((x - 1)^2/((x - 1)^2 + 1)^2 + 1/((x - 1)^2 + 1)^2)/sqrt((x - 1)^2 + 1)
integrate(f, x)

output:
-integrate((x - 1)*((x - 1)^2/((x - 1)^2 + 1)^2 + 1/((x - 1)^2 + 1)^2)/sqrt((x - 1)^2 + 1), x)

though it does works if i try to do:
-integrate((x - 1)*((x - 1)^2/((x - 1)^2 + 1)^2 + 1/((x - 1)^2 + 1)^2)/sqrt((x - 1)^2 + 1), x)

output:
1/sqrt((x - 1)^2 + 1)

maybe copy and paste that does the job, but then i cant run scripts, and i also want it to work straight on vectors.

пн, 25 окт. 2021 г. в 17:58, Nils Bruin <nbr...@sfu.ca>:
--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/8t-bKeAbYXk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/b48a9d01-3f6d-431c-93ee-9ed94dcb0c6dn%40googlegroups.com.

Nils Bruin

unread,
Oct 25, 2021, 1:06:17 PM10/25/21
to sage-devel
On Monday, 25 October 2021 at 08:49:30 UTC-7 zfrh...@gmail.com wrote:
but integrals do work on vectors, it just didnt worked in this particular case.
Ah OK. That's convenient! In that case, you're probably running into an integral that the backend doesn't know how to find an antiderivative for. If a numerical answer is sufficient for you, then you should look into numerical computation of integrals.
 

Mom Mam

unread,
Oct 25, 2021, 3:16:26 PM10/25/21
to sage-...@googlegroups.com
thank you for the answer !
its so weird, sometimes it works sometimes doesnt.
now i upgraded to sage 9.4, and the last example that i showed perfectly worked:
sage: f = -(x - 1)*((x - 1)^2/((x - 1)^2 + 1)^2 + 1/((x - 1)^2 + 1)^2)/sqrt((x - 1)^2 + 1)
sage: integrate(f, x)
1/sqrt(x^2 - 2*x + 2)

thank you for telling about numerical computation of integral, i didnt knew such thing existed and i will definitely use it!

but im also interesting into knowing the integral itself, although the last example is solved, but now i have a new very familiar problem:
sage: a,b = var('a,b')
sage: integrate((((a - b)^2/(abs(-a + b)^2 + 1) - 1)^2 + (a - b)^2/(abs(-a + b)^2 + 1)^2)/(abs(-a + b)^2 + 1)^(3/2), b)
integrate((a^4 - 4*a^3*b + 6*a^2*b^2 - 4*a*b^3 + b^4 - 2*a^2*abs(a - b)^2 + 4*a*b*abs(a - b)^2 - 2*b^2*abs(a - b)^2 + abs(a - b)^4 - a^2 + 2*a*b - b^2 + 2*abs(a - b)^2 + 1)/(abs(a - b)^2 + 1)^(7/2), b)
sage: integrate((a^4 - 4*a^3*b + 6*a^2*b^2 - 4*a*b^3 + b^4 - 2*a^2*abs(a - b)^2 + 4*a*b*abs(a - b)^2 - 2*b^2*abs(a - b)^2 + abs(a - b)^4 - a^2 + 2*a*b - b^2 + 2*abs(a - b)^2 + 1)/(abs(a - b)^2 + 1)^(7/2), b)
(outputs some good long answer that i can actually use)

i dont understand why when i run this the first time it cant find antiderivative, but when i run its output it does solves the integral.
its exactly the same expression just in a different form, then why it cant work on the first time ? (maybe its a bug ¿)




пн, 25 окт. 2021 г. в 20:06, Nils Bruin <nbr...@sfu.ca>:
On Monday, 25 October 2021 at 08:49:30 UTC-7 zfrh...@gmail.com wrote:
but integrals do work on vectors, it just didnt worked in this particular case.
Ah OK. That's convenient! In that case, you're probably running into an integral that the backend doesn't know how to find an antiderivative for. If a numerical answer is sufficient for you, then you should look into numerical computation of integrals.
 

--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/8t-bKeAbYXk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages