08-Jan-2022 07:59:06 quadrature_least_squares_test() MATLAB/Octave version 9.8.0.1380330 (R2020a) Update 2 Test quadrature_least_squares(). quadrature_least_squares_test01 WEIGHTS_LS computes the weights for a least squares quadrature rule. W1 = classical Newton Cotes weights, N = 5 W2 = least squares weights, D = 4, N = 5 I X(i) W1(i) W2(i) 1 -1.0000 0.155556 0.155556 2 -0.5000 0.711111 0.711111 3 0.0000 0.266667 0.266667 4 0.5000 0.711111 0.711111 5 1.0000 0.155556 0.155556 W1 = classical Newton Cotes weights, N = 9 W2 = least squares weights, D = 4, N = 9 I X(i) W1(i) W2(i) 1 -1.0000 0.0697707 0.0960373 2 -0.7500 0.415379 0.270085 3 -0.5000 -0.0654674 0.280963 4 -0.2500 0.740459 0.242113 5 0.0000 -0.320282 0.221601 6 0.2500 0.740459 0.242113 7 0.5000 -0.0654674 0.280963 8 0.7500 0.415379 0.270085 9 1.0000 0.0697707 0.0960373 quadrature_least_squares_test02 WEIGHTS_LS computes the weights for a least squares quadrature rule. Pick 50 random values in [-1,+1]. Compare Monte Carlo (equal weight) integral estimate to least squares estimates of degree D = 0, 1, 2, 3, 4. For low values of D, the least squares estimate improves. As D increases, the estimate can deteriorate. Rule Estimate Error MC 2.14335 0.603447 LS 0 2.14335 0.603447 LS 1 2.20369 0.543111 LS 2 2.57327 0.173533 LS 3 2.65322 0.093583 LS 4 2.73587 0.0109313 LS 5 2.7486 0.00179937 LS 6 2.66994 0.0768633 LS 7 2.64077 0.106031 LS 8 2.86432 0.117521 LS 9 2.85733 0.110533 LS10 2.61393 0.132873 LS11 2.60931 0.137488 LS12 2.90643 0.159631 LS13 2.91846 0.171659 LS14 2.62181 0.124993 LS15 2.60022 0.146577 EXACT 2.7468 0 quadrature_least_squares_test(): Normal end of execution. 08-Jan-2022 07:59:06