?? newton.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 + -