% matlab script to demonstrate use of Gauss quadrature

clear all
close all % first derive the 2-point Gauss quadrature rule eq1 = 'w1*1 + w2*1 = 2'; eq2 = 'x1*w1 + x2*w2 = 0'; eq3 = 'x1^2*w1 + x2^2*w2 = 2/3'; eq4 = 'x1^3*w1 + x2^3*w2 = 0'; [w1,w2,x1,x2] = solve(eq1,eq2,eq3,eq4)
pause % note: there are two solutions
% we pick the one where x1 < x2 [x1,index] = min(double(x1))
w1 = double(w1(index)) x2 = double(x2(index))
w2 = double(w2(index)) % define the integrand f = @(t) exp(-((t+1)./2).^2) % use Gauss-Legendre quadrature to approximate it gq = (w1*feval(f,x1) + w2*feval(f,x2));
% don't forget the scaling!
gq = gq/2 % now let's find the exact answer and see what the error is ... syms x
I = double(int(exp(-x^2),0,1)) errorGQ = I - gq % compare to Simpson's rule a = -1; b = 1; c = (a+b)/2;
s = (b-a)/6*(feval(f,a)+4*feval(f,c)+feval(f,b));
% don't forget the scaling!
s = s/2 errorS = I - s

Matlab Gauss quadrature的更多相关文章

  1. Matlab adaptive quadrature

    % script to perform adaptive quadrature clear all, close all global pts % function to be integrated ...

  2. Fortran与C/C++混合编程示例

    以下例子均来自网络,只是稍作了编辑,方便今后查阅. 子目录 (一) Fortran调用C语言 (二) C语言调用Fortran (三) C++ 调用Fortran (四) Fortran 调用 C++ ...

  3. 体积与边精确积分DGM方法

    Triangular DGM 1. Basis functions decomposing the domain \(\Omega\) into \(N_e\) conforming non-over ...

  4. MATLAB数值积分法

    MATLAB数值积分法 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ 一.实验目的 许多工程技术和数学研究中要用到定积分,如果无法直接算不出精确值(如含 ...

  5. OpenCASCADE Gauss Integration

    OpenCASCADE Gauss Integration eryar@163.com Abstract. Numerical integration is the approximate compu ...

  6. Matlab里面的SVM

    支持向量机是建立在统计学习理论基础之上的新一代机器学习算法,支持向量机的优势主要体现在解决线性不可分问题,它通过引入核函数,巧妙地解决了在高维空间中的内积运算,从而很好地解决了非线性分类问题. 构造出 ...

  7. 《数字图像处理原理与实践(MATLAB版)》一书之代码Part6

    本文系<数字图像处理原理与实践(MATLAB版)>一书之代码系列的Part6,辑录该书第281至第374页之代码,供有须要读者下载研究使用.代码运行结果请參见原书配图,建议下载代码前阅读下 ...

  8. 基于MATLAB的中值滤波均值滤波以及高斯滤波的实现

    基于MATLAB的中值滤波均值滤波以及高斯滤波的实现 作者:lee神 1.   背景知识 中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值. 中值滤 ...

  9. matlab 曲线拟合小记

    在matlab中经常需要对数据进行曲线拟合,如最常见的多项式拟合,一般可以通过cftool调用曲线拟合工具(curve fit tool),通过图形界面可以很方便的进行曲线拟合,但是有些时候也会遇到不 ...

随机推荐

  1. 前端之js中的函数

    函数 函数就是重复执行的代码片.   函数定义与执行 <script type="text/javascript">     // 函数定义     function ...

  2. PHP 文件处理----fopen(),fclose(),feof(),fgets(),fgetc()

    fopen() 函数用于在 PHP 中打开文件. 打开文件 fopen() 函数用于在 PHP 中打开文件. 此函数的第一个参数含有要打开的文件的名称,第二个参数规定了使用哪种模式来打开文件: < ...

  3. nova scheduler filters 配置

    scheduler_driver = nova.scheduler.filter_scheduler.FilterScheduler scheduler_default_filters = Avail ...

  4. JQuery Mobile - 固定住页面和页脚

    在点击页面空白时候,页眉和页脚会隐藏,在页眉和页脚加入以下代码就可以了: data-tap-toggle ="false" 例子: <div data-role=" ...

  5. turtle库实现汉诺塔

    import turtleturtle.screensize(800,800) class Stack: def __init__(self): self.items = [] def isEmpty ...

  6. LabVIEW(十四):VI属性

    1.VI的属性在项目研究中是很常用的,但是会经常忽略VI的属性设置,建议在编程事常常运用这些属性的设置,这样就可以使你的程序更加完善,易懂性也会提高. 属性快捷键:Ctrl+I. 2.常规 (1).编 ...

  7. ElasticSearch5.0之后的改变

    ES5的变化 search_type=count和scan都移除了 count可以用size=0代替 GET /my_index/_search { "size": 0, &quo ...

  8. ubuntu root默认密码(初始密码)

    ubuntu安装好后,root初始密码(默认密码)不知道,需要设置. 1.先用安装时候的用户登录进入系统 2.输入:sudo passwd  按回车 3.输入新密码,重复输入密码,最后提示passwd ...

  9. python常用模块os和sys

    一.os模块 说明:os模块是对操作系统进行调用的接口 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 os. ...

  10. Linux - 常用网络操作

    001 - Linux CentOS网络配置 CentOS---网络配置详解 002 - Linux查看端口状态 检测本机8080端口状态:netstat –apn | grep 8080 检测192 ...