How to make a code using Simpsons 1/3 and 3/8 rules that could use any data set?

조회 수: 4 (최근 30일)
Is it possible to make a code that can uses the Simpsons 1/3 and 3/8 rules together? Also, can this same code be used for most data sets? Like could we interchange the values in the code and it will still give accurate results. Down below is the code we have so far.
function x = JAZSimpsons()
ax = [0 1 2 3 4 5 6 7 8 9 10]; afx = [5 17 139 581 1553 3145 5207 7229 8221 6593 35];
bx = [0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10]; bfx = [5 7.09 17 52.53 139 305.47 581 990.91 1553 2273.84 3145 4139.28 5207 6272.22 7229 7937.66 8221 7860.59 6593 4106.03 35];
%DataSetA iq1a = 3 *(afx(1)+3*afx(2)+3*afx(3)+afx(4))/8; iq2a = 3 *(afx(4)+3*afx(5)+3*afx(6)+afx(7))/8; ip1a = 2 *(afx(7)+4*afx(8)+afx(9))/6; ip2a = 2 *(afx(9)+4*afx(10)+afx(11))/6;
Ia = iq1a + iq2a + ip1a + ip2a
%DataSetB iq1b = 1.5 * (bfx(1)+ 3*bfx(2)+3*bfx(3) + bfx(4))/8 iq2b = 1.5 * (bfx(4)+ 3*bfx(5)+3*bfx(6) + bfx(7))/8 iq3b = 1.5 * (bfx(7)+ 3*bfx(8)+3*bfx(9) + bfx(10))/8 iq4b = 1.5 * (bfx(10)+ 3*bfx(11)+3*bfx(12) + bfx(13))/8 iq5b = 1.5 * (bfx(13)+ 3*bfx(14)+3*bfx(15) + bfx(16))/8 iq6b = 1.5 * (bfx(16)+ 3*bfx(17)+3*bfx(18) + bfx(19))/8 ip1b = 1 * (bfx(19)+ 4*bfx(20)+bfx(21))/6
Ib = iq1b + iq2b + iq3b + iq4b + iq5b + iq6b + ip1b
  댓글 수: 1
John D'Errico
John D'Errico 2016년 3월 22일
Don't define all of your variables INSIDE the function! Learn to use input arguments to a function instead.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by