how to integrate functions with conditions using Maxima?

how to integrate functions with conditions using Maxima? - Messages

#1 Posted: 7/13/2021 1:52:18 PM
an10

an10

1 likes in 15 posts.

Group: User

Maxima breaks whenever I try to integrate a function that is defined using if-else statement, does anyone know a solution for this?
1 users liked this post
Martin Kraska 7/13/2021 2:25:00 PM
#2 Posted: 7/13/2021 2:24:56 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Handling of boolean expressions is a missing feature in the maxima plugin, see SS 99.

Freezing with "if" is a separate error, I'll add this to the BTS. Thanks for pointing it out.
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#3 Posted: 7/13/2021 3:23:36 PM
an10

an10

1 likes in 15 posts.

Group: User

Wrote

Wrote

Maxima breaks whenever I try to integrate a function that is defined using if-else statement, does anyone know a solution for this ?


Use native Smath.

Integrate Discontinuous [min(x)].sm (16 KiB) downloaded 41 time(s).
Integrate Discontinuous.sm (31 KiB) downloaded 36 time(s).



no thanks I need double integrals
#4 Posted: 7/13/2021 4:11:20 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

Maxima breaks whenever I try to integrate a function that is defined using if-else statement, does anyone know a solution for this?



Traditionally, CAS software cannot handle if to derive or integrate.

Clipboard02.jpg

Maple can integrate functions defined with if, if previously they are converted to piecewise functions, which have a syntax very similar to the cases in SMath.

Clipboard03.jpg

The most convenient way to integrate piecewise functions in Maxima is by converting the conditionals in your functions to expressions involving sign, abs or unit steps functions, which Maxima can sometimes find an expression with elementary functions.

Clipboard01.jpg

Wrote


no thanks I need double integrals



Clipboard05.jpg

Alvaro.
#5 Posted: 7/13/2021 5:39:40 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

A practical example.

example_if.sm (11 KiB) downloaded 38 time(s).

Clipboard01.jpg

Best regards.
Alvaro.
#6 Posted: 7/14/2021 2:49:13 AM
an10

an10

1 likes in 15 posts.

Group: User

So I tried maple and symbolic evaluation and now I don't know what to do with this, obviously there are holes in this function when denominators evaluate to zero.

1.png
#7 Posted: 7/14/2021 3:07:08 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

So I tried maple and symbolic evaluation and now I don't know what to do with this, obviously there are holes in this function when denominators evaluate to zero.



Max (with uppercase) is a function from CustomFunctions, not recognized by Maxima or Maple. Here, max(a, b ) is from Maxima or Maple (native SMath is with only one arg max(A) )

Clipboard01.jpg

The answer is the same: use sign, abs or unit step with maxima, and piecewise with maple.

Alvaro.
#8 Posted: 7/14/2021 3:31:49 AM
an10

an10

1 likes in 15 posts.

Group: User

Wrote

Wrote

So I tried maple and symbolic evaluation and now I don't know what to do with this, obviously there are holes in this function when denominators evaluate to zero.



Max (with uppercase) is a function from CustomFunctions, not recognized by Maxima or Maple. Here, max(a, b ) is from Maxima or Maple (native SMath is with only one arg max(A) )

Clipboard01.jpg

The answer is the same: use sign, abs or unit step with maxima, and piecewise with maple.

Alvaro.



how do I convert a function to piecewise representation?
#9 Posted: 7/14/2021 3:39:24 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote


how do I convert a function to piecewise representation?



Use the function If_GT defined above:

Clipboard01.jpg

Alvaro
#10 Posted: 7/14/2021 3:48:07 AM
an10

an10

1 likes in 15 posts.

Group: User

Wrote

Use the function If_GT defined above:



but I need a x != 0 condition, I don't think I can stitch together x > N conditions without a boolean OR to represent x != 0 somehow. (or at least I can't think of a way to do so)
#11 Posted: 7/14/2021 4:09:50 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

Wrote

Use the function If_GT defined above:



but I need a x != 0 condition, I don't think I can stitch together x > N conditions without a boolean OR to represent x != 0 somehow. (or at least I can't think of a way to do so)



Traditional way in CAS for handle isolate points is using Dirac's Delta "function". But that have some numerical issues, bigger one is that it is not a function but a distribution. Because you can take out a numerable infinity set of points from an integral without change its value, you don't need to exclude cases in the integrand, except for numerical evaluations, and that could be handled in SMath with try function.

