Re: Doubt about formula transcription
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Mon, 07 Apr 2008 20:38:15 GMT
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.
.
- Follow-Ups:
- Re: Doubt about formula transcription
- From: James Giles
- Re: Doubt about formula transcription
- References:
- Doubt about formula transcription
- From: Leonardo Marques
- Doubt about formula transcription
- Prev by Date: Re: Doubt about formula transcription
- Next by Date: Re: Zero-size arrays
- Previous by thread: Re: Doubt about formula transcription
- Next by thread: Re: Doubt about formula transcription
- Index(es):
Relevant Pages
|