simpsons_rule Function

public function simpsons_rule(f, dx) result(I)

Performs 1D integration using Simpsons rule

###References * Simpson's rule

Arguments

TypeIntentOptionalAttributesName
real(kind=Float64), intent(in), dimension(:):: f

Array of equally spaced values

real(kind=Float64), intent(in) :: dx

Spacing between x values

Return Value real(kind=Float64)


Called by

proc~~simpsons_rule~~CalledByGraph proc~simpsons_rule simpsons_rule proc~bt_maxwellian_eb bt_maxwellian_eb proc~bt_maxwellian_eb->proc~simpsons_rule proc~bt_maxwellian_q_n_m bt_maxwellian_q_n_m proc~bt_maxwellian_q_n_m->proc~simpsons_rule proc~bt_maxwellian_n bt_maxwellian_n proc~bt_maxwellian_n->proc~simpsons_rule proc~bt_maxwellian_q_n bt_maxwellian_q_n proc~bt_maxwellian_q_n->proc~simpsons_rule proc~bt_maxwellian_n_m bt_maxwellian_n_m proc~bt_maxwellian_n_m->proc~simpsons_rule interface~bt_maxwellian bt_maxwellian interface~bt_maxwellian->proc~bt_maxwellian_eb interface~bt_maxwellian->proc~bt_maxwellian_q_n_m interface~bt_maxwellian->proc~bt_maxwellian_n interface~bt_maxwellian->proc~bt_maxwellian_q_n interface~bt_maxwellian->proc~bt_maxwellian_n_m proc~write_bt_d_he3 write_bt_D_He3 proc~write_bt_d_he3->interface~bt_maxwellian proc~write_bt_h_aq write_bt_H_Aq proc~write_bt_h_aq->interface~bt_maxwellian proc~write_bt_d_t write_bt_D_T proc~write_bt_d_t->interface~bt_maxwellian proc~write_bt_h_h write_bt_H_H proc~write_bt_h_h->interface~bt_maxwellian proc~write_bt_d_d write_bt_D_D proc~write_bt_d_d->interface~bt_maxwellian proc~write_bt_h_e write_bt_H_e proc~write_bt_h_e->interface~bt_maxwellian program~generate_tables generate_tables program~generate_tables->proc~write_bt_d_he3 program~generate_tables->proc~write_bt_h_aq program~generate_tables->proc~write_bt_h_h program~generate_tables->proc~write_bt_d_d program~generate_tables->proc~write_bt_h_e

Contents

Source Code


Source Code

function simpsons_rule(f, dx) result(I)
    !+ Performs 1D integration using Simpsons rule
    !+
    !+ ###References
    !+* [Simpson's rule](http://mathworld.wolfram.com/SimpsonsRule.html)
    real(Float64), dimension(:), intent(in) :: f
        !+ Array of equally spaced \(f(x)\) values
    real(Float64), intent(in)               :: dx
        !+ Spacing between x values
    real(Float64)                           :: I

    integer :: s, ii

    s = size(f)
    I = 0.d0
    if(mod(s,2).eq.1) then
        write(*,'(a)') "Length of array must be even"
        return
    endif

    I = f(1)
    do ii=2,s-1
        if(mod(ii,2).eq.1) then
            I = I + 4.0*f(ii)
        else
            I = I + 2.0*f(ii)
        endif
    enddo
    I = I + f(s)
    I = (dx/3.0)*I

end function simpsons_rule