【发布时间】:2014-06-20 21:41:32
【问题描述】:
我有一个优化函数,比如说 f,在 matlab 中,该函数取决于我想要优化的变量 x=(x(1),x(2)) 以及两个不需要的参数 n 和 c进行优化,换句话说,我有一个 n 和 c 值矩阵,我想为每个 n 和 c 找到最佳 x 值。 这是我的代码:
clear all;
clc;
close all;
f=@(x,n,c)n*x(1)+(x(2)+3*c)/(x(1)+c);
for n=1:10
for c=1:20
x=zeros(length(n),length(c));
fun{n,c}=@(x)f(x,n,c);
options=optimset('Algorithm','interior-point')
x(n,c)=fmincon(fun{n,c},[0;0],[1 0;-1 0;0 1;0 -1],[40;0;40;0],[],[],[],[],[],options);
end
end
??? Subscripted assignment dimension mismatch.
Error in ==> forloop2 at 10
x(n,c)=fmincon(fun{n,c},[0;0],[1 0;-1 0;0 1;0
-1],[40;0;40;0],[],[],[],[],[],options);
Any helps? Thank you so much!
【问题讨论】:
标签: matlab function optimization cell handle