《精通MATLAB最优化计算》一书中Funval函数应用
发布网友
发布时间:2022-04-30 14:59
我来回答
共3个回答
热心网友
时间:2022-06-25 20:01
此书funval函数的作用即求函数值,可将funval直接改写为subs,不影响结果。subs的用法你会吧?~
热心网友
时间:2022-06-25 20:01
%%我用这个函数调试成功了
function fv = Funval(f,varvec,varval)
var = symvar(f);
varc = symvar(varvec);
s1 = length(var);
s2 = length(varc);
m =floor((s1-1)/3+1);
varv = zeros(1,m);
if s1 ~= s2
for i=0: ((s1-1)/3)
k = strfind(varc,var(3*i+1));
index = (k-1)/3;
varv(i+1) = varval(index+1);
end
fv = subs(f,var,varv);
else
fv = subs(f,varvec,transpose(varval));
end
end
热心网友
时间:2022-06-25 20:01
function fv = Funval(f,varvec,varval)
var = findsym(f);
varc = findsym(varvec);
s1 = length(var);
s2 = length(varc);
m =floor((s1-1)/3+1);
varv = zeros(1,m);
if s1 ~= s2
for i=0: ((s1-1)/3)
k = findstr(varc,var(3*i+1));
index = (k-1)/3;
varv(i+1) = varval(index+1);
end
fv = subs(f,var,varv);
else
fv = subs(f,varvec,varval);
end