How can I estimate a parameter of a nonlinear model?

2 次查看(过去 30 天)
if true
%%The following script I wrote is called simulate_dynamics.m
L = length(FlowReal);
N = round(L/2);
t_est = Ts*[0:N-1];
u_est = FlowReal(1:N)'; % Input to system
y_est = PressureReal(1:N)'; % Real output to system
simin = [t_est' u_est]; % Input to simulink model
k0 = mean(FlowReal(1:10)); % Initial condition for parameter "k"
K_opt = fminsearch(@(k) est_err,k0); % Find minimum of quadratic error
%%The function est_err is used to calculate the quadratic error between simulated output and real output, where the simulated output is depended on the parameter"k". This parameter"k" I want to find with fminsearch()
function error = est_err(k)
global k0 y_est t_est y_sim k t_sim
t_est = t_est';
k = k0;
sim('simpressure',t_sim) % The simulation is a nonlinear system. Its the differential equation with the variable "p" and the time derivative of it: d(p)/dt= 1/k*(u_est+1/(2*b)*(a+sqrt(a^2+4*b*p))). a and b are known constants.The input of the model is simin from workspace and the output of the model is called y_sim and is sent to workspace.
error = sum((y_sim-y_est).^2);
end
%%The problem I have is when I run my script matlab returns an error message, which I don't understand. I don't know what I'm doing wrong.
Error using reshape
To RESHAPE the number of elements must not change.
Error in timeseries/minus>localminus (line 149)
[tsout.DataInfo,tsout.Data] = tsdata.datametadata.defaultminus(...
Error in - (line 29)
tsout = localminus(ts1, ts2, false);
Error in est_err (line 12)
error = sum((y_sim-y_est).^2);
Error in @(k)est_err
Error in fminsearch (line 190)
fv(:,1) = funfcn(x,varargin{:});
Error in simulate_dynamics (line 73)
K_opt = fminsearch(@(k) est_err,k0);
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by