Integration with piecewise function

Hi! I have the following problem. I have a piecewise function and i need to integrate the function with the piecewise as variable. I have type the piecewise function (see pic) but don't know where to go from there.Your help in this regard is much appreciated. T' and T are the same. I have to determine the Pf (an integral) with Cv4 (a variable of S4) as piecewise function.

4 Comments

Is T' a distinct variable from T? Is T' the complex conjugate of T, even though the bounds suggest that T is never negative? Is T' the derivative of T?
Thank you Walter for your response. Both T and T' are exactly the same, consider them same. The difference is just to distinguish the integral function from integral upper limit. sorry for the confusing notations.
... Is the division by the current time value, or by the upper bound?
Fawad Ahmed
Fawad Ahmed on 20 Mar 2021
Edited: Fawad Ahmed on 20 Mar 2021
division is by the current time value, with values close to zero but not equal to zero. because I am dealing with temperature values close to absolute temperature i.e , 0_Kelvin. So T in S4 integral take values in range of 0<T<0.4. whereas T' in S4 just represents S4 as a function of T' which is same as T, so the actual eqn of S4 is int(Cv4/T) .Also plz ignore the algebraic equation besides S4 integral eqn, I only need to use integral form. Thanks

Sign in to comment.

 Accepted Answer

Doesn't this work:
C_v4 = @(T) 0.0516*T.^3.*double(T<=0.6) + .432*T.^6.7.*double(0.6<T).*double(T<1.1) + 0.468*T.^5.6.*double(1.1<=T).*double(T<=2.2);
S = @(T) integral(@(Tprime) C_v4(Tprime)./Tprime,0,T);
Then you might have to plug the piece-wise parts into a function and select what integrations you need. Perhaps something like this:
function S4 = S_4_piecewise(Tin)
if Tin > 1.1
S4 = integral(@(T) 0.0516*T.^2,0,0.6) + ...
integral(@(T) .432*T.^4.7,0.6,1.1) + ...
integral(@(T) 0.468*T.^4.6,1.1,Tin);
elseif Tin > 0.6
S4 = integral(@(T) 0.0516*T.^2,0,0.6) + ...
integral(@(T) .432*T.^5.7,0.6,Tin);
else
S4 = integral(@(T) 0.0516*T.^2,0,Tin);
end
HTH

6 Comments

Fawad Ahmed
Fawad Ahmed on 19 Mar 2021
Edited: Fawad Ahmed on 19 Mar 2021
Thankyou for your response Bjorn, my main function is Pf (an integral) with S4 and T as variables, function S4 has a variable Cv4 which is a piecewise function. Kindly check the attached problem.
After a second think-about it seems this is a trivial problem to solve by hand. Just plug in the piecewise expressions for Cv4 into the expression of S4 and then into pf, calculate the the integrals for the 3 different cases for T. This should take you no more than 30 minutes. You will get three integrals for the three ranges of T, the first will be a trivial integral of a T^2, the second integral will be a sum of that integral from 0 to 0.6 and another trivial integral from 0.6 to T, and the third will be of the same form.
HTH
Thankyou Bjorn, you are right about the hand calculation procedure, but I want to implement it as a matlab program.
Well then you either do it by hand and implement that result as a matlab-function, or convert the function S_4_piecewise above to handle array inputs so integral can handle it. Neither of those two procedures should require much work.
Thankyou Bjorn for your response! I need to use the piecewise function becuase i would keep changing my temperature range values in the future which would be much easier if i have a piecewise function. Otherwise i would have to do the hand caluculation all over again evertime i change my temperature range.
Well, then you either put the contents of my function S_4_piecewise inside a loop such that integral can use it, or you do it by hand. And by doing it by hand I mean do it properly, such that you can implement the result in a matlab-function where you also send in parameters for the coefficients and the temperature limits.

Sign in to comment.

More Answers (0)

Products

Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!