Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calka( a, b, n, func )
- Variables = {
- f = func,
- h = ( b-a )/n,
- w = 0,
- x1 = a + 0/n * (b-a)
- }
- local _ = Variables
- for i = 1, n do
- local xi = ( a + i/n * (b-a) )
- local ti = ( ( a + (i-1)/n * (b-a) ) +_.x1 +1 ) / 2
- print( xi..": ".._.f(xi) )
- print( ti..": ".._.f(ti) )
- _.w = _.w + _.f( a + i/n * (b-a) );
- end
- _.w = _.w + ( _.f( a ) + _.f( b )) / 2;
- _.w = _.w * _.h;
- print( "calka: ".._.w );
- end
- calka( 1, 5, 4, function ( x )
- return x^2 + 2*x;
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement