proportional_division_method

an anonymous user · January 23, 2021 · Fortran
program main 
    external func
    real:: a, b, e, func
    read*, a, b, e
    print'(2x, a, 8x, a, 10x, a, 10x, a)', "m", "x", "y"
    call proportional_division_method(a, b, e, func, x)
    print'(a, f6.3)', "Корень уравнения", x
end program main
subroutine proportional_division_method(a, b, e, func, x)
    real:: a, b, func, e, x_buf, x
    if (a > b) then 
        print*, "Change the period of isolation of the root: &
        &the left border of the interval is larger than the right one"
        return
    end if
    k = 1
    x = (a*func(b) - b*func(a))/(func(b) - func(a))
    !print*, x, func(x)
100 x_buf = x
    if (func(a)*func(x) < 0) then 
        b = x
    else 
        a = x
    end if
    x = (a*func(b) - b*func(a))/(func(b) - func(a))
    print'(1x, i2, 2x, f10.6, 2x, f10.7)', k, x_buf, func(x_buf)
    k = k + 1 
    if (abs(x - x_buf) >= e) goto 100
end subroutine proportional_division_method
function func(x)
    func = x**2 + (1/x) - 3
end function func 

Comments

Please sign up or log in to contribute to the discussion.