카테고리
Course Basiccourse-basic
코드와 해설을 함께 읽는 학습 문서
Code Detail
(번외) 베셀 함수 구경하기
course/basic/demo-03a.m
코드를 복사해 Octave에서 바로 실행할 수 있습니다.
90 lines
# filename: demo-03a.m
# writer: won sunggyu
# date: 2025-04-22
# language: octave
# description: (번외) 베셀 함수 구경하기
#------------------------------------------------------------------------------
# 초기화
#------------------------------------------------------------------------------
run("startup.m");
printf(fmt("{mfilename}\n", "#FF5733"));
#------------------------------------------------------------------------------
# 데이터 준비
#------------------------------------------------------------------------------
dx = 0.1;
nx = 1000;
x = 0:dx:dx*(nx-1);
#------------------------------------------------------------------------------
# 데이터 연산
#------------------------------------------------------------------------------
# 베셀 함수 (4종, 1-4차)
Jn = zeros(4, nx); # Bessel function of the first kind (Jₙ(x))
Yn = zeros(4, nx); # Bessel function of the second kind (Yₙ(x))
In = zeros(4, nx); # Bessel function of the third kind (Iₙ(x))
Kn = zeros(4, nx); # Bessel function of the fourth kind (Kₙ(x))
for i=1:4
Jn(i, :) = besselj(i, x);
Yn(i, :) = bessely(i, x);
In(i, :) = besseli(i, x);
Kn(i, :) = besselk(i, x);
end
Yn = Yn / max(max(abs(Yn)));
In = In / max(max(abs(In)));
Kn = Kn / max(max(abs(Kn)));
#------------------------------------------------------------------------------
# 그래프 그리기
#------------------------------------------------------------------------------
# 그래프
figured("Size", [1920, 960], "Move", [0, 0], "Name", mfilename);
ax = subplots(4, 4);
plot(ax(1, 1), x, Jn(1, :));
plot(ax(2, 1), x, Jn(2, :));
plot(ax(3, 1), x, Jn(3, :));
plot(ax(4, 1), x, Jn(4, :));
plot(ax(1, 2), x, Yn(1, :));
plot(ax(2, 2), x, Yn(2, :));
plot(ax(3, 2), x, Yn(3, :));
plot(ax(4, 2), x, Yn(4, :));
plot(ax(1, 3), x, In(1, :));
plot(ax(2, 3), x, In(2, :));
plot(ax(3, 3), x, In(3, :));
plot(ax(4, 3), x, In(4, :));
plot(ax(1, 4), x, Kn(1, :));
plot(ax(2, 4), x, Kn(2, :));
plot(ax(3, 4), x, Kn(3, :));
plot(ax(4, 4), x, Kn(4, :));
title(ax(1, 1), "Bessel Function of the First Kind (J₀(x))");
title(ax(2, 1), "Bessel Function of the First Kind (J₁(x))");
title(ax(3, 1), "Bessel Function of the First Kind (J₂(x))");
title(ax(4, 1), "Bessel Function of the First Kind (J₃(x))");
title(ax(1, 2), "Bessel Function of the Second Kind (Y₀(x))");
title(ax(2, 2), "Bessel Function of the Second Kind (Y₁(x))");
title(ax(3, 2), "Bessel Function of the Second Kind (Y₂(x))");
title(ax(4, 2), "Bessel Function of the Second Kind (Y₃(x))");
title(ax(1, 3), "Bessel Function of the Third Kind (I₀(x))");
title(ax(2, 3), "Bessel Function of the Third Kind (I₁(x))");
title(ax(3, 3), "Bessel Function of the Third Kind (I₂(x))");
title(ax(4, 3), "Bessel Function of the Third Kind (I₃(x))");
title(ax(1, 4), "Bessel Function of the Fourth Kind (K₀(x))");
title(ax(2, 4), "Bessel Function of the Fourth Kind (K₁(x))");
title(ax(3, 4), "Bessel Function of the Fourth Kind (K₂(x))");
title(ax(4, 4), "Bessel Function of the Fourth Kind (K₃(x))");