1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Octave で関数の描画

Posted at

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);

output_1_0.png

fplot("[cos(x), sin(x)]", [0, 2*pi])
warning: inline is obsolete; use anonymous functions instead

output_2_1.png

clf;
fplot(@cos, [0, 2*pi]);
hold on;
fplot(@sin, [0, 2*pi]);

output_3_0.png

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)

output_5_0.png

2.2. 二変数関数

ezplot(@(x, y) x.^2 - y.^2 - 1)

output_7_0.png

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

output_8_0.png

clf;
hold on;
for c = -10:10
    ezplot(@(x, y) x.^2 - x .* y + y.^2 - c, [-4, 4], n=1000)
end

output_9_0.png

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]);

output_11_0.png

f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezcontourf(f, [-3, 3]);

output_12_0.png

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]);

output_13_0.png

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]);

output_15_0.png

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);

output_17_0.png

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]);

output_19_0.png

ezmeshc(f, [-10, 10]);

output_20_0.png

f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezmesh(f, [-3, 3]);

output_21_0.png

f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
ezmeshc(f, [-3, 3]);

output_22_0.png

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);

output_23_0.png

ezmeshc(fx, fy, fz, [-pi, pi, -pi/2, pi/2], 50);

output_24_0.png

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]);

output_26_0.png

clf;
 colormap("default");
 f = @(x,y) sqrt(abs(x .* y)) ./ (1 + x.^2 + y.^2);
 ezsurf(f, [-3, 3]);

output_27_0.png

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);

output_28_0.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?