I got FMINCON requires the following inputs to be of data type double: 'A' error,How it can be solved????

39 次查看(过去 30 天)
% Load Solar Cell data
load elec_solar_iv_data.mat
% Display the Solar Cell model
Model = 'elec_solar';
open_system(Model);
% List of parameters and initial values prior to optimization ParsListMain = {'Is', 'Iph', 'ec', 'Rs', 'Rp'}; InitGuessMain = [ 3e-7 3.8 1.5 .004 10 ]; ParsListTemp = {'TIPH1', 'EG', 'TXIS1'}; InitGuessTemp = [ .001 1.11 3 ];
%Plot Data Versus Solar Cell Output Using Initial Parameters
load_system(Model);
set_param([Model '/Solar Cell'], 'prm', '3')
Pars = reshape([ParsListMain; cellstr(num2str(InitGuessMain'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:})
Pars = reshape([ParsListTemp; cellstr(num2str(InitGuessTemp'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:})
% Generate preliminary model curves and plot afminconinst data
num_lines = length(iv_data);
v_model = cell(1, num_lines);
i_model = cell(1, num_lines);
legend_info_data = cell(1, num_lines);
legend_info_model = cell(1, num_lines);
for idx_data = 1:num_lines
sim(Model);
v_model{idx_data} = Vo.signals.values;
i_model{idx_data} = Io.signals.values;
legend_info_data{idx_data} = [ 'Temp = ' ...
num2str(iv_data(idx_data).temperature) '\circC, Data'];
legend_info_model{idx_data} = [ 'Temp = ' ...
num2str(iv_data(idx_data).temperature) '\circC, Model'];
end
plot([iv_data.v], [iv_data.i], 'd', [v_model{:}], [i_model{:}])
xlabel('Solar cell output voltage (V)');
ylabel('Solar cell output current (A)');
legend([legend_info_data legend_info_model], 'Location', 'Best');
title('Model with Initial Parameter Values');
%Optimize Main Tab Dialog Parameters at Room Temperature (Step 1)
% Find room temperature data index
idx_data = find([iv_data.temperature]==25);%#ok
% Optimize parameters in main dialog tab of Solar Cell
ParsList = ParsListMain;
OptParsMain = fmincon(@elec_solar_lse, InitGuessMain, ...
optimset('TolX', 1e-3));
% Update Solar Cell block with optimized parameters
Pars = reshape([ParsList; cellstr(num2str(OptParsMain'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:});
% Display optimized parameters
display(sprintf(['Optimized parameters for the solar cell main ' ...
'dialog tab are:\n']));
display(sprintf('\t%5s = %s\n', Pars{:}));
%Optimize Parameters Controlling Temperature Dependence (Step 2)
% Find index into data for non-room temperatures
idx_data = find([iv_data.temperature]~=25);
% Optimize parameters in temperature dialog tab of Solar Cell
ParsList = ParsListTemp;
OptParsTemp = fmincon(@elec_solar_lse, InitGuessTemp, ...
optimset('TolX', 1e-3));
% Update Solar Cell block with optimized temperature parameters
Pars = reshape([ParsList; cellstr(num2str(OptParsTemp'))'],1,[]);
set_param([Model '/Solar Cell'], Pars{:});
% Display optimized parameters
display(sprintf(['Optimized parameters for the solar cell ' ...
'temperature dialog tab are:\n']));
display(sprintf('\t%5s = %s\n', Pars{:}));
%Display Optimized Curves
for idx_data = 1:num_lines
sim(Model);
v_model{idx_data} = Vo.signals.values;
i_model{idx_data} = Io.signals.values;
end
plot([iv_data.v], [iv_data.i], 'd', [v_model{:}], [i_model{:}])
xlabel('Solar cell output voltage (V)');
ylabel('Solar cell output current (A)');
legend([legend_info_data legend_info_model], 'Location', 'Best');
title('Model with Optimized Parameter Values');

采纳的回答

Steven Lord
Steven Lord 2018-7-18
OptParsTemp = fmincon(@elec_solar_lse, InitGuessTemp, ...
optimset('TolX', 1e-3));
You can't just skip required arguments. If you want to pass the options structure into fmincon you MUST specify the fun, x0, A, b, Aeq, beq, lb, ub, and nonlcon inputs first. You've just specified fun and x0, leaving fmincon to treat your options structure as the A input.
Since you don't appear to have any constraints, you probably don't want to use fmincon. Instead, use one of the unconstrained optimization functions. Their signatures are much shorter than that of fmincon, since they don't accept constraints.
  9 个评论
muhammad ilyas khattak khattak
@Steven Lord🙏☺️☺️🙂...Thanks steven once again...I exatly did by encapsulating the parameters into a structure and then calling "fmincon"...Below are the final fmincon commands/statments.... Also in the attachment in pdf format (convertable/can be copied to .m format) , is the full code that contains all the helping functions/main functions in case it is needed to run.....If I get successful execution/obtain minimization of what I am doing , a great part of my work will be solved... Therefore, I am trying to contact again and again..... I am literarly lacking words to say thanks... THanks once again in advance, even if you spare a little time, it is much for me..

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by