fortran - I cannot work out the error in the script -


i new programming , cannot debug program. whenever run it gives same error:

return type mismatch of function f @ (1) 

my code is:

      real function f(x)         implicit none         real:: x         f=exp(-x)-x       end function        program easycod         implicit none         real::xl,xu,xr,fu,test,xrold,fl,fr         integer ::i         i=1,50           xr=xrold           xr=(xl+xu)/2.0           fr =f(xr)           fl =f(xl)           test=fl*fr            if (test>0.0)             xl=xr              fr=fl           else if (test<0.0)             xu=xr            end if           if (test==0.0) exit            print*,xr         end       end program 

there few things wrong code.

first, getting compiler error because haven't declared function f in program:

program easycode     implicit none     real :: xl, xu, xr, fu, test, xrold, fl, fr     real :: f                    ! <----------------- add line     integer :: 

then assigning xr twice, makes first 1 unnecessary. finally, xold, xl , xr not initialized , can therefore given value compiler like.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -