@Nras I have modified the syntax and thanks for your help
%// 数据
x = [ 1.4 15.15 49.395 98.8 151.475 184.41 230.51 259.2 ];
y = [ 12.15 21.2125 25.15125 25.3 24.63125 28.8975 29.8725 35.2 ];
%// 创建模型函数 q,参数为 p(1) = k 和 p(2) = n
q = @(p, x) p(1)*x.^(-p(2));
%// 为最小化创建所需的误差函数
e = @(p) sum((y.^2 - q(p, x)).^2); %// 最小化函数
f = @(p) sum(abs(y - q(p, x))); %// 比绝对值更好的总和
g = @(p) sum(sqrt(abs(q(p, x) - y))); %// 最好取绝对值的平方根
h = @(p) sum((q(p, x) - y).^2); %// 默认最小化函数
p0 = [1, 0.5]; % an initial guess
A = [];
b=[];
Aeq = [];
beq=[];
lb = [-inf,0];
ub = [inf,1];
nonlcon= []
options = optimset('Display','iter','Algorithm','active-set');
options.MaxFunEvals = 100000;
options.MaxIter = 100000
[p_fit_e, r_e] = fmincon(e,p0,A,b,Aeq,beq,lb,ub,nonlcon,options) % Optimize
[p_fit_f, r_f] = fmincon(f, p0,A,b,Aeq,beq,lb,ub,nonlcon,options) % Optimize
[p_fit_g, r_g] = fmincon(g, p0,A,b,Aeq,beq,lb,ub,nonlcon,options) % Optimize
[p_fit_h, r_h] = fmincon(h,p0,A,b,Aeq,beq,lb,ub,nonlcon,options)% Optimize
[minVal minInd] = min(r_e)
[minVal minInd] = min(r_f)
[minVal minInd] = min(r_g)
[minVal minInd] = min(r_h)
e1 = p_fit_e(1)*x.^(-p_fit_e(2));
f1 = p_fit_f(1)*x.^(-p_fit_f(2));
g1 = p_fit_g(1)*x.^(-p_fit_g(2));
h1 = p_fit_h(1)*x.^(-p_fit_h(2));
figure(1)
plot(x,e1)
hold on
plot(x,y)
figure(2)
plot(x,f1)
hold on
plot(x,y)
figure(3)
plot(x,g1)
hold on
plot(x,y)
figure(4)
plot(x,h1)
hold on
plot(x,y)