MATLAB报错,为什么?Input argument "x" is undefined.Error in ==> m1 at 4%%%%%%%%%%目标函数f(x)%%%%%%%%%%function f=f1(x) %f1.mf=x(1)^2+x(2)^2-16*x(1)-10*x(2);(这句话错了)%%%%%%%%%%目标函数f(x)的梯度%%%%%%%%%%function df=df1(x)
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/09 10:50:29
MATLAB报错,为什么?Input argument "x" is undefined.Error in ==> m1 at 4%%%%%%%%%%目标函数f(x)%%%%%%%%%%function f=f1(x) %f1.mf=x(1)^2+x(2)^2-16*x(1)-10*x(2);(这句话错了)%%%%%%%%%%目标函数f(x)的梯度%%%%%%%%%%function df=df1(x)
MATLAB报错,为什么?Input argument "x" is undefined.Error in ==> m1 at 4
%%%%%%%%%%目标函数f(x)%%%%%%%%%%
function f=f1(x) %f1.m
f=x(1)^2+x(2)^2-16*x(1)-10*x(2);(这句话错了)
%%%%%%%%%%目标函数f(x)的梯度%%%%%%%%%%
function df=df1(x) %df1.m
df=[2*x(1)-16;2*x(2)-10];
%%%%%%%%%%约束函数%%%%%%%%%%
function [h,g]=cons(x) %cons.m
h=[]; %无等式约束
g=[-x(1)^2+6*x(1)-4*x(2)+11;...
x(1)*x(2)-3*x(2)-exp(x(1)-3)+1;x(1);x(2)]; %不等式约束 []>=0 左边部分
%%%%%%%%%%约束函数Jacobi 矩阵%%%%%%%%%%
function [dh,dg]=dcons(x) %dcons.m
dh=[];
dg=[-2*x(1)+6,-4;x(2)-exp(x(1)-3),x(1)-3;1,0;0,1];
x0=[4 4]';
mu0=[]';%等式个数
lam0=[0 0 0 0]';%不等式个数
[x,mu,lam,val,k]=sqpm(x0,mu0,lam0)
MATLAB报错,为什么?Input argument "x" is undefined.Error in ==> m1 at 4%%%%%%%%%%目标函数f(x)%%%%%%%%%%function f=f1(x) %f1.mf=x(1)^2+x(2)^2-16*x(1)-10*x(2);(这句话错了)%%%%%%%%%%目标函数f(x)的梯度%%%%%%%%%%function df=df1(x)
你好
请你贴出你调用目标函数的程序,应该是调用函数出问题,不然也不会出现x没有定义.