1. % matlab script to derive the 2-point Gauss-Laguerre quadrature rule
  2. % and use it on an example
  3.  
  4. % inelegantly set up equations from method of undetermined coefficients
  5. % and solve
  6.  
  7. clear all
  8. close all
  9. format long
  10.  
  11. eq1 = 'w1*1 + w2*1 = 1';
  12.  
  13. eq2 = 'w1*x1 + w2*x2 = 1';
  14.  
  15. eq3 = 'w1*x1^2 + w2*x2^2 = 2';
  16.  
  17. eq4 = 'w1*x1^3 + w2*x2^3 = 6';
  18.  
  19. [w1,w2,x1,x2] = solve(eq1,eq2,eq3,eq4)
  20. pause
  21.  
  22. % note: there are two solutions
  23. % we pick the one where x1 < x2
  24.  
  25. [x1,index] = min(double(x1))
  26. w1 = double(w1(index))
  27.  
  28. x2 = double(x2(index))
  29. w2 = double(w2(index))
  30.  
  31. % define the integrand
  32.  
  33. f = @(x) exp(x).*log(1+exp(-x));
  34.  
  35. % use Gauss-Laguerre quadrature to approximate it
  36.  
  37. glq = w1*feval(f,x1) + w2*feval(f,x2)
  38.  
  39. % now let's find the exact answer and see what the error is ...
  40.  
  41. syms x
  42. I = double(int(log(1+exp(-x)),0,Inf))
  43.  
  44. error = I - glq
  45. pause
  46.  
  47. % or we can estimate the neglected tail
  48. % trying integral(f,0,Inf) or integral(f,0,realmax)
  49. % won't work!
  50.  
  51. f = @(x) log(1+exp(-x));
  52. Q10 = integral(f,0,10)
  53. Q20 = integral(f,0,20)
  54. Q30 = integral(f,0,30)
  55. % from here we see that we have convergence to 8 decimal places
  56.  
  57. % we can also perform a change of variable to make the interval finite
  58. F = @(t) log(1+t)./t;
  59. integral(F,0,1)
  60.  
  61. % check for problems at t=0
  62. ezplot(F,0,1)
  63. 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. 中国移动物联网ONENET平台数据本地采集工具

    吧从中国移动物联网平台上接收的数据 实时按天保存为CSV文件或者是SQL SERVER数据库中方便进行数据处理 还可设置显示最大值,最小值,报警值,报警推送,tts语音报警等贴心功能

  2. 关于wifi网络基本原理了解

    对于esp32,其wifi功能还是十分强大的,为了能够良好的完成wifi的相关开发,这里需要计算机网络的结构体系进行大致的了解. 一.网络结构分层 对于计算机网络结构,大体上可以分为5层结构: 物理层 ...

  3. 踩了的Dockerfile的坑

    1.Dockerfile VOLUME的目录,RUN命令操作该目录无效 VOLUME $APP_HOME RUN mkdir -p $APP_HOME && mkdir -p $APP ...

  4. APK防护——Anti_Virtual App的思路和实现

    作者:HAI_i 原文来自:https://bbs.ichunqiu.com/thread-42982-1-1.html 0×00 前言 Virtual App是一个很强大的存在,破坏了Android ...

  5. JSON 字符串解析技巧总结

    在解析JSONObject的字符数据的时候,可以考虑去使用optString 解析网络JSON数据时,获取数据的两个方法optString和getString: 使用optString获取数据时,即使 ...

  6. Android 开发常用版本控制命令

    1. git 回退到指定版本 // 使用git log命令查看所有的历史版本,获取某个历史版本的id,假设查到历史版本的id是139dcfaa558e3276b30b6b2e5cbbb9c00bbdc ...

  7. Java 中的 HttpServletRequest 和 HttpServletResponse 对象

    HttpServletRequest对象详解 javax.servlet.http.HttpServletRequest是SUN制定的Servlet规范,是一个接口.表示请求,“HTTP请求协议”的完 ...

  8. Spring webFlux:坐等spring-boot-starter-data-mysql-reactive

    spring-boot-starter-data-mongodb-reactive spring-boot-starter-data-redis-reactive 坐等 spring-boot-sta ...

  9. EasyUI 获取展开表中行数据

    var index = $('#dg').datagrid('getRowIndex', row); //为destory_user.php传递参数id var ids = $("#dg&q ...

  10. ubuntu下TFTP Server 的安装和使用方法

    tftp是一种于1981年在RFC 783中定义的简化的文件传输协议(FTP).小型文件传输协议非常简单,通过少量存储器就能轻松实现 ——这在当时是很重要的考虑因素.所以TFTP被用于引导计算机,例如 ...