rctrap.m

来自「提供一个直接搜索算法程序」· M 代码 · 共 33 行

M
33
字号
function T=rctrap(f,a,b,n)%Input  - f is the integrand input as a string 'f'%       - a and b are upper and lower limits of integration%       - n is the number of times for recursion%Output - T is the recursive trapezoidal rule list%  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 07458M=1;h=b-a;T=zeros(1,n+1);T(1)=h*(feval(f,a)+feval(f,b))/2;for j=1:n   M=2*M;   h=h/2;   s=0;   for k=1:M/2      x=a+h*(2*k-1);      s=s+feval(f,x);   end   T(j+1)=T(j)/2+h*s;end

⌨️ 快捷键说明

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