我试图通过我自己的模型使用最小二乘来找到系统参数的值,即(a1 和 a2)。
我的模型是 MISO 系统: % tz(k) = a1*(((1/2*t)*(to*to(k-1)))- (1/2*t)*(tz*tz(k-1))) + a2*(((1/2*t)*(tn*tn(k-1)))- (1/2*t)*(tx*tx(k-1)));
我计算参数的方法:Xθ = (X'X)^(-1)X'Y
我试图用我自己的模型来拟合回归器,但它总是显示错误,我哪里出错了??
close all;
clear all;
clc;
%% =====================
% MISO system using Least Square
% Model of the system, described by diference equation
% tz(k) = a1*(((1/2*t)*(to*to(k-1)))- (1/2*t)*(tz*tz(k-1))) + a2*(((1/2*t)*(tn*tn(k-1)))- (1/2*t)*(tx*tx(k-1)));
% Sample Data input and output of the system,
t = 15 ; %sampling time 15 minutes
to=[23; 23; 23; 23; 23; 23; 23;]; %input 1
tz=[26; 27; 27; 27; 26; 27; 26]; %output
tn=[26; 27; 27; 27; 26; 27; 26]; %input 2
tx=[26; 27; 27; 27; 26; 27; 26]; %input 3
% Problem: Find the value of a1 and a2 with Least Square Algorithm.
%% =====================
% Least Square
% model: Y=Reg*Par;
% Reg: regresor, Par: parameter.
% Arranging elemen Y, Reg, and Par:
% Y=[y(2); ...; y(N);
% Reg=[-y(1) u(1); ....; -y(N-1) u(N-1)];
% Reg=[-y(1) u(1); ....; -y(N-1) u(N-1)];
% Par=[a1;b1];
% Find value of Parameter:
% Par=(Reg.'*Reg)\Reg.'*Y;
%% =====================
% Program MATLAB
N=length(tz); % Count Total element vektor tz.
% Register elemen Y
Y=tz(2:end,1);
% Register elemen Regressor
Reg=[((1/2*t)*to*(to(1:N-1,1)))-((1/2*t)*tz*(tz(1:N-1,1))) ((1/2*t)*tn*(tx(1:N-1,1)))-((1/2*t)*tn*(tx(1:N-1,1)))];
% Least Square for getting the value of a1 and b4:
Par=(Reg.'*Reg)\Reg.'*Y;
disp('Value of a1 and a2 :');
a1=Par(1)
a2=Par(2)
提前致谢