# Fitness functions error

Discussion in 'Programmer's Corner' started by shegmite, Mar 18, 2014.

1. ### shegmite Thread Starter New Member

Apr 5, 2013
4
0
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.

Code ( (Unknown Language)):
1.
2. [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
3. function[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Ap = insertionlossnew(x)
4. L1 = 3;
5. x(1)=Zcd1;
6. L2 = 24;
7. x(2)=Zcb;
8. L3=3;
9. x(3)=Zcd2;
10. Ap=zeros(1,15);
11. [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] v =[1 4 8 10 16 20 25 31.25 62.5 100 200 250 300 400 500];
12. Ap = (v*((L1)*(Zcd1)+(L2)*(Zcb)+(L3)*(Zcd2)));
13. 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];
14. [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end
15. [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Y1=sqrt(sum(Ap-Am)^2);
16. Y2=mean(Am);
17. Y3=sqrt(sum(Am-Y2)^2);
18. Y4=Y1/Y3;
19. Y=(1-Y4)*100;[/SIZE][/FONT][/SIZE][/FONT]
20.  [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]disp(Y);
21.
22. [/SIZE][/FONT][/SIZE][/FONT]
23.

Last edited by a moderator: Mar 18, 2014
2. ### ActivePower Active Member

Mar 15, 2012
155
23
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:
Code ( (Unknown Language)):
1. 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: Mar 18, 2014
3. ### Papabravo Expert

Feb 24, 2006
11,156
2,184
Maybe it would be a good idea to learn how to crawl before you try to run a marathon.

4. ### shegmite Thread Starter New Member

Apr 5, 2013
4
0
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);

5. ### ActivePower Active Member

Mar 15, 2012
155
23
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.