Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

모델 파라미터 값 추정하기(코드)

이 예제에서는 실험 데이터를 사용하여 모델 파라미터 값을 추정하는 방법을 보여줍니다.

항공기 모델

Simulink® 모델 sdoAircraftEstimation은 항공기의 세로 방향 비행 제어 시스템을 모델링합니다.

open_system('sdoAircraftEstimation')

추정 문제

측정된 데이터를 사용하여 항공기 모델 파라미터와 상태를 추정합니다.

측정된 출력 데이터:

  • 조종사 관성력, 즉 Pilot G-force calculation 블록의 출력값

  • 받음각(angle of attack), 즉 Aircraft Dynamics Model 블록의 네 번째 출력값

파라미터:

  • 액추에이터 시정수 Ta(Actuator Model 블록에서 사용)

  • 수직 속도 Zd(Aircraft Dynamics Model 블록에서 사용)

  • 피치 레이트 이득 Md(Aircraft Dynamics Model 블록에서 사용)

상태:

  • 1차 액추에이터 모델(sdoAircraftEstimation/Actuator 모델)의 초기 상태

추정 실험 정의하기

측정된 데이터를 가져옵니다.

[time,iodata] = sdoAircraftEstimation_Experiment;

sdoAircraftEstimation_Experiment 함수는 측정된 출력 데이터 iodata와 이에 대응되는 시간 벡터를 반환합니다. iodata의 첫 번째 열은 조종사 관성력이고 두 번째 열은 받음각입니다.

이 함수의 코드를 보려면 edit sdoAircraftEstimation_Experiment를 입력합니다.

실험 객체를 만들어 측정된 입력/출력 데이터를 저장합니다.

Exp = sdo.Experiment('sdoAircraftEstimation');

객체를 만들어 측정된 조종사 관성력 출력값을 저장합니다.

PilotG = Simulink.SimulationData.Signal;
PilotG.Name      = 'PilotG';
PilotG.BlockPath = 'sdoAircraftEstimation/Pilot G-force calculation';
PilotG.PortType  = 'outport';
PilotG.PortIndex = 1;
PilotG.Values    = timeseries(iodata(:,2),time);

객체를 만들어 측정된 받음각(alpha) 출력값을 저장합니다.

AoA = Simulink.SimulationData.Signal;
AoA.Name = 'AngleOfAttack';
AoA.BlockPath = 'sdoAircraftEstimation/Aircraft Dynamics Model';
AoA.PortType  = 'outport';
AoA.PortIndex = 4;
AoA.Values    = timeseries(iodata(:,1),time);

측정된 조종사 관성력 데이터와 받음각 데이터를 예상 출력 데이터로 실험에 추가합니다.

Exp.OutputData = [...
    PilotG; ...
    AoA];

Actuator Model 블록의 초기 상태를 실험에 추가합니다. 추정이 이루어지도록 초기 상태의 Free 필드를 true로 설정합니다.

Exp.InitialStates = sdo.getStateFromModel('sdoAircraftEstimation','Actuator Model');
Exp.InitialStates.Minimum = 0;
Exp.InitialStates.Free    = true;

측정된 출력과 초기의 시뮬레이션된 출력 비교하기

실험을 사용하여 시뮬레이션 시나리오를 만들고 시뮬레이션된 출력을 가져옵니다.

Simulator    = createSimulator(Exp);
Simulator    = sim(Simulator);

기록된 시뮬레이션 데이터에서 조종사 관성력 신호와 받음각 신호를 검색합니다.

SimLog       = find(Simulator.LoggedData,get_param('sdoAircraftEstimation','SignalLoggingName'));
PilotGSignal = find(SimLog,'PilotG');
AoASignal    = find(SimLog,'AngleOfAttack');

측정된 데이터와 시뮬레이션된 데이터를 플로팅합니다.

예상대로, 모델 응답은 실험 출력 데이터와 일치하지 않습니다.

plot(time, iodata, ...
    AoASignal.Values.Time,AoASignal.Values.Data,'--', ...
    PilotGSignal.Values.Time,PilotGSignal.Values.Data,'-.');
title('Simulated and Measured Responses Before Estimation')
legend('Measured angle of attack',  'Measured pilot g force', ...
     'Simulated angle of attack', 'Simulated pilot g force');

추정할 파라미터 지정하기

비행 제어 액추에이션 시스템을 설명하는 모델 파라미터를 선택합니다. 액추에이션 시스템에 대한 이해를 기반으로, 추정된 파라미터 값의 범위를 지정합니다.

p = sdo.getParameterFromModel('sdoAircraftEstimation',{'Ta','Md','Zd'});
p(1).Minimum = 0.01;  %Ta
p(1).Maximum = 1;
p(2).Minimum = -10;   %Md
p(2).Maximum = 0;
p(3).Minimum = -100;  %Zd
p(3).Maximum = 0;