So, you can read about Dirac in maple or maxima, and see how to implement an approximation for numerical evaluations looking how to approximate a limit of a succession of functions (that's what a distribution is, and this way is very useful in mathcad 11), or discard some few points or try to symbolic evaluating the integrals with maxima or maple and use try to catch numerical errors.

Alvaro.
#12 Posted: 7/17/2021 6:55:43 AM
overlord

overlord

552 likes in 1332 posts.

Group: Moderator

Original post was about using integrate functions with conditions using Maxima.
Some seems to ignore "with conditions using Maxima".
I understood from mkraska and Razonar this is not possible yet, using Maxima.
And there are some tricks for it to use with other plugins/functions.
Mkraska said he will add this feature to Maxima.
That answers should be enough for this question.

Regards
#13 Posted: 7/17/2021 7:53:39 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

Original post was about using integrate functions with conditions using Maxima.
Some seems to ignore "with conditions using Maxima".
I understood from mkraska and Razonar this is not possible yet, using Maxima.
And there are some tricks for it to use with other plugins/functions.
Mkraska said he will add this feature to Maxima.
That answers should be enough for this question.

Regards



Hi. But actually what I try to show is that it is possible, without plugins and only with simple and short SMath's definitions.

MaximaPiecwiseIntDif.sm (33 KiB) downloaded 35 time(s).
MaximaPiecwiseIntDif.pdf (192 KiB) downloaded 56 time(s).

Best regards
Alvaro
#14 Posted: 7/17/2021 8:11:41 AM
overlord

overlord

552 likes in 1332 posts.

Group: Moderator

Wrote

Hi. But actually what I try to show is that it is possible, without plugins and only with simple and short SMath's definitions.

Best regards
Alvaro


Yeah I got that, which I appreciate it too.
And I have no grievance against your answers too.
Main question is "with conditions using Maxima".
You have answered the question without drifting apart from main issue.
Mkraska even replied conditions are not added to maxima plugin yet.
Your point is "It is not possible with Maxima and you can use these functions".
It is possible with integrated functions as you have shown.
But the some replies are either same with previous ones.
Or not related with the subject. This is what I had tried to complain.

Regards
2 users liked this post
Alvaro Diaz Falconi 7/17/2021 8:32:00 AM, Oscar Campo 7/17/2021 9:30:00 AM
#15 Posted: 7/17/2021 9:32:51 AM
Oscar Campo

Oscar Campo

124 likes in 298 posts.

Group: Moderator

Wrote


Yeah I got that, which I appreciate it too.
And I have no grievance against your answers too.
Main question is "with conditions using Maxima".
Mkraska even replied conditions are not added to maxima plugin yet.
You have answered the question without drifting apart from main issue.
Your point is "It is not possible with Maxima and you can use these functions".
It is possible with integrated functions as you have shown.
But the some replies are either same with previous ones.
Or not related with the subject. This is what I had tried to complain.

Regards



I completely agree with you. Answers in a forum must be concrete and specific for the forum's health and traceability
#16 Posted: 7/18/2021 10:09:06 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

how do I convert a function to piecewise representation ?



PieceWise.PNG

#17 Posted: 7/18/2021 11:05:53 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

no thanks I need double integrals


Native Smath integrator supports double ... very slow.
Thus, convert/transit for end production.
Give your double integration for inspection.
#18 Posted: 7/18/2021 1:14:52 PM
an10

an10

1 likes in 15 posts.

Group: User

Wrote

Give your double integration for inspection.



I don't really understand your way of speaking, but if you mean that you want me to post what exactly I want to integrate then I already posted it. It's Smith shadowing masking function somewhere in there. All I ever wanted is to handle cases where denominator evaluates to zero to prevent undefined results so I used if-else statement, but it ended up not working with Maxima. I gave up using Smath, I'll integrate everything using C++ with Monte-Carlo estimator instead. Much less painful than trying to beat this mess and actually much more flexible which is ridiculous if you ask me. Thank you all for trying to help.
#19 Posted: 7/18/2021 2:04:29 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

but if you mean that you want me to post what exactly I want to integrate then I already posted it. It's Smith shadowing masking function somewhere in there.


Post the double integration again.
Sometimes Forum misses attachment.
If you mean the RHS is the double integration
result of the LHS, then make it productive.
As it looks, it should produce complex RHS.
#20 Posted: 7/18/2021 2:19:34 PM
an10

an10

1 likes in 15 posts.

Group: User

Wrote

Wrote

but if you mean that you want me to post what exactly I want to integrate then I already posted it. It's Smith shadowing masking function somewhere in there.


Post the double integration again.
Sometimes Forum misses attachment.
If you mean the RHS is the double integration
result of the LHS, then make it productive.
As it looks, it should produce complex RHS.



https://en.smath.com/forum/yaf_postsm71566_how-to-integrate-functions-with-conditions-using-Maxima.aspx#post71566
  • New Posts New Posts
  • No New Posts No New Posts