'"Too many input arguments." errror remove

1 次查看(过去 30 天)
1 %% Scoutbees: random search (only once)
2 U=X_random(n, para1_max, para2_max, para3_max, para4_max,para1_min,para2_min, para3_min, para4_min );
3 for S= 1: n
4 input = ([U(S,1),U(S,2),U(S,3),U(S,4)]);
5 Par_Q(S,1)= BLPMSM_1_75kW_640RPM(input);
6 end
7 Q= sortrows([ U(:,1), U(:,2),U(:,3), U(:,4),Par_Q],5);
8 clear U;
9
error show in line 5.. how to remove this eror
Error using fxbxuntitled>BLPMSM_1_75kW_640RPM
Too many input arguments.
Error in fxbxuntitled (line 5)
Par_Q(S,1)= BLPMSM_1_75kW_640RPM(input);
  2 个评论
Rik
Rik 2021-4-22
You're not telling anything about your custom function. What is its signature?
Shubham PATEL
Shubham PATEL 2021-4-22
respected sir ,
my program is bellow , and i saw error in line "Par_Q(S,1)= bf(input);"
error show massage too many argumant ,please solve my problem
%%%%%Bees Algorithm %%%%%%%
function bf
%% Setting the Parameter for the Algorithm
itr=50; % number of iterations
n= 50; % number of scout bees
e=2; % number of elite selected sites
m=10; % number of best selected sites
nep=15; % number of recruited bees around elite selected patches
nsp=5; % number of recruited bees around best selected patches
ngh=1; % Patch radius for neighbourhood search
%% Boundaries of prime variables
para1_max=900; para1_min=600; % Boundaries of Stator inner diameter
para2_max=900; para2_min=600; % Boundaries of axial length
para3_max=20; para3_min=13; % Boundaries of magnet thickness
para4_max=7.5; para4_min=5; % Boundaries of current density
F_result=zeros(itr,5);
%% Scoutbees: random search (only once)
U=X_random(n, para1_max, para2_max, para3_max, para4_max,para1_min,para2_min, para3_min, para4_min );
input= [U(:,1),U(:,2),U(:,3),U(:,4)]
Par_Q(S,1)= bf(input);
Q= sortrows([ U(:,1), U(:,2),U(:,3), U(:,4),Par_Q],5);
clear U; l=0;
%% Iterations of the algorithm
tic
for k=1:itr % iterations
for j=1:e % number of elite selected patches
for i=1:nep % number of bees around elite patches
U=bee_dance(ngh, Q(j,1), Q(j,2), Q(j,3),Q(j,4));
if bf([U(1),U(2),U(3),U(4)])< Q(j,5)
Q(j,:)=[ U(1),U(2),U(3),U(4),bf(U)];
end
l=l+1;
end
end
for j=e+1:m % number of best selected patches
for i= 1:nsp % number of bees around best patches
U=bee_dance(ngh, Q(j,1), Q(j,2), Q(j,3),Q(j,4));
if bf([U(1),U(2),U(3),U(4)])< Q(j,5)
Q(j,:)=[ U(1),U(2),U(3),U(4),bf(U)];
end
l=l+1;
end
end
for j=m+1:n
U=X_random(n, para1_max, para2_max, para3_max,para4_max,para1_min,para2_min,para3_min,para4_min);
Q(j,:)=[U(j,1), U(j,2),U(j,3), U(j,4), bf(U(j,:))];
l=l+1;
end
Q=sortrows(Q,5);
F_result(k,:)= Q(1,:);
end % iterations
Q(1,:)
xxx=1:itr;
figure(1)
plot(xxx,F_result(:,1),'-+',xxx,F_result(:,2),'-o',xxx,F_result(:,3),'-*',xxx,F_result(:,4),'-s');
grid on
xlabel ('Number of Iteration')
ylabel (' Parameters Values')
figure (2)
plot(xxx,F_result(:,5),'-*');
grid on
xlabel ('Number of Iteration')
ylabel (' Output of Objective Function')
toc
%%%%%% Function for random initialisation %%%%%%
function X = X_random(n, para1_max, para2_max,para3_max, para4_max,para1_min, para2_min, para3_min, para4_min )
X = [para1_min+((rand(n,1)).*(para1_max-para1_min)),para2_min + ((rand(n,1)).*(para2_max-para2_min)),para3_min+((rand(n,1)).*(para3_max-para3_min)),para4_min+((rand(n,1)).*(para4_max-para4_min))];
end
%%%%% Neighbourhood search function %%%%%%
function U=bee_dance(ngh,x1, x2, x3, x4)
U(:,1)=(x1-ngh)+(2*ngh.*rand(size(x1,1),1));
U(:,2)=(x2-ngh)+(2*ngh.*rand(size(x2,1),1));
U(:,3)=(x3-ngh)+(2*ngh.*rand(size(x3,1),1));
U(:,4)=(x4-ngh)+(2*ngh.*rand(size(x4,1),1));
end
% OPTIMISATION PROBLEM FUNCTION
function bf(output)
end
end

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2021-4-22
function bf
Which is a function that does not accept any parameters.
Then you have some stuff, and then you have
function bf(output)
end
which declares a different function named bf that expects one parameter, and does no work.
Normally MATLAB would have given you an error about having two functions by the same name in the same file. However...
Par_Q(S,1)= BLPMSM_1_75kW_640RPM(input);
we can tell from that line that you stored those functions in a file named BLPMSM_1_75kW_640RPM.m and that inside BLPMSM_1_75kW_640RPM.m you do not have any function named BLPMSM_1_75kW_640RPM . When you have a file that starts with a function, then MATLAB treats the first function specially, and ignores the function name that you coded for it, and treats it as-if you had coded the name of the file as the function name. So MATLAB is treating the file as-if you had started it with
function BLPMSM_1_75kW_640RPM
and then there is no conflict about bf being duplicated because it is treating the first one as-if it were named BLPMSM_1_75kW_640RPM .
... But this still leaves you with the problem that your function is not expecting any parameter, and also leaving you with the unused function bf at the end of the file.
  2 个评论
Shubham PATEL
Shubham PATEL 2021-4-22
respected @Walter Roberson sir,
i hardly stuck in this program.please help me sir, can you modified above program and comment that file will greatly help me sir. thank you so mach sir.
Walter Roberson
Walter Roberson 2021-4-22
You start the file with
function bf
which declares that bf is a function that accepts no input and creates no output.
Then you have
U=X_random(n, para1_max, para2_max, para3_max, para4_max,para1_min,para2_min, para3_min, para4_min );
input= [U(:,1),U(:,2),U(:,3),U(:,4)]
Par_Q(S,1)= bf(input);
That attempts to invoke bf with one parameter, and returning a scalar. But you declared that function bf does not accept any inputs and does not produce any outputs. You are within function bf but you are trying to call function bf... and failing because function bf does not accept any inputs.
You have nested function definition
function bf(output)
end
and perhaps you were thinking that the nested function would be called instead of the function you are already inside. But even if that worked, that second bf might accept an input parameter but it does not return any outputs, so you would fail the assignment to Par_Q(S,1) which requires that the function produces an output.
  1. Do not use one function name for two different purposes inside the same code: it is going to confuse yourself,and confuse other people reading the code, and possibly confuse MATLAB. Rename your functions so it becomes clear which function is being called at which point;
  2. The function you call there must accept one parameter of input (that is a vector of 4 values), and must return a scalar.
I suspect that at that point in the code, the function that is being invoked is intended to be the function you are optimizing over four parameters. You have not defined what you are optimizing anywhere.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by