Translation of a function

16 visualizaciones (últimos 30 días)
Andrew Harris
Andrew Harris el 14 de Oct. de 2015
Editada: John D'Errico el 14 de Oct. de 2015
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))

Respuesta aceptada

John D'Errico
John D'Errico el 14 de Oct. de 2015
Editada: John D'Errico el 14 de Oct. de 2015
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.

Más respuestas (0)

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by