Octave で関数の描画
1. 一変数関数の描画
usage:
fplot(fn, limits)
fplot(…, tol)
fplot(…, n)
fplot(…, fmt)
[x, y] = fplot(…)
f 関数(文字列,インライン関数,関数ハンドル)
limits 描画範囲([min, max] または [xmin, xmax, ymin, ymax])
n 描画に使用する点の数
fmt 線種
fplot(@sin, [-10, 10], 201);
fplot("[cos(x), sin(x)]", [0, 2*pi])
warning: inline is obsolete; use anonymous functions instead
clf;
fplot(@cos, [0, 2*pi]);
hold on;
fplot(@sin, [0, 2*pi]);
2. 二次元関数の描画
usage:
ezplot(f)
ezplot(f2v)
ezplot(fx, fy)
ezplot(…, dom)
ezplot(…, n)
ezplot(hax, …)
h = ezplot(…)
2.1. 一変数関数
ezplot(@(x) x.^2 - 3 .* x +5)
2.2. 二変数関数
ezplot(@(x, y) x.^2 - y.^2 - 1)
clf;
hold on;
for c = [-50, -30, -20, -15, -10, 0, 1, 2, 5, 10, 20, 30, 50]
ezplot(@(x, y) (x.^2 + y.^2 - 2 .* x).^3- 4*(x .* y).^2 - c, [-1.5, 3.5, -2.5, 2.5], n=1000)
end
clf;
hold on;
for c = -10:10
ezplot(@(x, y) x.^2 - x .* y + y.^2 - c, [-4, 4], n=1000)
end
3. 等高線図
usage:
ezcontour(f)
ezcontour(…, dom)
ezcontour(…, n)
ezcontour(hax, …)
h = ezcontour(…)
f 関数(文字列,インライン関数,関数ハンドル)
dom 描画範囲([min, max] または [xmin, xmax, ymin, ymax])
clf;
colormap("default");
f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezcontour(f, [-3, 3]);
clf;
colormap("default");
f = @(x,y) 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2);
ezcontour(f, [-3, 3]);
f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezcontourf(f, [-3, 3]);
clf;
colormap("default");
f = @(x,y) 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2);
ezcontourf(f, [-3, 3]);
4. 極座標で関数描画
usage:
ezpolar(f)
ezpolar(…, dom)
ezpolar(…, n)
ezpolar(hax, …)
h = ezpolar(…)
dom 描画範囲を [min, max] で指定する( min ≦ θ max)
n 描画する点の数
hax axes handle
ezpolar(@(t) sin(5/4 * t), [0, 8*pi]);
5. 三次元プロット
5.1. 関数プロット
usage:
ezplot3(fx, fy, fz)
ezplot3(…, dom)
ezplot3(…, n)
ezplot3(…, "animate")
ezplot3(hax, …)
h = ezplot3(…)
clf;
fx = @(t) cos(t);
fy = @(t) sin(t);
fz = @(t) t;
ezplot3(fx, fy, fz, [0, 10*pi], 1000);
5.2. 線で描画(ワイヤーフレーム)
ezmesh(f)
ezmesh(fx, fy, fz)
ezmesh(…, dom)
ezmesh(…, n)
ezmesh(…, "circ")
ezmesh(hax, …)
h = ezmesh(…)
関数名が ezmeshc の場合は,底面に等高線を加える
f = @(x,y) sin(sqrt((x.^ 2 + y .^ 2))) ./ sqrt((x.^ 2 + y .^ 2));
ezmesh(f, [-10, 10]);
ezmeshc(f, [-10, 10]);
f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezmesh(f, [-3, 3]);
f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezmeshc(f, [-3, 3]);
fx = @(s,t) cos(s) .* cos(t);
fy = @(s,t) sin(s) .* cos(t);
fz = @(s,t) sin(t);
ezmesh(fx, fy, fz, [-pi, pi, -pi/2, pi/2], 50);
ezmeshc(fx, fy, fz, [-pi, pi, -pi/2, pi/2], 50);
5.3. 面で描画(サーフェス)
usage:
ezsurf(f)
ezsurf(fx, fy, fz)
ezsurf(…, dom)
ezsurf(…, n)
ezsurf(…, "circ")
ezsurf(hax, …)
h = ezsurf(…)
関数名が ezsurfc の場合は,底面に等高線を加える
colormap("spring");
f = @(x,y) sin(sqrt((x.^ 2 + y .^ 2))) ./ sqrt((x.^ 2 + y .^ 2));
ezsurf(f, [-10, 10]);
clf;
colormap("default");
f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezsurf(f, [-3, 3]);
clf;
colormap("pink");
fx = @(s,t) cos(s) .* cos(t);
fy = @(s,t) sin(s) .* cos(t);
fz = @(s,t) sin(t);
ezsurf(fx, fy, fz, [-pi, pi, -pi/2, pi/2], 50);