MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]程序出错,大家帮忙. (https://www.labfans.com/bbs/showthread.php?t=6216)

amour120 2009-01-11 16:32

[求助]程序出错,大家帮忙.
 
我的M文件编辑如下:
x=('double');
function [beta,g]=zhaoguofan26(x) %编写m 文件
beta=sqrt(((x(1)-38)/3.8)^2+((x(2)-54)/2.7)^2); %目标函数
g(1)=x(1)*x(2) -1140; %等式约束条件,等式约束条件要求置于最前
g(2)= -x(1); % x(1)表示f,要求x(1)>0
g(3)= -x(2); % x(2)表示W,要求x(2)>0
[COLOR="Red"]当我调用M文件的时候就弹出错误提示:Function definitions are not permitted at the prompt or in scripts.(能在命令窗口或者脚本文件中定义函数
)[/COLOR]

[COLOR="red"]以下为实例:命令窗口操作:[/COLOR]
%在命令窗口中调用m 文件
>> x0=[38 54]; %给出初始值,一般取均值就可
>> options(13)=1; %设定options(13)的参数,约束条件中最前面的是一个等式
约束条件
>> [x,options]=constr('zhaoguofan26',x0,options); %用命令constr 调用m 文件
>> [beta,g]=zhaoguofan26(x)%

[COLOR="red"]我在哪里出错了呢,大家帮忙下[/COLOR]:lol:

nb004 2009-01-11 16:46

回复: [求助]程序出错,大家帮忙.
 
在m文件中编写函数应该在第一行写函数声明,即把function [beta,g]=zhaoguofan26(x) 写在第一行。

amour120 2009-01-11 22:18

回复: [求助]程序出错,大家帮忙.
 
[QUOTE=nb004;23487]在m文件中编写函数应该在第一行写函数声明,即把function [beta,g]=zhaoguofan26(x) 写在第一行。[/QUOTE]

我也试过了,还是不行,


所有时间均为北京时间。现在的时间是 15:42

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.