我尝试使用自己的模型使用最小二乘法找到系统参数的值,即(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
我试图将REGRESSOR与我自己的模型相匹配,但它总是显示错误,我犯了错误?
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)
提前致谢
答案 0 :(得分:0)
尝试:
Color c = Color.FromArgb(84, 141, 212);
parag.Range.Font.TextColor.RGB = (c.R + 0x100 * c.G + 0x10000 * c.B)
或者:
Reg=zeros(6,2);
for ii=2:length(to)
Reg(ii-1,:) = [(((1/2*t)*(to(ii)*to(ii-1)))- (1/2*t)*(tz(ii)*tz(ii-1))),...
(((1/2*t)*(tn(ii)*tn(ii-1)))- (1/2*t)*(tx(ii)*tx(ii-1)))];
end
Reg1 = [(((1/2*t)*(to(1:end-1).*to(2:end)))- (1/2*t)*(tz(1:end-1).*tz(2:end))),...
(((1/2*t)*(tn(1:end-1).*tn(2:end)))- (1/2*t)*(tx(1:end-1).*tx(2:end)))];
告诉我他们会得到相同的答案。
但是,由于isequal
的第二列全部为零而Reg
将成为Par(2)
,因此您的数据必定存在问题。