Fitness functions error

Thread Starter

shegmite

Joined Apr 5, 2013
4
I tried to run this function in matlab to minimize measured data and simulation from equations and I got this message: input argument is undefined ??? Can anyone tell what the correct syntax is.

Rich (BB code):

function Ap = insertionlossnew(x)
L1 = 3;
x(1)=Zcd1;
L2 = 24;
x(2)=Zcb;
L3=3;
x(3)=Zcd2;
Ap=zeros(1,15);
for v =[1 4 8 10 16 20 25 31.25 62.5 100 200 250 300 400 500];
Ap = (v*((L1)*(Zcd1)+(L2)*(Zcb)+(L3)*(Zcd2)));
Am=[20.3 23.4 24.6 25.3 23.4 26.4 27.5 22.9 23.7 29.8 31.3 32.8 27.9 25.8 35.6];
end
Y1=sqrt(sum(Ap-Am)^2);
Y2=mean(Am);
Y3=sqrt(sum(Am-Y2)^2);
Y4=Y1/Y3;
Y=(1-Y4)*100;
 disp(Y);

 
Last edited by a moderator:

ActivePower

Joined Mar 15, 2012
155
I'm not really sure that you understand MATLAB functions. For syntax queries, built-in MATLAB Help is a great resource. As is their website. As is Google.

MATLAB functions, like their counterparts in many other languages, require you to pass a list of input arguments which they process to provide a list of outputs.
The error you're getting means that you're not passing any value for the function to act upon.

Skimming though your code listing - your function takes a single input, x (a vector perhaps), to spit out a number. Variables Zcb1, Zcb and Zcd2 don't get a value anywhere (remember assignment works right to left). Yet you're assigning their values to elements located in x - this will certainly fetch you an error. I guess what you intended to do was this:
Rich (BB code):
Zcd1 = x(1)
Also (and I don't know whether you intended it to do this), your function's return value is the vector Ap.

HTH.
 
Last edited:

Thread Starter

shegmite

Joined Apr 5, 2013
4
I have just done as you suggested in your last message. I hope am right ?
function Ap = insertionlossnew(x)
L1 = 3;
Zcd1=x(1);
L2 = 24;
Zcb=x(2);
L3=3;
Zcd2=x(3);
Ap=zeros(1,15);
for v =[1 4 8 10 16 20 25 31.25 62.5 100 200 250 300 400 500];
Ap = (v*((L1)*(Zcd1)+(L2)*(Zcb)+(L3)*(Zcd2
)));
Am=[20.3 23.4 24.6 25.3 23.4 26.4 27.5 22.9 23.7 29.8 31.3 32.8 27.9 25.8 35.6];
end
Y1=sqrt(sum(Ap-Am)^2);
Y2=mean(Am);
Y3=sqrt(sum(Am-Y2)^2);
Y4=Y1/Y3;
Y=(1-Y4)*100;

disp(Y);


 

ActivePower

Joined Mar 15, 2012
155
The assignments look correct. I'm not sure how you're calling this function from your shell/main script though, as that was the cause of your original error. Why don't you try it and see for yourself? That'll give you a better idea.

PS: Use the Code tags (the ones indicated by the pound ('#') sign), when posting code. It'll help you format your post better and make it more readable for others.
 
Top