secant.m
来自「优化设计中的一维搜索方法」· M 代码 · 共 24 行
M
24 行
function [fx,fy,iter] = secant(func,limt)
if length(limt)~=2
error('error input limt!');
end
%falpha1 = subs(func,limt(1));
fdalpha1 = subs(diff(func),limt(1));
fdalpha2 = subs(diff(func),limt(2));
newp = limt(1) - ((limt(1)-limt(2))*fdalpha1)/(fdalpha1-fdalpha2);
fdnewp = subs(diff(func),newp);
iter = 0;
while abs(fdnewp)>10^10*eps
if fdnewp<0
limt(1) = newp;
else
limt(2) = newp;
end
fdalpha1 = subs(diff(func),limt(1));
fdalpha2 = subs(diff(func),limt(2));
newp = limt(1) - ((limt(1)-limt(2))*fdalpha1)/(fdalpha1-fdalpha2);
fdnewp = subs(diff(func),newp);
iter = iter+1;
end
fx = newp;
fy = subs(func,newp);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?