声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1443|回复: 10

[编程技巧] 请教各位大侠一个优化问题!

[复制链接]
发表于 2006-4-4 15:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
关于一个非线性约束,
(x1^2+x2^2)/( x1^2+x2^2-2*x1*x2*cos(2t)) dt
前面有一个积分符号实在不知道怎么打出来,积分上下限是11/75,6/25

fun*1000*41/48-0.06<0 (非线性约束式)
fun即为这个积分式。
请问这个约束该怎么写,直接放在约束文件函数里行不(但它还要先求出积分式的结果),好像不能直接写成c(n)=……的形式,请问该怎么写呢?
回复
分享到:

使用道具 举报

发表于 2006-4-4 22:17 | 显示全部楼层
应该是可以的,可以参考帖子
http://forum.vibunion.com/thread-8802-1-1.html
 楼主| 发表于 2006-4-5 09:56 | 显示全部楼层
谢谢帮忙!
但我还是头大!
发表于 2006-4-5 14:53 | 显示全部楼层
多大几次以后就不用大了
发表于 2006-4-5 15:06 | 显示全部楼层
恩,大几次之后基本会收敛到一个极限的
 楼主| 发表于 2006-4-5 15:44 | 显示全部楼层
??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:

Undefined function or variable 'x'.

Error in ==> D:\matlab\优化\tuoyuanyouhua.m
On line 3 ==> [x,y]=fmincon(@ff8,x0,[],[],[],[],[],[],nonlcon)
为什么老是这样呢!!!
发表于 2006-4-6 09:18 | 显示全部楼层
  1. ??? Error using ==> fmincon
  2. FMINCON cannot continue because user supplied nonlinear constraint function
  3. failed with the following error:

  4. Undefined function or variable 'x'.

  5. Error in ==> D:\matlab\优化\tuoyuanyouhua.m
  6. On line 3 ==> [x,y]=fmincon(@ff8,x0,[],[],[],[],[],[],nonlcon)
  7. 为什么老是这样呢!!!
复制代码

把代码贴出来,可能是你的function写的有问题
 楼主| 发表于 2006-4-6 17:25 | 显示全部楼层
  1. function [c,g]=fun2(x)
  2. c1=x(1)-x(2);
  3. c2=25-(+(atan(-(x(2)^2-x(1)^2)^0.5/x(1))));
  4. c3=17*x(2)-x(2)^2+x(1)^2;
  5. c4=3*x(1)*x(2)-x(1)^2-x(2)^2;
  6. c5=41/48*(x(1)^2+x(2)^2)-1.25*(x(2)-x(1))^2;
  7. c6=0.4*(x(1)+x(2))^2-41/48*(x(1)^2+x(2)^2);
  8. fun=int((x(1)^2+x(2)^2)/(x(1)^2+x(2)^2-2*x(1)*x(2)*cos(25*pi*t/3)),t,11/75,6/25);
  9. c7=fun*1000*41/48-0.06;
  10. g=[];
复制代码

这是我写的函数.运行后老是这样:
??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:

Undefined function or variable 't'.

Error in ==> D:\matlab\优化\tuoyuanyouhua.m
On line 3 ==> [x,y]=fmincon(@fun1,x0,[],[],[],[],[],[],nonlcon)
>>
发表于 2006-4-6 20:09 | 显示全部楼层
你给初始值了吗?
 楼主| 发表于 2006-4-11 10:44 | 显示全部楼层
我的初始值给了x0=[1,1]
现在程序运行出来了,不过却出来了下面的结果:
Optimization terminated: No feasible solution found.
Magnitude of directional derivative in search direction
less than 2*options.TolFun but constraints are not satisfied.

这又是怎么回事啊?
发表于 2006-4-11 21:26 | 显示全部楼层
没有找到可行解。
可能是你的约束条件太强了
或者是你给的初始解不好,多换几个初始解试试。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-24 23:29 , Processed in 0.060730 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表