Octave Atelier

코드와 해설을 함께 읽는 학습 문서

Code Detail

demo-03a

(번외) 베셀 함수 구경하기

course/basic/demo-03a.m

목록으로

코드를 복사해 Octave에서 바로 실행할 수 있습니다.

카테고리

Course Basic

course-basic

코드 길이

90

lines

작성자

won sunggyu

2025-04-22

패키지

none

pkg load

전체 코드

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

코드 해설

목적

  • (번외) 베셀 함수 구경하기

입력

  • 스크립트 상단에서 정의한 파라미터/입력 데이터를 사용합니다.

출력

  • 그래프/figure 출력
  • 콘솔 텍스트 출력

실행 흐름

  1. 초기화
  2. 데이터 준비
  3. 데이터 연산
  4. 베셀 함수 (4종, 1-4차)
  5. 그래프 그리기
  6. 그래프

핵심 함수

  • ax
  • Kind
  • plot
  • title
  • max
  • In
  • Jn
  • Kn

실습 과제

  • 질량/감쇠/강성 또는 전달함수 계수를 바꿔 응답 변화를 확인해보세요.
  • 축 범위와 라벨을 바꿔 그래프 해석성이 어떻게 달라지는지 확인해보세요.
  • 핵심 함수 ax의 인자를 한 가지 바꿔 결과 변화를 기록해보세요.

학습 팁

  • 그래프 비교 시 축 범위(XLim/YLim)와 단위를 먼저 고정하면 해석 오류를 줄일 수 있습니다.

같은 카테고리 코드

이전 코드 demo-02 다음 코드 demo-03b