nestexample.m
来自「matlab7.0这本书的源代码」· M 代码 · 共 29 行
M
29 行
function fhandle=nestexample(num,den)
%NESTEXAMPLE Example Nested Function.
% NESTEXAMPLE(Num,Den) returns a function handle to a function that can
% be used to evaluate a rational polynomial. Num and Den are vectors
% containing the numerator and denominator polynomial coefficients.
%
% For example, ratpoly=nestexample([1 2],[1 2 3]) returns a function
% handle that facilitates evaluation of the rational polynomial
%
% x + 2
% ------------
% x^2 + 2x + 3
if ~isnumeric(num) || ~isnumeric(den)
error('Num and Den Must be Numeric Vectors.')
end
num=reshape(num,1,[]); % make num into a row vector
den=reshape(den,1,[]); % make den into a row vector
fhandle=@nested_ratpoly;
function out=nested_ratpoly(x)
% Nested function that evaluates a rational polynomial, where the
% numerator and denominator coefficients are shared with the primary
% function workspace
out=polyval(num,x)./polyval(den,x);
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?