%2jiyouhua.m
vlb=[0.25;18;1.5];%x1,x2,x3的下限值
vub=[1;100;6];%x1,x2,x3的上限值
x0=[0.9;50;2.5];%x1,x2,x3的初始值
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon('funn',x0,[],[],[],[],vlb,vub,'nonlcon')
%目标函数
function y=funn(x)
y=x(2)*x(3)+(x(2)*x(3))/x(1)
%约束条件
function[c,ceq]=nonlcon(x)
c(1)=(863.4*x(1))/x(2)-x(3).^3;
c(2)=x(2)+x(2)/x(1)-120;
ceq=[];
运行时出现了问题,显示是
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 274
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error using ==> feval
Undefined command/function 'funn'.
我也不知道为什么,该怎么办
1.为什么我已经写了funn函数了,会出现Undefined command/function 'funn',而你这样写就能用啊
2.我自己的程序有些问题,就是约束条件里x1是只能小于1的,不能等于1,但我又不知道怎么修改,而你的优化出来的结果刚好又是等于1,这不是我想要的,能否再帮我看下
我这么跟你说吧,整个计算其实和x1关系不大,你只要取一个你在精度范围类接近于1就可以了,x1是做分母的,当然允许时越大越好