関数 y(x) の値を x の異なる値 (y(x) < 5) で見たい:
y = abs(x)+abs(x+2)-5
どうすればいいですか?
fplot(@(x) abs(x)+abs(x+2)-5, [-10 10])
hold all
fplot(@(x) 5, [-10 10])
legend({'y=abs(x)+abs(x+2)-5' 'y=5'})
値のベクトルを作成し、x
そのベクトルを調べy
たり、プロットしたりできます。
% Create a vector with 20 equally spaced entries in the range [-1,1].
x = linspace(-1,1,20);
% Calculate y, and see the result
y = abs(x) + abs(x + 2) - 5
% Plot.
plot(x, y);
% View the minimum and maximum.
min(y)
max(y)
% create a vector x with values between 1 and 5
x = 1:0.1:5;
% create a vector y with your function
y = abs(x) + abs(x+2) - 5;
% find all elements in y that are under 5
y(find(y<5))