声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2077|回复: 2

[应用数学] 求救,谢谢大家了,这个程序是怎么了MATLAB,函数加了引号还不行

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

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

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

x
A=[-17.7166,5.1179;50.3437,-20.9333;-99.3832,66.756;236.1567,-192.9286;-169.4007,141.9878];
b=[73.8263;75.5454;13.6275;21.772;15.2625];
x0=[3;3];
x=fmincon('((405.5574*x(3)-334.9164*x(4)+35.0546)^2+(-17.7166*x(3)+5.1179*x(4)+36.0007)^2)^(1/2)',x0,A,b)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error using ==> inlineeval
Error in inline expression ==> ((405.5574*x(3)-334.9164*x(4)+35.0546)^2+(-17.7166*x(3)+5.1179*x(4)+36.0007)^2)^(1/2)
??? Error using ==> eval
Index exceeds matrix dimensions.
谢谢,很不好意思
回复
分享到:

使用道具 举报

发表于 2006-12-4 22:45 | 显示全部楼层
你的函数中只有两个变量,却用了x(3)和x(4),因此出现“Index exceeds matrix dimensions”的警告。分别改为x(1)和x(2)后,得到了如下结果,不知是否你箱要的?
x=fmincon('((405.5574*x(1)-334.9164*x(2)+35.0546)^2+(-17.7166*x(1)+5.1179*x(2)+36.0007)^2)^(1/2)',x0,A,b)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
Optimization terminated: Magnitude of directional derivative in search
direction less than 2*options.TolFun and maximum constraint violation
  is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
  lower      upper     ineqlin   ineqnonlin
                          5           

x =

    2.5212
    3.1154
 楼主| 发表于 2006-12-5 10:33 | 显示全部楼层

感谢

x0=[3;3];这个起始点变化为什么结果不变,它对结果有什么影响?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-5-17 00:34 , Processed in 0.065547 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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