main_02_rjw

Statistics + Control & Dynamics 중심의 Octave 학습 예제

ex-recv/02/02_rjw/main_02_rjw.m

코드 인덱스로 돌아가기

카테고리

Submission Archive

학습 소스 그룹

코드 길이

71

lines

작성자

-

날짜 정보 없음

패키지

none

pkg load 기준

전체 코드

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

%main_02_RJW.m
%Goole 2024 주가 데이터 분석
%작성자 : RJW
%작성 날짜 : 2025.03.26
##########################################
clc; clear; close all;

% 1. 입력 변수 준비
filename = 'google_data_2024.csv';
closing_prices = read_csv_data(filename);
save 'closing_prices.mat' closing_prices;
##################################

% 2. 각 연산 함수를 개별적으로 호출
mean_custom = calc_mean(closing_prices); %162.48
var_custom = calc_variance(closing_prices, mean_custom); %243.0047
std_custom = calc_std(var_custom); % 15.5886
rms_custom = calc_rms(closing_prices); % 165.4850

%옥타브 연산 코드로 실행
mean_code = mean(closing_prices);
var_code = var(closing_prices);
std_code = std(closing_prices);
rms_code = sqrt(mean(closing_prices.^2));

%비교
fprintf('Mean: Custom = %.4f, Code-in = %.4f\n', mean_custom, mean_code);
fprintf('Variance: Custom = %.4f, Code-in = %.4f\n', var_custom, var_code);
fprintf('Standard Deviation: Custom = %.4f, Code-in = %.4f\n', std_custom, std_code);
fprintf('RMS: Custom = %.4f, Code-in = %.4f\n', rms_custom, rms_code);
##################################

% 3. 플로팅 변수 준비
window_size = 30;

%평균, 분산, 표준 편차, rms 이동선 (N, 1)
[moving_mean, moving_var, moving_std, moving_rms] = ...
    moving_statistics(closing_prices, window_size);

save 'moving_statistics.mat' moving_mean moving_var moving_std moving_rms;  % 결과 저장

days = (window_size:length(closing_prices)); %x축 day로 표기

% 4. 플로팅
figure(123)
set(gcf, 'position', [100,100,1200,600]);
plot(days, moving_mean, 'b', 'LineWidth', 2); hold on
plot(days, moving_var, 'r', 'LineWidth', 2); hold on
plot(days, moving_std, 'g', 'LineWidth', 2); hold on
plot(days, moving_rms, 'm', 'LineWidth', 2); hold off
grid on
title('30일 이동선','FontSize', 16);
xlabel('Days', 'FontSize', 14);
ylabel('Prices','FontSize', 14);
xlim([0 300])
ylim([0 200])
legend('평균', '분산', '표준 편차', 'RMS');
set(gca, 'fontsize',14)

#######################################









코드 해설

목적

Statistics + Control & Dynamics 중심의 Octave 학습 예제

입력

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

출력

  • 그래프/figure 출력

실행 흐름

  1. Goole 2024 주가 데이터 분석
  2. 1. 입력 변수 준비
  3. 2. 각 연산 함수를 개별적으로 호출
  4. 옥타브 연산 코드로 실행

핵심 함수/주제

fprintfplotmeansetcalc_meancalc_rmscalc_stdcalc_variance

실습 과제

  • 같은 연산을 내장 함수와 사용자 함수 두 방식으로 계산해 오차를 비교해보세요.
  • 질량/감쇠/강성 또는 전달함수 계수를 바꿔 응답 변화를 확인해보세요.
  • 축 범위와 라벨을 바꿔 그래프 해석성이 어떻게 달라지는지 확인해보세요.

학습 팁

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

같은 카테고리의 다른 코드