フィルターのクリア

How to create this fucntion below

1 回表示 (過去 30 日間)
NoYeah
NoYeah 2020 年 3 月 27 日
コメント済み: Walter Roberson 2020 年 3 月 27 日
I`m very new to matlab and don`t know how to create below function
first, I have made function
fx.m
function result = fx(t)
if -1<=t & t
result = 1;
elseif t>=0 & t
result = -1;
else
result = 0;
end
in console space
t=linspace(0,1);
x=fx(t)
and the compiler said x=0 and that`s it
how to deal with this?
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 27 日
That diagram requires that at t = 0, f(t) is all of the values between -2 and +2 simultaneously. Even if you restrict yourself to numbers that are representable in IEEE 754 double precision, I figure that is 9223372036854775804 different numbers that would have to be returned at f(0) . This is not in any way practical.

サインインしてコメントする。

採用された回答

Birdman
Birdman 2020 年 3 月 27 日
You can try the Symbolic approach:
syms y(t)
y(t)=piecewise(t<-1,0,t>=-1 & t<0,2,t>=0 & t<=1,-2,t>1,0);
%plotting
t=-5:0.001:5;
plot(t,y(t))

その他の回答 (1 件)

Tommy
Tommy 2020 年 3 月 27 日
If you want fx to return an array the same size as t:
function result = fx(t)
result = zeros(size(t)); % f(t) is mostly 0
result(-1<=t & t<0) = 2; % except when t is between -1 and 0, in which case it's 2
result(t>=0 & t<1) = -2; % and when t is between 0 and 1, in which case it's -2
end
Then,
t = linspace(-1.5, 1.5);
x = fx(t);
plot(t, x)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by