% matlab script to derive the 2-point Gauss-Laguerre quadrature rule
% and use it on an example % inelegantly set up equations from method of undetermined coefficients
% and solve clear all
close all
format long eq1 = 'w1*1 + w2*1 = 1'; eq2 = 'w1*x1 + w2*x2 = 1'; eq3 = 'w1*x1^2 + w2*x2^2 = 2'; eq4 = 'w1*x1^3 + w2*x2^3 = 6'; [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 = @(x) exp(x).*log(1+exp(-x)); % use Gauss-Laguerre quadrature to approximate it glq = w1*feval(f,x1) + w2*feval(f,x2) % now let's find the exact answer and see what the error is ... syms x
I = double(int(log(1+exp(-x)),0,Inf)) error = I - glq
pause % or we can estimate the neglected tail
% trying integral(f,0,Inf) or integral(f,0,realmax)
% won't work! f = @(x) log(1+exp(-x));
Q10 = integral(f,0,10)
Q20 = integral(f,0,20)
Q30 = integral(f,0,30)
% from here we see that we have convergence to 8 decimal places % we can also perform a change of variable to make the interval finite
F = @(t) log(1+t)./t;
integral(F,0,1) % check for problems at t=0
ezplot(F,0,1)
integral(F,realmin,1)

Gauss-Laguerre quadrature rule的更多相关文章

  1. Matlab Gauss quadrature

    % matlab script to demonstrate use of Gauss quadrature clear all close all % first derive the 2-poin ...

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

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

  3. 双二次Lagrange 有限元计算特征值程序(基于iFEM)

    function lambda = c0P2(h) %% Mesh [node,elem] = squarequadmesh([,,,],h); elem = elem(:,[,,,]); showm ...

  4. QuantLib 金融计算——数学工具之数值积分

    目录 QuantLib 金融计算--数学工具之数值积分 概述 常见积分方法 高斯积分 如果未做特别说明,文中的程序都是 Python3 代码. QuantLib 金融计算--数学工具之数值积分 载入模 ...

  5. OpenCASCADE Gauss Integration

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

  6. Matlab adaptive quadrature

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

  7. Salesforce的sharing Rule 不支持Lookup型字段解决方案

    Salesforce 中 sharing rule 并不支持Look up 字段 和 formula 字段.但在实际项目中,有时会需要在sharing rule中直接取Look up型字段的值,解决方 ...

  8. yii2权限控制rbac之rule详细讲解

    作者:白狼 出处:http://www.manks.top/yii2_rbac_rule.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留 ...

  9. RBAC中 permission , role, rule 的理解

    Role Based Access Control (RBAC)——基于角色的权限控制 permission e.g. creating posts, updating posts role A ro ...

随机推荐

  1. [solution] JZOJ 5459. 密室

    [solution] JZOJ 5459. 密室 Description 小X 正困在一个密室里,他希望尽快逃出密室. 密室中有$N$ 个房间,初始时,小X 在1 号房间,而出口在N 号房间. 密室的 ...

  2. Django——用户认证和判断用户是否登录

    用户认证 必须通过认证之后才能login(request,user)这样才能保存会话到request中,注销后会话结束 注意 自定义的用户登陆时只不止需要验证用户名和密码的需要写认证,就例如在线教育平 ...

  3. Hive记录-Beeline常用操作命令

    Beeline和其他工具有一些不同,执行查询都是正常的SQL输入,但是如果是一些管理的命令, 比如进行连接,中断,退出,执行Beeline命令需要带上"!",不需要终止符.常用命令 ...

  4. RabbitMQ基本理论

    本节内容 一  RabbitMQ介绍 二  RabbitMQ安装配置 三  RabbitMQ的Python实现-pika 1. 生产者消费者 2. 工作队列 3. 持久化和公平分发 4. 发布与订阅 ...

  5. firewall 和 iptables 常用命令

    [参考文章]:Centos7 关闭防火墙 [参考文章]:Centos7 firewall防火墙常用配置 CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 ...

  6. python实现归并排序算法

    归并排序(英语:Merge sort,或mergesort),是创建在归并操作上的一种有效的排序算法,效率为O(nlogn). 1945年由约翰·冯·诺伊曼首次提出.该算法是采用分治法(Divide ...

  7. centos7的ssh服务连接

    ---恢复内容开始--- SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定:SSH 为建立在应用层基础上的安全协议.SSH 是 ...

  8. 彻底理解Java中的基本数据类型转换(自动、强制、提升)

    说基本数据类型转换之前,先了解下 Java 中的 8 种基本数据类型,以及它们的占内存的容量大小和表示的范围,如下图所示. 重新温故了下原始数据类型,现在来解释下它们之间的转换关系. 自动类型转换 自 ...

  9. Spark Core

    Spark Core    DAG概念        有向无环图        Spark会根据用户提交的计算逻辑中的RDD的转换(变换方法)和动作(action方法)来生成RDD之间的依赖关系,同时 ...

  10. 微信开发之获取openid及推送模板消息

    有很多的朋友再问我怎么获取code,openid之类的问题,在这里我就给大家分享一下. 在做微信支付是需要获取openid的,推送模板消息也是需要openid包括其他一些功能分享等也都是需要的,ope ...