RE: How to ...? Piecewise Function Definition
- To: mathgroup at smc.vnet.net
- Subject: [mg36337] RE: [mg36309] How to ...? Piecewise Function Definition
- From: "David Park" <djmp at earthlink.net>
- Date: Mon, 2 Sep 2002 04:08:45 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
PasKo, You could look up "piecewise functions" in the Master Index in Help. Unfortunately, the book does not have a unified discussion of methods for defining piecewise functions. The first method is to use a set of conditional definitions. For completeness I made f[x] = 0 if one of the conditional definitions is not met. f[x_] /; 0 < x < 6 := x^2 f[x_] /; x >= 6 := x + 1 f[x_] := 0 Plot[f[x], {x, 0, 10}]; The second method is to use a Which statement. Clear[f]; f[x_] := Which[ 0 < x < 6, x^2, x >= 6, x + 1, True, 0] Plot[f[x], {x, 0, 10}]; The above methods are fine in many cases, but if you want to perform functions on f, such as differentiation or integration, you should use the UnitStep function. So our third method is... Clear[f] f[x_] := x^2(UnitStep[x] - UnitStep[x - 6]) + (x + 1)UnitStep[x - 6] Plot[f'[x], {x, 0, 10}]; Plot[Integrate[f[y], {y, 0, x}] // Evaluate, {x, 0, 10}]; David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Paskoski [mailto:berlusconi_pagliusi at fis.unical.it] To: mathgroup at smc.vnet.net Dear MathGroup, I'd like to use Mathematica 4.0 to write a function having different expressions in different domain's intervals. Let's say: F[x_]= x^2 if 0<x<6 x+1 if x>=6 I know It's a stupid syntax problem, but I really do not know how/where to search the solution on the Mathematica Book Thank you in advance, PasKo.