From: Leonardo Marques on
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
From: Michael Metcalf on

"Leonardo Marques" <surf3r0(a)gmail.com> wrote in message
news:9c4bdee7-084e-4644-8b90-74cbef524878(a)u3g2000hsc.googlegroups.com...
> 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)
>

I don't know Maple, but in Fortran 4/9 gives zero. Try 4.0/9.0.

Regards,

Mike Metcalf


From: fj on
On 7 avr, 22:09, "Michael Metcalf" <michaelmetc...(a)compuserve.com>
wrote:
> "Leonardo Marques" <surf...(a)gmail.com> wrote in message
>
> news:9c4bdee7-084e-4644-8b90-74cbef524878(a)u3g2000hsc.googlegroups.com...
>
> > 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)
>
> I don't know Maple, but in Fortran 4/9 gives zero. Try 4.0/9.0.
>
> Regards,
>
> Mike Metcalf

I don't agree : (pi)*4/9 is computed as ((pi)*4)/9) and this is OK.

But the "parameter(k=0.8" is strange, k being no declared REAL !
From: e p chandler on
On Apr 7, 4:09 pm, "Michael Metcalf" <michaelmetc...(a)compuserve.com>
wrote:
> "Leonardo Marques" <surf...(a)gmail.com> wrote in message
>
> news:9c4bdee7-084e-4644-8b90-74cbef524878(a)u3g2000hsc.googlegroups.com...
>
> > 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)
>
> I don't know Maple, but in Fortran 4/9 gives zero. Try 4.0/9.0.
>
> Regards,
>
> Mike Metcalf

The underlying mess has masked the implicit typing of K as INTEGER.
k=0.8 sets K to 0. :-(.

From: Gordon Sande on
On 2008-04-07 16:36:05 -0300, Leonardo Marques <surf3r0(a)gmail.com> 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.