Last active
March 14, 2019 13:13
-
-
Save kirkbyo/306b4145e10055d329a91e26b26ad860 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function I = simp(f, a, b, n) | |
I = 0; | |
dx = (b-a) / n; | |
for i = 1:2:n | |
xi = a + (i - 1) * dx; | |
xi_1 = a + (i * dx); | |
xi_2 = a + (i + 1) * dx; | |
I = I + (1/3) * (f(xi) + 4 * f(xi_1) + f(xi_2)) * dx; | |
end | |
function I = trap(f, a, b, n) | |
I = 0; | |
dx = (b-a) / n; | |
for i = 1:n | |
xi = a + (i-1) * dx; | |
xi_1 = a + i * dx; | |
I = I + (1/2) * (f(xi) + f(xi_1)) * dx; | |
end | |
function I = simp_data(f, a, b) | |
I = 0; | |
n = length(f); | |
dx = (b-a) / n; | |
for i = 1:2:n | |
I = I + (1/3) * (f(i) + 4*f(i+1) + f(i+2)) * dx; | |
end | |
function I = lhr(f, a, b, n) | |
I = 0; | |
dx = (b-a) / n; | |
for i = 1:n | |
xi = a + (i-1) * dx; | |
I = I + f(xi) * dx; | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment