Cody

Problem 1031. Composite Trapezoidal Rule for Numeric Integration

Solution 2111257

Submitted on 30 Jan 2020 by Steven Beumer
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
p=[2 0 -4 0 -1 1]; a=-2; b=4; f = @(x) polyval(p,x); assert(isequal(trapezoidal_rule(f,a,b,1),5280))

I = 5280

2   Pass
p=[2 0 -4 0 -1 1]; a=-2; b=4; f = @(x) polyval(p,x); assert(isequal(trapezoidal_rule(f,a,b,2),2634))

I = -46.5000 I = 2634

3   Pass
p=[2 0 -4 0 -1 1]; a=-2; b=4; f = @(x) polyval(p,x); assert(isequal(trapezoidal_rule(f,a,b,4),1516.875))

I = -20.2969 I = -20.3438 I = 76.6406 I = 1.5169e+03

4   Pass
p=[2 0 -4 0 -1 1]; a=-2; b=4; f = @(x) polyval(p,x); P=polyint(p); I_correct=polyval(P,b)-polyval(P,a); I=trapezoidal_rule(f,a,b); assert(abs(I-I_correct)<1)

I = -1.5544 I = -2.7641 I = -3.6796 I = -4.3459 I = -4.8035 I = -5.0882 I = -5.2316 I = -5.2614 I = -5.2020 I = -5.0742 I = -4.8959 I = -4.6823 I = -4.4461 I = -4.1976 I = -3.9455 I = -3.6962 I = -3.4549 I = -3.2253 I = -3.0099 I = -2.8102 I = -2.6269 I = -2.4600 I = -2.3089 I = -2.1726 I = -2.0499 I = -1.9394 I = -1.8394 I = -1.7486 I = -1.6654 I = -1.5886 I = -1.5172 I = -1.4502 I = -1.3871 I = -1.3277 I = -1.2721 I = -1.2205 I = -1.1736 I = -1.1324 I = -1.0979 I = -1.0717 I = -1.0550 I = -1.0494 I = -1.0565 I = -1.0776 I = -1.1139 I = -1.1662 I = -1.2350 I = -1.3200 I = -1.4204 I = -1.5342 I = -1.6586 I = -1.7895 I = -1.9213 I = -2.0466 I = -2.1566 I = -2.2400 I = -2.2833 I = -2.2704 I = -2.1825 I = -1.9977 I = -1.6905 I = -1.2319 I = -0.5889 I = 0.2758 I = 1.4040 I = 2.8428 I = 4.6442 I = 6.8662 I = 9.5725 I = 12.8336 I = 16.7265 I = 21.3356 I = 26.7529 I = 33.0783 I = 40.4205 I = 48.8968 I = 58.6343 I = 69.7697 I = 82.4502 I = 96.8337 I = 113.0897 I = 131.3994 I = 151.9565 I = 174.9677 I = 200.6530 I = 229.2466 I = 260.9975 I = 296.1696 I = 335.0429 I = 377.9135 I = 425.0950 I = 476.9182 I = 533.7325 I = 595.9061 I = 663.8270 I = 737.9034 I = 818.5645 I = 906.2610 I = 1.0015e+03 I = 1.1047e+03

5   Pass
p=[2 0 -4 0 -1 1]; a=-2; b=4; f = @(x) polyval(p,x); I = trapezoidal_rule(f,a,b,1000); P=polyint(p); I_correct=polyval(P,b)-polyval(P,a); assert(abs(trapezoidal_rule(f,a,b,1000)-I_correct)<1e-1)

