📄 xintegration.m
字号:
function xIntegration
% 积分例子
% An Example of Integration of a function f(x) from a to b
% by using TRAPZ (trapezoidal numerical integration),
% QUAD (adaptive Simpson quadrature), and QUADL (adaptive Lobatto quadrature)
%
% Author: HUANG Huajiang
% Copyright 2002 UNILAB Research Center,
% East China University of Science and Technology, Shanghai, PRC
% $Revision: 1.0 $ $Date: 2002/05/9 $
clear all
clc
% the interval: [a, b], the step: d
a = 0; % 积分下限
b = 3*pi; % 积分上限
d = pi/1000; % 积分步长
t = a:d:b;
y = func(t);
format long
% 梯形数值积分(Trapezoidal numerical integration)
y_trapz = trapz(y) * d
% 自适应Simpson法(Adaptive Simpson quadrature, low order)
y_quad = quad(@func,a,b)
% 自适应Lobatto求积法(Adaptive Lobatto quadrature, high order)
y_quadl = quadl(@func,a,b)
disp('Results:')
disp(' Trapz Qquad Quadl')
disp([y_trapz,y_quad,y_quadl])
% ------------------------------------------------------------------
function y = func(t)
y = exp(-0.5*t) .* sin(t+pi/6);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -