Why do I get the error 'The number of inputs and outputs of the model must match that of the data.'?

12 Ansichten (letzte 30 Tage)
I am attempting to run a nonlinear grey box estimation on a defined ODE function, and I keep recieving the same error, no matter what I change. I don't see where the problem comes from. I have tried to change the input, but that has not worked. Here are the three files:
%6-11-19
%u = [u0*sin(w*t); u0*w*cos(w*t)];
function [dx, y] = DOF1damped(t, x, u, w, u0, m, k, c)
y = [x(1);x(2)];
dx = [x(2) ;((-k/m).*x(1) - (c/m).*x(2) + (k/m).*(u0*sin(w*t)) + (c/m).*(u0*w*cos(w*t)))];
end
_
%6-12-19
clear
close all
clc
u0 = 1; %amplitude ()
w = 1; %hz
m = 0.85048569375; %kg
k = 356.9085; % N/m
c = 10; %N/m*s
tspan = [0 10];
t = [0:.1:10];
u = [u0*sin(w*t); u0*w*cos(w*t)];
x0 = [0;0];
[t, x] = ode45(@(t,x)DOF1damped(t, x, u, w, u0, m, k, c), tspan, x0);
data = iddata(x, t, .1);
plot(t, x)
_
filename = 'DOF1damped';
Order = [2 0 2];
u0 = 1; %amplitude ()
w = 1; %hz
m = 0.85048569375; %kg
k = 356.9085; % N/m
c = 10; %N/m*s
Parameters = {u0,w,m,k,c};
InitialStates = [0; 0];
Ts = 0;
nlgr = idnlgrey(filename, Order, Parameters, InitialStates, Ts, 'Name','DOF1grey');
nlgr = setinit(nlgr, 'Fixed', {false false}); % Estimate the initial states.
setpar(nlgr,'Fixed',{true true true true false});
opt = nlgreyestOptions('Display', 'on');
nlgr = nlgreyest(data,nlgr,'Display','Full');
c_est = nlgr.Parameters(5).Value;
[nonlinear_c_est, dnonlinear_c_est] = getpvec(nlgr,'free')
compare(data,nlgr)
Thanks for any help
  4 Kommentare
Omar
Omar am 11 Mär. 2025
Figured it out, In my case, my iddata object had only one output, and the equation was outputting 2 variables, and I have defined the order as [2 1 2]
once I updated the ODE to output only one variable, and the order to be [1 1 2] the error disappeared.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 14 Mär. 2025
You define iddata as 2 output (y = 597x2) and 1 input (t = 597x1).
Your model nlgr is defined as having order [2 0 2], which corresponds to the number of model outputs, inputs, and states. This must match the output and input size of iddata.
Change order to [2 1 2] to resolve the error,

Kategorien

Mehr zu Grey-Box Model Estimation finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by