⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newton.m

📁 无约束优化问题一维搜索的常用方法:黄金分割法(golden_section.m)、加步搜索法(plus_step_search.m)、牛顿法(newton.m)、抛物线法(parabola.m)
💻 M
字号:
function [mini,point,times]=newton(str,ini,err)
%  File name:newton.m      
%  Author:Yan Anxin
%  ID number:081810
%  Date:finished on 2008.11.24
%  Description:  
%       Here defines a function,to solve the one-dimensional searching problems by newton-method
%       In the syntax [mini,point,times]=newton(str,ini,err),
%       str----input,means the expression of objective function
%       ini----input,sets the starting point to ini 
%       err----input,sets admissible error
%       mini=newton(str,ini,err) attempts to find mini, i.e. the minimum of objective function   
%       [mini,point]=newton(str,ini,err) returns point, i.e. the independent variable value corresponding to minimum 
%       [mini,point,times]=golden_section(str,ini,acc) returns times, i.e. the times of iterative      

f=sym(str);
syms x
k=1;times=0;y(k)=ini;           %setting initial value
while 1                         %applying Newton's iterative method
    df=diff(f);ddf=diff(df);
    if abs(subs(df,x,y(k)))<err,break,end
    y(k+1)=y(k)-subs(df,x,y(k))/subs(ddf,x,y(k));
    k=k+1;times=times+1;
end
point=y(k);
mini=subs(f,x,point);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -