Message Boards Message Boards

0
|
5743 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Integration of functions involving If statements

Posted 11 years ago
I am having trouble with Integrating functions that involve If statements.
For example, I can integrate 
If [Cos[-y] Sin Sin < 0, -1, 1]
with x over the range -pi to pi and y over the range 0 to pi

However, trying to integrate
If[(Cos[-y] Sin Sin + Cos) < 0, -1, 1]
over the same ranges fails with Mathematica just returning the entered integration command.

Is there any way to have Mathematica integrate functions containing If statements of this nature?
Thanks in anticipation.

 
POSTED BY: Roger Mc Murtrie
7 Replies
Correction
Cos[-y] Sin Sin should be
Cos[-y] Sin Sin

and Cos[-y] Sin Sin + Cos should beCos[-y] Sin Sin + Cos
POSTED BY: Roger Mc Murtrie
If statements are good for programming, but you don't want to define mathematicals functions with it.

Instead, try using Piecewise: http://reference.wolfram.com/mathematica/ref/Piecewise.html
I also find using HeavisideTheta and UnitStep to be useful sometimes: http://reference.wolfram.com/mathematica/ref/HeavisideTheta.html

If statements are meant for control flow in a program and aren't meant to be symbolicaly manipulatable parts of the definition of a Mathematical function. 
POSTED BY: Sean Clarke
Hi Roger,

It is not clear from your posts what are the integrant functions. Is the first one
If[Cos[-y] Sin[x]^2 < 0, -1, 1]
or
If[Cos[-y] Sin[Sin[x]] < 0, -1, 1]

Is the second one 
If[(Cos[-y] Sin[x] Sin[x] + Cos[x]) < 0, -1, 1]
POSTED BY: Anton Antonov
If[Cos[-y] Sin^2 < 0, -1, 1]
is the first one.
If[(Cos[-y] Sin Sin + Cos) < 0, -1, 1]
is the second one.

Sorry for the confusion.
POSTED BY: Roger Mc Murtrie
Thanks very much for your response Sean.

Could you please expand on this:
"If statements"  "aren't meant to be symbolicaly manipulatable parts of the definition of a Mathematical function."

I think I get into problems with this quite a lot so it would help me to understand better, distinctions with respect to "symbolicaly manipulatable parts".
POSTED BY: Roger Mc Murtrie
I'm not sure I am able to clarify this with words very effectively beyond that statement.

If statements are meant for programming. They are meant to help define a program.

They aren't meant to be used as a mathematical formalism in the definition of a function.  The symbolic mathematical functions in Mathematica don't handle if statements because If statements aren't meant to be used in the definition of a mathematica formula. If statements are meant to be used in the definition of a program.
POSTED BY: Sean Clarke
Thanks Sean
POSTED BY: Roger Mc Murtrie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract