Problem with piece-wise function with logical indexing.
이전 댓글 표시
I created the following piece-wise fuction using logical indexing.
%Piece-wise function
F = @(coef,t) ((t < 0).*...
0 + ...
(t >= 0 & t < 1200).*...
(1/coef(1) + t./coef(2) + 1/(coef(3))*(1-exp(-t))) + ...
(t >= 1200).*...
(1200/coef(2) + 1/(coef(3))*(1-exp(-t)) - 1/(coef(3))*(1-exp(-(t-1200)))));
coef0 = [200, 200000, 100];
% Test that function is valid for wide range of t.
x = linespace(-10, 1300, 1310);
plot(x,F(coef0,x))
I must be missing somethign in the syntax. The function is invalid when t<~500. The rest of the graph looks correct. When I poke around, it seems that the very last part of the fuction:
exp(-(t-1200))
is being evaluated outside of it's defined region (t >= 1200). And when t< ~500, it blows up and goes to inf.
댓글 수: 3
madhan ravi
2019년 4월 8일
Also did you notice the first 10 elements becomes NaN?? illustrate with a picture.
Bryan Wilson
2019년 4월 8일
Bryan Wilson
2019년 4월 8일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

