am1x icon

qtrap1m001.jl

am1x | PRO | 04/10/24 04:29:43 PM UTC (Edited) | 0 ⭐ | 14565 👁️ | Never ⏰ | []
Julia |

340 B

|

Fixit

|

0 👍

/

0 👎

@fastmath function quad_trap(f, a, b, n)
    h = (b - a) / n
    res = 0.5 * (f(a) + f(b))
    for i in 1:n-1
        res += f(a + i*h)
    end
    res * h
end
 
 
function g()
    a = 0.0
    for _ in 1:100000
        a = quad_trap(x -> exp(x) - 10.0, -1.0, 1.0, 10000)
    end
    a
end
 
println(g())
flush(stdout)
@timev g()

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