Octave で関数の描画

# 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    線種


```matlab
fplot(@sin, [-10, 10], 201);
```


    
![output_1_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/de8cb3cb-b5e2-f948-b9c0-e20c135232a7.png)

    



```matlab
fplot("[cos(x), sin(x)]", [0, 2*pi])
```

    warning: inline is obsolete; use anonymous functions instead



    
![output_2_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/834866b9-73d1-aa22-46ad-8943f41874b0.png)    



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


    
![output_3_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/ea7756c1-70a7-bf2f-d86e-b822a6a81cbd.png)
   


## 2.　二次元関数の描画

    usage:
    ezplot(f)
    ezplot(f2v)
    ezplot(fx, fy)
    ezplot(…, dom)
    ezplot(…, n)
    ezplot(hax, …)
    h = ezplot(…)

### 2.1.　一変数関数


```matlab
ezplot(@(x) x.^2 - 3 .* x +5)
```


![output_5_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/f806da6b-b36f-06fd-8555-861fc2abb382.png)
  


### 2.2.　二変数関数


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


    
![output_7_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/3b2a47b4-cc95-63e1-75f3-ca6de9bc7812.png)




```matlab
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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/e35c4644-eef8-4eb0-15c0-56a1143ec1d6.png)




```matlab
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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/0bae6648-1005-6352-c3d1-b146f538740f.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]);


```matlab
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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/445b86a4-d2b2-174a-9403-250c9698a094.png)




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


    
![output_12_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/d143b23f-4c2b-0e10-8748-8822a9a19c3e.png)




```matlab
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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/f70091aa-28be-f280-7f75-ddd7950a4baa.png)



## 4.　極座標で関数描画

    usage:
    ezpolar(f)
    ezpolar(…, dom)
    ezpolar(…, n)
    ezpolar(hax, …)
    h = ezpolar(…)
    
    dom    描画範囲を [min, max] で指定する（　min ≦ θ max）
    n      描画する点の数
    hax    axes handle


```matlab
ezpolar(@(t) sin(5/4 * t), [0, 8*pi]);
```


    
![output_15_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/73a6499f-a49c-7c14-6534-da0fe6004264.png)



## 5.　三次元プロット

### 5.1.　関数プロット

    usage:
    ezplot3(fx, fy, fz)
    ezplot3(…, dom)
    ezplot3(…, n)
    ezplot3(…, "animate")
    ezplot3(hax, …)
    h = ezplot3(…)


```matlab
clf;
fx = @(t) cos(t);
fy = @(t) sin(t);
fz = @(t) t;
ezplot3(fx, fy, fz, [0, 10*pi], 1000);
```


    
![output_17_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/28dfc101-a5b0-70a9-4713-caa54313cf0d.png)



### 5.2.　線で描画（ワイヤーフレーム）

    ezmesh(f)
    ezmesh(fx, fy, fz)
    ezmesh(…, dom)
    ezmesh(…, n)
    ezmesh(…, "circ")
    ezmesh(hax, …)
    h = ezmesh(…)
    
    関数名が ezmeshc の場合は，底面に等高線を加える


```matlab
f = @(x,y) sin(sqrt((x.^ 2 + y .^ 2))) ./ sqrt((x.^ 2 + y .^ 2));
ezmesh(f, [-10, 10]);
```


    
![output_19_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/98bee419-a9d5-6fa2-9e81-b06e7a525165.png)




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


    
![output_20_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/b8035aaa-1838-5f1f-6af3-5564353dedd8.png)




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


    

![output_21_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/11e2f7d2-3ecf-68ac-e7ed-a2ea48f6a34c.png)




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



    
![output_22_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/90b2f802-331f-c871-c55a-45aad0ca0be3.png)



```matlab
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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/a53026d9-2cd5-f9ab-b7e6-6b20aeab66ef.png)



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


    
    
![output_24_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/4ed78b54-f9bc-8a83-87d4-f4c14f41bf12.png)


### 5.3.　面で描画（サーフェス）

    usage:
    ezsurf(f)
    ezsurf(fx, fy, fz)
    ezsurf(…, dom)
    ezsurf(…, n)
    ezsurf(…, "circ")
    ezsurf(hax, …)
    h = ezsurf(…)
    
    関数名が ezsurfc の場合は，底面に等高線を加える


```matlab
colormap("spring");
f = @(x,y) sin(sqrt((x.^ 2 + y .^ 2))) ./ sqrt((x.^ 2 + y .^ 2));
ezsurf(f, [-10, 10]);
```


    
![output_26_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/84944520-a3bf-5f02-2d7b-0ea2a914a32c.png)



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

    
![output_27_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/8901644a-c681-56b4-4f19-cc86b36c40e4.png)



```matlab
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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2611739/19ee336f-2a64-c6d7-7809-f60645a73b63.png)