{"id":2182,"date":"2016-03-01T06:00:23","date_gmt":"2016-03-01T04:00:23","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=2182"},"modified":"2016-05-01T20:03:19","modified_gmt":"2016-05-01T18:03:19","slug":"integracion-por-el-metodo-de-los-rectangulos","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/integracion-por-el-metodo-de-los-rectangulos\/","title":{"rendered":"Integraci\u00f3n por el m\u00e9todo de los rect\u00e1ngulos"},"content":{"rendered":"<p>La integral definida de una funci\u00f3n f entre los l\u00edmites a y b puede calcularse mediante la <a href=\"http:\/\/bit.ly\/1FDhZ1z\">regla del rect\u00e1ngulo<\/a> usando la f\u00f3rmula<\/p>\n<pre lang=\"text\">\n   h * (f(a+h\/2) + f(a+h+h\/2) + f(a+2h+h\/2) + ... + f(a+nh+h\/2))\n<\/pre>\n<p>con a+nh+h\/2 \u2264 b &lt; a+(n+1)h+h\/2 y usando valores peque\u00f1os para h.<\/p>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   integral :: (Fractional a, Ord a) => a -> a -> (a -> a) -> a -> a\n<\/pre>\n<p>tal que (integral a b f h) es el valor de dicha expresi\u00f3n. Por ejemplo, el c\u00e1lculo de la integral de f(x) = x^3 entre 0 y 1, con paso 0.01, es<\/p>\n<pre lang=\"text\">\n   integral 0 1 (^3) 0.01  ==  0.24998750000000042\n<\/pre>\n<p>Otros ejemplos son<\/p>\n<pre lang=\"text\">\n   integral 0 1 (^4) 0.01                        ==  0.19998333362500048\n   integral 0 1 (\\x -> 3*x^2 + 4*x^3) 0.01       ==  1.9999250000000026\n   log 2 - integral 1 2 (\\x -> 1\/x) 0.01         ==  3.124931644782336e-6\n   pi - 4 * integral 0 1 (\\x -> 1\/(x^2+1)) 0.01  ==  -8.333333331389525e-6\n<\/pre>\n<p><strong>Nota<\/strong>: Definir la funci\u00f3n tambi\u00e9n en Maxima. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   (%i3) integral (0,1,lambda ([x],x^3),0.01);\n   (%o3) 0.2499875\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa soluci\u00f3n\n-- ===========\n\nintegral :: (Fractional a, Ord a) => a -> a -> (a -> a) -> a -> a\nintegral a b f h = h * suma (a+h\/2) b (+h) f\n\n-- (suma a b s f) es l valor de\n--    f(a) + f(s(a)) + f(s(s(a)) + ... + f(s(...(s(a))...))\n-- hasta que s(s(...(s(a))...)) > b. Por ejemplo,\n--    suma 2 5 (1+) (^3)  ==  224\nsuma :: (Ord t, Num a) => t -> t -> (t -> t) -> (t -> a) -> a\nsuma a b s f = sum [f x | x <- sucesion a b s]\n\n-- (sucesion x y s) es la lista\n--    [a, s(a), s(s(a), ..., s(...(s(a))...)]\n-- hasta que s(s(...(s(a))...)) > b. Por ejemplo,\n--    sucesion 3 20 (+2)  ==  [3,5,7,9,11,13,15,17,19]\nsucesion :: Ord a => a -> a -> (a -> a) -> [a]\nsucesion a b s = takeWhile (<=b) (iterate s a)\n\n-- 2\u00aa soluci\u00f3n\n-- ===========\n\nintegral2 :: (Fractional a, Ord a) => a -> a -> (a -> a) -> a -> a\nintegral2 a b f h\n    | a+h\/2 > b = 0\n    | otherwise = h * f (a+h\/2) + integral2 (a+h) b f h\n\n-- 3\u00aa soluci\u00f3n\n-- ===========\n\nintegral3 :: (Fractional a, Ord a) => a -> a -> (a -> a) -> a -> a\nintegral3 a b f h = aux a where\n    aux x | x+h\/2 > b = 0\n          | otherwise = h * f (x+h\/2) + aux (x+h)\n<\/pre>\n<h4>Soluci\u00f3n en Maxima<\/h4>\n<pre lang=\"text\">\nintegral (a,b,f,h) := block ([c:a+h\/2, s:0],\n  while c <= b do\n    ( s : s + f(c),\n      c : c+h),\n  float(h*s))$  \n<\/pre>\n<p>Nota: En Maxima esta definida la funci\u00f3n integrate para calcular integrales definidas. Por ejemplo,<\/p>\n<pre lang=\"text\">\n     (%i7) integrate (x^3,x,0,1);\n           1\n     (%o7) -\n           4\n     (%i8) %, numer;\n     (%o8) 0.25\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>La integral definida de una funci\u00f3n f entre los l\u00edmites a y b puede calcularse mediante la regla del rect\u00e1ngulo usando la f\u00f3rmula h * (f(a+h\/2) + f(a+h+h\/2) + f(a+2h+h\/2) + &#8230; + f(a+nh+h\/2)) con a+nh+h\/2 \u2264 b &lt; a+(n+1)h+h\/2 y usando valores peque\u00f1os para h. Definir la funci\u00f3n integral :: (Fractional a, Ord a)&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[4],"tags":[8,50,11,6,40,34],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2182"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/comments?post=2182"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2182\/revisions"}],"predecessor-version":[{"id":2209,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2182\/revisions\/2209"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=2182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=2182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=2182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}