실험에서 추정할 액추에이터 초기 상태 값을 가져옵니다.

s = getValuesToEstimate(Exp);

함께 추정할 모델 파라미터와 초기 상태를 그룹화합니다.

v = [p;s]
 
v(1,1) =
 
       Name: 'Ta'
      Value: 0.5000
    Minimum: 0.0100
    Maximum: 1
       Free: 1
      Scale: 0.5000
       Info: [1x1 struct]

 
v(2,1) =
 
       Name: 'Md'
      Value: -1
    Minimum: -10
    Maximum: 0
       Free: 1
      Scale: 1
       Info: [1x1 struct]

 
v(3,1) =
 
       Name: 'Zd'
      Value: -80
    Minimum: -100
    Maximum: 0
       Free: 1
      Scale: 128
       Info: [1x1 struct]

 
v(4,1) =
 
       Name: 'sdoAircraftEstimation/Actuator...'
      Value: 0
    Minimum: 0
    Maximum: Inf
       Free: 1
      Scale: 1
    dxValue: 0
     dxFree: 1
       Info: [1x1 struct]

 
4x1 param.Continuous
 

추정 목적 함수 정의하기

추정된 파라미터 값을 사용하여 생성된 시뮬레이션 출력이 측정된 데이터와 얼마나 근접하게 일치하는지 평가하기 위해 추정 목적 함수를 만듭니다.

sdoAircraftEstimation_Objective 함수를 호출하는 하나의 입력 인수를 갖는 익명 함수를 사용합니다. 각 최적화 반복에서 함수를 실행하는 sdo.optimize에 익명 함수를 전달합니다.

estFcn = @(v) sdoAircraftEstimation_Objective(v,Simulator,Exp);

sdoAircraftEstimation_Objective 함수:

  • 액추에이터 파라미터 값과 액추에이터 초기 상태를 지정하는 하나의 입력 인수를 갖습니다.

  • 측정된 데이터가 포함된 실험 객체를 지정하는 하나의 입력 인수를 갖습니다.

  • 시뮬레이션된 출력과 실험 출력 간의 오차로 구성된 벡터를 반환합니다.

sdoAircraftEstimation_Objective 함수에는 두 개의 입력값이 필요하지만 sdo.optimize에는 하나의 입력 인수를 갖는 함수가 필요합니다. 이를 해결하기 위해, estFcn은 하나의 입력 인수 v를 갖는 익명 함수이지만 두 개의 입력 인수 vExp를 사용하여 sdoAircraftEstimation_Objective를 호출합니다.

익명 함수에 대한 자세한 내용은 익명 함수 항목을 참조하십시오.

sdo.optimize 명령은 익명 함수 estFcn의 반환 인수(즉, sdoAircraftEstimation_Objective에서 반환되는 잔차 오차)를 최소화합니다. sdo.optimize 명령과 함께 사용할 목적/제약 조건 함수를 작성하는 방법에 대한 자세한 내용을 보려면 MATLAB® 명령 프롬프트에서 help sdoExampleCostFunction을 입력하십시오.

추정 목적 함수를 더 자세히 살펴보려면 MATLAB 명령 프롬프트에서 edit sdoAircraftEstimation_Objective를 입력하십시오.

type sdoAircraftEstimation_Objective
function vals = sdoAircraftEstimation_Objective(v,Simulator,Exp) 
%SDOAIRCRAFTESTIMATION_OBJECTIVE
%
%    The sdoAircraftEstimation_Objective function is used to compare model
%    outputs against experimental data.
%
%    vals = sdoAircraftEstimation_Objective(v,Exp) 
%
%    The |v| input argument is a vector of estimated model parameter values
%    and initial states.
%
%    The |Simulator| input argument is a simulation object used 
%    simulate the model with the estimated parameter values.
%
%    The |Exp| input argument contains the estimation experiment data.
%
%    The |vals| return argument contains information about how well the
%    model simulation results match the experimental data and is used by
%    the |sdo.optimize| function to estimate the model parameters.
%
%    See also sdo.optimize, sdoExampleCostFunction,
%    sdoAircraftEstimation_cmddemo
%
 
% Copyright 2012-2015 The MathWorks, Inc.

%%
% Define a signal tracking requirement to compute how well the model output
% matches the experiment data. Configure the tracking requirement so that
% it returns the tracking error residuals (rather than the
% sum-squared-error) and does not normalize the errors.
%
r = sdo.requirements.SignalTracking;
r.Type      = '==';
r.Method    = 'Residuals';
r.Normalize = 'off';

%%
% Update the experiments with the estimated parameter values.
%
Exp  = setEstimatedValues(Exp,v);

%%
% Simulate the model and compare model outputs with measured experiment
% data.
%
Simulator = createSimulator(Exp,Simulator);
Simulator = sim(Simulator);

SimLog       = find(Simulator.LoggedData,get_param('sdoAircraftEstimation','SignalLoggingName'));
PilotGSignal = find(SimLog,'PilotG');
AoASignal    = find(SimLog,'AngleOfAttack');

PilotGError = evalRequirement(r,PilotGSignal.Values,Exp.OutputData(1).Values);
AoAError    = evalRequirement(r,AoASignal.Values,Exp.OutputData(2).Values);

%%
% Return the residual errors to the optimization solver.
%
vals.F = [PilotGError(:); AoAError(:)];
end

파라미터 추정하기

sdo.optimize 함수를 사용하여 액추에이터 파라미터 값과 초기 상태를 추정합니다.

최적화 옵션을 지정합니다. 추정 함수 sdoAircraftEstimation_Objective는 시뮬레이션된 데이터와 실험 데이터 간의 오차 잔차를 반환하며 제약 조건을 포함하지 않습니다. 이 예제에서는 lsqnonlin 솔버를 사용합니다.

opt = sdo.OptimizeOptions;
opt.Method = 'lsqnonlin';

파라미터를 추정합니다.

vOpt = sdo.optimize(estFcn,v,opt)
 Optimization started 2023-Sep-27, 03:27:47

                                          First-order 
 Iter F-count        f(x)      Step-size  optimality
    0      8      27955.2            1
    1     17      10121.6       0.4744     5.68e+04
    2     26      3127.21        0.385     1.24e+04
    3     35        872.7       0.4291     2.81e+03
    4     44      238.697       0.5151          618
    5     53      71.8976       0.4934          147
    6     62      17.2406       0.4242         44.1
    7     71      1.87093       0.2937         11.9
    8     80    0.0435025       0.1403         1.46
    9     89  0.000712311      0.02668        0.133
   10     98  0.000153464      0.00737      0.00688
Local minimum possible.

lsqnonlin stopped because the final change in the sum of squares relative to 
its initial value is less than the value of the function tolerance.
 
vOpt(1,1) =
 
       Name: 'Ta'
      Value: 0.0500
    Minimum: 0.0100
    Maximum: 1
       Free: 1
      Scale: 0.5000
       Info: [1x1 struct]

 
vOpt(2,1) =
 
       Name: 'Md'
      Value: -6.8848
    Minimum: -10
    Maximum: 0
       Free: 1
      Scale: 1
       Info: [1x1 struct]

 
vOpt(3,1) =
 
       Name: 'Zd'
      Value: -63.9982
    Minimum: -100
    Maximum: 0
       Free: 1
      Scale: 128
       Info: [1x1 struct]

 
vOpt(4,1) =
 
       Name: 'sdoAircraftEstimation/Actuator...'
      Value: 1.0434e-04
    Minimum: 0
    Maximum: Inf
       Free: 1
      Scale: 1
    dxValue: 0
     dxFree: 1
       Info: [1x1 struct]

 
4x1 param.Continuous
 

측정된 출력과 시뮬레이션된 최종 출력 비교하기

추정된 파라미터 값으로 실험을 업데이트합니다.

Exp = setEstimatedValues(Exp,vOpt);

업데이트된 실험을 사용하여 모델을 시뮬레이션하고 시뮬레이션된 데이터를 실험 데이터와 비교합니다.

추정된 파라미터 값을 사용한 모델 응답은 실험 출력 데이터와 근접하게 일치합니다.

Simulator    = createSimulator(Exp,Simulator);
Simulator    = sim(Simulator);
SimLog       = find(Simulator.LoggedData,get_param('sdoAircraftEstimation','SignalLoggingName'));
PilotGSignal = find(SimLog,'PilotG');
AoASignal    = find(SimLog,'AngleOfAttack');

plot(time, iodata, ...
    AoASignal.Values.Time,AoASignal.Values.Data,'-.', ...
    PilotGSignal.Values.Time,PilotGSignal.Values.Data,'--')
title('Simulated and Measured Responses After Estimation')
legend('Measured angle of attack',  'Measured pilot g force', ...
    'Simulated angle of attack', 'Simulated pilot g force');

모델 파라미터 값 업데이트하기

추정된 액추에이터 파라미터 값으로 모델을 업데이트합니다. 모델 액추에이터 초기 상태(vOpt의 네 번째 요소)는 실험에 따라 달라지므로 업데이트하지 마십시오.

sdo.setValueInModel('sdoAircraftEstimation',vOpt(1:3));

관련 예제

파라미터 추정기 앱을 사용하여 모델 파라미터를 추정하는 방법을 알아보려면 모델 파라미터 값 추정하기(GUI) 항목을 참조하십시오.

모델을 닫습니다.

bdclose('sdoAircraftEstimation')