Fortran 如何获得一个角度,而不是随机数的正常值
我试着创建一个随机数,我想得到下面代码中的角度Fortran 如何获得一个角度,而不是随机数的正常值,fortran,gfortran,Fortran,Gfortran,我试着创建一个随机数,我想得到下面代码中的角度 but I always got a number not an angle between 0 and 180 Fortran !Now start determining the angle !First angle theta1 is Va*rab =|Va|*|rab|*cos(theta1) !First I can determine Va*rab and call it V1 then |Va|*|rab|and c
but I always got a number not an angle between 0 and 180
Fortran
!Now start determining the angle
!First angle theta1 is Va*rab =|Va|*|rab|*cos(theta1)
!First I can determine Va*rab and call it V1 then |Va|*|rab|and call it V2 then calculate the angle
!V1=(a2*a4)+(b2*b4)+(c2*c4)
V1=(a2*a4)+(b2*b4)+(c2*c4)
write(10,*) 'v1',V1
V2=(Va*rab)
write(10,*) 'V2',V2
theta1 = acos(V1/V2)
print*, 'The angle The acos function (and its "friends") all work with radians.
From the satndard:
16.9.4 ACOS (X)
- Description. Arccosine (inverse cosine) function.
- Class. Elemental function.
- Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1, or of type complex.
- Result Characteristics. Same as X.
- Result Value. The result has a value equal to a processor-dependent approximation to arccos(X). If it is real
it is expressed in radians and lies in the range 0 ≤ ACOS (X) ≤ π. If it is complex the real part is expressed in
radians and lies in the range 0 ≤ REAL (ACOS (X)) ≤ π.
Replace the radians based ACOS
theta1 = acos(V1/V2)
!现在开始确定角度
!第一个角度θ1是Va*rab=|Va |*| rab |*cos(θ1)
!首先我可以确定Va*rab,称之为V1,然后称之为| Va |*| rab,称之为V2,然后计算角度
!V1=(a2*a4)+(b2*b4)+(c2*c4)
V1=(a2*a4)+(b2*b4)+(c2*c4)
写(10,*)'v1',v1
V2=(Va*rab)
写(10,*)‘V2’,V2
θ1=acos(V1/V2)
打印*,“角度acos函数(及其“朋友”)都使用弧度
从标准:
16.9.4 ACOS(X)
描述。反余弦函数
班级。基本功能
争论。X应为实型,其值满足不等式| X |≤ 1,或复杂类型
结果特征。和X一样
结果值。结果的值等于与处理器相关的arccos(X)近似值。如果是真的
它以弧度表示,范围为0≤ 助理文书主任(X)≤ π. 如果是复杂的,则实际部分用
弧度和位于0范围内≤ REAL(ACOS(X))≤ π
更换基于弧度的ACO
theta1 = acosd(V1/V2)
以学位为基础的ACOSD
抱歉,我不太明白你的意思,你的代码中的theta1
是弧度,但你的评论是你希望它在0到180之间,这表明你是在用度思考,而不是弧度。所以你需要转换。但是我得到的V1和V2的数字,如果我用普通计算器测量它们,它给了我一个直角,但程序中她给了我一个像1.57或1.65这样的数字,那么我如何转换它们呢?你的计算器设置为使用角度(DEG
sign)。您需要将计算器更改为RAD(使用弧度)。转换通过angle\u RAD=angle\u deg*PI/180
完成。我建议不要使用此解决方案-ACOSD不是标准Fortran的一部分。因此,您依赖于编译器来支持它作为扩展