too many input arguments

1 view (last 30 days)
Ben25
Ben25 on 24 Jun 2019
Commented: Ben25 on 25 Jun 2019
I am attempting to run a nonlinear grey box estimation, but when I run code to estimate unknown parameters, it says I have too many input arguments. I made sure to match the dimensions of the iddata object and the idnlgrey object, so I don't know where my problem lies.
The error is:
>> DOF2grey
Error using iddata/nlgreyest (line 59)
Error or mismatch in the specified ODE file "DOF2greyfxn".
The error message is: "Too many input arguments."
Error in DOF2grey (line 20)
nlgr = nlgreyest(estdata, nlgr, opt); %estimates unknown parameters in(nlgr)
my code is shown below:
filename = 'DOF2greyfxn'; %calls model file
Order = [4 2 4]; %number of outputs, inputs, states
%check book to see if 4 inputs are necessary in state eqs
global u0 omega m1 m2 k1 k2 c1 c2
Parameters = {u0,omega,m1,m2,k1,k2,c1,c2};
InitialStates = [0; 0; 0; 0]; % x1 position, x1 velo, x2 pos, x2 velo
Ts = 0; %sample time = continuous time
nlgr = idnlgrey(filename, Order, Parameters, InitialStates, Ts, 'Name','DOF2grey'); %setup nlgrey object
setpar(nlgr,'Fixed',{true true true true true true false false}); %tells matlab which parameters to estimate (c1, c2)
nlgr = setinit(nlgr, 'Fixed', {false false false false}); % tells matlab to estimate the initial states (all of them)
estdata = iddata(x, u, 10/1417153); %creates data object based on ode45_2DOF, input (u), output (x), sample time = data points/total time
opt = nlgreyestOptions('Display', 'on'); %shows estimation progress
nlgr = nlgreyest(estdata, nlgr, opt); %estimates unknown parameters in(nlgr)
%using estdata as input argument, estdata and nlgr must have same input and output dimensions
present(nlgr)
size(estdata)
compare(estdata,nlgr)
it uses this function to model the nlgrey object:
%6-20-19
function [dx, y] = DOF2greyfxn(t, x, u, u0, omega, m1, m2, k1, k2, c1, c2)
y = [x(1);x(2);x(3);x(4)];
dx = [x(2);(((-k1 - k2)/m1)*x(1) + ((-c1 - c2)/m1)*x(2) + (k2/m1)*x(3) + (c2/m1)*x(4) +(k1/m1)*u(1) + (c1/m1)*u(2))
;x(4); ((k2/m2)*x(1) + (c2/m2)*x(2) + (-k2/m2)*x(3) + (-c2/m2)*x(4))];
end
and it uses this data from this function and a corresponding ode45 file to create the iddata object:
function [dx, y] = DOF2damped(t, x)
u0 = .1; %amplitude ()
omega = 1; %hz
m1 = 0.85048569375; %kg
m2 = 0.7370876; %kg
k1 = 100000; % N/m 35
k2 = 356.9085; % N/m
c1 = 100000; %N/m*s
c2 = 1; %N/m*s
u = [u0*sin(omega*t); u0*omega*cos(omega*t)];
y = [x(1);x(2);x(3);x(4)]; %x1, x1dot, x2, x2dot
dx = [x(2);(((-k1 - k2)/m1)*x(1) + ((-c1 - c2)/m1)*x(2) + (k2/m1)*x(3) + (c2/m1)*x(4) +(k1/m1)*u(1) + (c1/m1)*u(2))
;x(4); ((k2/m2)*x(1) + (c2/m2)*x(2) + (-k2/m2)*x(3) + (-c2/m2)*x(4))];
end
%if variables are defined as global inside function, takes forever to run
ode file:
clear
close all
clc
global u0 omega m1 m2 k1 k2 c1 c2
tspan = [0 10];
x0 = [0;0;0;0];
[t, x] = ode45(@(t,x)DOF2damped(t, x), tspan, x0);
u = [(u0*sin(omega*t)), (u0*omega*cos(omega*t))];
plot(t, x, t, u)
Thanks for any help
  2 Comments
Bob Thompson
Bob Thompson on 24 Jun 2019
Documentation for nlgeyest states that the initial conditions, 'nlgr' need to be created with indlgrey. I see your code creating them with setinit, however.
Not sure if that is actually the cause, I do not admittedly do anything with greybox stuff.
Ben25
Ben25 on 25 Jun 2019
initial states are specified in the variable named InitialStates above that. The setinit part of the code is to set those predefined initial states as variables to be estimated in nlgreyest.

Sign in to comment.

Answers (0)

Categories

Find more on Grey-Box Model Estimation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!