フィルターのクリア

Why do I get the error "Too many input arguments"?

8 ビュー (過去 30 日間)
Ben25
Ben25 2019 年 6 月 21 日
回答済み: Valerie Cala 2019 年 10 月 26 日
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 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 21 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 21 日
Not sure, I have doubt with nlgreyest options, try with default options.
Ben25
Ben25 2019 年 6 月 23 日
I get the same error with default options

サインインしてコメントする。

回答 (1 件)

Valerie Cala
Valerie Cala 2019 年 10 月 26 日
unction [dx, y] = DOF2greyfxn(t, x, u, u0, omega, m1, m2, k1, k2, c1, c2,varargin)
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
Try this and run the code again.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by