I = -0.1720 I = -0.3401 I = -0.5043 I = -0.6647 I = -0.8213 I = -0.9742 I = -1.1234 I = -1.2691 I = -1.4112 I = -1.5498 I = -1.6850 I = -1.8168 I = -1.9452 I = -2.0704 I = -2.1923 I = -2.3111 I = -2.4267 I = -2.5393 I = -2.6488 I = -2.7554 I = -2.8590 I = -2.9597 I = -3.0576 I = -3.1527 I = -3.2450 I = -3.3347 I = -3.4217 I = -3.5060 I = -3.5878 I = -3.6671 I = -3.7439 I = -3.8183 I = -3.8902 I = -3.9598 I = -4.0271 I = -4.0921 I = -4.1548 I = -4.2154 I = -4.2738 I = -4.3301 I = -4.3843 I = -4.4365 I = -4.4867 I = -4.5349 I = -4.5812 I = -4.6255 I = -4.6680 I = -4.7087 I = -4.7476 I = -4.7848 I = -4.8202 I = -4.8539 I = -4.8860 I = -4.9164 I = -4.9453 I = -4.9726 I = -4.9984 I = -5.0226 I = -5.0454 I = -5.0668 I = -5.0868 I = -5.1054 I = -5.1226 I = -5.1385 I = -5.1532 I = -5.1665 I = -5.1787 I = -5.1896 I = -5.1993 I = -5.2079 I = -5.2154 I = -5.2217 I = -5.2270 I = -5.2312 I = -5.2344 I = -5.2366 I = -5.2378 I = -5.2381 I = -5.2374 I = -5.2358 I = -5.2333 I = -5.2300 I = -5.2258 I = -5.2208 I = -5.2150 I = -5.2084 I = -5.2011 I = -5.1930 I = -5.1842 I = -5.1747 I = -5.1645 I = -5.1536 I = -5.1422 I = -5.1301 I = -5.1174 I = -5.1041 I = -5.0902 I = -5.0758 I = -5.0608 I = -5.0454 I = -5.0294 I = -5.0130 I = -4.9961 I = -4.9787 I = -4.9609 I = -4.9427 I = -4.9240 I = -4.9050 I = -4.8856 I = -4.8658 I = -4.8457 I = -4.8253 I = -4.8045 I = -4.7834 I = -4.7621 I = -4.7404 I = -4.7185 I = -4.6963 I = -4.6739 I = -4.6512 I = -4.6283 I = -4.6052 I = -4.5819 I = -4.5584 I = -4.5347 I = -4.5109 I = -4.4869 I = -4.4628 I = -4.4385 I = -4.4141 I = -4.3896 I = -4.3649 I = -4.3402 I = -4.3154 I = -4.2905 I = -4.2655 I = -4.2404 I = -4.2153 I = -4.1902 I = -4.1650 I = -4.1397 I = -4.1145 I = -4.0892 I = -4.0639 I = -4.0386 I = -4.0133 I = -3.9880 I = -3.9627 I = -3.9375 I = -3.9122 I = -3.8870 I = -3.8619 I = -3.8368 I = -3.8117 I = -3.7867 I = -3.7617 I = -3.7368 I = -3.7120 I = -3.6872 I = -3.6626 I = -3.6380 I = -3.6135 I = -3.5890 I = -3.5647 I = -3.5405 I = -3.5164 I = -3.4923 I = -3.4684 I = -3.4446 I = -3.4210 I = -3.3974 I = -3.3740 I = -3.3506 I = -3.3275 I = -3.3044 I = -3.2815 I = -3.2587 I = -3.2360 I = -3.2135 I = -3.1912 I = -3.1689 I = -3.1468 I = -3.1249 I = -3.1031 I = -3.0815 I = -3.0600 I = -3.0387 I = -3.0175 I = -2.9965 I = -2.9756 I = -2.9549 I = -2.9344 I = -2.9140 I = -2.8938 I = -2.8737 I = -2.8538 I = -2.8341 I = -2.8145 I = -2.7951 I = -2.7759 I = -2.7568 I = -2.7379 I = -2.7192 I = -2.7006 I = -2.6822 I = -2.6639 I = -2.6459 I = -2.6279 I = -2.6102 I = -2.5926 I = -2.5752 I = -2.5579 I = -2.5408 I = -2.5239 I = -2.5071 I = -2.4905 I = -2.4741 I = -2.4578 I = -2.4417 I = -2.4257 I = -2.4099 I = -2.3943 I = -2.3788 I = -2.3635 I = -2.3483 I = -2.3333 I = -2.3184 I = -2.3037 I = -2.2891 I = -2.2747 I = -2.2604 I = -2.2463 I = -2.2324 I = -2.2185 I = -2.2048 I = -2.1913 I = -2.1779 I = -2.1646 I = -2.1515 I = -2.1385 I = -2.1257 I = -2.1130 I = -2.1004 I = -2.0880 I = -2.0756 I = -2.0635 I = -2.0514 I = -2.0395 I = -2.0277 I = -2.0160 I = -2.0044 I = -1.9930 I = -1.9816 I = -1.9704 I = -1.9593 I = -1.9483 I = -1.9375 I = -1.9267 I = -1.9161 I = -1.9055 I = -1.8951 I = -1.8848 I = -1.8745 I = -1.8644 I = -1.8544 I = -1.8445 I = -1.8346 I = -1.8249 I = -1.8153 I = -1.8057 I = -1.7963 I = -1.7869 I = -1.7776 I = -1.7684 I = -1.7593 I = -1.7503 I = -1.7413 I = -1.7325 I = -1.7237 I = -1.7150 I = -1.7064 I = -1.6978 I = -1.6893 I = -1.6809 I = -1.6726 I = -1.6643 I = -1.6561 I = -1.6480 I = -1.6399 I = -1.6319 I = -1.6240 I = -1.6161 I = -1.6083 I = -1.6006 I = -1.5929 I = -1.5852 I = -1.5777 I = -1.5701 I = -1.5627 I = -1.5552 I = -1.5479 I = -1.5406 I = -1.5333 I = -1.5261 I = -1.5189 I = -1.5118 I = -1.5048 I = -1.4978 I = -1.4908 I = -1.4839 I = -1.4770 I = -1.4701 I = -1.4633 I = -1.4566 I = -1.4499 I = -1.4432 I = -1.4366 I = -1.4300 I = -1.4234 I = -1.4169 I = -1.4104 I = -1.4040 I = -1.3976 I = -1.3912 I = -1.3849 I = -1.3786 I = -1.3724 I = -1.3662 I = -1.3600 I = -1.3539 I = -1.3478 I = -1.3417 I = -1.3357 I = -1.3297 I = -1.3237 I = -1.3178 I = -1.3119 I = -1.3061 I = -1.3002 I = -1.2945 I = -1.2887 I = -1.2830 I = -1.2774 I = -1.2717 I = -1.2661 I = -1.2606 I = -1.2551 I = -1.2496 I = -1.2442 I = -1.2388 I = -1.2334 I = -1.2281 I = -1.2228 I = -1.2176 I = -1.2124 I = -1.2073 I = -1.2022 I = -1.1971 I = -1.1921 I = -1.1871 I = -1.1822 I = -1.1773 I = -1.1725 I = -1.1677 I = -1.1630 I = -1.1583 I = -1.1537 I = -1.1491 I = -1.1446 I = -1.1402 I = -1.1358 I = -1.1314 I = -1.1271 I = -1.1229 I = -1.1187 I = -1.1146 I = -1.1106 I = -1.1066 I = -1.1027 I = -1.0989 I = -1.0951 I = -1.0914 I = -1.0877 I = -1.0842 I = -1.0807 I = -1.0772 I = -1.0739 I = -1.0706 I = -1.0674 I = -1.0643 I = -1.0613 I = -1.0583 I = -1.0555 I = -1.0527 I = -1.0500 I = -1.0474 I = -1.0449 I = -1.0425 I = -1.0401 I = -1.0379 I = -1.0358 I = -1.0337 I = -1.0318 I = -1.0299 I = -1.0282 I = -1.0266 I = -1.0250 I = -1.0236 I = -1.0223 I = -1.0211 I = -1.0200 I = -1.0190 I = -1.0181 I = -1.0174 I = -1.0168 I = -1.0162 I = -1.0158 I = -1.0156 I = -1.0154 I = -1.0154 I = -1.0155 I = -1.0157 I = -1.0161 I = -1.0166 I = -1.0172 I = -1.0180 I = -1.0189 I = -1.0199 I = -1.0210 I = -1.0224 I = -1.0238 I = -1.0254 I = -1.0271 I = -1.0290 I = -1.0310 I = -1.0332 I = -1.0355 I = -1.0380 I = -1.0406 I = -1.0433 I = -1.0463 I = -1.0493 I = -1.0526 I = -1.0559 I = -1.0595 I = -1.0632 I = -1.0670 I = -1.0711 I = -1.0752 I = -1.0796 I = -1.0841 I = -1.0887 I = -1.0935 I = -1.0985 I = -1.1037 I = -1.1090 I = -1.1145 I = -1.1201 I = -1.1259 I = -1.1319 I = -1.1380 I = -1.1443 I = -1.1508 I = -1.1574 I = -1.1642 I = -1.1712 I = -1.1783 I = -1.1856 I = -1.1930 I = -1.2007 I = -1.2085 I = -1.2164 I = -1.2245 I = -1.2328 I = -1.2412 I = -1.2498 I = -1.2586 I = -1.2675 I = -1.2765 I = -1.2858 I = -1.2952 I = -1.3047 I = -1.3144 I = -1.3242 I = -1.3342 I = -1.3443 I = -1.3546 I = -1.3650 I = -1.3756 I = -1.3863 I = -1.3971 I = -1.4081 I = -1.4192 I = -1.4304 I = -1.4418 I = -1.4532 I = -1.4648 I = -1.4766 I = -1.4884 I = -1.5003 I = -1.5124 I = -1.5246 I = -1.5368 I = -1.5492 I = -1.5616 I = -1.5742 I = -1.5868 I = -1.5995 I = -1.6123 I = -1.6251 I = -1.6380 I = -1.6510 I = -1.6640 I = -1.6771 I = -1.6903 I = -1.7034 I = -1.7167 I = -1.7299 I = -1.7432 I = -1.7564 I = -1.7697 I = -1.7830 I = -1.7963 I = -1.8096 I = -1.8229 I = -1.8362 I = -1.8494 I = -1.8626 I = -1.8757 I = -1.8888 I = -1.9018 I = -1.9148 I = -1.9277 I = -1.9405 I = -1.9532 I = -1.9658 I = -1.9782 I = -1.9906 I = -2.0028 I = -2.0149 I = -2.0269 I = -2.0387 I = -2.0503 I = -2.0617 I = -2.0729 I = -2.0840 I = -2.0948 I = -2.1054 I = -2.1157 I = -2.1258 I = -2.1356 I = -2.1452 I = -2.1545 I = -2.1635 I = -2.1721 I = -2...

Suggested Problems

More from this Author17

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!