Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

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 で「ソンブレロ」を描画

Last updated at Posted at 2022-07-27

Octave で「ソンブレロ」を描画

3 次元空間の曲面,いわゆる「ソンブレロ」を描く。

z = sin(sqrt(x^2 + y^2)) / (sqrt(x^2 + y^2))

$z = \displaystyle \frac{\sin \big(\sqrt{x^2 + y^2}\big)}{\sqrt{x^2 + y^2}}$

sombrero()
sombrero(n)
z = sombrero(…)
[x, y, z] = sombrero(…)

Plot the familiar 3-D sombrero function.
The function plotted is

引数無しで呼べば [-8, 8] での曲面を描く。

n がスカラーならば n 本のグリッドで曲面を描く(n=41 がデフォルト)。

戻り値を 1 個指定した場合は z 座標値を返す。

戻り値を 3 個指定した場合は x, y, z 座標値を返し,引き続いて surf(x, y, z) で曲面, mesh(x, y, z) でワイヤーフレームを描くことができる。

sombrero()

output_1_0.png

colormap("pink")
sombrero(100)

output_2_0.png

[x, y, z] = sombrero(21);
colormap("autumn")
surf(x, y, z)

output_3_0.png

colormap("spring")
mesh(x, y, z)

output_4_0.png

sombrero() の結果を使わずに meshgrid() を計算し,z 座標を計算して,さらに mesh() でワイヤーフレームを描くのは以下のようになる。

colormap("summer")
tx = ty = linspace(-8, 8, 21)';
[x, y] = meshgrid(tx, ty);
r = sqrt(x .^ 2 + y .^ 2) + eps;
z = sin(r) ./ r;
mesh(x, y, z);
xlabel("x");
ylabel("y");
zlabel("z");
title("3-D Sombrero plot");

output_6_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

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

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?