Re: Doubt about formula transcription



On 2008-04-07 16:36:05 -0300, Leonardo Marques <surf3r0@xxxxxxxxx> said:

hey guys,

im with a little problem when im transcripting a math formula from
maple to fortran, because when i put a solution on the equation, i got
a result diferent from zero.

The formula is: 2*arctan(sin(a)*cos(a)/(.8-cos(a)^2))-4/9*Pi ;
I've transcripted to fortran as: 2*atan((sin(a)*cos(a))/(0.8-
cos(a)**2))-((pi)*4/9)

There's correct?!
a piece of my code:

! usando o metodo da zoada kkkkk
program missel
!constantes e variaveis
real FUNCAO
! programa
write(*,*)'Valor de f:',FUNCAO(1.023762140);
end
! funcoes, para facilitar, tava foda ficar repetindo...
real function FUNCAO(a);
real pi,a; parameter(k=0.8,pi=3.141592653);
FUNCAO=dble(2*atan((sin(a)*cos(a))/(k-cos(a)**2))-((pi)*4/9))
return
end


real function FUNCAO(a);
real pi,a
real k
parameter(k=0.8,pi=3.141592653)
FUNCAO = 2.0 * atan( (sin(a)*cos(a)) / (k-cos(a)**2) )- pi*4.0/9.0
return
end

The DBLE serves no obvious purpose as it argument will be single and
the result is then assigned to a single.

The 2 would be converted by default but easier to make it real.

k is a default integer so needs an explicit decalaration. In general all
should be declared and IMPLICIT NONE used. The value is simple enough
that the use of a PARAMETER is just an extra source of error. As writen
it will be 0 because the value will be truncated.

The exponent **2 is fine. The form **2.0 may not work if applied to a
negative value and may be less accurate as this form general powering
with log and exp rather than just squaring. (Some compilers will notice
that it is a special case and use squaring.)

4/9 evaluates to 0 as noted elsewhere because it is all integer. All the
brackets are not really needed once the literals become real.

In Fortran 90 form this would be

real function FUNCAO ( a )
implicit none
real :: a
real, parameter :: pi=3.141592653
FUNCAO = 2.0 * atan( (sin(a)*cos(a)) / (0.8-cos(a)**2) )- pi*4.0/9.0
return
end

as the readable form of PARAMETER has evolved since F77. If you really meant
to use double precision then ALL the real literals will need a D0 to promote
then to double. It is not important for 4.0 and 9.0 but matters a lot for
PI.

.



Relevant Pages

  • please try this program (generic resolution)
    ... According to my understanding of Section 14.1.2.4.1 of the Fortran 95 ... standard and Section 12.4.4.1 of the Fortran 2003 standard, ... REAL FUNCTION MYCOS ... PRINT statement should call the intrinsic specific function COS, ...
    (comp.lang.fortran)
  • Re: please try this program (generic resolution)
    ... standard and Section 12.4.4.1 of the Fortran 2003 standard, ... REAL FUNCTION MYCOS ... ifort 10.1 20070913 ...
    (comp.lang.fortran)
  • Re: how can I parameterize a 1d function by extracting it from a 2d function?
    ... Richard's suggestion of using Fortran 90/95 instead of Fortran ... 77 compiler is the best advice. ... Second, while not advised, you can use Fortran 77 Single Precision as ... real function A ...
    (comp.lang.fortran)
  • Re: please try this program (generic resolution)
    ... standard and Section 12.4.4.1 of the Fortran 2003 standard, ... REAL FUNCTION MYCOS ... gfortran and g95 gave as the answer 1.0, CVF however gave the answer ...
    (comp.lang.fortran)
  • What did I do?
    ... real function fnc ... I was trying to call some Fortran from a C++ program (via a shared ... incorrect; changing the code to ... Compiler is GCC's gfortran, v 4.0.2. ...
    (comp.lang.fortran)