From: robin 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)
>
> There's correct?!
> a piece of my code:

You need the statement IMPLICIT NONE after the FUNCTION statement
(and in all other procedures).

That will reveal errors of the kind that you made in the code.


From: e p chandler on
On Apr 7, 3:36 pm, Leonardo Marques <surf...(a)gmail.com> wrote:
> hey guys,
>
> im with a little problem when im transcripting a mathformulafrom
> maple to fortran, because when i put a solution on the equation, i got
> a result diferent from zero.
>
> Theformulais: 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)

[code snipped]

Your equation has closed form solutions.

let gamma=(2pi)/9

1. invert the equation
2. apply formulas for sin(2x) and cos(2x)

sin(2a) sin(gamma)
---------- = tan(gamma) = ----------
.6-cos(2a) cos(gamma)

3. cross multiply and simplify

sin(2a) cos(gamma) + cos(2a) sin(gamma) = .6 sin(gamma)

4. apply formula for sin(A+B)

sin(2a+gamma) = .6 sin(gamma)

5. let beta = arcsine(.6 sin(gamma))

note that sin(x) = sin(pi-x)

2x + gamma = beta

pi - (2y + gamma) = beta

solve for principal solutions x and y

= (beta-gamma)/2 and (pi-beta-gamma)/2

[other solutions can of course be obtained by adding or subtracting
multiples of 2pi above.]

- e

From: glen herrmannsfeldt on
On Apr 7, 3:36 pm, Leonardo Marques <surf...(a)gmail.com> wrote:

> I've transcripted to fortran as: 2*atan((sin(a)*cos(a))/(0.8-
> cos(a)**2))-((pi)*4/9)

I would use atan2(sin(a)*cos(a),0.8-cos(a)**2)-pi*4/9

You might also want it in double precision. Likely it won't
come out exactly zero, but should be close if a is close
to a solution.

-- glen

From: Terence on
On May 5, 12:55 pm, glen herrmannsfeldt <g...(a)ugcs.caltech.edu> wrote:
> On Apr 7, 3:36 pm, Leonardo Marques <surf...(a)gmail.com> wrote:
>
>  > I've transcripted to fortran as: 2*atan((sin(a)*cos(a))/(0.8-
>  > cos(a)**2))-((pi)*4/9)
>
> I would use atan2(sin(a)*cos(a),0.8-cos(a)**2)-pi*4/9
>
> You might also want it in double precision.  Likely it won't
> come out exactly zero, but should be close if a is close
> to a solution.
>
> -- glen

Small typo there Glen (and biy, do I make them with this small type
face). Should be
atan2(sin(a)*cos(a)/0.8-cos(a)**2)-pi*4/9

And I would still prefer seeing that 4/9 as 4.0/9.0 !