MathGroup Archive 2003

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

Search the Archive

Re: piecewise definition of a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43886] Re: piecewise definition of a function
  • From: franksdaddy at yahoo.com (nate)
  • Date: Fri, 10 Oct 2003 03:05:54 -0400 (EDT)
  • References: <bm2ub8$6s1$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I found that the integration did work but spit out some warnings:
In[347]:=
f[x_] = If[x < 0, 0, If[x > 1, 0, 1]] 

Out[347]=
If[x < 0, 0, If[x > 1, 0, 1]]

In[354]:=
Integrate[f[x], {x, -50, 50}] // N

NIntegrate::"slwcon": "Numerical integration converging too slowly;
suspect \
one of the following: singularity, value of the integration being 0, \
oscillatory integrand, or insufficient WorkingPrecision. If your
integrand is \
oscillatory try using the option Method->Oscillatory in NIntegrate."

NIntegrate::"ncvb": "NIntegrate failed to converge to prescribed
accuracy \
after \!\(7\) recursive bisections in \!\(x\) near \!\(x\) =
\!\(1.171875`\)."

Out[354]=
1.01002

Maybe you have one of a few problems.  The first is that your function
is not continuous, and that might pose some problems for mathematica's
integrate function.  The second is that you might not have passed the
output of the integration to N[] to force a numerical answer.  Note
that you can get the exact answer by piecewise integration.  Integrate
from -50 to 0, 0 to 1, and then 1 to 50.

-nate

Nathan Moore <nmoore at physics.umn.edu> wrote in message news:<bm2ub8$6s1$1 at smc.vnet.net>...
> I'd like to define a function in a piecewise manner.  As of yet I've 
> been unsuccessful with even the simplest example.  Consider the 
> following:
> 
> first define a 1-d bump,
> 
> f[x_] = If[x < 0, 0,If[x > 1, 0, 1]]
>   Mathematica doesn't seem to mind this, as f[0.1] evaluates 1 and 
> f[-23] evaluates 0.
> The problem comes when I try to integrate the function.  The 
> following command which should evaluate to 1 doesn't work AT ALL!
> 
> Integrate[f[x], {x, -50, 50}]
> 
> What is the proper technique here?
> 
> Nathan Moore
> University of Minnesota Physics


  • Prev by Date: Re: $CommandLine
  • Next by Date: help in speeding up code involving a recursive function
  • Previous by thread: RE: piecewise definition of a function
  • Next by thread: Re: Using Symbols in Functions