MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Piecewise functions definition and usage

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24109] Re: Piecewise functions definition and usage
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 28 Jun 2000 02:11:35 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <8j9ddk$50v@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

> 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 !!

Surprise, surprise, and it will never work because it is nonsense.
If[] evaluate Abs[x-3]<10 and find not True or False (x is an symbol)
so it can't decide what part of Then/Else must be evaluated. 
So the expression is unevaluated no f[x] is defined and the full
If[] expression is lost in the Out[] variables.

f[x_?NumericQ]:=If[Abs[N[x-3]]<10, Sqrt[1- ( (x-3)/10)^2  ] , 0 ]

do what you want because the pattern gets evaluated only when x 
is a number and the test evaluates to True or False

Your first problem is more complicated. The Sqrt[] function has no
derivative at x==0 and Mathematica can't estimate the numerical
error of the integration when the function under the integral sign
is evaluated at x==-7 and x==13 because it find no error estimation.
That's why you get a message about the convergence.

So you may carefull look at your function for x-values where no
derivative exist, eventual split the integration range at this
points and use a open integration formula like a midpoint rule 
or an open Newton Cotes formula.

Hope that helps
  Regards
     Jens



Viorel Ontalus wrote:
> 
> 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: Conditionals with multiple tests?
  • Next by Date: RE: Resources for high school student?
  • Previous by thread: Re: Piecewise functions definition and usage
  • Next by thread: RE: Piecewise functions definition and usage