フィルターのクリア

Translation of a function

6 ビュー (過去 30 日間)
Andrew Harris
Andrew Harris 2015 年 10 月 14 日
編集済み: John D'Errico 2015 年 10 月 14 日
This has to be simpler than I'm making it. I have a function f(x) = 1-abs(x) where -1<x<1 and f(x) = 0 otherwise. I want to evaluate it for a translation f(x-2) and f(x-3). In algebra I know this should just take the initial function graph and move it to the right, however evaluating it in MATLAB changes the function from a triangle to a straight line, and over the wrong range. Any ideas what I'm missing?
f = @(x) 1-abs(x)
x = linspace(-1, 1)
figure
plot(x, f(x))
x1 = linspace(1, 3);
x2 = linspace(2, 4);
figure
plot(x1, f(x-2))
hold on
plot(x2, f(x-3))

採用された回答

John D'Errico
John D'Errico 2015 年 10 月 14 日
編集済み: John D'Errico 2015 年 10 月 14 日
Try this modification instead. You almost had it right.
f = @(x) max(1-abs(x),0);
ezplot(f,-3,3)
ezplot(@(x) f(x-1),-3,3)
In your original function, when you translated it, you were seeing only one half of the abs function, and you were allowing it to go to -inf. The max that I added cuts off the function when it wants to go negative.

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by