필터 지우기
필터 지우기

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 CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by