Skip to content

Instantly share code, notes, and snippets.

@kenluck2001
Last active August 29, 2015 14:25
Show Gist options
  • Save kenluck2001/e5b588c8db87016e14c5 to your computer and use it in GitHub Desktop.
Save kenluck2001/e5b588c8db87016e14c5 to your computer and use it in GitHub Desktop.
a = 0; b = 4; c = -2; d = 2
n = 20;
h = (b - a)/n; k = (d - c)/n;
x= a:h:b; y=c:k:d;
totallist = zeros( 1, length(y) )
for yi = 1:length(y)
total = 0
for xi = 2:length(x)-1
temp = x(xi)^2 - 3*y(yi)^2 + x(xi)*y(yi)^3;
total = total + 2*temp;
end
firstLast = [1,length(x)];
for i=1:length(firstLast)
xelm = firstLast(i);
temp = x(xelm)^2 - 3*y(yi)^2 + x(xelm)*y(yi)^3;
total = total + temp;
end
total = total*h/2;
totallist(yi) = total ;
end
stotal = 0
for yi = 2:length(totallist)-1
temp = totallist(yi);
stotal = stotal + 2*temp;
end
totalLength = length(totallist);
stotal = stotal + totallist(1) + totallist(totalLength);
stotal = stotal*h/2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment