I am trying to integrate a hat function for a project that I am doing and have found a method to do so but I find it sloppy. Currently I have the basis function
\[Psi][z_] := z - Subscript[Z, i]/ \[CapitalDelta]z + 1;
which I am trying to integrate from zi−1 to zi+1. I break the basis function up into two pieces and integrate the left side from zi−1 to zi and then the right side from zi to zi+1. My first question is, is there a way to integrate piecewise functions? The second question I have is, is there a way to set global assumptions like zi−1<zi<zi+1, zi−zi−1=Δz , etc?
Edit: This is the piece wise function taken directly from my code I am trying to integrate
\[Psi][z_, c_] := Piecewise[{{(z - c)/\[CapitalDelta]z + 1,
z <= c}, {-(z - c)/\[CapitalDelta]z + 1, z > c}}];
where c is the center of the hat function. Here is my attempt to integrate the piece wise function
FullSimplify[
Integrate[\[Psi][z, Subscript[Z, i]], {z, Subscript[Z, i - 1],
Subscript[Z, i + 1]}],
Assumptions -> {-(Subscript[Z, i + 1] - Subscript[Z,
i ]) == -\[CapitalDelta]z,
Subscript[Z, i + 1] - Subscript[Z,
i ] == \[CapitalDelta]z, -(Subscript[Z, i] - Subscript[Z,
i - 1 ]) == -\[CapitalDelta]z,
Subscript[Z, i] - Subscript[Z, i - 1 ] == \[CapitalDelta]z}]
I do not get a usable answer. Am I doing something wrong (ie can one integrate a piece wise function)?
Answer
Short answer: Mathematica has no problem integrating piecewise or hat functions.
Your notation seems to me to be needlessly complex. Why bother to define Zi when it's just Z0+iΔz? Isn't your ψ just 1-Abs[z-c]/Δz
? However, I'll try to adhere to the spirit of your notation. Here's some code that works for me:
Zdefs = {Subscript[Z, i] - Subscript[Z, i - 1] == Δz,
Subscript[Z, i + 1] - Subscript[Z, i] == Δz};
Integrate[ψ[z, Subscript[Z, i]],
{z, Subscript[Z, i - 1], Subscript[Z, i + 1]} /.
Solve[Zdefs, {Subscript[Z, i + 1], Subscript[Z, i - 1]}][[1]],
Assumptions -> Δz > 0 &&
Subscript[Z, i] ∈ Reals]
Comments
Post a Comment