Indicator Function Error

10 ビュー (過去 30 日間)
Ammar
Ammar 2011 年 11 月 3 日
I am trying to define a piece-wise function over several different intervals. However, the indicator function won't let the function evaluate for a specified input value. It keeps telling me that input argument a is undefined. I can't seem to figure out what I am doing wrong though. Here is what I have:
v = @(t,a,b) (t>=a) & (t<b);
f=@(t) 0.*v(t<0) + 2*t.*v(0<=t & t<0.5) + 0.*v(t==0.5) + ...
(2*t-2).*v(t,0.5,1) + 0.*v(t>=1)
t=[0:0.01:1];
The program won't let me evaluate f(t). Also, am I allowed to set the intervals as logicals or do I have to have values? This is not covered in my book or in my lecture notes. Thanks for the help.

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
Your v is an anonymous function. It has three input arguments.
In your f (also an anonymous function), there are v(t<0), v(0<=t & t<0.5), v(t==0.5) and v(t>=1). All just have one input argument. That is why it complains that the second input argument a is not provided.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStair Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by