Skip to content

Instantly share code, notes, and snippets.

@mvanzulli
Last active March 15, 2022 02:56
Show Gist options
  • Save mvanzulli/9ab92decf4218a638db0ae13758b9f02 to your computer and use it in GitHub Desktop.
Save mvanzulli/9ab92decf4218a638db0ae13758b9f02 to your computer and use it in GitHub Desktop.
Integration gauss points
function [xIntPoints, wIntPoints] = GaussPointsAndWeights (numGaussPoints )
%Integration Gauss Points based on https://keisan.casio.com/exec/system/1329114617
if numGaussPoints == 1
xIntPoints = 0;
wIntPoints = 2;
elseif numGaussPoints == 2
xIntPoints = [ -sqrt(1/3) sqrt(1/3) ];
wIntPoints = [ 1 1 ];
elseif numGaussPoints == 3
xIntPoints = [ -sqrt(3/5) 0 sqrt(3/5) ];
wIntPoints = [ 5/9 8/9 5/9 ];
elseif numGaussPoints == 4
xIntPoints = [ -sqrt( 3 - 2 * sqrt(6 / 5) ) / sqrt(7), sqrt( 3 - 2 * sqrt(6 / 5) ) / sqrt(7) ...
-sqrt( 3 + 2 * sqrt(6 / 5) ) / sqrt(7), sqrt( 3 + 2 * sqrt(6 / 5) ) / sqrt(7) ];
wIntPoints = [ ( 18 + sqrt(30) ) / 36 ( 18 + sqrt(30) ) / 36 ...
( 18 - sqrt(30) ) / 36 ( 18 - sqrt(30) ) / 36 ];
elseif numGaussPoints == 5
xIntPoints = [ -0.9061798459386639927976, -0.5384693101056830910363, 0 , ...
0.5384693101056830910363, 0.9061798459386639927976 ] ;
wIntPoints = [ 0.2369268850561890875143, 0.4786286704993664680413, 0.5688888888888888888889, ...
0.4786286704993664680413, 0.2369268850561890875143 ] ;
elseif numGaussPoints == 6
xIntPoints = [ -0.9324695142031520278123, -0.661209386466264513661, -0.2386191860831969086305, ...
0.238619186083196908631 , 0.661209386466264513661, 0.9324695142031520278123 ] ;
wIntPoints = [ 0.1713244923791703450403, 0.3607615730481386075698, 0.4679139345726910473899, ...
0.46791393457269104739, 0.3607615730481386075698, 0.1713244923791703450403 ] ;
elseif numGaussPoints == 7
xIntPoints = [ -0.9491079123427585245262, -0.7415311855993944398639, -0.4058451513773971669066, ...
0 , 0.4058451513773971669066, 0.7415311855993944398639, ...
0.9491079123427585245262 ] ;
wIntPoints = [ 0.1294849661688696932706 , 0.2797053914892766679015, 0.38183005050511894495 , ...
0.417959183673469387755 , 0.38183005050511894495 , 0.279705391489276667901, ...
0.129484966168869693271 ] ;
elseif numGaussPoints == 8
xIntPoints = [ -0.9602898564975362316836, -0.7966664774136267395916, -0.5255324099163289858177, ...
-0.1834346424956498049395, 0.1834346424956498049395, 0.5255324099163289858177, ...
0.7966664774136267395916, 0.9602898564975362316836 ] ;
wIntPoints = [ 0.1012285362903762591525, 0.2223810344533744705444, 0.313706645877887287338, ...
0.3626837833783619829652, 0.3626837833783619829652, 0.313706645877887287338, ...
0.222381034453374470544, 0.1012285362903762591525 ] ;
elseif numGaussPoints == 9
xIntPoints = [ -0.9681602395076260898356, -0.8360311073266357942994, -0.6133714327005903973087, ...
-0.3242534234038089290385, 0 , 0.3242534234038089290385, ...
0.6133714327005903973087, 0.8360311073266357942994, 0.9681602395076260898356 ] ;
wIntPoints = [ 0.0812743883615744119719, 0.1806481606948574040585, 0.2606106964029354623187, ...
0.312347077040002840069, 0.330239355001259763165 , 0.312347077040002840069 , ...
0.260610696402935462319, 0.1806481606948574040585, 0.081274388361574411972 ] ;
elseif numGaussPoints == 10
xIntPoints = [ -0.973906528517171720078, -0.8650633666889845107321, -0.6794095682990244062343, ...
-0.4333953941292471907993, -0.1488743389816312108848, 0.1488743389816312108848, ...
0.4333953941292471907993, 0.6794095682990244062343, 0.8650633666889845107321, ...
0.973906528517171720078 ] ;
wIntPoints = [ 0.0666713443086881375936, 0.149451349150580593146, 0.219086362515982043996, ...
0.2692667193099963550912, 0.2955242247147528701739, 0.295524224714752870174, ...
0.269266719309996355091, 0.2190863625159820439955, 0.1494513491505805931458, ...
0.0666713443086881375936 ] ;
else
error('The number of gauss cuadrature points introduced are not implemented, only between 1 and 10')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment