用matlab fminsearch 函数怎么求z=2x^2+3y^2-4xy-y-3x的最小值?我是这么写的:x=linspace(-2,0,40);y=linspace(0,3,40);z=2*x.^2+3*y.^2-4*x.*y-y-3*y;[x,fval]=fminsearch(z,[-2,0])结果显示:? Error using ==> fcnchk at 108FUN must be a fun
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/22 00:45:35
用matlab fminsearch 函数怎么求z=2x^2+3y^2-4xy-y-3x的最小值?我是这么写的:x=linspace(-2,0,40);y=linspace(0,3,40);z=2*x.^2+3*y.^2-4*x.*y-y-3*y;[x,fval]=fminsearch(z,[-2,0])结果显示:? Error using ==> fcnchk at 108FUN must be a fun
用matlab fminsearch 函数怎么求z=2x^2+3y^2-4xy-y-3x的最小值?
我是这么写的:
x=linspace(-2,0,40);y=linspace(0,3,40);
z=2*x.^2+3*y.^2-4*x.*y-y-3*y;
[x,fval]=fminsearch(z,[-2,0])
结果显示:
? Error using ==> fcnchk at 108
FUN must be a function, a valid string expression, or an inline function object.
Error in ==> fminsearch at 178
funfcn = fcnchk(funfcn,length(varargin));
用matlab fminsearch 函数怎么求z=2x^2+3y^2-4xy-y-3x的最小值?我是这么写的:x=linspace(-2,0,40);y=linspace(0,3,40);z=2*x.^2+3*y.^2-4*x.*y-y-3*y;[x,fval]=fminsearch(z,[-2,0])结果显示:? Error using ==> fcnchk at 108FUN must be a fun
我看了一下帮助文件,fminsearch的调用方式是这样的:
banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2;
[x,fval] = fminsearch(banana,[-1.2,1])
针对lz的题,则是:
z=@(x)2*x(1).^2+3*x(2).^2-4*x(1).*x(2)-x(2)-3*x(1);
[x,fval]=fminsearch(z,[-2,0])
但是lz题中给定了限定条件,即x,y从属于一个闭区间.
fminbnd是计算一元函数在给定边界约束的局部最小值.
因此以上都不适用.暂时还不知道,其他函数合适不.
个人倒觉得可以这么做:
x=linspace(-2,0,40);y=linspace(0,3,40);
[x,y]=meshgrid(x,y)
z=2*x.^2+3*y.^2-4*x.*y-y-3*y;
[C I]=min(z)