Matlab Gauss quadrature
% 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的更多相关文章
- Matlab adaptive quadrature
% script to perform adaptive quadrature clear all, close all global pts % function to be integrated ...
- Fortran与C/C++混合编程示例
以下例子均来自网络,只是稍作了编辑,方便今后查阅. 子目录 (一) Fortran调用C语言 (二) C语言调用Fortran (三) C++ 调用Fortran (四) Fortran 调用 C++ ...
- 体积与边精确积分DGM方法
Triangular DGM 1. Basis functions decomposing the domain \(\Omega\) into \(N_e\) conforming non-over ...
- MATLAB数值积分法
MATLAB数值积分法 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ 一.实验目的 许多工程技术和数学研究中要用到定积分,如果无法直接算不出精确值(如含 ...
- OpenCASCADE Gauss Integration
OpenCASCADE Gauss Integration eryar@163.com Abstract. Numerical integration is the approximate compu ...
- Matlab里面的SVM
支持向量机是建立在统计学习理论基础之上的新一代机器学习算法,支持向量机的优势主要体现在解决线性不可分问题,它通过引入核函数,巧妙地解决了在高维空间中的内积运算,从而很好地解决了非线性分类问题. 构造出 ...
- 《数字图像处理原理与实践(MATLAB版)》一书之代码Part6
本文系<数字图像处理原理与实践(MATLAB版)>一书之代码系列的Part6,辑录该书第281至第374页之代码,供有须要读者下载研究使用.代码运行结果请參见原书配图,建议下载代码前阅读下 ...
- 基于MATLAB的中值滤波均值滤波以及高斯滤波的实现
基于MATLAB的中值滤波均值滤波以及高斯滤波的实现 作者:lee神 1. 背景知识 中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值. 中值滤 ...
- matlab 曲线拟合小记
在matlab中经常需要对数据进行曲线拟合,如最常见的多项式拟合,一般可以通过cftool调用曲线拟合工具(curve fit tool),通过图形界面可以很方便的进行曲线拟合,但是有些时候也会遇到不 ...
随机推荐
- 用jstack自动化捕抓异常java代码脚本
#!/bin/bashdate=` date +%y%m%d-%H%M`pid=`top -bn1 |grep java | awk '{print $1 "\t" $9}' |h ...
- 《mysql必知必会》学习_第19章_20180809_欢
第19章 插入数据 P132 insert into customers VALUES(NULL,'Pep E.Lapew','100 Main Street',,Los Angeles','CA', ...
- Python logging模块简介
logging模块提供logger,handler,filter,formatter. logger:提供日志接口,供应用代码使用.logger最长用的操作有两类:配置和发送日志消息.可以通过logg ...
- 描述linux下文件删除的原理
Linux文件删除原理: Linux是通过link的数量来控制文件删除的,只有当一个文件不存在任何link的时候,这个文件才会被删除. 一般来说,每个文件都有2个link计数器:i_count 和 i ...
- 第九节:详细讲解Java中的泛型,多线程,网络编程
前言 大家好,给大家带来详细讲解Java中的泛型,多线程,网络编程的概述,希望你们喜欢 泛型 泛型格式:ArrayList list= new ArrayList(); ArrayList list= ...
- Typescript 学习笔记四:回忆ES5 中的类
中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...
- PyTorch(二)Intermediate
Convolutional Neural Network import torch import torch.nn as nn import torchvision import torchvisio ...
- Go语言之Interface(一)
Go语言之Interface(一) 什么是interface 在面向对象语言中接口是:接口定义了一个对象的行为,但在Go中接口就是方法签名的集合,当一个类型提供了这个接口中的所有的方法,就可以说这个类 ...
- JAVA发送http get/post请求,调用http接口、方法
import java.io.BufferedReader; import java.io.IOException;import java.io.InputStream; import java.io ...
- 关于vue中钩子函数非常好的博客
http://www.cnblogs.com/caimuqing/p/6728568.html