fzero with vector input

Forums Questions on and problems with the toolbox fzero with vector input

This topic contains 2 replies, has 2 voices, and was last updated by Gianni Lombardo September 26, 2022 at 10:21 am.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2011

    Gianni Lombardo
    User

    Hi,
    I understand that the INTERFACE fzero allows to automatically use Broydn when the input is not a scalar.
    I’ve created a copy of the FOC function in the stochastic growth model returning a vector of residuals and receiving a vector of guesses

    function foc2(x_both)
    
            use toolbox
    
            implicit none
            real*8, intent(in), dimension(2) :: x_both
            real*8 :: foc2(2)
            real*8 :: kplus, cplus,vplus(NS),Ev,xin1,xin2
            integer :: is_p
    
    [....]
            ! get first order condition
            foc2(1) = xin1 - (beta*foc2(1))**(-gamma)
            foc2(2) = xin2 - (1-beta)*x_in**(1d0-1d0/gamma)/(1d0-1d0/gamma)+beta*Ev**(1/theta)
    
        end function
    

    I then call it as done for fzero in the original code

    
    call fzero(x_both, foc2, check) !
    

    Already at that stage I get the warning from vscode (then error in compilation with ifort) that

    The characteristics of the associated actual function result differ from the characteristics of the dummy function result

    Yet I don’t see any discrepancy in declarations (real*8, dimension(2) for both input and function return).

    Any suggestion/example on how to deal with this problem?

    Thanks
    Gianni

    #2012

    Fabian Kindermann
    Moderator

    Hi Gianni,

    I think the issue is that the toolbox functions can only work with assumed size arrays. That’s a particular issue with the interface construct that I haven’t been able to solve so far.

    In any case, try the following function specification:

    
    function foc2(x_both)
    
            use toolbox
    
            implicit none
            real*8, intent(in), dimension(:) :: x_both
            real*8 :: foc2(size(x_both, 1))        
    
    [....]
    
        end function
    

    and see whether this works.

    Keep me posted.

    Best,
    Fabiab´n

    #2013

    Gianni Lombardo
    User

    Dear Fabian,
    Thanks a million for your prompt reply. Now, seeing the solution I feel silly. I should have tried it.
    It works!!
    Thanks again so much for the suits of codes and the books!
    Cheers
    Gianni

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.