下沙论坛

标题: VB中定义Arccos函数 [打印本页]

作者: 游侠无极限    时间: 2003-4-18 01:11
标题: VB中定义Arccos函数
我是这样的:
! |) c( R& F) C) vPrivate Function Arccos(x As Double, n As Long)9 e0 ]) |( e5 y4 c8 B
Dim i As Long, y As Double
- j: a2 C3 {: J6 N. ]& \1 lFor i = 1 To n
, R+ g5 i) o. ~3 ~) u# t& f, M    y = y + (-1 / Sqr(1 + (x / n * i) ^ 2)) * x / n2 C- ], I" ]. \/ U/ N" P1 D2 g
Next
# D9 }& D  g6 `( ]3 @9 NArccos = y2 u  R  c* u5 Z* a) m
End Function) _; X; e6 U# d  J( {' G& n

( k& k+ Z$ c: i$ Y  p用的是Arccos的微分来算近似值,怎么不对?
. y# R2 J6 ~# @, e# z& e% a
作者: 煎饼    时间: 2003-4-19 22:04
公式对就没有问题拉
作者: 游侠无极限    时间: 2003-4-24 22:58
Const pi As Double = 3.141592653595 |1 d: K* |- A) ^
Private Function Arccos(x As Double, n As Long) ' n 为函数精度,建议为100
5 o, i4 H/ j+ ~4 [: D    Select Case x0 P& e0 l5 `  n/ w
    Case 1+ k  v1 J2 H' g$ }" z7 k
        Arccos = 0
2 l! q( t5 S# {" P/ ?# K7 ^    Case -1
% ^/ g" G" F% r        Arccos = pi" T: ~: C. ~% t5 G* F
    Case -1 To 1- t8 O, F7 d, \4 q' h
        Dim dx As Double, y As Double, i As Long1 \8 C9 }. e2 @7 e, S* t
        dx = x / n5 V4 w) b$ k* Q1 y3 C
        For i = 1 To n
0 o, q; U/ b/ w            y = y + (-1 / Sqr(1 - (dx * i + dx / 2) ^ 2)) * dx
( c" ?& s+ j) _* H2 r: ?8 u        Next
' G8 N* M% P; |# K" k        Arccos = y + pi / 2
; Q7 q2 t. R: P. ^    Case Else
  T+ j& o; j2 \% I9 m) L        '异常# P: J; C: ^; h
    End Select5 S/ l$ N9 @5 C* L% k
End Function
) G4 H5 D0 P2 g& ~$ A& B
* M# e' Z+ y$ ?2 w) R8 s搞定了




欢迎光临 下沙论坛 (http://bbs.xiasha.cn/) Powered by Discuz! X3.3