Re: Sheer frustration with integration of piecewise continuous functions
- To: mathgroup at smc.vnet.net
- Subject: [mg40922] Re: [mg40907] Sheer frustration with integration of piecewise continuous functions
- From: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
- Date: Thu, 24 Apr 2003 05:28:27 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
And here's a slightly different approach that parameterizes the
intervals and functions a bit more:
f1 = {(fpeak/L)*(x/a), {x, 0, a*L}};
f2 = {(fpeak/L)*L, {x, a*L, b*L}};
f3 = {(fpeak/L)*((L - x)/(1 - b)),
{x, b*L, L}};
functions = {f1, f2, f3};
conditional[{f_, {a_, b_, c_}}] :=
{b <= a < c], f}
f = Which@@Flatten@{conditional/@functions, True, 0}
values = {L -> 1, fpeak -> 1, a -> 3/5, b -> 9/10};
Plot[Evaluate[f /. values], {x, 0, 1}];
Simplify@(Plus @@ Integrate @@@ functions)
% /. values
% // N
or
values = {L -> 1, fpeak -> 1, a -> 3/7, b -> 9/11};
Plot[Evaluate[f /. values], {x, 0, 1}];
Simplify@(Plus @@ Integrate @@@ functions)
% /. values
% // N
The "values" could be determined by solving equations if necessary.
For instance, if we know the area is 7/10, b==2a, and fpeak==L==1, then
the values are given by
Solve[{Plus @@ Integrate @@@ functions == 7/10,
fpeak == L == 1, a/b == 1/2}]
{L, fpeak, a, b} /. First@%;
values = Thread[Rule[{L, fpeak, a, b}, %]]
Plot[Evaluate[f /. values], {x, 0, 1}];
{L -> 1, fpeak -> 1, a -> 2/5, b -> 4/5}
That can yield "spurious" solutions at times, of course -- when the
solution doesn't satisfy 0 <= a <= b <= 1.
Bobby
-----Original Message-----
From: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
To: mathgroup at smc.vnet.net
Subject: [mg40922] Re: [mg40907] Sheer frustration with integration of piecewise
continuous functions
Here's a slightly less exhaustive solution:
f1 = {(fpeak/L)*(x/0.6), {x, 0, 0.6*L}};
f2 = {(fpeak/L)*L, {x, 0.6*L, 0.9*L}};
f3 = {(fpeak/L)*10*(L - x), {x, 0.9*L, L}};
functions = {f1, f2, f3};
conditional[{f_, {a_, b_, c_}}] :=
{b <= a < c, f}
f = Which @@ Flatten@{conditional /@ functions, True, 0}
Plot[Evaluate[f /. {L -> 1, fpeak -> 1}], {x, 0, 1}];
Plus @@ Integrate @@@ functions
% /. {L -> 1, fpeak -> 1}
Bobby
-----Original Message-----
From: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
To: mathgroup at smc.vnet.net
Subject: [mg40922] Re: [mg40907] Sheer frustration with integration of piecewise
continuous functions
I hope somebody comes up with a better solution, but here's an
interesting one.
First, a breakdown of the function into intervals:
before = {0, {x, -Infinity, 0}};
f1 = {(fpeak/L)*(x/0.6), {x, 0, 0.6*L}};
f2 = {(fpeak/L)*L, {x, 0.6*L, 0.9*L}};
f3 = {(fpeak/L)*10*(L - x), {x, 0.9*L, L}};
after = {0, {x, L, Infinity}};
functions = {before, f1, f2, f3, after};
Second, a helper function:
conditional[{f_, {a_, b_, c_}}] := {b <= a < c, f}
This defines and plots the overall function:
f = Which @@ Flatten[conditional /@ functions]
Plot[Evaluate[f /. {L -> 1, fpeak -> 1}], {x, 0, 1}];
And this integrates it:
Plus @@ Integrate @@@ functions
% /. {L -> 1, fpeak -> 1}
Bobby
-----Original Message-----
From: Madhusudan Singh <spammers-go-here at yahoo.com>
To: mathgroup at smc.vnet.net
Subject: [mg40922] [mg40907] Sheer frustration with integration of piecewise
continuous functions
Clear["'*"];
(*ClearAttributes[Which, HoldAll];*)
f[x_, L_, fpeak_] := (fpeak /L) Which[((0 <= x) && (x < 0.6 L)), x/(0.6
),((0.6 L <= x) && (x <= 0.9 L)), L, ((0.9 L < x) && (x <= L)) , 10 (L
-x)];
Plot[f[x, 1, 1], {x, 0, 1}];
Print[Integrate[f[x, L, fpeak], {x, 0, L}, Assumptions -> {L >= 0,
fpeak >=
0, x >= 0, x <= L}]];
I have struggled with the above integration (believe me, its just a
test
case, I have a much more complicated function) for an hour now.
What is missing above ? The plot evaluates but the integral does not.
Why
does Mathematica make it so damned difficult to work with piecewise
continuous functions ?