Re: Piecewise functions definition and usage

• To: mathgroup at smc.vnet.net
• Subject: [mg24123] Re: Piecewise functions definition and usage
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Wed, 28 Jun 2000 02:11:44 -0400 (EDT)
• References: <8j9ddk\$50v@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Viorel,
We can warn NIntegrate of possible trouble at x = 13:

Clear[f, x]

f[x_] := Sqrt[1 - ((x - 3)/10)^2] /; Abs[x - 3] < 10
f[x_] := 0 /; Abs[x - 3] >= 3

NIntegrate[f[x], {x, -1, 13, 17}]

11.7446

NIntegrate[f, {x, x0, x1, ? , xk] tests for singularities at each of the
intermediate points xi. If there are no singularities, the result is
equivalent to an integral from x0 to xk. You can use complex numbers xito
specify an integration contour in the complex plane.
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Viorel Ontalus" <vio2 at mail.lehigh.edu> wrote in message
news:8j9ddk\$50v at smc.vnet.net...
> It seems I got into an area where Mathematica has some problems, and I
> hope somebody can give me a hint on how to go around these problems.
>
> 1.  I am trying to define a piecewise function and do some computations
> with it. When I integrate mathematica does not behave. Here is an simple
> example you can run and see what I am talking about
>
> Clear[f,x}
> f[x_] := Sqrt[ 1- ( (x-3)/10)^2  ] /;
> Abs[x-3]<10
> f[x_] := 0 /;
> Abs[x-3]>3 ;          (*this is a very simple piecewise function but one
> must be sure the Sqrt is from a positive # )
>
> NIntegrate[f[x],{x,-1,17}]   (* Here Mathematica goes nuts !!!*)
>
> Of course it gives an answer but if your program is more complex, then
> you never get an answer !!
> ( I tried to make the upper limit a variable  etc !!)
> Does anybody know how to avoid the error , or non convergence messages I
> get !!
>
>
>
> 2. For fun I tried the only reference from the book on piecewise
> functions:
> If[Abs[x-3]<10, f[x_]:=Sqrt[1- ( (x-3)/10)^2  ] , f[x_]:=0 ]
>
> This definition does not work !!
>
>
>
>
>
>
>
>
>

```

• Prev by Date: Re: Piecewise functions definition and usage
• Next by Date: RE: Re: "misbehaving" Union function
• Previous by thread: Re: Piecewise functions definition and usage
• Next by thread: Re: Piecewise functions definition and usage