作业帮 > 综合 > 作业

我的.m函数如下:function F = myfun(x)F = [(2*x(1)+3*x(2)+x(3))^2*(x

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/13 16:04:06
我的.m函数如下:
function F = myfun(x)
F = [(2*x(1)+3*x(2)+x(3))^2*(x(1)+x(2))*(1-x(3))/((1-x(1)-x(2))*(2-0.5*x(1))^0.5*(1+3+1.5*x(1)+2*x(2))^1.5)-3.46e+11;
(2*x(1)+3*x(2)+x(3))^3*(x(1)+x(2))*(1-x(3))/((1-x(1)-x(2))*(1-x(2)-x(3))^0.5*(1+3+1.5*x(1)+2*x(2))^2)-0.966;
(2*x(1)+3*x(2)+x(3))*(x(1)+x(2))*x(3)/((x(1)+x(2))*(1-x(3))*(1-x(2)-x(3))) -1.176];
end
运行程序如下:
>> x0 = [-23 23]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call solver
出错信息:
Attempted to access x(3); index out of bounds because numel(x)=2.
Error in ==> myfun at 2
F = [(2*x(1)+3*x(2)+x(3))^2*(x(1)+x(2))*(1-x(3))/((1-x(1)-x(2))*(2-0.5*x(1))^0.5*(1+3+1.5*x(1)+2*x(2))^1.5)-3.46e+11;
Error in ==> fsolve at 248
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation.FSOLVE cannot continue.
我的.m函数如下:function F = myfun(x)F = [(2*x(1)+3*x(2)+x(3))^2*(x
function函数的输入值应该是个1*3的矩阵,但你的输入变量是1*2的,超出范围了
再问: 我改了,还是不行啊。具体指点下行么?
再答: 第二个问题是你的矩阵第二行式子写错了,多了个右括号