Skip to content

Instantly share code, notes, and snippets.

@soldev-42
Last active November 3, 2015 18:03
Show Gist options
  • Select an option

  • Save soldev-42/cb7b4c91a44dbc869b2e to your computer and use it in GitHub Desktop.

Select an option

Save soldev-42/cb7b4c91a44dbc869b2e to your computer and use it in GitHub Desktop.
function [result] = gauss_quadrature(f,lower, upper, n, intervals)
res = 0;
bigInterval = upper - lower;
smallInterval = bigInterval/intervals;
down = lower;
up = down + smallInterval;
for i=1:intervals
calk = 0;
for j=1:n
calk = calk + ((up - down)/2) * (w(n, j) * f(((up - down)/2)*z(n, j) + ((up + down)/2)))
end;
res = res + calk;
down = down + smallInterval;
up = down + smallInterval;
end;
result = res;
endfunction
//Przykład wywołania:
function result = funkcja_testowa_1(y)
result=y^2-2*y+1;
endfunction;
gauss_quadrature(funkcja_testowa_1, -1, 1, 1, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment