matlab piece wise function

조회 수: 4 (최근 30일)
Victor Parra
Victor Parra 2021년 1월 25일
댓글: Victor Parra 2021년 1월 25일
Hello everyone,
I have this piece-wise function uEx as a function of some integers x and t. But I really can't decypher what exactly is going to turn out. Could you please help me to translate it to mathematical language?
uEx =@(x,t) (x>-0.5).*(x<0.5+0.5.*t).*(1.*(x>-0.5+t) + (x+0.5)./(1.0*t).*(x<-0.5+t));
Thanks :)

답변 (1개)

Walter Roberson
Walter Roberson 2021년 1월 25일
(x>-0.5)
So x is greater than -1/2
(x<0.5+0.5.*t)
and x < 1/2 + t/2.
If x is not in that range the the overall result will be 0. If it is in that range then the overall result is determined by the remainder:
(1.*(x>-0.5+t) + (x+0.5)./(1.0*t).*(x<-0.5+t))
That breaks into two contributions:
1.*(x>-0.5+t)
which is 1 if x > t - 1/2 and 0 otherwise
(x+0.5)./(1.0*t).*(x<-0.5+t)
which is (x + 1/2)/t if x < t - 1/2 and 0 otherwise.
Putting the parts together:
if x > -1/2 & x < (t+1)/2 & x < t - 1/2 then (x + 1/2)/t
if x > -1/2 & x < (t+1)/2 & x > t - 1/2 then 1
otherwise 0
There is probably a bug in the formula. Consider x = t - 1/2 then x > -0.5+t is false because x == -0.5+t and the > is strict not >= . So the case that contributes 1 is not invoked. And x<-0.5+t is false becuase x == -0.5+t and the < is strict not <= so the case that contributs (x+1/2)/t is not invoked. So at x = t - 1/2 neither branch is invoked and you are left with all 0. But if you examine the limit as x = t - 1/2 then if x >= t - 1/2 instead of x > t - 1/2 were coded then the contribution would be 1; if x <= t-1/2 instead of x<t-1/2 then (x+1/2)/t would be (t-1/2+1/2)/t which would be (t+0)/t which would be 1 unless t = 0 . The left and right side would both lead to 1 at that case, so the limit would be 1... but the code gives 0. Likely a bug.
The whole formula will fail for t == 0 exactly. The division by 1.0*t would give infinity and infinity times 0 gives nan.
  댓글 수: 1
Victor Parra
Victor Parra 2021년 1월 25일
Thank you so much!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Boundary Conditions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by