📄 approot.m
字号:
function R = approot (X,epsilon)% Input - f is object function saved as an M-file named f.m% - X is the vector of abscissas% - epsilon is the tolerance % Output - R is the vector of approximate locations for roots% NUMERICAL METHODS: Matlab Programs% (c) 2004 by John H. Mathews and Kurtis D. Fink% Complementary Software to accompany the textbook:% NUMERICAL METHODS: Using Matlab, Fourth Edition% ISBN: 0-13-065248-2% Prentice-Hall Pub. Inc.% One Lake Street% Upper Saddle River, NJ 07458Y=f(X);yrange = max(Y)-min(Y);epsilon2 = yrange*epsilon;n=length(X);m=0;X(n+1)=X(n);Y(n+1)=Y(n);for k=2:n, if Y(k-1)*Y(k) <= 0, m=m+1; R(m)=(X(k-1)+X(k))/2; end s=(Y(k)-Y(k-1))*(Y(k+1)-Y(k)); if (abs(Y(k)) < epsilon2) & (s <= 0), m=m+1; R(m)=X(k); endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -