dongriliuhuo
2009-06-07, 11:28
各位好,我最近在做一个fmincon优化问题,但始终有个错误,恳请各位高手指教!!!!
我已经查看了很多关于fmincom的帖子,并且help里面的调用格式也看了,还是不知道错在哪。
M文件程序:
1 x0=[0.055;5.0;30];
2 ub=[0.07;8.0;50];
3 lb=[0.04;1.7;20];
4 [x,fn]=fmincon(@lianyouhua_f,x0,[],[],[], [],lb,ub,@lianyouhua_g);
5 disp
6 fprintf(1,' x1= % 3.4f \n',x(1))
7 fprintf(1,' x2= % 3.4f \n',x(2))
8 fprintf(1,' x3= % 3.4f \n',x(3))
9 fprintf(1,' f= % 3.4f \n',fn)
10 g=lianyouhua_g(x);
11 disp'
12 fprintf(1,' g1= % 3.4f \n',g(1))
13 fprintf(1,' g2= % 3.4f \n',g(2))
14 function f=lianyouhua_f(x);
15 f=(127.4*((444.5*x(1)/x(2))^1.35))*sqrt(x(1)^2+x(2)^2+2*x(1)*x(2)*cos(pi*x(3)/180))+1 6.9*cos(x(3))+0.00023*x(1);16
16 function [g,ceq]=lianyouhua_g(x);
17 g(1)=444.5*x(1)/x(2)-15;
18 g(2)=3-444.5*x(1)/x(2);
19 ceq=[];
问题:
??? Error: File: E:\MATLAB7.0\work\lian.m Line: 14 Column: 1Function definitions are not permitted at the prompt or in scripts.
说实话,我学MATLAB只有三天,这段程序是我从别人论文上摘录的,想运行好了之后自己用,可现在原程序都运行不好!!!
(第14行)function f=lianyouhua_f(x); 这和help里面fmincon的调用格式完全一致啊,为什么会错呢。
谢谢各位大虾了 !!!!!
我已经查看了很多关于fmincom的帖子,并且help里面的调用格式也看了,还是不知道错在哪。
M文件程序:
1 x0=[0.055;5.0;30];
2 ub=[0.07;8.0;50];
3 lb=[0.04;1.7;20];
4 [x,fn]=fmincon(@lianyouhua_f,x0,[],[],[], [],lb,ub,@lianyouhua_g);
5 disp
6 fprintf(1,' x1= % 3.4f \n',x(1))
7 fprintf(1,' x2= % 3.4f \n',x(2))
8 fprintf(1,' x3= % 3.4f \n',x(3))
9 fprintf(1,' f= % 3.4f \n',fn)
10 g=lianyouhua_g(x);
11 disp'
12 fprintf(1,' g1= % 3.4f \n',g(1))
13 fprintf(1,' g2= % 3.4f \n',g(2))
14 function f=lianyouhua_f(x);
15 f=(127.4*((444.5*x(1)/x(2))^1.35))*sqrt(x(1)^2+x(2)^2+2*x(1)*x(2)*cos(pi*x(3)/180))+1 6.9*cos(x(3))+0.00023*x(1);16
16 function [g,ceq]=lianyouhua_g(x);
17 g(1)=444.5*x(1)/x(2)-15;
18 g(2)=3-444.5*x(1)/x(2);
19 ceq=[];
问题:
??? Error: File: E:\MATLAB7.0\work\lian.m Line: 14 Column: 1Function definitions are not permitted at the prompt or in scripts.
说实话,我学MATLAB只有三天,这段程序是我从别人论文上摘录的,想运行好了之后自己用,可现在原程序都运行不好!!!
(第14行)function f=lianyouhua_f(x); 这和help里面fmincon的调用格式完全一致啊,为什么会错呢。
谢谢各位大虾了 !!!!!